Class NetworkList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.io.NetworkList<E>
-
- All Implemented Interfaces:
ListEventListener<E>
,EventList<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.EventListener
,java.util.List<E>
public final class NetworkList<E> extends TransformedList<E,E>
AnEventList
that is either published to the network or subscribed from the network. Since list elements must be transmitted over the network, eachNetworkList
requires aByteCoder
to convertObject
s to and from bytes.To instantiate a
NetworkList
, use thesubscribe()
andpublish()
methods of a startedListPeer
.NetworkList
s may be taken offline and brought back online with theconnect()
anddisconnect()
methods. This allows an application to use aNetworkList
in spite of an unreliable network connection.As a consequence of imperfect networks,
NetworkList
s may sometimes go offline on their own. Some causes of this include the server program shutting down or crashing, the local network connection becoming unavailable, or a problem with the physical link, such as an unplugged cable.NetworkList
s use a subset of HTTP/1.1 for transport, including chunked encoding. This protocol brings its own set of advantages:- HTTP is a standard well-understood protocol
- Clients may be served even if they are behind NAT or Firewalls
- The connection could be proxied by a standard HTTP proxy server, if necessary
- In theory, the served port could be shared with another HTTP daemon such as Tomcat
And HTTP brings some disadvantages also:
- A persistent connection must be held, even if updates are infrequent
- It cannot be differentiated from web traffic for analysis
Warning: The protocol used by this version of
NetworkList
will be incompatible with future versions. Eventually the protocol will be finalized but the current protocol is a work in progress.Warning: This class breaks the contract required by
List
. SeeEventList
for an example.EventList Overview Writable: yes Concurrency: Requires ReadWriteLock
for every access, even for single-threaded usePerformance: N/A Memory: O(N) Unit Tests: N/A Issues: N/A - Author:
- Jesse Wilson
-
-
Field Summary
-
Fields inherited from class ca.odell.glazedlists.TransformedList
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStatusListener(NetworkListStatusListener listener)
Registers the specified listener to receive events about the status of thisNetworkList
.void
connect()
Attempts to bring thisNetworkList
online.void
disconnect()
Attempts to take thisNetworkList
offline.void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.boolean
isConnected()
Returns true if this resource is on the network.boolean
isWritable()
Gets whether the sourceEventList
is writable via this API.void
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.void
removeStatusListener(NetworkListStatusListener listener)
Deregisters the specified listener from receiving events about the status of thisNetworkList
.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, getSourceIndex, remove, removeAll, retainAll, set, size
-
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
-
-
-
-
Method Detail
-
isWritable
public boolean isWritable()
Gets whether the sourceEventList
is writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritable
in classTransformedList<E,E>
-
listChanged
public void listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.
- Specified by:
listChanged
in interfaceListEventListener<E>
- Specified by:
listChanged
in classTransformedList<E,E>
- Parameters:
listChanges
- aListEvent
describing the changes to the list
-
isConnected
public boolean isConnected()
Returns true if this resource is on the network. For published lists, this requires that the list is being served. For subscribed lists, this requires that a connection to the server has been established.
-
connect
public void connect()
Attempts to bring thisNetworkList
online. When the connection attempt is successful (or when it fails), allResourceStatusListener
s will be notified.
-
disconnect
public void disconnect()
Attempts to take thisNetworkList
offline. When theNetworkList
is fully disconnected, allResourceStatusListener
s will be notified.
-
addStatusListener
public void addStatusListener(NetworkListStatusListener listener)
Registers the specified listener to receive events about the status of thisNetworkList
.
-
removeStatusListener
public void removeStatusListener(NetworkListStatusListener listener)
Deregisters the specified listener from receiving events about the status of thisNetworkList
.
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.A
TransformedList
will be garbage collected without a call toTransformedList.dispose()
, but not before its sourceEventList
is garbage collected. By callingTransformedList.dispose()
, you allow theTransformedList
to be garbage collected before its sourceEventList
. This is necessary for situations where aTransformedList
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on a
TransformedList
after it has been disposed.
-
-