mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Some enhancements to time management:
- remove unnecessary generation of Calendar and Date objects - synchronized SimpleDateFormat objects in blog-, message- and wikiBoard - correct use of TimeZones and SimpleDateFormats git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4288 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
52dd015218
commit
4748d5c1ab
|
@ -51,7 +51,6 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -77,9 +76,12 @@ public class blogBoardComments {
|
||||||
private static final String dateFormat = "yyyyMMddHHmmss";
|
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||||
private static final int recordSize = 512;
|
private static final int recordSize = 512;
|
||||||
|
|
||||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
|
||||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||||
|
|
||||||
|
static {
|
||||||
|
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
}
|
||||||
|
|
||||||
private kelondroMapObjects datbase = null;
|
private kelondroMapObjects datbase = null;
|
||||||
|
|
||||||
public blogBoardComments(File actpath, long preloadTime) {
|
public blogBoardComments(File actpath, long preloadTime) {
|
||||||
|
@ -98,8 +100,10 @@ public class blogBoardComments {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String dateString(Date date) {
|
private static String dateString(Date date) {
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.format(date);
|
return SimpleFormatter.format(date);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String normalize(String key) {
|
private static String normalize(String key) {
|
||||||
if (key == null) return "null";
|
if (key == null) return "null";
|
||||||
|
@ -132,7 +136,7 @@ public class blogBoardComments {
|
||||||
record = new HashMap();
|
record = new HashMap();
|
||||||
key = nkey;
|
key = nkey;
|
||||||
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
||||||
if(date == null) date = new GregorianCalendar(GMTTimeZone).getTime();
|
if(date == null) date = new Date();
|
||||||
record.put("date", dateString(date));
|
record.put("date", dateString(date));
|
||||||
if (subject == null) record.put("subject","");
|
if (subject == null) record.put("subject","");
|
||||||
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
|
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
|
||||||
|
@ -172,7 +176,9 @@ public class blogBoardComments {
|
||||||
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
|
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.parse(c);
|
return SimpleFormatter.parse(c);
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
@ -240,7 +246,7 @@ public class blogBoardComments {
|
||||||
key = normalize(key);
|
key = normalize(key);
|
||||||
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
||||||
Map record = base.getMap(key);
|
Map record = base.getMap(key);
|
||||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
|
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes());
|
||||||
return new CommentEntry(key, record);
|
return new CommentEntry(key, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +259,7 @@ public class blogBoardComments {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
|
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes());
|
||||||
return new CommentEntry(key, record.record);
|
return new CommentEntry(key, record.record);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -62,9 +61,12 @@ public class messageBoard {
|
||||||
private static final String dateFormat = "yyyyMMddHHmmss";
|
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||||
private static final int recordSize = 512;
|
private static final int recordSize = 512;
|
||||||
|
|
||||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
|
||||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||||
|
|
||||||
|
static {
|
||||||
|
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
}
|
||||||
|
|
||||||
private kelondroMapObjects database = null;
|
private kelondroMapObjects database = null;
|
||||||
private int sn = 0;
|
private int sn = 0;
|
||||||
|
|
||||||
|
@ -85,7 +87,9 @@ public class messageBoard {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String dateString() {
|
private static String dateString() {
|
||||||
return SimpleFormatter.format(new GregorianCalendar(GMTTimeZone).getTime());
|
synchronized (SimpleFormatter) {
|
||||||
|
return SimpleFormatter.format(new Date());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String snString() {
|
private String snString() {
|
||||||
|
@ -143,7 +147,9 @@ public class messageBoard {
|
||||||
try {
|
try {
|
||||||
String c = key.substring(categoryLength);
|
String c = key.substring(categoryLength);
|
||||||
c = c.substring(0, c.length() - 2);
|
c = c.substring(0, c.length() - 2);
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.parse(c);
|
return SimpleFormatter.parse(c);
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -62,9 +61,12 @@ public class wikiBoard {
|
||||||
private static final String dateFormat = "yyyyMMddHHmmss";
|
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||||
private static final int recordSize = 512;
|
private static final int recordSize = 512;
|
||||||
|
|
||||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
|
||||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||||
|
|
||||||
|
static {
|
||||||
|
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
}
|
||||||
|
|
||||||
private kelondroMapObjects datbase = null;
|
private kelondroMapObjects datbase = null;
|
||||||
private kelondroMapObjects bkpbase = null;
|
private kelondroMapObjects bkpbase = null;
|
||||||
private static HashMap authors = new HashMap();
|
private static HashMap authors = new HashMap();
|
||||||
|
@ -94,12 +96,14 @@ public class wikiBoard {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String dateString() {
|
private static String dateString() {
|
||||||
return dateString(new GregorianCalendar(GMTTimeZone).getTime());
|
return dateString(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String dateString(Date date) {
|
public static String dateString(Date date) {
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.format(date);
|
return SimpleFormatter.format(date);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String normalize(String key) {
|
private static String normalize(String key) {
|
||||||
if (key == null) return "null";
|
if (key == null) return "null";
|
||||||
|
@ -169,7 +173,9 @@ public class wikiBoard {
|
||||||
System.out.println("DEBUG - ERROR: date field missing in wikiBoard");
|
System.out.println("DEBUG - ERROR: date field missing in wikiBoard");
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.parse(c);
|
return SimpleFormatter.parse(c);
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
@ -207,7 +213,9 @@ public class wikiBoard {
|
||||||
try {
|
try {
|
||||||
String c = (String) record.get("date");
|
String c = (String) record.get("date");
|
||||||
if (c == null) return null;
|
if (c == null) return null;
|
||||||
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.parse(c);
|
return SimpleFormatter.parse(c);
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,7 +389,7 @@ public final class httpHeader extends TreeMap implements Map {
|
||||||
if (containsKey(kind)) {
|
if (containsKey(kind)) {
|
||||||
Date parsedDate = serverDate.parseHTTPDate((String) get(kind));
|
Date parsedDate = serverDate.parseHTTPDate((String) get(kind));
|
||||||
if (parsedDate == null) parsedDate = new Date();
|
if (parsedDate == null) parsedDate = new Date();
|
||||||
return new Date(parsedDate.getTime());
|
return parsedDate;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -442,7 +442,7 @@ public final class httpHeader extends TreeMap implements Map {
|
||||||
if (containsKey(httpHeader.IF_RANGE)) {
|
if (containsKey(httpHeader.IF_RANGE)) {
|
||||||
Date rangeDate = serverDate.parseHTTPDate((String) get(httpHeader.IF_RANGE));
|
Date rangeDate = serverDate.parseHTTPDate((String) get(httpHeader.IF_RANGE));
|
||||||
if (rangeDate != null)
|
if (rangeDate != null)
|
||||||
return new Date(rangeDate.getTime());
|
return rangeDate;
|
||||||
|
|
||||||
return get(httpHeader.IF_RANGE);
|
return get(httpHeader.IF_RANGE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,6 @@ import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -109,7 +108,6 @@ public final class httpc {
|
||||||
// final statics
|
// final statics
|
||||||
private static final String vDATE = "20040602";
|
private static final String vDATE = "20040602";
|
||||||
private static final int terminalMaxLength = 30000;
|
private static final int terminalMaxLength = 30000;
|
||||||
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
|
|
||||||
private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||||
private static final HashMap reverseMappingCache = new HashMap();
|
private static final HashMap reverseMappingCache = new HashMap();
|
||||||
private static final HashSet activeConnections = new HashSet(); // all connections are stored here and deleted when they are finished
|
private static final HashSet activeConnections = new HashSet(); // all connections are stored here and deleted when they are finished
|
||||||
|
@ -130,7 +128,7 @@ public final class httpc {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// set the time zone
|
// set the time zone
|
||||||
HTTPGMTFormatter.setTimeZone(GMTTimeZone); // The GMT standard date format used in the HTTP protocol
|
HTTPGMTFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); // The GMT standard date format used in the HTTP protocol
|
||||||
|
|
||||||
// set time-out of InetAddress.getByName cache ttl
|
// set time-out of InetAddress.getByName cache ttl
|
||||||
java.security.Security.setProperty("networkaddress.cache.ttl" , "60");
|
java.security.Security.setProperty("networkaddress.cache.ttl" , "60");
|
||||||
|
@ -343,7 +341,7 @@ public final class httpc {
|
||||||
* @return Date-object with the current time.
|
* @return Date-object with the current time.
|
||||||
*/
|
*/
|
||||||
public static Date nowDate() {
|
public static Date nowDate() {
|
||||||
return new GregorianCalendar(GMTTimeZone).getTime();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|
|
@ -33,8 +33,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -818,10 +817,9 @@ public class kelondroCollectionIndex {
|
||||||
|
|
||||||
// finally dump the removed entries to a file
|
// finally dump the removed entries to a file
|
||||||
newcommon.sort();
|
newcommon.sort();
|
||||||
TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
|
|
||||||
Calendar gregorian = new GregorianCalendar(GMTTimeZone);
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
String filename = serverCodings.encodeHex(kelondroBase64Order.enhancedCoder.decode(new String(key))) + "_" + formatter.format(gregorian.getTime()) + ".collection";
|
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
String filename = serverCodings.encodeHex(kelondroBase64Order.enhancedCoder.decode(new String(key))) + "_" + formatter.format(new Date()) + ".collection";
|
||||||
File storagePath = new File(commonsPath, filename.substring(0, 2)); // make a subpath
|
File storagePath = new File(commonsPath, filename.substring(0, 2)); // make a subpath
|
||||||
storagePath.mkdirs();
|
storagePath.mkdirs();
|
||||||
File file = new File(storagePath, filename);
|
File file = new File(storagePath, filename);
|
||||||
|
|
|
@ -64,12 +64,10 @@ import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import de.anomic.server.serverDomains;
|
import de.anomic.server.serverDomains;
|
||||||
|
@ -85,9 +83,6 @@ public class ftpc {
|
||||||
private PrintStream err;
|
private PrintStream err;
|
||||||
private boolean glob = true; // glob = false -> filenames are taken literally for mget, ..
|
private boolean glob = true; // glob = false -> filenames are taken literally for mget, ..
|
||||||
|
|
||||||
// for time measurement
|
|
||||||
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("PST"); // the GMT Time Zone
|
|
||||||
|
|
||||||
// transfer type
|
// transfer type
|
||||||
private static final char transferType = 'i'; // transfer binary
|
private static final char transferType = 'i'; // transfer binary
|
||||||
|
|
||||||
|
@ -1673,7 +1668,7 @@ cd ..
|
||||||
|
|
||||||
private void get(String fileDest, String fileName) throws IOException {
|
private void get(String fileDest, String fileName) throws IOException {
|
||||||
// store time for statistics
|
// store time for statistics
|
||||||
long start = Calendar.getInstance(GMTTimeZone).getTime().getTime();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
// prepare data channel
|
// prepare data channel
|
||||||
if (DataSocketPassiveMode) createPassiveDataPort(); else createActiveDataPort();
|
if (DataSocketPassiveMode) createPassiveDataPort(); else createActiveDataPort();
|
||||||
|
@ -1729,7 +1724,7 @@ cd ..
|
||||||
//if (!success) throw new IOException(reply);
|
//if (!success) throw new IOException(reply);
|
||||||
|
|
||||||
// write statistics
|
// write statistics
|
||||||
long stop = Calendar.getInstance(GMTTimeZone).getTime().getTime();
|
long stop = System.currentTimeMillis();
|
||||||
out.print("---- downloaded " +
|
out.print("---- downloaded " +
|
||||||
((length < 2048) ? length + " bytes" : ((int) length / 1024) + " kbytes") +
|
((length < 2048) ? length + " bytes" : ((int) length / 1024) + " kbytes") +
|
||||||
" in " +
|
" in " +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user