Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

refactoring

Michael Peter Christen74206a10c707
diff --git a/htroot/PerformanceSearch_p.java b/htroot/PerformanceSearch_p.java
index 0ade95fd2..2cb0e5673 100644
--- a/htroot/PerformanceSearch_p.java
+++ b/htroot/PerformanceSearch_p.java
@@ -24,7 +24,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import java.util.Date;
import java.util.Iterator;
import net.yacy.cora.protocol.RequestHeader;
@@ -52,11 +51,11 @@ public class PerformanceSearch_p {
prop.put("table_" + c + "_event", search.processName.name());
prop.put("table_" + c + "_comment", search.comment);
prop.putNum("table_" + c + "_count", search.resultCount);
- prop.putNum("table_" + c + "_delta", event.time - lastt);
- prop.put("table_" + c + "_time", (new Date(event.time)).toString());
+ prop.putNum("table_" + c + "_delta", event.time.getTime() - lastt);
+ prop.put("table_" + c + "_time", (event.time).toString());
prop.putNum("table_" + c + "_duration", search.duration);
c++;
- lastt = event.time;
+ lastt = event.time.getTime();
}
}
prop.put("table", c);
diff --git a/htroot/api/timeline.java b/htroot/api/timeline.java
deleted file mode 100644
index f96cf08ea..000000000
--- a/htroot/api/timeline.java
+++ /dev/null
@@ -1,123 +0,0 @@
-// timeline.java
-// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
-// first published 27.02.2009 on http://yacy.net
-//
-// This is a part of YaCy, a peer-to-peer based web search engine
-//
-// $LastChangedDate: 2009-02-10 01:06:59 +0100 (Di, 10 Feb 2009) $
-// $LastChangedRevision: 5586 $
-// $LastChangedBy: orbiter $
-//
-// LICENSE
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import java.util.Date;
-import java.util.Iterator;
-
-import net.yacy.cora.date.GenericFormatter;
-import net.yacy.cora.protocol.RequestHeader;
-import net.yacy.cora.storage.HandleSet;
-import net.yacy.cora.util.ConcurrentLog;
-import net.yacy.cora.util.SpaceExceededException;
-import net.yacy.kelondro.data.word.WordReference;
-import net.yacy.kelondro.rwi.ReferenceContainer;
-import net.yacy.kelondro.rwi.TermSearch;
-import net.yacy.kelondro.util.ISO639;
-import net.yacy.peers.Network;
-import net.yacy.search.Switchboard;
-import net.yacy.search.index.Segment;
-import net.yacy.search.query.QueryGoal;
-import net.yacy.search.query.QueryParams;
-import net.yacy.server.serverObjects;
-import net.yacy.server.serverSwitch;
-
-public final class timeline {
-
- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
- // return variable that accumulates replacements
- final Switchboard sb = (Switchboard) env;
-
- final serverObjects prop = new serverObjects();
- if ((post == null) || (env == null)) return prop;
- final boolean authenticated = sb.adminAuthenticated(header) >= 2;
-
- Segment segment = sb.index;
-
- final String querystring = post.get("query", ""); // a string of word hashes that shall be searched and combined
- final int count = Math.min((authenticated) ? 1000 : 10, post.getInt("maximumRecords", 1000)); // SRU syntax
- final int maxdist= post.getInt("maxdist", Integer.MAX_VALUE);
- String language = post.get("language", "");
- if (!ISO639.exists(language)) {
- // take language from the user agent
- String agent = header.get("User-Agent");
- if (agent == null) agent = System.getProperty("user.language");
- language = (agent == null) ? "en" : ISO639.userAgentLanguageDetection(agent);
- if (language == null) language = "en";
- }
- final QueryGoal qg = new QueryGoal(querystring);
- HandleSet q = qg.getIncludeHashes();
-
- // tell all threads to do nothing for a specific time
- sb.intermissionAllThreads(3000);
-
- // prepare search
- final long timestamp = System.currentTimeMillis();
-
- // prepare an abstract result
- int indexabstractContainercount = 0;
- int joincount = 0;
-
- // retrieve index containers
- //yacyCore.log.logInfo("INIT TIMELINE SEARCH: " + plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + count + " links");
-
- // get the index container with the result vector
- TermSearch<WordReference> search = null;
- try {
- search = segment.termIndex().query(q, qg.getExcludeHashes(), null, Segment.wordReferenceFactory, maxdist);
- } catch (final SpaceExceededException e) {
- ConcurrentLog.logException(e);
- }
- ReferenceContainer<WordReference> index = search.joined();
-
- Iterator<WordReference> i = index.entries();
- WordReference entry;
- int c = 0;
- Date lm;
- String lms;
- while (i.hasNext() && c < count) {
- entry = i.next();
- lm = new Date(entry.lastModified());
- lms = GenericFormatter.ANSIC_FORMATTER.format(lm);
- prop.put("event_" + c + "_start", lms); // like "Wed May 01 1963 00:00:00 GMT-0600"
- prop.put("event_" + c + "_end", lms); // like "Sat Jun 01 1963 00:00:00 GMT-0600"
- prop.put("event_" + c + "_isDuration", 0); // 0 (only a point) or 1 (period of time)
- prop.putHTML("event_" + c + "_title", "test"); // short title of the event
- prop.putHTML("event_" + c + "_description", ""); // long description of the event
- c++;
- }
- prop.put("event", c);
-
- // log
- Network.log.info("EXIT TIMELINE SEARCH: " +
- QueryParams.anonymizedQueryHashes(q) + " - " + joincount + " links found, " +
- prop.get("linkcount", "?") + " links selected, " +
- indexabstractContainercount + " index abstracts, " +
- (System.currentTimeMillis() - timestamp) + " milliseconds");
-
- return prop;
- }
-
-}
diff --git a/htroot/api/timeline.xml b/htroot/api/timeline.xml
deleted file mode 100644
index d0f054aaa..000000000
--- a/htroot/api/timeline.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<data>
-#{event}#
- <event
- start="#[start]#"
- end="#[end]#"
- isDuration=#(isDuration)#"false"::"true"#(/isDuration)#
- title="#[title]#">
- #[description]#
- </event>
-#{/event}#
-</data>
\ No newline at end of file
diff --git a/htroot/api/timeline_p.java b/htroot/api/timeline_p.java
new file mode 100644
index 000000000..2f3c83c66
--- /dev/null
+++ b/htroot/api/timeline_p.java
@@ -0,0 +1,68 @@
+// timeline.java
+// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+// first published 27.02.2009 on http://yacy.net
+//
+// This is a part of YaCy, a peer-to-peer based web search engine
+//
+// $LastChangedDate: 2009-02-10 01:06:59 +0100 (Di, 10 Feb 2009) $
+// $LastChangedRevision: 5586 $
+// $LastChangedBy: orbiter $
+//
+// LICENSE
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.yacy.cora.protocol.RequestHeader;
+import net.yacy.search.EventTracker;
+import net.yacy.search.Switchboard;
+import net.yacy.server.serverObjects;
+import net.yacy.server.serverSwitch;
+
+public final class timeline_p {
+
+ public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ // return variable that accumulates replacements
+ final Switchboard sb = (Switchboard) env;
+
+ final serverObjects prop = new serverObjects();
+ if ((post == null) || (env == null)) return prop;
+
+
+ final String[] data = post.get("data", "").split(","); // a string of word hashes that shall be searched and combined
+ Map<String, Map<Date, EventTracker.Event>> proc = new HashMap<>();
+ for (String s: data) proc.put(s, null);
+
+ /*
+ while (i.hasNext() && c < count) {
+ entry = i.next();
+ lm = new Date(entry.lastModified());
+ lms = GenericFormatter.ANSIC_FORMATTER.format(lm);
+ prop.put("event_" + c + "_time", lms); // like "Wed May 01 1963 00:00:00 GMT-0600"
+ prop.put("event_" + c + "_isDuration", 0); // 0 (only a point) or 1 (period of time)
+ prop.put("event_" + c + "_isDuration_duration", 0); // 0 (only a point) or 1 (period of time)
+ prop.putHTML("event_" + c + "_type", "type"); // short title of the event
+ prop.putHTML("event_" + c + "_description", ""); // long description of the event
+ c++;
+ }
+ prop.put("event", c);
+*/
+ return prop;
+ }
+
+}
diff --git a/htroot/api/timeline_p.xml b/htroot/api/timeline_p.xml
new file mode 100644
index 000000000..bc5cf0642
--- /dev/null
+++ b/htroot/api/timeline_p.xml
@@ -0,0 +1,7 @@
+<timeline>
+#{event}#
+ <event time="#[time]#" isDuration=#(isDuration)#"false"::duration="#[duration]#"#(/isDuration)# type="#[type]#">
+ #[description]#
+ </event>
+#{/event}#
+</timeline>
\ No newline at end of file
diff --git a/source/net/yacy/peers/graphics/ProfilingGraph.java b/source/net/yacy/peers/graphics/ProfilingGraph.java
index 6e02f099f..aa87caf8d 100644
--- a/source/net/yacy/peers/graphics/ProfilingGraph.java
+++ b/source/net/yacy/peers/graphics/ProfilingGraph.java
@@ -117,7 +117,7 @@ public class ProfilingGraph {
EventTracker.Event event;
while (events.hasNext()) {
event = events.next();
- time = event.time - now;
+ time = event.time.getTime() - now;
bytes = ((Long) event.payload).longValue();
x1 = (int) (time/1000);
y1 = (int) (bytes / 1024 / 1024);
@@ -138,7 +138,7 @@ public class ProfilingGraph {
int words;
while (events.hasNext()) {
event = events.next();
- time = event.time - now;
+ time = event.time.getTime() - now;
words = (int) ((Long) event.payload).longValue();
x1 = (int) (time/1000);
y1 = words;
@@ -158,7 +158,7 @@ public class ProfilingGraph {
int ppm;
while (events.hasNext()) {
event = events.next();
- time = event.time - now;
+ time = event.time.getTime() - now;
ppm = (int) ((Long) event.payload).longValue();
x1 = (int) (time/1000);
y1 = ppm;
@@ -180,7 +180,7 @@ public class ProfilingGraph {
String pingPeer;
while (events.hasNext()) {
event = events.next();
- time = event.time - now;
+ time = event.time.getTime() - now;
ping = (EventPing) event.payload;
x1 = (int) (time/1000);
y1 = Math.abs((ping.outgoing ? ping.toPeer : ping.fromPeer).hashCode()) % vspace;
diff --git a/source/net/yacy/search/EventTracker.java b/source/net/yacy/search/EventTracker.java
index 6ae7965bc..d5486a365 100644
--- a/source/net/yacy/search/EventTracker.java
+++ b/source/net/yacy/search/EventTracker.java
@@ -26,12 +26,14 @@
package net.yacy.search;
+import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
+import net.yacy.cora.date.GenericFormatter;
import net.yacy.peers.graphics.ProfilingGraph;
@@ -81,7 +83,7 @@ public class EventTracker {
history = new LinkedBlockingQueue<Event>();
// update entry
- history.offer(new Event(eventPayload));
+ history.offer(new Event(new Date(), 0, "update", eventPayload, 0));
// store map
historyMaps.put(eventName, history);
@@ -89,7 +91,7 @@ public class EventTracker {
}
// update history
- history.offer(new Event(eventPayload));
+ history.offer(new Event(new Date(), 0, "update", eventPayload, 0));
// clean up too old entries
int tp = history.size() - maxQueueSize;
@@ -101,7 +103,7 @@ public class EventTracker {
final long now = System.currentTimeMillis();
while (!history.isEmpty()) {
e = history.peek();
- if (now - e.time < maxQueueAge) break;
+ if (now - e.time.getTime() < maxQueueAge) break;
history.poll();
}
}
@@ -121,19 +123,23 @@ public class EventTracker {
final long now = System.currentTimeMillis();
int count = 0;
while (event.hasNext()) {
- if (now - event.next().time < time) count++;
+ if (now - event.next().time.getTime() < time) count++;
}
return count;
}
public final static class Event {
- public Object payload;
- public long time;
-
- public Event(final Object payload) {
- this.payload = payload;
- this.time = System.currentTimeMillis();
+ final public Date time;
+ final public int duration; // ms
+ final public String type;
+ final public Object payload;
+ final public int count;
+ public Event(final Date time, final int duration, final String type, final Object payload, final int count) {
+ this.time = time; this.duration = duration; this.type = type; this.payload = payload; this.count = count;
+ }
+ @Override
+ public String toString() {
+ return type + " " + GenericFormatter.SHORT_SECOND_FORMATTER.format(time) + (duration == 0 ? " " : "(" + duration + "ms) ") + (count == 0 ? " " : "[" + count + "] ") + payload;
}
}
-
}
diff --git a/source/net/yacy/search/query/AccessTracker.java b/source/net/yacy/search/query/AccessTracker.java
index b8767ba8b..17ce9e931 100644
--- a/source/net/yacy/search/query/AccessTracker.java
+++ b/source/net/yacy/search/query/AccessTracker.java
@@ -40,6 +40,7 @@ import net.yacy.cora.document.WordCache;
import net.yacy.cora.document.encoding.UTF8;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.kelondro.util.MemoryControl;
+import net.yacy.search.EventTracker;
public class AccessTracker {
@@ -48,7 +49,7 @@ public class AccessTracker {
private static final int minSize = 100;
private static final int maxSize = 1000;
private static final int maxAge = 24 * 60 * 60 * 1000;
-
+
public static class QueryEvent {
final public String address;
final public String userAgent;
@@ -207,8 +208,8 @@ public class AccessTracker {
* @param to the right boundary of the sequence to search for (excluded)
* @return a list of lines within the given dates
*/
- public static ArrayList<String> readLog(File f, Date from, Date to) {
- ArrayList<String> list = new ArrayList<String>();
+ public static ArrayList<EventTracker.Event> readLog(File f, Date from, Date to) {
+ ArrayList<EventTracker.Event> list = new ArrayList<>();
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(f, "r");
@@ -221,7 +222,17 @@ public class AccessTracker {
raf.seek(seekFrom);
String line;
while (raf.getFilePointer() < seekTo && (line = raf.readLine()) != null) {
- list.add(line);
+ // parse the line
+ String[] ls = line.split(" ");
+ EventTracker.Event event;
+ try {
+ event = new EventTracker.Event(GenericFormatter.SHORT_SECOND_FORMATTER.parse(ls[0]), 0, "query", line.substring(ls[0].length() + ls[1].length() + 2), Integer.valueOf(ls[1]));
+ list.add(event);
+ } catch (NumberFormatException e) {
+ continue;
+ } catch (ParseException e) {
+ continue;
+ }
}
} catch (final FileNotFoundException e) {
ConcurrentLog.logException(e);
@@ -291,8 +302,8 @@ public class AccessTracker {
try {
from = GenericFormatter.SHORT_SECOND_FORMATTER.parse(args[1]);
Date to = GenericFormatter.SHORT_SECOND_FORMATTER.parse(args[2]);
- ArrayList<String> dump = readLog(new File(file), from, to);
- for (String s: dump) System.out.println(s);
+ ArrayList<EventTracker.Event> dump = readLog(new File(file), from, to);
+ for (EventTracker.Event s: dump) System.out.println(s.toString());
} catch (ParseException e) {
e.printStackTrace();
}