|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fulmine.AbstractLifeCycle fulmine.distribution.connection.tcp.TcpConnectionParameters fulmine.distribution.connection.tcp.AbstractSocketChannelConnection
public abstract class AbstractSocketChannelConnection
A SocketChannel
connection to a remote IFrameworkContext
instance. This uses the Java NIO framework.
Field Summary | |
---|---|
protected boolean |
destroyWhenMessagesProcessed
A flag to inform the MessageConsumedEventHandler that the
connection should be destroyed when all messages have been consumed. |
protected IEventSource |
eventSourceDelegate
The delegate for the IEventSource operations of this |
protected int |
messagesToProcess
Tracks the number of messages received and not yet processed. |
Constructor Summary | |
---|---|
AbstractSocketChannelConnection(IFrameworkContext context,
String identity,
String address,
int port,
int connectionHashCode)
Standard constructor for the parameters of the connection. |
Method Summary | |
---|---|
void |
addEvent(IEvent event)
Add the event to the source and notify any registered IEventListener instances with the event. |
boolean |
addListener(IEventListener listener)
Add the listener to the end of the list of listeners registered against this. |
protected void |
connectionHandshakeComplete()
This method is called when all relevant details of the connection have been established. |
protected void |
doComponentDestroy()
|
protected void |
doDestroy()
Destroy the internal TCP I/O components. |
protected void |
doStart()
Overridden in subclasses to perform custom logic on activation. |
protected IFrameworkContext |
getContext()
|
byte |
getEventSourceGroupId()
A byte identifying the event source group id. |
List<IEventListener> |
getListeners()
Get the list of IEventListener instances observing this. |
protected SocketChannel |
getSocketChannel()
|
boolean |
isConnected()
|
protected boolean |
isConnectionHandshakeComplete()
Determine if the application level connection handshake has been established. |
boolean |
isOutbound()
Indicates the connecting direction. |
boolean |
removeListener(IEventListener listener)
Remove the listener from the list of listeners registered against this. |
List<IEventListener> |
removeListeners()
Remove all listeners registered for receiving IEvent events
originating from this. |
String |
toDetailedString()
Provides a formatted string describing this object in detail. |
String |
toIdentityString()
Get a string that provides the identification for this object. |
String |
toString()
|
Methods inherited from class fulmine.distribution.connection.tcp.TcpConnectionParameters |
---|
equals, getAddress, getDomain, getIdentity, getRemoteContextHashCode, getRemoteContextIdentity, getRemoteHostAddress, getRemoteHostTcpPort, getType, hashCode, isEqual, setIdentity, setRemoteContextHashCode |
Methods inherited from class fulmine.AbstractLifeCycle |
---|
checkActive, destroy, finalize, getLog, isActive, start |
Methods inherited from class java.lang.Object |
---|
clone, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fulmine.distribution.connection.IConnection |
---|
send |
Methods inherited from interface fulmine.ILifeCycle |
---|
isActive, start |
Methods inherited from interface fulmine.IDestroyable |
---|
destroy |
Methods inherited from interface fulmine.IAddressable |
---|
getAddress, getDomain, getIdentity, getType |
Methods inherited from interface fulmine.distribution.connection.IConnectionParameters |
---|
getRemoteContextHashCode, getRemoteContextIdentity, isEqual |
Field Detail |
---|
protected IEventSource eventSourceDelegate
IEventSource
operations of this
protected volatile boolean destroyWhenMessagesProcessed
MessageConsumedEventHandler
that the
connection should be destroyed when all messages have been consumed.
messagesToProcess
protected int messagesToProcess
MessageConsumedEvent
is raised that is
intercepted by the MessageConsumedEventHandler
which decrements
this.
Access must be synchronized on the
AbstractSocketChannelConnection
instance.
Constructor Detail |
---|
public AbstractSocketChannelConnection(IFrameworkContext context, String identity, String address, int port, int connectionHashCode)
context
- the context this connection servicesidentity
- the connection identityaddress
- the IP address or resolvable host name of the remote contextport
- the port for the socket connection to the remote contextconnectionHashCode
- the hashcode of the connection to the remote context
IllegalStateException
- if the socket could not be constructedMethod Detail |
---|
protected void doComponentDestroy()
protected IFrameworkContext getContext()
protected void doStart()
AbstractLifeCycle
RuntimeException
or subclass
thereof. When this method is called, the AbstractLifeCycle.isActive()
method will
return true
.
doStart
in class TcpConnectionParameters
public boolean isConnected()
public boolean isOutbound()
isOutbound
in interface IConnection
true
if this socket connects to a server socket,
false
if it was an inbound connection from another
contextprotected void doDestroy()
doDestroy
in class TcpConnectionParameters
public void addEvent(IEvent event)
IEventSource
IEventListener
instances with the event. The manner of activating
listeners with the event may be synchronous or asynchronous; it is the
implementation that decides this.
addEvent
in interface IEventSource
event
- the event to pass on to the registered listenerspublic boolean addListener(IEventListener listener)
IEventSource
IPriorityEventListener
, it is added
to the beginning of the list.
Listeners are reference counted. Adding the same listener multiple times simply increments a reference count of the listener instance; if a listener is added twice, it must be removed twice for the listener instance reference to be removed from the internal list.
addListener
in interface IEventSource
listener
- the listener to add
true
if the listener instance was added (there were
no reference counts for it), false
if it already
existed (the reference count was incremented)public byte getEventSourceGroupId()
IEventSource
EventProcessor
that will distribute the events from this source.
getEventSourceGroupId
in interface IEventSource
EventProcessor
servicing this.public List<IEventListener> getListeners()
IEventSource
IEventListener
instances observing this. The list
is the order of registration and the notification order for any
IEvent
raised by this event source.
The list is not modifiable.
getListeners
in interface IEventSource
null
if
there are no listenerspublic boolean removeListener(IEventListener listener)
IEventSource
null
.
Listeners are reference counted. When removing a listener, this method decrements the reference count until there are no more references, at which point the listener instance reference is actually removed.
removeListener
in interface IEventSource
listener
- the listener to remove
true
if the listener was found and the reference
count was 0 and it was removed, false
otherwisepublic List<IEventListener> removeListeners()
IEventSource
IEvent
events
originating from this.
removeListeners
in interface IEventSource
public String toDetailedString()
IDescriptor
Object.toString()
method.
toDetailedString
in interface IDescriptor
public String toIdentityString()
IDescriptor
Object.toString()
method.
toIdentityString
in interface IDescriptor
protected SocketChannel getSocketChannel()
protected boolean isConnectionHandshakeComplete()
Each context marks its end of the connection as established as per the following;
true
if the connection handshake has been completed
and the details about the remote context are known.protected void connectionHandshakeComplete()
isConnectionHandshakeComplete()
public String toString()
toString
in class TcpConnectionParameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |