Skip to content

Commit

Permalink
update to the server core
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5591 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Feb 10, 2009
1 parent bc1e7da commit 6c627db
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 49 deletions.
7 changes: 4 additions & 3 deletions htroot/AccessTracker_p.java
Expand Up @@ -29,6 +29,7 @@
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Map.Entry;
Expand All @@ -45,7 +46,7 @@

public class AccessTracker_p {

private static final TreeMap<Long, String> treemapclone(final TreeMap<Long, String> m) {
private static final SortedMap<Long, String> treemapclone(final SortedMap<Long, String> m) {
final TreeMap<Long, String> accessClone = new TreeMap<Long, String>();
try {
accessClone.putAll(m);
Expand All @@ -68,7 +69,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
if (page == 0) {
final Iterator<String> i = sb.accessHosts();
String host;
TreeMap<Long, String> access;
SortedMap<Long, String> access;
int entCount = 0;
try {
while ((entCount < maxCount) && (i.hasNext())) {
Expand Down Expand Up @@ -98,7 +99,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
if (page == 1) {
String host = (post == null) ? "" : post.get("host", "");
int entCount = 0;
TreeMap<Long, String> access;
SortedMap<Long, String> access;
Map.Entry<Long, String> entry;
if (host.length() > 0) {
access = sb.accessTrack(host);
Expand Down
1 change: 0 additions & 1 deletion source/de/anomic/crawler/NoticeURLImporter.java
Expand Up @@ -107,7 +107,6 @@ public String getStatus() {
return theStatus.toString();
}

@SuppressWarnings("unchecked")
public void run() {
try {
// waiting on init thread to finish
Expand Down
7 changes: 4 additions & 3 deletions source/de/anomic/plasma/plasmaGrafics.java
Expand Up @@ -38,6 +38,7 @@
import de.anomic.yacy.yacySearch;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacySeedDB;
import de.anomic.yacy.dht.FlatWordPartitionScheme;
import de.anomic.ymage.ymageMatrix;
import de.anomic.ymage.ymageToolPrint;

Expand Down Expand Up @@ -128,15 +129,15 @@ public static ymageMatrix getSearchEventPicture(final yacySeedDB seedDB, final S
// draw in the primary search peers
for (int j = 0; j < primarySearches.length; j++) {
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.RED : ymageMatrix.GREEN);
angle = (int) (360.0 * (((double) primarySearches[j].target().dhtPosition()) / ((double) Long.MAX_VALUE)));
angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(primarySearches[j].target().hash, null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle);
}

// draw in the secondary search peers
if (secondarySearches != null) {
for (int j = 0; j < secondarySearches.length; j++) {
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.RED : ymageMatrix.GREEN);
angle = (int) (360.0 * (((double) secondarySearches[j].target().dhtPosition()) / ((double) Long.MAX_VALUE)));
angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(secondarySearches[j].target().hash, null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1);
}
Expand Down Expand Up @@ -248,7 +249,7 @@ private static void drawNetworkPicturePeer(final ymageMatrix img, final int x, f
final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/;
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
final int angle = (int) (360.0 * (((double) seed.dhtPosition()) / ((double) Long.MAX_VALUE)));
final int angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(seed.hash, null)) / ((double) Long.MAX_VALUE)));
//System.out.println("Seed " + seed.hash + " has distance " + seed.dhtDistance() + ", angle = " + angle);
int linelength = 20 + outerradius * (20 * (name.length() - shortestName) / (longestName - shortestName) + Math.abs(seed.hash.hashCode() % 20)) / 60;
if (linelength > outerradius) linelength = outerradius;
Expand Down
9 changes: 0 additions & 9 deletions source/de/anomic/plasma/plasmaSearchEvent.java
Expand Up @@ -376,15 +376,6 @@ private boolean anyWorkerAlive() {
return false;
}

private int countWorkerFinished() {
if (this.workerThreads == null) return 0;
int c = 0;
for (int i = 0; i < workerThreadCount; i++) {
if (this.workerThreads[i] == null || !this.workerThreads[i].isAlive()) c++;
}
return c;
}

boolean anyRemoteSearchAlive() {
// check primary search threads
if ((this.primarySearchThreads != null) && (this.primarySearchThreads.length != 0)) {
Expand Down
1 change: 0 additions & 1 deletion source/de/anomic/server/serverAbstractBlockingThread.java
Expand Up @@ -38,7 +38,6 @@ public serverProcessor<J> getManager() {
return this.manager;
}

@SuppressWarnings("unchecked")
public void run() {
this.open();
if (log != null) {
Expand Down
45 changes: 23 additions & 22 deletions source/de/anomic/server/serverAbstractSwitch.java
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -39,20 +40,20 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
private static final long maxTrackingTimeDefault = 1000 * 60 * 60; // store only access data from the last hour to save ram space

// configuration management
private final File configFile;
private final String configComment;
private final File rootPath;
protected boolean firstInit;
protected Log log;
protected int serverJobs;
protected long maxTrackingTime;
private Map<String, String> configProps;
private final Map<String, String> configRemoved;
private final HashMap<InetAddress, String> authorization;
private final TreeMap<String, serverBusyThread> workerThreads;
private final TreeMap<String, serverSwitchAction> switchActions;
protected ConcurrentHashMap<String, TreeMap<Long, String>> accessTracker; // mappings from requesting host to an ArrayList of serverTrack-entries
private final LinkedBlockingQueue<E> cacheStack;
private final File configFile;
private final String configComment;
private final File rootPath;
protected boolean firstInit;
protected Log log;
protected int serverJobs;
private long maxTrackingTime;
private Map<String, String> configProps;
private final Map<String, String> configRemoved;
private final HashMap<InetAddress, String> authorization;
private final TreeMap<String, serverBusyThread> workerThreads;
private final TreeMap<String, serverSwitchAction> switchActions;
private final LinkedBlockingQueue<E> cacheStack;
private final ConcurrentHashMap<String, SortedMap<Long, String>> accessTracker; // mappings from requesting host to an ArrayList of serverTrack-entries

public serverAbstractSwitch(final File rootPath, final String initPath, final String configPath, final boolean applyPro) {
// we initialize the switchboard with a property file,
Expand Down Expand Up @@ -132,7 +133,7 @@ public serverAbstractSwitch(final File rootPath, final String initPath, final St

// other settings
authorization = new HashMap<InetAddress, String>();
accessTracker = new ConcurrentHashMap<String, TreeMap<Long, String>>();
accessTracker = new ConcurrentHashMap<String, SortedMap<Long, String>>();

// init thread control
workerThreads = new TreeMap<String, serverBusyThread>();
Expand Down Expand Up @@ -160,7 +161,7 @@ public Log getLog() {
* remove all entries from the access tracker where the age of the last access is greater than the given timeout
*/
public void cleanupAccessTracker(final long timeout) {
final Iterator<Map.Entry<String, TreeMap<Long, String>>> i = accessTracker.entrySet().iterator();
final Iterator<Map.Entry<String, SortedMap<Long, String>>> i = accessTracker.entrySet().iterator();
while (i.hasNext()) {
if (i.next().getValue().tailMap(Long.valueOf(System.currentTimeMillis() - timeout)).size() == 0) i.remove();
}
Expand All @@ -169,7 +170,7 @@ public void cleanupAccessTracker(final long timeout) {
public void track(final String host, String accessPath) {
// learn that a specific host has accessed a specific path
if (accessPath == null) accessPath="NULL";
TreeMap<Long, String> access = accessTracker.get(host);
SortedMap<Long, String> access = accessTracker.get(host);
if (access == null) access = new TreeMap<Long, String>();

synchronized (access) {
Expand All @@ -179,10 +180,10 @@ public void track(final String host, String accessPath) {
}
}

public TreeMap<Long, String> accessTrack(final String host) {
public SortedMap<Long, String> accessTrack(final String host) {
// returns mapping from Long(accesstime) to path

TreeMap<Long, String> access = accessTracker.get(host);
SortedMap<Long, String> access = accessTracker.get(host);
if (access == null) return null;
// clear too old entries
synchronized (access) {
Expand All @@ -198,13 +199,13 @@ public TreeMap<Long, String> accessTrack(final String host) {
return access;
}

private TreeMap<Long, String> clearTooOldAccess(final TreeMap<Long, String> access) {
return new TreeMap<Long, String>(access.tailMap(Long.valueOf(System.currentTimeMillis() - maxTrackingTime)));
private SortedMap<Long, String> clearTooOldAccess(final SortedMap<Long, String> access) {
return access.tailMap(Long.valueOf(System.currentTimeMillis() - maxTrackingTime));
}

public Iterator<String> accessHosts() {
// returns an iterator of hosts in tracker (String)
final HashMap<String, TreeMap<Long, String>> accessTrackerClone = new HashMap<String, TreeMap<Long, String>>();
final HashMap<String, SortedMap<Long, String>> accessTrackerClone = new HashMap<String, SortedMap<Long, String>>();
accessTrackerClone.putAll(accessTracker);
return accessTrackerClone.keySet().iterator();
}
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/server/serverSwitch.java
Expand Up @@ -34,7 +34,7 @@ this is an interface for possible switchboard implementations
import java.net.InetAddress;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.SortedMap;

import de.anomic.kelondro.util.Log;

Expand All @@ -49,7 +49,7 @@ public interface serverSwitch<E> {

// access tracker
public void track(String host, String accessPath); // learn that a specific host has accessed a specific path
public TreeMap<Long, String> accessTrack(String host); // returns mapping from Long(accesstime) to path
public SortedMap<Long, String> accessTrack(String host); // returns mapping from Long(accesstime) to path
public Iterator<String> accessHosts(); // returns an iterator of hosts in tracker (String)

// a switchboard can have action listener
Expand Down
8 changes: 0 additions & 8 deletions source/de/anomic/yacy/yacySeed.java
Expand Up @@ -676,14 +676,6 @@ public final boolean isOnline(final String type) {
return type.equals(yacySeed.PEERTYPE_SENIOR) || type.equals(yacySeed.PEERTYPE_PRINCIPAL);
}

/**
* @deprecated this does not reflect the vertical DHT. A peer may have several positions now.
*/
public final long dhtPosition() {
// normalized to Long.MAX_VALUE
return FlatWordPartitionScheme.std.dhtPosition(this.hash, null);
}

private static String bestGap(final yacySeedDB seedDB) {
if ((seedDB == null) || (seedDB.sizeConnected() <= 2)) {
// use random hash
Expand Down

0 comments on commit 6c627db

Please sign in to comment.