public class P2PDictionary
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.Object>
Constructor and Description |
---|
P2PDictionary(java.lang.String description,
int port,
java.lang.String ns,
P2PDictionaryServerMode serverMode,
P2PDictionaryClientMode clientMode,
int searchForClientsTimespan)
Creates a dictionary object.
|
P2PDictionary(java.lang.String description,
int port,
java.lang.String ns,
P2PDictionaryServerMode serverMode,
P2PDictionaryClientMode clientMode,
int searchForClientsTimespan,
com.rhfung.P2PDictionary.IDictionaryCallback cb)
Creates a dictionary object.
|
Modifier and Type | Method and Description |
---|---|
void |
abort() |
void |
clear()
Removes all keys that are currently owned by this peer.
|
void |
close() |
boolean |
ConstructNetwork()
Searches for peers on the network using Apple Bonjour
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsKey(java.lang.String key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet() |
static int |
findFreePort(int basePort) |
java.lang.Object |
get(java.lang.Object key) |
java.lang.Object |
get(java.lang.String key) |
java.util.List<EndPointMetadata> |
getActiveEndPoints() |
java.util.List<com.rhfung.P2PDictionary.EndpointInfo> |
getAllEndPoints()
Returns a list of all known endpoints.
|
java.io.PrintStream |
getDebugBuffer() |
java.lang.String |
getDefaultKey()
Returns the default key for the web interface's root resource (/).
|
java.lang.String |
getDescription()
Describes the user-friendly name of this P2P client for web browser requests.
|
java.lang.String |
getFullKey(java.lang.String userKey) |
EndPoint |
getLocalEndPoint()
Returns the IP address of the server.
|
int |
getLocalID()
Returns a unique ID number for the dictionary.
|
java.lang.String |
getNamespace()
Name of the dictionary partition.
|
com.rhfung.P2PDictionary.Subscription |
getSubscriptions() |
java.lang.Object |
getTag()
User-defined tag.
|
java.lang.Object |
getWithTimeout(java.lang.String key,
int msTimeout)
Blocking call to read from the dictionary, throws IndexOutOfRangeException
|
boolean |
isConnected(int uniqueID)
Returns true if the dictionary with uniqueID is connected directly to this dictionary.
|
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
void |
onAddedSubscription(com.rhfung.P2PDictionary.Subscription s,
java.lang.String wildcardString,
SubscriptionInitiator initiator)
Should not be called by client.
|
int |
onBroadcastToWire(com.rhfung.P2PDictionary.SendBroadcastMemory msg)
Should not be called by client.
|
void |
onConnected(com.rhfung.P2PDictionary.DataConnection conn)
Should not be called by client.
|
void |
onDisconnected(com.rhfung.P2PDictionary.DataConnection conn)
Should not be called by client.
|
void |
onNotified(NotificationEventArgs args)
Should not be called by client.
|
int |
onPullFromPeer(com.rhfung.P2PDictionary.DataHeader header)
Should not be called by client.
|
int |
onPullFromPeer(java.util.List<com.rhfung.P2PDictionary.DataHeader> headers)
Should not be called by client.
|
void |
onRemovedSubscription(com.rhfung.P2PDictionary.Subscription s,
java.lang.String wildcardString)
Should not be called by client.
|
int |
onSendToPeer(java.util.List<com.rhfung.P2PDictionary.SendMemoryToPeer> message)
Should not be called by client.
|
int |
onSendToPeer(com.rhfung.P2PDictionary.SendMemoryToPeer message)
Should not be called by client.
|
void |
onSubscriptionChanged(SubscriptionEventArgs args)
Should not be called by client.
|
boolean |
OpenClient(java.net.InetAddress addr,
int port)
Manually connect to another peer.
|
void |
openServer(java.net.InetAddress addr,
int port)
Opens a server and binds to the specific port.
|
void |
openServer(int port)
Opens a server and binds to all interfaces.
|
java.lang.Object |
put(java.lang.String key,
java.lang.Object value) |
void |
putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m) |
java.lang.Object |
remove(java.lang.Object key) |
java.lang.Object |
remove(java.lang.String key)
Removes a dictionary entry
|
void |
removeSubscription(java.lang.String regularExpression)
removes a previously subscription that matches the pattern.
|
void |
setCallback(com.rhfung.P2PDictionary.IDictionaryCallback newCallback)
Sets a callback.
|
void |
setDebugBuffer(java.io.PrintStream debugBuffer)
Configures logging with only important messages.
|
void |
setDebugBuffer(java.io.PrintStream writer,
int level,
boolean autoFlush)
Configures logging.
|
void |
setDefaultKey(java.lang.String key)
When the web interface's root key is called, the value for the following
key is returned instead.
|
void |
setTag(java.lang.Object tag)
User-defined tag.
|
int |
size()
Returns number of dictionary entries including non-subscribed entries
|
java.lang.Object |
tryGetValue(java.lang.String key,
int msTimeout,
java.lang.Object defaultValue)
Blocking call to read from the dictionary, waits for msTimeout, returns false if cannot get the value
|
java.util.Collection<java.lang.Object> |
values() |
public P2PDictionary(java.lang.String description, int port, java.lang.String ns, P2PDictionaryServerMode serverMode, P2PDictionaryClientMode clientMode, int searchForClientsTimespan)
description
- User-friendly description of the dictionary to appear on its websiteport
- Port for binding a serverns
- Namespace of the dictionary, must be IDENTICAL between all connected peers.serverMode
- Can start the server on constructor or OpenServer, or not at all. Can open start server once.clientMode
- Determines if other dictionary peers are connected automatically using searchForClientsTimespansearchForClientsTimespan
- time in millisecondspublic P2PDictionary(java.lang.String description, int port, java.lang.String ns, P2PDictionaryServerMode serverMode, P2PDictionaryClientMode clientMode, int searchForClientsTimespan, com.rhfung.P2PDictionary.IDictionaryCallback cb)
description
- User-friendly description of the dictionary to appear on its websiteport
- Port for binding a serverns
- Namespace of the dictionary, must be IDENTICAL between all connected peers.serverMode
- Can start the server on constructor or OpenServer, or not at all. Can open start server once.clientMode
- Determines if other dictionary peers are connected automatically using searchForClientsTimespansearchForClientsTimespan
- time in millisecondscb
- Callback object to handle callbacks from the dictionary on alternate threadspublic void setCallback(com.rhfung.P2PDictionary.IDictionaryCallback newCallback)
callback
- null or objectpublic int getLocalID()
public java.lang.String getNamespace()
public java.io.PrintStream getDebugBuffer()
public void setDebugBuffer(java.io.PrintStream debugBuffer)
debugBuffer
- null to disablepublic void setDebugBuffer(java.io.PrintStream writer, int level, boolean autoFlush)
writer
- null to disablelevel
- 0 = all in/out messages, 1 = connection messages onlyautoFlush
- flush writer stream after every log messagepublic java.lang.String getDescription()
public EndPoint getLocalEndPoint()
public void setDefaultKey(java.lang.String key)
empty
- string to use the default homepage; null to disable homepagepublic java.lang.String getDefaultKey()
public boolean containsKey(java.lang.String key)
public java.lang.Object getWithTimeout(java.lang.String key, int msTimeout) throws SubscriptionException
key
- msTimeout
- SubscriptionException
public java.lang.Object tryGetValue(java.lang.String key, int msTimeout, java.lang.Object defaultValue)
key
- msTimeout
- timeout in millisecondsdefaultValue
- returns this value if not able to get the key from the dictionarypublic java.lang.Object get(java.lang.String key) throws SubscriptionException
key
- Unique string, cannot contain regular expression control characters.SubscriptionException
- if the key is not subscribed previously (or added with put)public java.lang.Object put(java.lang.String key, java.lang.Object value)
put
in interface java.util.Map<java.lang.String,java.lang.Object>
key
- Unique string, cannot contain regular expression control characters.value
- public void clear()
clear
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object remove(java.lang.String key)
key
- public int size()
size
in interface java.util.Map<java.lang.String,java.lang.Object>
public void openServer(int port) throws NotSupportedException, java.io.IOException
port
- open port numberNotSupportedException
java.io.IOException
public void openServer(java.net.InetAddress addr, int port) throws NotSupportedException, java.io.IOException
addr
- server interface to bind toport
- port number to listenNotSupportedException
java.io.IOException
public void abort()
public void close()
public boolean OpenClient(java.net.InetAddress addr, int port)
addr
- port
- public int onBroadcastToWire(com.rhfung.P2PDictionary.SendBroadcastMemory msg)
public int onPullFromPeer(com.rhfung.P2PDictionary.DataHeader header)
public int onPullFromPeer(java.util.List<com.rhfung.P2PDictionary.DataHeader> headers)
public int onSendToPeer(com.rhfung.P2PDictionary.SendMemoryToPeer message)
public int onSendToPeer(java.util.List<com.rhfung.P2PDictionary.SendMemoryToPeer> message)
public void removeSubscription(java.lang.String regularExpression)
regularExpression
- The exact string that was added to the subscription.public com.rhfung.P2PDictionary.Subscription getSubscriptions()
public void onAddedSubscription(com.rhfung.P2PDictionary.Subscription s, java.lang.String wildcardString, SubscriptionInitiator initiator)
public void onRemovedSubscription(com.rhfung.P2PDictionary.Subscription s, java.lang.String wildcardString)
public boolean ConstructNetwork()
public java.lang.Object getTag()
public void setTag(java.lang.Object tag)
tag
- public static int findFreePort(int basePort)
public void onNotified(NotificationEventArgs args)
public void onSubscriptionChanged(SubscriptionEventArgs args)
public java.util.List<EndPointMetadata> getActiveEndPoints()
public boolean isConnected(int uniqueID)
public void onConnected(com.rhfung.P2PDictionary.DataConnection conn)
public void onDisconnected(com.rhfung.P2PDictionary.DataConnection conn)
public java.util.List<com.rhfung.P2PDictionary.EndpointInfo> getAllEndPoints()
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.String,java.lang.Object>
public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
putAll
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Set<java.lang.String> keySet()
keySet
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Collection<java.lang.Object> values()
values
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,java.lang.Object>
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.String getFullKey(java.lang.String userKey)