|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.TimerTask
lbg.searchengine.SearchEngineClient
public abstract class SearchEngineClient
A local database of peer handles, automatically updating from a server.
Handle removal is not automatic and should be done when encountering a problem with a handle.
The local database may hold handles that the server doesn't know of: they might be locally added or currently not expired. The server may hold handles that are not locally known: they will be downloaded at next update.
The local database may hold the handle of the peer owning this client, as he is not required to identify himself before contacting the server.
This object is Thread-safe.
Field Summary | |
---|---|
static int |
DEFAULT_SEARCH_COUNT
Default handle count that should be returned by a search. |
Method Summary | |
---|---|
void |
add(ExternalPeerHandle handle)
Adds a handle to the local database. |
void |
add(ExternalPeerHandle[] handles)
Adds a bunch of handles handle to the local database. |
java.util.Iterator<ExternalPeerHandle> |
iterator()
Returns an iterator over the handles known to this client. |
static void |
main(java.lang.String[] argv)
Stress test. |
void |
refresh()
Refreshes the local database by recontacting the reference server. |
void |
remove(ExternalPeerHandle handle)
Removes a handle from the local database. |
SearchEngineHandle |
renewReferenceServer(SearchEngineHandle handle)
Changes this client's reference server. |
void |
run()
|
ExternalPeerHandle[] |
search()
Get 40 random handles from the cache. |
ExternalPeerHandle[] |
search(int k)
Get k random handles from the cache. |
ExternalPeerHandle |
search(java.lang.String id)
Searches for a handle in the local database. |
ExternalPeerHandle[] |
searchAll()
Returns a complete snapshot of the local database. |
void |
setOwnerPeer(ExternalPeerHandle owner_peer)
Sets this client's owner peer. |
int |
size()
Returns the number of entries currently in this cache. |
java.lang.String |
toString()
Returns a String representation of this client. |
java.lang.String |
toStringDetailed()
Returns a detailed (i.e. |
Methods inherited from class java.util.TimerTask |
---|
cancel, scheduledExecutionTime |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_SEARCH_COUNT
Method Detail |
---|
public void setOwnerPeer(ExternalPeerHandle owner_peer) throws GridException
Registering an owner is not a requirement to access the server's information, but the owner will then not be listed in the server's database.
Registering an owner can be done only once.
owner_peer
- The owner peer
GridException
- If this client already had an ownerpublic SearchEngineHandle renewReferenceServer(SearchEngineHandle handle) throws GridException
handle
- The new reference server
GridException
- if the new server is invalidpublic void refresh() throws GridException
GridException
public void add(ExternalPeerHandle handle)
You can expect log(n) times from this operation.
handle
- The peer handle to addpublic void add(ExternalPeerHandle[] handles)
You can expect log(n) times from this operation.
handles
- The peer handles to addpublic void remove(ExternalPeerHandle handle) throws GridException
handle
- The handle to remove
GridException
- if the handle is invalidpublic ExternalPeerHandle search(java.lang.String id) throws GridException
If the ID is currently known by the reference server, it is garanteed that this method won't return null, regardless of the current state of local database.
id
- The ID of the handle to search for
GridException
- if the ID is invalidpublic ExternalPeerHandle[] searchAll()
Don't mess with the returned array if you want consistent behaviour as it's always the same one that is returned as long as the database doesn't change
The array is not garanteed to be of the exact size of the database. If the array is larger, the first irrelevant element is set to null.
public ExternalPeerHandle[] search(int k) throws GridException
k
- The number of random handles
GridException
- if k > size()
public ExternalPeerHandle[] search() throws GridException
GridException
DEFAULT_SEARCH_COUNT
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringDetailed()
public java.util.Iterator<ExternalPeerHandle> iterator()
search()
is a costy but more reliable alternative.
iterator
in interface java.lang.Iterable
public void run()
run
in interface java.lang.Runnable
run
in class java.util.TimerTask
public static void main(java.lang.String[] argv) throws java.lang.Exception
Usage: java lbg.searchengine.SearchEngineClient NUM_HANDLES SAMPLES RATIO.
java.lang.Exception
|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.