Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Orbiter committed Jun 27, 2014
1 parent fec673c commit 74206a1
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 159 deletions.
7 changes: 3 additions & 4 deletions htroot/PerformanceSearch_p.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,11 +51,11 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
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);
Expand Down
123 changes: 0 additions & 123 deletions htroot/api/timeline.java

This file was deleted.

11 changes: 0 additions & 11 deletions htroot/api/timeline.xml

This file was deleted.

68 changes: 68 additions & 0 deletions htroot/api/timeline_p.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// timeline.java
// (C) 2009 by Michael Peter Christen; mc@yacy.net, 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;
}

}
7 changes: 7 additions & 0 deletions htroot/api/timeline_p.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<timeline>
#{event}#
<event time="#[time]#" isDuration=#(isDuration)#"false"::duration="#[duration]#"#(/isDuration)# type="#[type]#">
#[description]#
</event>
#{/event}#
</timeline>
8 changes: 4 additions & 4 deletions source/net/yacy/peers/graphics/ProfilingGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static RasterPlotter performanceGraph(final int width, final int height,
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);
Expand All @@ -138,7 +138,7 @@ public static RasterPlotter performanceGraph(final int width, final int height,
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;
Expand All @@ -158,7 +158,7 @@ public static RasterPlotter performanceGraph(final int width, final int height,
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;
Expand All @@ -180,7 +180,7 @@ public static RasterPlotter performanceGraph(final int width, final int height,
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;
Expand Down
28 changes: 17 additions & 11 deletions source/net/yacy/search/EventTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -81,15 +83,15 @@ public final static void update(final EClass eventName, final Object eventPayloa
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);
return;
}

// 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;
Expand All @@ -101,7 +103,7 @@ public final static void update(final EClass eventName, final Object eventPayloa
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();
}
}
Expand All @@ -121,19 +123,23 @@ public final static int countEvents(final EClass eventName, final long time) {
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;
}
}

}
Loading

0 comments on commit 74206a1

Please sign in to comment.