|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mirrormap.collections.NotifyingMap<K,V> mirrormap.MirrorMap<K,V>
K
- The key type for the mapV
- The value type for the mappublic class MirrorMap<K extends Serializable,V extends Serializable>
MirrorMap is a replicating Java map implementation. Its key features are:
MirrorMap is built on top of a NotifyingMap
; this is a Map
implementation that has the ability to notify observer objects when map
entries are added, updated or removed. The operations to the map are further
categorised into a 'before' and 'after' events e.g. when adding an entry to a
NotifyingMap, observers receive a 'will add' notification, the entry is
added, then the observers receive a 'did add' notification. A similar for
pattern follows for update and remove operations.
Logically, replication is peer-to-peer. Physically, all peer communication is done using a server component. The server holds the master copy of the named MirrorMap. New peers register with the server for replication and will receive the full map image upon registration. The connection with the server is point-to-point using TCP; the server performs the fan out of changes to all peers.
MirrorMap is written using the Java NIO library. A mirror map has a single
I/O thread dealing with network communication. The mirror map server (
server(String, int)
) creates 2 threads; one to handle reading and
one to handle writing.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Method Summary | ||
---|---|---|
static boolean |
connect(MirrorMap<? extends Serializable,? extends Serializable> map,
String host,
int port)
Connects the passed in MirrorMap to the mirror map server
identified by the host and port. |
|
static
|
create(String name,
Map<Key,Value> data)
Create a MirrorMap identified by a unique name that wraps the
passed in Map . |
|
static boolean |
disconnect(MirrorMap<? extends Serializable,? extends Serializable> map)
Disconnects the passed in MirrorMap from the mirror map server. |
|
static
|
get(String name)
Get the MirrorMap identified by the name. |
|
IMirrorMapConnectionListener |
getConnectionListener()
Get the connection listener attached to this mirror map |
|
String |
getName()
The name of this instance |
|
static TcpServer |
server(String address,
int port)
Create a TcpServer with the corresponding server socket details. |
|
void |
setConnectionListener(IMirrorMapConnectionListener listener)
Set the IMirrorMapConnectionListener on this mirror map |
|
String |
toString()
|
Methods inherited from class mirrormap.collections.NotifyingMap |
---|
addListener, clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, removeListener, size, values |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static <Key extends Serializable,Value extends Serializable> MirrorMap<Key,Value> create(String name, Map<Key,Value> data)
MirrorMap
identified by a unique name that wraps the
passed in Map
. If the mirror map already exists, the current
instance is returned and nothing is done with the Map
argument.
Key
- Value
- name
- the name identifying the MirrorMap
data
- the underlying Map
for the MirrorMap
MirrorMap
or null
if there is none for
this namepublic static <Key extends Serializable,Value extends Serializable> MirrorMap<Key,Value> get(String name)
MirrorMap
identified by the name.
Key
- Value
- name
- the name identifying the MirrorMap
MirrorMap
or null
if there is none for
this namepublic static boolean connect(MirrorMap<? extends Serializable,? extends Serializable> map, String host, int port)
MirrorMap
to the mirror map server
identified by the host and port. After this method completes, the
instance will receive changes from remote instances and local updates
will be sent to the server for distribution to other instances.
map
- the map to connecthost
- the host or IP of the mirror map server to connect toport
- the port of the mirror map server to connect to
true
if the map was connected, false
otherwisepublic static boolean disconnect(MirrorMap<? extends Serializable,? extends Serializable> map)
MirrorMap
from the mirror map server.
After this method completes, the instance will no longer receive changes
from remote instances and local updates will no longer be sent to the
server for distribution to other instances.
map
- the instance to disconnect
true
if the map was disconnected, false
otherwisepublic static TcpServer server(String address, int port)
TcpServer
with the corresponding server socket details.
The returned server will be started.
address
- the IP address or host name for the server socketport
- the TCP port for the server socket
TcpServer
public String getName()
MirrorMap
public String toString()
toString
in class NotifyingMap<K extends Serializable,V extends Serializable>
public void setConnectionListener(IMirrorMapConnectionListener listener)
IMirrorMapConnectionListener
on this mirror map
listener
- the listener to setpublic IMirrorMapConnectionListener getConnectionListener()
IMirrorMapConnectionListener
attached to this
instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |