|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.alien.enterpriseRFID.discovery.NetworkDiscoveryListenerService
NetworkDiscoveryListenerService
is the service that deals with
Alien Readers that are appearing and disappearing on the network. Each Alien
reader is configured by default to broadcast heartbeat messages over its local
subnet. These messages are UDP (User Datagram Protocol) packets containing
small XML documents which detail the reader's type, name, and contact information.
By listening for these heartbeat messages, the network discovery classes can
identify and report back details of readers that exist on the network.
Once the NetworkDiscoveryListenerService
class is instantiated
and started, it will run in its own thread until it is stopped. While running,
the object listens for reader heartbeats, calling either the readerAdded() or
readerRenewed() methods of a registered DiscoveryListener
when it
detects a reader. Part of the heartbeat sent out by the reader indicates the
time until the next heartbeat is expected. If this time expires before a new
heartbeat is received, then the NetworkDiscoveryListenerService
will assume the reader has gone offline and will call the readerRemoved() method.
At any time, the current list of online networked readers can be obtained by
calling the getDiscoveryItems()
method, which returns an array of
DiscoveryItem
s.
Field Summary | |
static int |
DEFAULT_LISTENER_PORT
The default port on which this service will listen for reader heartbeats, if no port is specified when the service is created. |
static int |
DEFAULT_LISTENER_TIMEOUT_SECONDS
The default timeout value for opening up the socket to receive reader heartbeat messages on. |
boolean |
isDebug
|
Constructor Summary | |
NetworkDiscoveryListenerService()
Creates a new NetworkDiscoveryListenerService, using the default port number. |
|
NetworkDiscoveryListenerService(int listenerPort)
Creates a new NetworkDiscoveryListenerService, using the specified port number. |
Method Summary | |
void |
allDiscoveryItemsExpired()
|
void |
discoveryItemExpired(DiscoveryItem discoveryItem)
Removes a DiscoveryItem from the hashtable, and notifies listeners. |
DiscoveryItem[] |
getDiscoveryItems()
Returns an array of DiscoveryItem s representing all of the readers
that this NetworkDiscoveryListenerService knows about. |
DiscoveryListener |
getDiscoveryListener()
Returns the object that has been registered by this NetworkDiscoveryListenerService
to receive messages when readers are discovered, renewed, or removed from the
network. |
int |
getListenerPort()
Returns the port number for this service to listen on. |
boolean |
isRunning()
Returns true if this NetworkDiscoveryListenerService
is running, and false if it is not. |
void |
run()
Reads heartbeat messages off the UDP port, and handle the data received. |
void |
setDiscoveryListener(DiscoveryListener discoveryListener)
Registers an object with this NetworkDiscoveryListenerService
to receive messages when readers are discovered, renewed, or removed from the
network. |
void |
setListenerPort(int listenerPort)
Sets the port number for this service to listen on. |
void |
startService()
Starts up this NetworkDiscoveryListenerService . |
void |
startService(boolean doPing)
Starts up this NetworkDiscoveryListenerService . |
void |
stopService()
Stops this NetworkDiscoveryListenerService . |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_LISTENER_PORT
public static final int DEFAULT_LISTENER_TIMEOUT_SECONDS
public boolean isDebug
Constructor Detail |
public NetworkDiscoveryListenerService()
public NetworkDiscoveryListenerService(int listenerPort)
set HeartbeatPort
command.
listenerPort
- the port number to listen for heartbeat messages onMethod Detail |
public DiscoveryListener getDiscoveryListener()
NetworkDiscoveryListenerService
to receive messages when readers are discovered, renewed, or removed from the
network. Registered listeners must implement the DiscoveryListener
interface.
public void setDiscoveryListener(DiscoveryListener discoveryListener)
NetworkDiscoveryListenerService
to receive messages when readers are discovered, renewed, or removed from the
network. Registered listeners must implement the DiscoveryListener
interface.
discoveryListener
- the listening objectpublic void startService() throws AlienDiscoverySocketException
NetworkDiscoveryListenerService
. This service will
continue to run on its own thread until its stopService()
method is
called.
This invocation automatically sends out a UDP "heartbeat ping" packet
that newer readers can respond to with an immediate heartbeat, which improves
discovery time. If you do not wish for this extra packet to be sent, use
startService(boolean doPing)
instead.
AlienDiscoverySocketException
- if a socket can not be openedpublic void startService(boolean doPing) throws AlienDiscoverySocketException
NetworkDiscoveryListenerService
. This service will
continue to run on its own thread until its stopService()
method is
called.
The service will optionally send out a UDP "heartbeat ping" packet, depending on the doPing argument. Newer readers can respond to this extra ping packet with an immediate heartbeat, which improves discovery time.
AlienDiscoverySocketException
- if a socket can not be openedpublic void stopService()
NetworkDiscoveryListenerService
.
public void run()
run
in interface java.lang.Runnable
public boolean isRunning()
true
if this NetworkDiscoveryListenerService
is running, and false
if it is not.
public void discoveryItemExpired(DiscoveryItem discoveryItem)
DiscoveryItem
from the hashtable, and notifies listeners.
This method is public so that external sources can cancel leases...
for example if an external source tries to connect and fails, it can cancel
the lease that way.
discoveryItem
- the item that has expiredpublic void allDiscoveryItemsExpired()
public DiscoveryItem[] getDiscoveryItems()
DiscoveryItem
s representing all of the readers
that this NetworkDiscoveryListenerService
knows about. Items that
were discovered by a SerialDiscoveryListenerService
are not
included in this list.
DiscoveryItems
public int getListenerPort()
public void setListenerPort(int listenerPort)
listenerPort
- the new port number to listen on.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |