Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
hack to generate a unique message-id for messages created in the same second by optionally add a 1 second offset counter to the current time (which is used as the unique id part)
regere51ab8c7aabb
diff --git a/htroot/TransNews_p.java b/htroot/TransNews_p.javaindex 98c432afd..a4e9e1e71 100644--- a/htroot/TransNews_p.java+++ b/htroot/TransNews_p.java@@ -74,6 +74,7 @@ public class TransNews_p {// read votingif ((post != null) && post.containsKey("publishtranslation")) {Iterator<String> filenameit = localTrans.keySet().iterator();+ int msgcounter = 0;while (filenameit.hasNext()) {String file = filenameit.next();Map<String, String> tmptrans = localTrans.get(file);@@ -109,6 +110,7 @@ public class TransNews_p {map.put("file", file);map.put("source", sourcetxt);map.put("target", targettxt);+ map.put("#", Integer.toString(msgcounter++));sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_TRANSLATION_ADD, map);}}diff --git a/source/net/yacy/peers/NewsDB.java b/source/net/yacy/peers/NewsDB.javaindex e2dbbde26..a984e3dec 100644--- a/source/net/yacy/peers/NewsDB.java+++ b/source/net/yacy/peers/NewsDB.java@@ -261,12 +261,33 @@ public class NewsDB {removeStandards();}+ /**+ * Create a new news record and assign data for the unique message id.+ * This is composed of Date-String + PeerHash. Date string is with precision+ * seconds.+ *+ * To allow programatically to create more than one message per second+ * a counter which is added to the date part can be given as attritues+ * with key "#"+ * @param mySeed+ * @param category+ * @param attributes+ */private Record(final Seed mySeed, final String category, final Map<String, String> attributes) {if (category.length() > NewsDB.categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + NewsDB.categoryStringLength + ")");if (attributes.toString().length() > NewsDB.this.attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + NewsDB.this.attributesMaxLength + ")");this.attributes = attributes;this.received = null;- this.created = new Date();+ // workaround for publishing multiple messages. Message id must be unique and is generated date-sting(yyyyMMddhhmmss)+peerhash+ // publishing programatically 2 messages creates same id (because created in the same second). To work around this, if map contains+ // key="#" use value as message counter and put this conter as offset in seconds to the id time part 20161231123001 .. 20161231123002 ..+ if (attributes.containsKey("#")) {+ int cnt = Integer.parseInt(attributes.get("#")); // get number used as counter/offset added as second+ // add (counter * millisecond)+ this.created = new Date(System.currentTimeMillis() + (cnt * 1000));+ } else {+ this.created = new Date();+ }this.category = category;this.distributed = 0;this.originator = mySeed.hash;@@ -295,6 +316,7 @@ public class NewsDB {this.attributes.remove("cre");this.attributes.remove("rec");this.attributes.remove("dis");+ this.attributes.remove("#"); // special attribute for id offset (see Record(mySeed... )}@Override@@ -350,4 +372,4 @@ public class NewsDB {}}-}+}