- fixed problem with yacyVersion and own version generation

- within this context: generalized date format handling
- extended Update interface:
 * a version lookup can be triggered manually
 * a complete lookup + download + re-boot process can be triggered with one click

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3986 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2007-07-16 23:47:21 +00:00
parent b1630e73c8
commit b6d9cca67e
24 changed files with 224 additions and 162 deletions

View File

@ -3,7 +3,7 @@ javacSource=1.4
javacTarget=1.4
# Release Configuration
releaseVersion=0.536
releaseVersion=0.537
releaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
proReleaseFile=yacy_pro_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
releaseFileParentDir=yacy

View File

@ -38,6 +38,7 @@ import de.anomic.http.httpHeader;
import de.anomic.net.natLib;
import de.anomic.plasma.plasmaSearchQuery;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore;
@ -97,7 +98,7 @@ public class AccessTracker_p {
while (ii.hasNext()) {
entry = (Map.Entry) ii.next();
prop.put("page_list_" + entCount + "_host", host);
prop.put("page_list_" + entCount + "_date", yacyCore.universalDateShortString(new Date(((Long) entry.getKey()).longValue())));
prop.put("page_list_" + entCount + "_date", serverDate.shortSecondTime(new Date(((Long) entry.getKey()).longValue())));
prop.put("page_list_" + entCount + "_path", (String) entry.getValue());
entCount++;
}
@ -113,7 +114,7 @@ public class AccessTracker_p {
while (ii.hasNext()) {
entry = (Map.Entry) ii.next();
prop.put("page_list_" + entCount + "_host", host);
prop.put("page_list_" + entCount + "_date", yacyCore.universalDateShortString(new Date(((Long) entry.getKey()).longValue())));
prop.put("page_list_" + entCount + "_date", serverDate.shortSecondTime(new Date(((Long) entry.getKey()).longValue())));
prop.put("page_list_" + entCount + "_path", (String) entry.getValue());
entCount++;
}
@ -135,7 +136,7 @@ public class AccessTracker_p {
// put values in template
prop.put("page_list_" + entCount + "_dark", ((dark) ? 1 : 0) ); dark =! dark;
prop.put("page_list_" + entCount + "_host", (String) searchProfile.get("host"));
prop.put("page_list_" + entCount + "_date", yacyCore.universalDateShortString(new Date(trackerHandle.longValue())));
prop.put("page_list_" + entCount + "_date", serverDate.shortSecondTime(new Date(trackerHandle.longValue())));
prop.put("page_list_" + entCount + "_timestamp", Long.toString(trackerHandle.longValue()));
if (page == 2) {
// local search
@ -171,7 +172,7 @@ public class AccessTracker_p {
Iterator ii = handles.iterator();
while (ii.hasNext()) {
Long timestamp = (Long) ii.next();
prop.put("page_list_" + entCount + "_dates_" + dateCount + "_date", yacyCore.universalDateShortString(new Date(timestamp.longValue())));
prop.put("page_list_" + entCount + "_dates_" + dateCount + "_date", serverDate.shortSecondTime(new Date(timestamp.longValue())));
prop.put("page_list_" + entCount + "_dates_" + dateCount + "_timestamp", timestamp.toString());
dateCount++;
}

View File

@ -23,19 +23,30 @@
<option #(selected)#::selected#(/selected)# value="#[url]#">#[name]#</option>
#{/availreleases}#
</select>
&nbsp;&nbsp;<input type="submit" name="downloadRelease" value="DownloadRelease" />
&nbsp;&nbsp;<input type="submit" name="downloadRelease" value="Download Release" />
&nbsp;&nbsp;<input type="submit" name="checkRelease" value="Check for new Release" />
</form></dd>
<dt>Downloaded Releases</dt>
<dt><br />Downloaded Releases</dt>
<dd><form action="Steering.html" method="get">
&nbsp;<select name="releaseinstall">
#{downloadedreleases}#
<option #(selected)#::selected#(/selected)# value="#[file]#">#[name]#</option>
#{/downloadedreleases}#
</select>#(deployenabled)#::no&nbsp;automated installation on development environments::
&nbsp;&nbsp;<button type="submit" name="update" value="InstallRelease">
<img src="/env/grafics/lock.gif" alt="" />
Install Release
</button>#(/deployenabled)#
</select>
#(deployenabled)#::no&nbsp;automated installation on development environments::
&nbsp;&nbsp;<input type="submit" name="update" value="Install Release" />
#(/deployenabled)#
</form></dd>
<dt><br />Automatic Update</dt>
<dd><form action="ConfigUpdate_p.html" method="get">
&nbsp;check for new releases, download if available and restart with downloaded release<br />
&nbsp;&nbsp;<input type="submit" name="autoUpdate" value="Check + Download + Install Release Now" /><br />
#(autoUpdate)#::
<div class="commit">Download of release #[downloadedRelease]# finished. Restart Initiated.</div>::
<div class="error">No more recent release found.</div>::
<div class="error">Omiting update because this is a development environment.</div>::
<div class="error">Omiting update because download of relase #[downloadedRelease]# failed.</div>
#(/autoUpdate)#
</form></dd>
</dl>
</fieldset>

View File

@ -46,6 +46,7 @@ public class ConfigUpdate_p {
final plasmaSwitchboard sb = (plasmaSwitchboard) env;
prop.put("candeploy_configCommit", 0);
prop.put("candeploy_autoUpdate", 0);
if (post != null) {
if (post.containsKey("downloadRelease")) {
@ -61,6 +62,38 @@ public class ConfigUpdate_p {
}
}
if (post.containsKey("checkRelease")) {
yacyVersion.allReleases(true);
}
if (post.containsKey("autoUpdate")) {
yacyVersion updateVersion = yacyVersion.rulebasedUpdateInfo(true);
if (updateVersion == null) {
prop.put("candeploy_autoUpdate", 2); // no more recent release found
} else try {
// there is a version that is more recent. Load it and re-start with it
sb.getLog().logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.url);
yacyVersion.downloadRelease(updateVersion);
prop.put("candeploy_autoUpdate_downloadedRelease", updateVersion.name);
File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/" + updateVersion.name);
boolean devenvironment = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")).startsWith("dev");
if (devenvironment) {
sb.getLog().logInfo("AUTO-UPDATE: omiting update because this is a development environment");
prop.put("candeploy_autoUpdate", 3);
} else if ((!releaseFile.exists()) || (releaseFile.length() == 0)) {
sb.getLog().logInfo("AUTO-UPDATE: omiting update because download failed (file cannot be found or is too small)");
prop.put("candeploy_autoUpdate", 4);
} else {
yacyVersion.deployRelease(updateVersion.name);
sb.terminate(5000);
sb.getLog().logInfo("AUTO-UPDATE: deploy and restart initiated");
prop.put("candeploy_autoUpdate", 1);
}
} catch (IOException e) {
sb.getLog().logSevere("AUTO-UPDATE: could not download and install release " + updateVersion.url + ": " + e.getMessage());
}
}
if (post.containsKey("configSubmit")) {
prop.put("candeploy_configCommit", 1);
sb.setConfig("update.process", (post.get("updateMode", "manual").equals("manual")) ? "manual" : "auto");

View File

@ -51,6 +51,7 @@ import java.util.Map;
import de.anomic.http.httpHeader;
import de.anomic.http.httpc;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore;
@ -137,10 +138,10 @@ public class News {
String category = record.category();
prop.put("table_list_" + i + "_id", record.id());
prop.put("table_list_" + i + "_ori", (seed == null) ? record.originator() : seed.getName());
prop.put("table_list_" + i + "_cre", yacyCore.universalDateShortString(record.created()));
prop.put("table_list_" + i + "_cre", serverDate.shortSecondTime(record.created()));
prop.put("table_list_" + i + "_crerfcdate", httpc.dateString(record.created()));
prop.put("table_list_" + i + "_cat", category);
prop.put("table_list_" + i + "_rec", (record.received() == null) ? "-" : yacyCore.universalDateShortString(record.received()));
prop.put("table_list_" + i + "_rec", (record.received() == null) ? "-" : serverDate.shortSecondTime(record.received()));
prop.put("table_list_" + i + "_dis", record.distributed());
Map attributeMap = record.attributes();

View File

@ -39,6 +39,7 @@ import de.anomic.kelondro.kelondroRow;
import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.urlPattern.plasmaURLPattern;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
@ -104,7 +105,7 @@ public class Supporter {
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
kelondroMScoreCluster ranking = new kelondroMScoreCluster(); // score cluster for url hashes
kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120, String refid-" + (yacyCore.universalDateShortPattern.length() + 12), kelondroNaturalOrder.naturalOrder, 0);
kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120, String refid-" + (serverDate.shortSecondFormatterPattern.length() + 12), kelondroNaturalOrder.naturalOrder, 0);
HashMap Supporter = new HashMap(); // a mapping from an url hash to a kelondroRow.Entry with display properties
accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
//accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);

View File

@ -39,6 +39,7 @@ import de.anomic.kelondro.kelondroRow;
import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.urlPattern.plasmaURLPattern;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
@ -112,7 +113,7 @@ public class Surftips {
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
kelondroMScoreCluster ranking = new kelondroMScoreCluster(); // score cluster for url hashes
kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120, String refid-" + (yacyCore.universalDateShortPattern.length() + 12), kelondroNaturalOrder.naturalOrder, 0);
kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120, String refid-" + (serverDate.shortSecondFormatterPattern.length() + 12), kelondroNaturalOrder.naturalOrder, 0);
HashMap surftips = new HashMap(); // a mapping from an url hash to a kelondroRow.Entry with display properties
accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
//accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);

View File

@ -46,13 +46,13 @@
// javac -classpath .:../../classes hello.java
// if the shell's current path is HTROOT
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyClient;
@ -205,7 +205,7 @@ public final class hello {
seeds.append("seed0=").append(yacyCore.seedDB.mySeed.genSeedStr(key)).append(serverCore.crlfString);
}
prop.putASIS("mytime", yacyCore.universalDateShortString(new Date()));
prop.putASIS("mytime", serverDate.shortSecondTime());
prop.putASIS("seedlist", seeds.toString());
// return rewrite properties
return prop;

View File

@ -46,10 +46,9 @@
// javac -classpath .:../../classes query.java
// if the shell's current path is HTROOT
import java.util.Date;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore;
@ -86,7 +85,7 @@ public final class query {
final String obj = post.get("object", ""); // keyword for query subject
final String env = post.get("env", ""); // argument to query
prop.putASIS("mytime", yacyCore.universalDateShortString(new Date()));
prop.putASIS("mytime", serverDate.shortSecondTime());
// check if we are the right target and requester has correct information about this peer
if (yacyCore.seedDB.mySeed == null || !yacyCore.seedDB.mySeed.hash.equals(youare)) {

View File

@ -51,11 +51,11 @@ import java.text.ParseException;
import de.anomic.http.httpHeader;
import de.anomic.index.indexURLEntry;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaURL;
import de.anomic.plasma.urlPattern.plasmaURLPattern;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.serverDate;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacyNetwork;
import de.anomic.yacy.yacySeed;
@ -66,7 +66,7 @@ public final class transferURL {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) throws InterruptedException {
long start = System.currentTimeMillis();
long freshdate = 0;
try {freshdate = plasmaURL.shortDayFormatter.parse("20061101").getTime();} catch (ParseException e1) {}
try {freshdate = serverDate.shortDayFormatter.parse("20061101").getTime();} catch (ParseException e1) {}
// return variable that accumulates replacements
final plasmaSwitchboard sb = (plasmaSwitchboard) env;

View File

@ -48,14 +48,11 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -70,16 +67,13 @@ import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroMapObjects;
import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.server.serverDate;
public class blogBoard {
public static final int keyLength = 64;
private static final String dateFormat = "yyyyMMddHHmmss";
private static final int recordSize = 512;
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
private kelondroMapObjects datbase = null;
public blogBoard(File actpath, long preloadTime) {
@ -97,10 +91,6 @@ public class blogBoard {
datbase.close();
}
private static String dateString(Date date) {
return SimpleFormatter.format(date);
}
private static String normalize(String key) {
if (key == null) return "null";
return key.trim().toLowerCase();
@ -132,8 +122,8 @@ public class blogBoard {
record = new HashMap();
key = nkey;
if (key.length() > keyLength) key = key.substring(0, keyLength);
if(date == null) date = new GregorianCalendar(GMTTimeZone).getTime();
record.put("date", dateString(date));
if(date == null) date = serverDate.nowDate();
record.put("date", serverDate.shortSecondTime(date));
if (subject == null) record.put("subject","");
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
if (author == null) record.put("author","");
@ -177,7 +167,7 @@ public class blogBoard {
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return new Date();
}
return SimpleFormatter.parse(c);
return serverDate.shortSecondFormatter.parse(c);
} catch (ParseException e) {
return new Date();
}
@ -187,7 +177,7 @@ public class blogBoard {
String c = (String) record.get("date");
if (c == null) {
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return dateString(new Date());
return serverDate.shortSecondTime();
}
return c;
}
@ -264,7 +254,7 @@ public class blogBoard {
key = normalize(key);
if (key.length() > keyLength) key = key.substring(0, keyLength);
Map record = base.getMap(key);
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes(), null, null);
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", serverDate.nowDate(), "".getBytes(), null, null);
return new entry(key, record);
}
@ -315,7 +305,7 @@ public class blogBoard {
}
try {
date = SimpleFormatter.parse(StrDate);
date = serverDate.shortSecondFormatter.parse(StrDate);
} catch (ParseException e1) {
date = new Date();
}

View File

@ -44,6 +44,7 @@ import de.anomic.plasma.plasmaSearchQuery;
import de.anomic.plasma.plasmaURL;
import de.anomic.server.serverCharBuffer;
import de.anomic.server.serverCodings;
import de.anomic.server.serverDate;
import de.anomic.tools.crypt;
import de.anomic.tools.nxTools;
import de.anomic.index.indexRWIEntry;
@ -204,17 +205,17 @@ public class indexURLEntry {
this.entry.setCol(col_hash, plasmaURL.urlHash(url), null);
this.entry.setCol(col_comp, encodeComp(url, descr, author, tags, ETag));
try {
this.entry.setCol(col_mod, encodeDate(plasmaURL.shortDayFormatter.parse(prop.getProperty("mod", "20000101"))));
this.entry.setCol(col_mod, encodeDate(serverDate.shortDayFormatter.parse(prop.getProperty("mod", "20000101"))));
} catch (ParseException e) {
this.entry.setCol(col_mod, encodeDate(new Date()));
}
try {
this.entry.setCol(col_load, encodeDate(plasmaURL.shortDayFormatter.parse(prop.getProperty("load", "20000101"))));
this.entry.setCol(col_load, encodeDate(serverDate.shortDayFormatter.parse(prop.getProperty("load", "20000101"))));
} catch (ParseException e) {
this.entry.setCol(col_load, encodeDate(new Date()));
}
try {
this.entry.setCol(col_fresh, encodeDate(plasmaURL.shortDayFormatter.parse(prop.getProperty("fresh", "20000101"))));
this.entry.setCol(col_fresh, encodeDate(serverDate.shortDayFormatter.parse(prop.getProperty("fresh", "20000101"))));
} catch (ParseException e) {
this.entry.setCol(col_fresh, encodeDate(new Date()));
}
@ -252,9 +253,9 @@ public class indexURLEntry {
s.append(",author=").append(crypt.simpleEncode(comp.author()));
s.append(",tags=").append(crypt.simpleEncode(comp.tags()));
s.append(",ETag=").append(crypt.simpleEncode(comp.ETag()));
s.append(",mod=").append(plasmaURL.shortDayFormatter.format(moddate()));
s.append(",load=").append(plasmaURL.shortDayFormatter.format(loaddate()));
s.append(",fresh=").append(plasmaURL.shortDayFormatter.format(freshdate()));
s.append(",mod=").append(serverDate.shortDayFormatter.format(moddate()));
s.append(",load=").append(serverDate.shortDayFormatter.format(loaddate()));
s.append(",fresh=").append(serverDate.shortDayFormatter.format(freshdate()));
s.append(",referrer=").append(referrerHash());
s.append(",md5=").append(md5());
s.append(",size=").append(size());

View File

@ -2015,7 +2015,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
// check if update is available and
// if auto-update is activated perform an automatic installation and restart
yacyVersion updateVersion = yacyVersion.rulebasedUpdateInfo();
yacyVersion updateVersion = yacyVersion.rulebasedUpdateInfo(false);
if (updateVersion != null) try {
// there is a version that is more recent. Load it and re-start with it
log.logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.url);

View File

@ -27,7 +27,6 @@
package de.anomic.plasma;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -45,9 +44,6 @@ import de.anomic.yacy.yacySeedDB;
public class plasmaURL {
// day formatter for entry export
public static final SimpleDateFormat shortDayFormatter = new SimpleDateFormat("yyyyMMdd");
// TLD separation in political and cultural parts
// https://www.cia.gov/cia/publications/factbook/index.html
// http://en.wikipedia.org/wiki/List_of_countries_by_continent

View File

@ -195,7 +195,7 @@ public class plasmaWebStructure {
private static String map2refstr(Map map) {
StringBuffer s = new StringBuffer(map.size() * 10);
s.append(plasmaURL.shortDayFormatter.format(new Date()));
s.append(serverDate.shortDayFormatter.format(new Date()));
Iterator i = map.entrySet().iterator();
Map.Entry entry;
String h;

View File

@ -51,8 +51,84 @@ import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import de.anomic.server.logging.serverLog;
public final class serverDate {
// standard date formatters
public static final String shortDayFormatterPattern = "yyyyMMdd";
public static final String shortSecondFormatterPattern = "yyyyMMddHHmmss";
public static final SimpleDateFormat shortDayFormatter = new SimpleDateFormat(shortDayFormatterPattern);
public static final SimpleDateFormat shortSecondFormatter = new SimpleDateFormat(shortSecondFormatterPattern);
public static final SimpleDateFormat longFullFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
public static long nowTime() {
return nowDate().getTime();
}
public static Date nowDate() {
return new GregorianCalendar(GMTTimeZone).getTime();
}
/*
* Synchronization of formatters is needed because SimpleDateFormat is not thread-safe.
* See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579
*/
public static String shortDayTime() {
return shortDayTime(nowDate());
}
public static String shortDayTime(Date date) {
synchronized (serverDate.shortDayFormatter) {
return shortDayFormatter.format(date);
}
}
public static Date parseShortDayTime(String timeString) throws ParseException {
synchronized (serverDate.shortDayFormatter) {
return serverDate.shortDayFormatter.parse(timeString);
}
}
public static String shortSecondTime() {
return shortSecondTime(nowDate());
}
public static String shortSecondTime(Date date) {
synchronized (serverDate.shortSecondFormatter) {
return serverDate.shortSecondFormatter.format(date);
}
}
public static Date parseShortSecondTime(String timeString) throws ParseException {
synchronized (serverDate.shortSecondFormatter) {
return serverDate.shortSecondFormatter.parse(timeString);
}
}
public static Date parseShortSecondTime(String remoteTimeString, String remoteUTCOffset) {
if (remoteTimeString == null || remoteTimeString.length() == 0) { return new Date(); }
if (remoteUTCOffset == null || remoteUTCOffset.length() == 0) { return new Date(); }
try {
/*
* This synchronized is needed because SimpleDateFormat is not thread-safe.
* See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579
*/
synchronized(serverDate.shortSecondFormatter) {
return new Date(serverDate.shortSecondFormatter.parse(remoteTimeString).getTime() - serverDate.UTCDiff() + serverDate.UTCDiff(remoteUTCOffset));
}
} catch (java.text.ParseException e) {
serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
} catch (java.lang.NumberFormatException e) {
serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
}
}
// statics
public final static long secondMillis = 1000;
@ -294,16 +370,6 @@ public final class serverDate {
public static String dateToiso8601(Date date){
return new SimpleDateFormat("yyyy-MM-dd").format(date)+"T"+(new SimpleDateFormat("HH:mm:ss")).format(date)+"Z";
}
// the following is only here to compare the kelondroDate with java-Date:
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
private static Calendar gregorian = new GregorianCalendar(GMTTimeZone);
private static SimpleDateFormat testSFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
private static SimpleDateFormat testLFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
public static String testSDateShortString() {
return testSFormatter.format(gregorian.getTime());
}
public static String intervalToString(long millis) {
try {
@ -339,13 +405,13 @@ public final class serverDate {
//System.out.println("kelondroDate is (" + new kelondroDate().toString() + ")");
System.out.println("offset is " + (UTCDiff()/1000/60/60) + " hours, javaDate is " + new Date() + ", correctedDate is " + new Date(correctedUTCTime()));
System.out.println("serverDate : " + new serverDate().toShortString(false));
System.out.println(" javaDate : " + testSDateShortString());
System.out.println(" javaDate : " + shortSecondTime());
System.out.println("serverDate : " + new serverDate().toString());
System.out.println(" JavaDate : " + testLFormatter.format(new Date()));
System.out.println(" JavaDate : " + longFullFormatter.format(new Date()));
System.out.println("serverDate0: " + new serverDate(0).toShortString(false));
System.out.println(" JavaDate0: " + testSFormatter.format(new Date(0)));
System.out.println(" JavaDate0: " + shortSecondFormatter.format(new Date(0)));
System.out.println("serverDate0: " + new serverDate(0).toString());
System.out.println(" JavaDate0: " + testLFormatter.format(new Date(0)));
System.out.println(" JavaDate0: " + longFullFormatter.format(new Date(0)));
// parse test
try {
System.out.println("serverDate re-parse short: " + new serverDate(new serverDate().toShortString(false)).toShortString(true));
@ -362,7 +428,7 @@ public final class serverDate {
System.out.println("time for " + cycles + " calls to serverDate:" + (System.currentTimeMillis() - start) + " milliseconds");
start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++) /*testresult =*/ testSDateShortString();
for (int i = 0; i < cycles; i++) /*testresult =*/ shortSecondTime();
System.out.println("time for " + cycles + " calls to javaDate:" + (System.currentTimeMillis() - start) + " milliseconds");
}
}

View File

@ -62,23 +62,17 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import de.anomic.http.httpc;
import de.anomic.net.URL;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore;
import de.anomic.server.serverDate;
import de.anomic.server.serverSemaphore;
import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog;
@ -119,62 +113,6 @@ public class yacyCore {
private static int onlineMode = 1;
private plasmaSwitchboard switchboard;
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("America/Los_Angeles");
public static String universalDateShortPattern = "yyyyMMddHHmmss";
private static SimpleDateFormat shortFormatter = new SimpleDateFormat(universalDateShortPattern);
public static long universalTime() {
return universalDate().getTime();
}
public static Date universalDate() {
return new GregorianCalendar(GMTTimeZone).getTime();
}
public static String universalDateShortString() {
return universalDateShortString(universalDate());
}
public static String universalDateShortString(Date date) {
/*
* This synchronized is needed because SimpleDateFormat is not thread-safe.
* See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579
*/
synchronized(yacyCore.shortFormatter) {
return shortFormatter.format(date);
}
}
public static Date parseUniversalDate(String timeString) throws ParseException {
/*
* This synchronized is needed because SimpleDateFormat is not thread-safe.
* See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579
*/
synchronized(yacyCore.shortFormatter) {
return yacyCore.shortFormatter.parse(timeString);
}
}
public static Date parseUniversalDate(String remoteTimeString, String remoteUTCOffset) {
if (remoteTimeString == null || remoteTimeString.length() == 0) { return new Date(); }
if (remoteUTCOffset == null || remoteUTCOffset.length() == 0) { return new Date(); }
try {
/*
* This synchronized is needed because SimpleDateFormat is not thread-safe.
* See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579
*/
synchronized(yacyCore.shortFormatter) {
return new Date(yacyCore.shortFormatter.parse(remoteTimeString).getTime() - serverDate.UTCDiff() + serverDate.UTCDiff(remoteUTCOffset));
}
} catch (java.text.ParseException e) {
log.logFinest("parseUniversalDate " + e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
} catch (java.lang.NumberFormatException e) {
log.logFinest("parseUniversalDate " + e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
}
}
public static int yacyTime() {
// the time since startup of yacy in seconds
return (int) ((System.currentTimeMillis() - startupTime) / 1000);

View File

@ -31,6 +31,7 @@ import java.util.Date;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCodings;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
@ -77,7 +78,7 @@ public class yacyNetwork {
if (targetHash != null) post.put("youare", targetHash);
// time information for synchronization
post.put("mytime", yacyCore.universalDateShortString(new Date()));
post.put("mytime", serverDate.shortSecondTime(new Date()));
post.put("myUTC", System.currentTimeMillis());
// network identification

View File

@ -142,7 +142,7 @@ public class yacyNewsDB {
return yacyNewsRecord.newRecord(
b.getColString(0, null),
b.getColString(1, "UTF-8"),
(b.empty(2)) ? null : yacyCore.parseUniversalDate(b.getColString(2, null), serverDate.UTCDiffString()),
(b.empty(2)) ? null : serverDate.parseShortSecondTime(b.getColString(2, null), serverDate.UTCDiffString()),
(int) b.getColLong(3),
serverCodings.string2map(b.getColString(4, "UTF-8"), ",")
);
@ -156,7 +156,7 @@ public class yacyNewsDB {
kelondroRow.Entry entry = this.news.row().newEntry();
entry.setCol(0, r.id().getBytes());
entry.setCol(1, r.category().getBytes("UTF-8"));
entry.setCol(2, (r.received() == null) ? null : yacyCore.universalDateShortString(r.received()).getBytes());
entry.setCol(2, (r.received() == null) ? null : serverDate.shortSecondTime(r.received()).getBytes());
entry.setCol(3, kelondroBase64Order.enhancedCoder.encodeLong(r.distributed(), 2).getBytes());
entry.setCol(4, attributes.getBytes("UTF-8"));
return entry;

View File

@ -53,6 +53,7 @@ import de.anomic.kelondro.kelondroColumn;
import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.kelondro.kelondroRow;
import de.anomic.kelondro.kelondroStack;
import de.anomic.server.serverDate;
public class yacyNewsQueue {
@ -62,7 +63,7 @@ public class yacyNewsQueue {
public static final kelondroRow rowdef = new kelondroRow(new kelondroColumn[]{
new kelondroColumn("newsid", kelondroColumn.celltype_string, kelondroColumn.encoder_bytes, yacyNewsRecord.idLength, "id = created + originator"),
new kelondroColumn("last touched", kelondroColumn.celltype_string, kelondroColumn.encoder_bytes, yacyCore.universalDateShortPattern.length(), "")
new kelondroColumn("last touched", kelondroColumn.celltype_string, kelondroColumn.encoder_bytes, serverDate.shortSecondFormatterPattern.length(), "")
},
kelondroNaturalOrder.naturalOrder, 0
);
@ -160,7 +161,7 @@ public class yacyNewsQueue {
}
kelondroRow.Entry b = queueStack.row().newEntry(new byte[][]{
r.id().getBytes(),
yacyCore.universalDateShortString(new Date()).getBytes()});
serverDate.shortSecondTime(new Date()).getBytes()});
return b;
}

View File

@ -56,7 +56,7 @@ public class yacyNewsRecord {
public static final int maxNewsRecordLength = 512;
public static final int categoryStringLength = 8;
public static final int idLength = yacyCore.universalDateShortPattern.length() + yacySeedDB.commonHashLength;
public static final int idLength = serverDate.shortSecondFormatterPattern.length() + yacySeedDB.commonHashLength;
private String originator; // hash of originating peer
private Date created; // Date when news was created by originator
@ -68,13 +68,13 @@ public class yacyNewsRecord {
public static final int attributesMaxLength = maxNewsRecordLength
- idLength
- categoryStringLength
- yacyCore.universalDateShortPattern.length()
- serverDate.shortSecondFormatterPattern.length()
- 2;
public static final kelondroRow rowdef = new kelondroRow(
"String idx-" + idLength + " \"id = created + originator\"," +
"String cat-" + categoryStringLength + "," +
"String rec-" + yacyCore.universalDateShortPattern.length() + "," +
"String rec-" + serverDate.shortSecondFormatterPattern.length() + "," +
"short dis-2 {b64e}," +
"String att-" + attributesMaxLength,
kelondroNaturalOrder.naturalOrder, 0
@ -112,8 +112,8 @@ public class yacyNewsRecord {
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : "";
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
this.received = (attributes.containsKey("rec")) ? yacyCore.parseUniversalDate((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? yacyCore.parseUniversalDate((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date();
this.received = (attributes.containsKey("rec")) ? serverDate.parseShortSecondTime((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? serverDate.parseShortSecondTime((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date();
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt((String) attributes.get("dis")) : 0;
this.originator = (attributes.containsKey("ori")) ? (String) attributes.get("ori") : "";
removeStandards();
@ -136,10 +136,10 @@ public class yacyNewsRecord {
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = received;
this.created = yacyCore.parseUniversalDate(id.substring(0, yacyCore.universalDateShortPattern.length()), serverDate.UTCDiffString());
this.created = serverDate.parseShortSecondTime(id.substring(0, serverDate.shortSecondFormatterPattern.length()), serverDate.UTCDiffString());
this.category = category;
this.distributed = distributed;
this.originator = id.substring(yacyCore.universalDateShortPattern.length());
this.originator = id.substring(serverDate.shortSecondFormatterPattern.length());
removeStandards();
}
@ -156,8 +156,8 @@ public class yacyNewsRecord {
// attention: this has no additional encoding
if (this.originator != null) attributes.put("ori", this.originator);
if (this.category != null) attributes.put("cat", this.category);
if (this.created != null) attributes.put("cre", yacyCore.universalDateShortString(this.created));
if (this.received != null) attributes.put("rec", yacyCore.universalDateShortString(this.received));
if (this.created != null) attributes.put("cre", serverDate.shortSecondTime(this.created));
if (this.received != null) attributes.put("rec", serverDate.shortSecondTime(this.received));
attributes.put("dis", Integer.toString(this.distributed));
String theString = attributes.toString();
removeStandards();
@ -165,7 +165,7 @@ public class yacyNewsRecord {
}
public String id() {
return yacyCore.universalDateShortString(created) + originator;
return serverDate.shortSecondTime(created) + originator;
}
public String originator() {

View File

@ -216,7 +216,7 @@ public class yacySeed {
this.dna.put(yacySeed.IPTYPE, "&empty;");
// settings that can only be computed by visiting peer
this.dna.put(yacySeed.LASTSEEN, yacyCore.universalDateShortString(new Date(System.currentTimeMillis() - serverDate.UTCDiff()))); // for last-seen date
this.dna.put(yacySeed.LASTSEEN, serverDate.shortSecondTime(new Date(System.currentTimeMillis() - serverDate.UTCDiff()))); // for last-seen date
this.dna.put(yacySeed.USPEED, yacySeed.ZERO); // the computated uplink speed of the peer
this.dna.put(yacySeed.CRWCNT, yacySeed.ZERO);
@ -507,7 +507,7 @@ public class yacySeed {
// because java thinks it must apply the UTC offset to the current time,
// to create a string that looks like our current time, it adds the local UTC offset to the
// time. To create a corrected UTC Date string, we first subtract the local UTC offset.
dna.put(yacySeed.LASTSEEN, yacyCore.universalDateShortString(new Date(System.currentTimeMillis() - serverDate.UTCDiff())) );
dna.put(yacySeed.LASTSEEN, serverDate.shortSecondTime(new Date(System.currentTimeMillis() - serverDate.UTCDiff())) );
}
/**
@ -515,7 +515,7 @@ public class yacySeed {
*/
public final long getLastSeenUTC() {
try {
final long t = yacyCore.parseUniversalDate(get(yacySeed.LASTSEEN, "20040101000000")).getTime();
final long t = serverDate.parseShortSecondTime(get(yacySeed.LASTSEEN, "20040101000000")).getTime();
// getTime creates a UTC time number. But in this case java thinks, that the given
// time string is a local time, which has a local UTC offset applied.
// Therefore java subtracts the local UTC offset, to get a UTC number.
@ -542,7 +542,7 @@ public class yacySeed {
/** @return the age of the seed in number of days */
public final int getAge() {
try {
final long t = yacyCore.parseUniversalDate(get(yacySeed.BDATE, "20040101000000")).getTime();
final long t = serverDate.parseShortSecondTime(get(yacySeed.BDATE, "20040101000000")).getTime();
return (int) ((System.currentTimeMillis() - (t - getUTCDiff() + serverDate.UTCDiff())) / 1000 / 60 / 60 / 24);
} catch (java.text.ParseException e) {
return -1;
@ -725,7 +725,7 @@ public class yacySeed {
} else {
newSeed.dna.put(yacySeed.PORT, Integer.toString(serverCore.getPortNr(sb.getConfig("port", "8080"))));
}
newSeed.dna.put(yacySeed.BDATE, yacyCore.universalDateShortString(new Date(System.currentTimeMillis() - serverDate.UTCDiff())) );
newSeed.dna.put(yacySeed.BDATE, serverDate.shortSecondTime(new Date(System.currentTimeMillis() - serverDate.UTCDiff())) );
newSeed.dna.put(yacySeed.LASTSEEN, newSeed.dna.get(yacySeed.BDATE)); // just as initial setting
newSeed.dna.put(yacySeed.UTC, serverDate.UTCDiffString());
newSeed.dna.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);

View File

@ -191,7 +191,7 @@ public final class yacyVersion implements Comparator, Comparable {
return true;
}
public static final yacyVersion rulebasedUpdateInfo() {
public static final yacyVersion rulebasedUpdateInfo(boolean manual) {
// according to update properties, decide if we should retrieve update information
// if true, the release that can be obtained is returned.
// if false, null is returned
@ -199,12 +199,18 @@ public final class yacyVersion implements Comparator, Comparable {
// check if update process allowes update retrieve
String process = sb.getConfig("update.process", "manual");
if (!process.equals("auto")) return null; // no, its a manual or guided process
if ((!manual) && (!process.equals("auto"))) {
yacyCore.log.logInfo("rulebasedUpdateInfo: not a automatic update selected");
return null; // no, its a manual or guided process
}
// check if the last retrieve time is a minimum time ago
long cycle = Math.max(1, sb.getConfigLong("update.cycle", 168)) * 24 * 60 * 60 * 1000;
long timeLookup = sb.getConfigLong("update.time.lookup", System.currentTimeMillis());
if (timeLookup + cycle > System.currentTimeMillis()) return null; // no we have recently made a lookup
if ((!manual) && (timeLookup + cycle > System.currentTimeMillis())) {
yacyCore.log.logInfo("rulebasedUpdateInfo: too early for a lookup for a new release");
return null; // no we have recently made a lookup
}
// check if we know that there is a release that is more recent than that which we are using
TreeSet[] releasess = yacyVersion.allReleases(true); // {0=promain, 1=prodev, 2=stdmain, 3=stddev}
@ -213,20 +219,36 @@ public final class yacyVersion implements Comparator, Comparable {
yacyVersion latestdev = (yacyVersion) releasess[(pro) ? 1 : 3].first();
String concept = sb.getConfig("update.concept", "any");
String blacklist = sb.getConfig("update.blacklist", ".\\...[123]");
if (concept.equals("any")) {
if ((manual) || (concept.equals("any"))) {
// return a dev-release or a main-release
if ((latestdev.compareTo(latestmain) > 0) && (!(Float.toString(latestdev.releaseNr).matches(blacklist)))) {
return (latestdev.compareTo(thisVersion()) > 0) ? latestdev : null;
if (latestdev.compareTo(thisVersion()) > 0) return latestdev; else {
yacyCore.log.logInfo("rulebasedUpdateInfo: latest dev is not more recent than installed release");
return null;
}
} else {
if ((Float.toString(latestmain.releaseNr).matches(blacklist))) return null;
return (latestmain.compareTo(thisVersion()) > 0) ? latestmain : null;
if ((Float.toString(latestmain.releaseNr).matches(blacklist))) {
yacyCore.log.logInfo("rulebasedUpdateInfo: latest dev matches with blacklist");
return null;
}
if (latestmain.compareTo(thisVersion()) > 0) return latestmain; else {
yacyCore.log.logInfo("rulebasedUpdateInfo: latest main is not more recent than installed release (1)");
return null;
}
}
}
if (concept.equals("main")) {
// return a main-release
if ((Float.toString(latestmain.releaseNr).matches(blacklist))) return null;
return (latestmain.compareTo(thisVersion()) > 0) ? latestmain : null;
if ((Float.toString(latestmain.releaseNr).matches(blacklist))) {
yacyCore.log.logInfo("rulebasedUpdateInfo: latest main matches with blacklist");
return null;
}
if (latestmain.compareTo(thisVersion()) > 0) return latestmain; else {
yacyCore.log.logInfo("rulebasedUpdateInfo: latest main is not more recent than installed release (2)");
return null;
}
}
yacyCore.log.logInfo("rulebasedUpdateInfo: failed to find more recent release");
return null;
}
@ -316,7 +338,7 @@ public final class yacyVersion implements Comparator, Comparable {
httpc.wget(
release.url,
release.url.getHost(),
1000,
300000,
null,
null,
plasmaSwitchboard.getSwitchboard().remoteProxyConfig,

View File

@ -268,10 +268,10 @@ public final class yacy {
sb.setConfig("version", Double.toString(version));
sb.setConfig("vString", yacyVersion.combined2prettyVersion(Double.toString(version)));
sb.setConfig("vdate", vDATE);
sb.setConfig("vdate", (vDATE.startsWith("@")) ? serverDate.shortDayTime() : vDATE);
sb.setConfig("applicationRoot", homePath);
sb.startupTime = startup;
serverLog.logConfig("STARTUP", "YACY Version: " + version + ", Built " + vDATE);
serverLog.logConfig("STARTUP", "YACY Version: " + version + ", Built " + sb.getConfig("vdate", "00000000"));
yacyVersion.latestRelease = version;
// read environment