Package ca.odell.glazedlists.io
Class ListPeer
- java.lang.Object
-
- ca.odell.glazedlists.io.ListPeer
-
public class ListPeer extends java.lang.ObjectAListPeermanages the network resources for publishing and subscribing toNetworkLists.A
ListPeermust have itsstart()method complete successfully before it can be used topublish()andsubscribe()EventLists.When a
ListPeeris started, it listens for incoming connections on the specified port. When it is stopped, all activeNetworkLists aredisconnected, and the port is closed.To bring and individual
NetworkListonline or offline, use itsdisconnect()andconnect()methods.- Author:
- Jesse Wilson
-
-
Constructor Summary
Constructors Constructor Description ListPeer(int listenPort)Creates a new ListPeer that binds to the specified port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> NetworkList<E>publish(EventList<E> source, java.lang.String path, ByteCoder byteCoder)Publish the specified EventList with the specified name.voidstart()Starts the peer.voidstop()Stops the peer.NetworkListsubscribe(java.lang.String host, int port, java.lang.String path, ByteCoder byteCoder)Subscribe to the EventList with the specified name.
-
-
-
Method Detail
-
start
public void start() throws java.io.IOExceptionStarts the peer. This binds to the listen port and allows connections to be sent and received.- Throws:
java.io.IOException- if the listen port cannot be binded to. This will be due to the port being in use or as a consequence of insufficient privileges.
-
stop
public void stop()
Stops the peer. This disconnects all activeEventLists and releases the listen port.
-
publish
public <E> NetworkList<E> publish(EventList<E> source, java.lang.String path, ByteCoder byteCoder)
Publish the specified EventList with the specified name.- Parameters:
source- theEventListto publish. Each change to thisEventListwill be immediately published to all subscribers.path- the address that theEventListshall be published under. The path must start with a slash character. This must be unique among allEventLists published on thisListPeer.byteCoder- a helper that can convert the elements of theEventListinto binary network-transmittable form. Some general purposeByteCoders are available in theGlazedListsfactory class.- Returns:
- a simple decorator of the published
EventListwith additional methods to bring the list offline. This list is writable.
-
subscribe
public NetworkList subscribe(java.lang.String host, int port, java.lang.String path, ByteCoder byteCoder)
Subscribe to the EventList with the specified name.- Parameters:
host- the network hostname of the machine serving the original copy of the data of interest. Together with the port, this should map to a properInetSocketAddress.port- the port theEventListof interest is being published on.path- the address that theEventListis published under.byteCoder- a helper that can convert the binary data from the network into list elements for thisEventList. Some general purposeByteCoders are available in theGlazedListsfactory class.- Returns:
- the
EventListthat gets its data from the specified remote source. ThisEventListwill contain no data until the connection completes. This list is not writable.
-
-