|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfulmine.AbstractLifeCycle
fulmine.distribution.connection.AbstractConnectionDiscoverer
public abstract class AbstractConnectionDiscoverer
A base-class for IConnectionDiscoverer instances. The implementation
uses a UDP discovery process.
This discoverer sends out a heartbeat pulse message at a period specified by
the heartbeatPeriod variable. This period can be changed dynamically
at runtime using setNetworkHeartbeatPeriod(long). The pulse message
encapsulates the parameters to make a connection to this local context. Once
a pulse message is received by a remote context, the heartbeat pulses are
expected periodically by the remote context. The expected period for
receiving heartbeat pulses is determined by the remote context; it equals the
remote context's heartbeat period multiplied by an allowed heartbeat miss
counter. The count of missed heartbeats can also be set dynamically at
runtime using setAllowableNetworkHeartbeatMissCount(int). This
mechanism allows for a difference in the heartbeat periods between contexts
but with a certain tolerance.
The following events are raised by this:
ContextDiscoveredEvent when a new heartbeat pulse is received.
ContextNotAvailableEvent when the heartbeat pulse from a
previously found context is not received for more than the allowed number of
missed pulses multiplied by this discoverer's heartbeat period
The discoverer uses an IContextWatchdog component to determine if
heartbeat pulses should be sent out. The IContextWatchdog component
is also informed if the discoverer encounters any delay between sending out
consecutive pulses; this would generally indicate some form of CPU time
starvation for the heartbeat generator thread.
The parameters for the UDP network and port can be configured by setting
system properties UDP_DISCOVERY_NETWORK and
UDP_DISCOVERY_PORT.
These have defaults of
DEFAULT_UDP_DISCOVERY_NETWORK and
DEFAULT_UDP_DISCOVERY_PORT respectively. The network interface to bind to
can be specified using the system property
NETWORK_INTERFACE_NAME. This must specify the name of the NIC to bind to.
| Field Summary | |
|---|---|
static int |
DEFAULT_DUPLICATE_PING_WINDOW
The default time window to use to ignore duplicate pulse messages; 5sec |
static String |
DEFAULT_UDP_DISCOVERY_NETWORK
The default UDP multicast network for discovery |
static String |
DEFAULT_UDP_DISCOVERY_PORT
The default UDP multicast port for discovery |
protected String |
description
The string description |
protected fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatGenerator |
heartbeatGenerator
Handles sending out heartbeats and listening for heartbeats from other contexts |
protected Thread |
heartbeatGeneratorThread
The thread running the heartbeatGenerator |
protected fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatListener |
heartbeatListener
Listens for heartbeats messages from other contexts |
protected Thread |
heartbeatListenerThread
The thread running the heartbeatListener |
protected fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatProcessor |
heartbeatProcessor
Processes heartbeats from other contexts |
protected Thread |
heartbeatProcessorThread
The thread running the heartbeatProcessor |
protected InetAddress |
network
The UDP discovery network |
static String |
NETWORK_INTERFACE_NAME
The system property to use to set the NIC. |
protected int |
port
The UDP discovery port |
protected String |
pulse
The pulse message this context sends out. |
protected MulticastSocket |
socket
The multicast socket to use for discovering other connections |
static String |
UDP_DISCOVERY_NETWORK
The system property to override the default UDP multicast network for discovery. |
static String |
UDP_DISCOVERY_PORT
The system property to override the default UDP multicast port for discovery. |
| Fields inherited from interface fulmine.distribution.IHeartbeatMonitor |
|---|
DEFAULT_ALLOWED_MISSED_COUNT, DEFAULT_HEARTBEAT_PERIOD |
| Constructor Summary | |
|---|---|
AbstractConnectionDiscoverer(IFrameworkContext context)
Constructor that retrieves network values from system properties or use default values if no system properties are set. |
|
AbstractConnectionDiscoverer(IFrameworkContext context,
String udpNetwork,
int udpPort,
String udpNic)
Constructor that uses parameters for the network values. |
|
| Method Summary | |
|---|---|
void |
connectionDestroyed(String remoteContextIdentity)
This removes the connection details in the ConnectionDestroyedEvent from the
current map of known connections. |
void |
disablePulsing()
Disable the discoverer from sending out pulses. |
protected void |
doDestroy()
Overridden in subclasses to perform custom logic on destruction. |
protected void |
doStart()
Overridden in subclasses to perform custom logic on activation. |
void |
enablePulsing()
Enable the discoverer to send out pulses. |
int |
getAllowableNetworkHeartbeatMissCount()
Get the number of allowed missed heartbeats before a remote context is deemed to be not available. |
protected abstract IConnectionParameters |
getConnectionParameters(String data)
Template method for sub-classes to provide the implementation of how to handle the 'pulse' message received from a peer IConnectionDiscoverer. |
protected AsyncLog |
getLog()
Get the log to use for the object hierarchy |
InetAddress |
getNetwork()
Get the UDP network for connection discovery |
long |
getNetworkHeartbeatPeriod()
Get the heartbeat period in milliseconds. |
int |
getPort()
Get the UDP port used for connection discovery |
protected abstract String |
getProtocolConnectionParameters()
Overridden by subclasses to provide the protocol specific parameters for connecting to the connection broker of this context. |
String |
getPulse()
Get the pulse message sent out to other IConnectionDiscoverer
instances over the discovery network |
MulticastSocket |
getSocket()
Get the multicast socket used for connection discovery |
protected boolean |
isPulseFromContext(String contextIdentity,
String pulseMessage)
Determine if the pulse message is from the named context |
protected boolean |
isPulsingEnabled()
|
void |
pulse()
Send out a pulse on the discovery network. |
protected void |
send(String msg)
Send the message to the multicast socket |
void |
setAllowableNetworkHeartbeatMissCount(int allowedHeartbeatMissCount)
Set the allowable number of missed heartbeats from other contexts on the network before that context is deemed to be not available anymore. |
void |
setNetworkHeartbeatPeriod(long periodInMillis)
Set the network heartbeat period. |
String |
toString()
|
| Methods inherited from class fulmine.AbstractLifeCycle |
|---|
checkActive, destroy, finalize, isActive, start |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface fulmine.distribution.connection.IConnectionDiscoverer |
|---|
start |
| Methods inherited from interface fulmine.ILifeCycle |
|---|
isActive |
| Methods inherited from interface fulmine.IDestroyable |
|---|
destroy |
| Field Detail |
|---|
public static final String UDP_DISCOVERY_NETWORK
DEFAULT_UDP_DISCOVERY_NETWORK,
Constant Field Valuespublic static final String DEFAULT_UDP_DISCOVERY_NETWORK
public static final String NETWORK_INTERFACE_NAME
public static final String UDP_DISCOVERY_PORT
DEFAULT_UDP_DISCOVERY_PORT,
Constant Field Valuespublic static final String DEFAULT_UDP_DISCOVERY_PORT
public static final int DEFAULT_DUPLICATE_PING_WINDOW
protected MulticastSocket socket
protected final fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatListener heartbeatListener
protected final Thread heartbeatListenerThread
heartbeatListener
protected final fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatProcessor heartbeatProcessor
protected final Thread heartbeatProcessorThread
heartbeatProcessor
protected final fulmine.distribution.connection.AbstractConnectionDiscoverer.HeartbeatGenerator heartbeatGenerator
protected final Thread heartbeatGeneratorThread
heartbeatGenerator
protected String pulse
protected final int port
protected final InetAddress network
protected String description
| Constructor Detail |
|---|
public AbstractConnectionDiscoverer(IFrameworkContext context)
context - the local context
public AbstractConnectionDiscoverer(IFrameworkContext context,
String udpNetwork,
int udpPort,
String udpNic)
context - the local contextudpNetwork - the UDP networkudpPort - the UDP portudpNic - the network interface card name to bind to, null
for default| Method Detail |
|---|
public final int getPort()
public final InetAddress getNetwork()
public final MulticastSocket getSocket()
public final String getPulse()
IConnectionDiscoverer
instances over the discovery network
public final void connectionDestroyed(String remoteContextIdentity)
ConnectionDestroyedEvent from the
current map of known connections.
connectionDestroyed in interface IConnectionDiscovererremoteContextIdentity - the remote context that has had a connection destroyedpublic final long getNetworkHeartbeatPeriod()
IHeartbeatMonitor
getNetworkHeartbeatPeriod in interface IHeartbeatMonitorpublic final int getAllowableNetworkHeartbeatMissCount()
IHeartbeatMonitor
getAllowableNetworkHeartbeatMissCount in interface IHeartbeatMonitorpublic final void setAllowableNetworkHeartbeatMissCount(int allowedHeartbeatMissCount)
IHeartbeatMonitor
setAllowableNetworkHeartbeatMissCount in interface IHeartbeatMonitorallowedHeartbeatMissCount - the number of missed heartbeats allowed before a remote
context is deemed to be not availableIHeartbeatMonitor.setNetworkHeartbeatPeriod(long)public final void setNetworkHeartbeatPeriod(long periodInMillis)
IHeartbeatMonitorAs a general rule-of-thumb, the heartbeat period should be small and the allowed heartbeat miss count high. This provides more leniency for not cancelling a context if heartbeats are missed.
setNetworkHeartbeatPeriod in interface IHeartbeatMonitorperiodInMillis - the heartbeat period in millisecondspublic void disablePulsing()
IConnectionDiscovererIConnectionDiscoverer instances from their pulses,
it just will not send out any pulses for itself; effectively it is in
listening-only mode.
disablePulsing in interface IConnectionDiscovererpublic void enablePulsing()
IConnectionDiscovererIConnectionDiscoverer.start() sets the discoverer in this mode unless
IConnectionDiscoverer.disablePulsing() is called before IConnectionDiscoverer.start().
enablePulsing in interface IConnectionDiscovererprotected final void doDestroy()
AbstractLifeCycleRuntimeException or subclass
thereof.
doDestroy in class AbstractLifeCycleprotected void doStart()
AbstractLifeCycleRuntimeException or subclass
thereof. When this method is called, the AbstractLifeCycle.isActive() method will
return true.
doStart in class AbstractLifeCycle
protected boolean isPulseFromContext(String contextIdentity,
String pulseMessage)
contextIdentity - the context to compare against the pulse messagepulseMessage - the pulse message
true if the pulse message is from the identified
contextprotected void send(String msg)
msg - public String toString()
toString in class AbstractLifeCycleprotected AsyncLog getLog()
AbstractLifeCycle
getLog in class AbstractLifeCyclepublic final void pulse()
IConnectionDiscovererIConnectionDiscoverer instances on the same network to detect
this one.
pulse in interface IConnectionDiscovererprotected abstract IConnectionParameters getConnectionParameters(String data)
IConnectionDiscoverer. This method inspects the data string and
creates an appropriate IConnectionParameters instance
representing it.
data - the pulse message from a peer IConnectionDiscoverer
IConnectionParameters extracted from the pulse
message or null if the message could not be
deciphered.protected boolean isPulsingEnabled()
protected abstract String getProtocolConnectionParameters()
ProtocolMessageConstants.DELIMITER. There is
no need to prepend the delimiter.
ProtocolMessageConstants.DELIMITER
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||