|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.root.RootObject
com.neeve.link.LnkObject
com.neeve.link.LnkPeerEndpoint
public final class LnkPeerEndpoint
Peer endpoint class.
This class implements the ILnkPeerEndpoint
interface. Internally,
this class implements a portion that is common to all peer endpoint
implementations and a portion that is link type specific. The class abstracts
link type specific implementations via the ILnkPeerEndpointCore
interface. At endpoint creation time, link type specific implementations
wrap an instance of this class around the actual implementation and return
the wrapped class to the user as ILnkPeerEndpoint
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.neeve.link.ILnkPeerEndpoint |
---|
ILnkPeerEndpoint.AsynchronousFlushContext, ILnkPeerEndpoint.FlushContext, ILnkPeerEndpoint.State, ILnkPeerEndpoint.SynchronousBlockingFlushContext, ILnkPeerEndpoint.SynchronousNonBlockingFlushContext |
Field Summary |
---|
Fields inherited from interface com.neeve.link.ILnkEndpoint |
---|
IOFLAG_FLUSH_FORCE, IOFLAG_FLUSH_SUPPRESS, IOFLAG_IMMEDIATE_DISPATCH, IOFLAG_NO_ASYNC, LVFLAG_ALLOW_FLUSH_PENDING, LVFLAG_SUPPRESS_IMPLICT_CLOSE |
Methods inherited from class com.neeve.root.RootObject |
---|
getChecked, getThreaded, getTracer, setChecked, setTracer |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static ILnkPeerEndpoint create(RootConfig.ObjectConfig config, ILnkPeerEndpointCore pep, HashMap<String,Object> props, String type) throws ELnkException
config
- The object to use to configure the endpoint object.pep
- The wrapped endpoint implementation.props
- A property table used to configure the endpoint.type
- A string describing the link type. This is the value that
will be returned by the getType()
method.
ELnkException
- Thrown in case an error occurs while creating the
peer endpoint.public final void setAttachment(Object object)
ILnkPeerEndpoint.setAttachment(java.lang.Object)
setAttachment
in interface ILnkPeerEndpoint
public final Object getAttachment()
ILnkPeerEndpoint.getAttachment()
getAttachment
in interface ILnkPeerEndpoint
public String getName()
ILnkPeerEndpoint.getName()
getName
in interface ILnkPeerEndpoint
public String getNameInternal()
ILnkPeerEndpoint.getNameInternal()
getNameInternal
in interface ILnkPeerEndpoint
Each endpoint generates a unique name to identify itself. The internally
generated name is used as the name of the endpoint (returned by the
ILnkPeerEndpoint.getName()
method) in case the user does not override it (e.g. by
using the 'name' property in the link descriptor). This method returns
the internal name generated by the endpoint for itself. The name returned
by this method will be the same as the name returned by ILnkPeerEndpoint.getName()
in case the user has not overriden the endpoints internally generated
name.
public String getType()
ILnkPeerEndpoint.getType()
getType
in interface ILnkPeerEndpoint
This method returns the type of the link for this endpoint. This is only used for tracing and debugging purposes.
public short getLtp()
ILnkPeerEndpoint.getLtp()
getLtp
in interface ILnkPeerEndpoint
public final Date getWhenCreated()
ILnkPeerEndpoint.getWhenCreated()
getWhenCreated
in interface ILnkPeerEndpoint
public final ILnkPeerEndpoint.State getState()
ILnkPeerEndpoint.getState()
getState
in interface ILnkPeerEndpoint
public final long getNextSequenceNum()
ILnkPeerEndpoint.getNextSequenceNum()
getNextSequenceNum
in interface ILnkPeerEndpoint
public final ILnkPeerEndpoint.EventHandlerChain getHandlerChain()
ILnkPeerEndpoint.getHandlerChain()
getHandlerChain
in interface ILnkPeerEndpoint
public final boolean isGroupEndpoint()
ILnkPeerEndpoint.isGroupEndpoint()
isGroupEndpoint
in interface ILnkPeerEndpoint
Some link implementations connect to entities that manage communication groups. With such links, the user can join one or more communication groups and communicate with other members of the group. Groups are addressed using topics that are wildcard enabled hierarchical strings. The group communication semantics e.g. delivery reliability and ordering, membership management etc is defined by the link implementation.
public final boolean isRootEndpoint()
ILnkPeerEndpoint.isRootEndpoint()
isRootEndpoint
in interface ILnkPeerEndpoint
public final ILnkRootEndpoint getRootEndpoint()
ILnkPeerEndpoint.getRootEndpoint()
getRootEndpoint
in interface ILnkPeerEndpoint
public final boolean isReadOperational()
ILnkPeerEndpoint.isReadOperational()
isReadOperational
in interface ILnkPeerEndpoint
public final LnkContainer getContainer()
ILnkPeerEndpoint.getContainer()
getContainer
in interface ILnkPeerEndpoint
public final void setContainer(LnkContainer container) throws ELnkInvalidStateException, ELnkPrivateException, ELnkReadOperationalException, ELnkNotCompatibleException
ILnkPeerEndpoint.setContainer(com.neeve.link.LnkContainer)
setContainer
in interface ILnkPeerEndpoint
container
- The container to which this endpoint is to be moved.
The method will do nothing in case this specifies the container in
which the endpoint is currently in.
ELnkInvalidStateException
- Thrown in case the user is attempting
to migrate a failed, closing or closed endpoint.
ELnkPrivateException
- Thrown in case the user is attempting to
migrate a private endpoint.
ELnkReadOperationalException
- Thrown in case the user is attempting
to migrate a link whose read is operational.
ELnkNotCompatibleException
- Thrown in case the endpoint is not
compatible with the new container.
This method migrates an endpoint to a new container. The endpoint can only be migrated in case the endpoint is in a connected state, is not a private endpoint, the read not operational on the endpoint's link tree and the threading model of the endpoint's link tree is compatible with the new container.
public final int getEnqueuedSize() throws ELnkInvalidStateException
ILnkPeerEndpoint.getEnqueuedSize()
getEnqueuedSize
in interface ILnkPeerEndpoint
ELnkInvalidStateException
- Thrown in case the user is attempting
to get the enqueued packet size in a failed or closed endpoint.public final boolean isJoined(short ltp)
ILnkPeerEndpoint.isJoined(short)
isJoined
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user for which to perform the check.
An caller should specify -1 or the LTP returned by the ILnkPeerEndpoint.getLtp()
method to indicate an end user.ILnkPeerEndpoint.join(short, com.neeve.link.ILnkEventHandler)
,
ILnkPeerEndpoint.leave(short, int)
public final void join(short ltp, ILnkEventHandler handler) throws ELnkInvalidStateException, ELnkAlreadyJoinedException, ELnkMaxUsersReachedException
ILnkPeerEndpoint.join(short, com.neeve.link.ILnkEventHandler)
join
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user that is joining the endpoint.
An end user should specify either -1 or the LTP returned by the
ILnkPeerEndpoint.getLtp()
method in this parameter.handler
- The event handler to be associated with the joining
user. Each event that is dispatched by an endpoint is targeted towards
one or more endpoint nodes in the link tree to which the source endpoint
belongs. The handler through which an event is to be dispatched is
determined by the LTP of the endpoint node to which the event is
targeted. The mechanism by which events are mapped to their recipients
is event type specific. For example, packet event recipients are
determined via the LTP present in a packet while flush completion
events are dispatched to endpoints that have issued enque or flush
requests that resulted in incomplete flushes with the flush scheduled
for asynchronous completion. Refer to event type documentation for
how the receipients for events of a particular type is determined.
ELnkInvalidStateException
- Thrown in case the user is attempting
to join a failed, closing or closed endpoint.
ELnkAlreadyJoinedException
- Thrown in case a user with the
specified LTP has already joined the endpoint.
ELnkMaxUsersReachedException
- Thrown in case the maximum number
of configured users for the link has already been reached. Default is
LnkLTPAuthority.MAX_LTP
+ 1.
This method is used by a user of a peer endpoint to register itself with
the endpoint. Once the user is registered, it can send packets through
the endpoint via the ILnkPeerEndpoint.enque(short, com.neeve.pkt.PktPacket, com.neeve.link.ILnkPeerEndpoint.FlushContext, int)
and ILnkPeerEndpoint.flush(short, com.neeve.link.ILnkPeerEndpoint.FlushContext)
methods and to
receive packets and other events from the endpoint through the handler
specified in handler parameter. When an event is dispatched by
the endpoint (including packet events), the endpoint determines the
event's recipient endpoint(s) using an event type specific mechanism.
The event is then dispatched through the registered event handlers
corresponding to the LTPs of the event receipient(s). In case no event
handler is found, the event is dropped.
An end user should specify an LTP of -1 (indicating 'this' endpoint) or
the value obtained from the ILnkPeerEndpoint.getLtp()
method. A layered endpoint
user should specify its own LTP when invoking this method.
ILnkPeerEndpoint.isJoined(short)
,
ILnkPeerEndpoint.leave(short, int)
public final void leave(short ltp, int flags) throws ELnkInvalidStateException, ELnkFlushInProgressException, ELnkNotJoinedException, ELnkOpFailedException
ILnkPeerEndpoint.leave(short, int)
leave
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user that is leaving the endpoint.
An end user should specify either -1 or the LTP returned by the
ILnkPeerEndpoint.getLtp()
method in this parameter.flags
- Flags used to qualify the leave operation. The following
flags are permissible for use here:ILnkEndpoint.LVFLAG_ALLOW_FLUSH_PENDING
ILnkEndpoint.LVFLAG_SUPPRESS_IMPLICT_CLOSE
ELnkInvalidStateException
- Thrown in case the user is attempting
to leave a closed endpoint.
ELnkFlushInProgressException
- Thrown in case there is a flush
currently in progress that is pending async completion. This exception
will not be thrown if ILnkEndpoint.LVFLAG_ALLOW_FLUSH_PENDING
is specified in the flags parameter.
ELnkNotJoinedException
- Thrown in case the user with the specified
LTP has not joined the endpoint.
ELnkOpFailedException
- Thrown in case the leave resulted in a
close being invoked and there was an exception encountered during the
close operation.
This method is used by a user of an endpoint to deregister itself from
the endpoint. If the leave results in all users having left the endpoint,
this method issues an implicit close on the endpoint unless instructed
not to do so via the flags. See ILnkPeerEndpoint.close(short)
for details on
the close operation.
An end user should specify an LTP of -1 (indicating 'this' endpoint) or
the value obtained from the ILnkPeerEndpoint.getLtp()
method. A layered endpoint
should specify its own LTP when invoking this method.
ILnkPeerEndpoint.join(short, com.neeve.link.ILnkEventHandler)
,
ILnkPeerEndpoint.close(short)
public final boolean enque(short ltp, PktPacket packet, ILnkPeerEndpoint.FlushContext flushContext, int flags) throws ELnkInvalidStateException, ELnkNotOwnerException, ELnkNotJoinedException, ELnkFlushInProgressException, ELnkOpFailedException
ILnkPeerEndpoint.enque(short, com.neeve.pkt.PktPacket, com.neeve.link.ILnkPeerEndpoint.FlushContext, int)
enque
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user that is issuing the enque.
This parameter is only used in case (1) the provided flush context
specified in the flushContext parameter in as async flush context
(2) the enque operation results in an automatic flush (3) the flush
could not be completed synchronously and was scheduled for asynchronous
completion. In this case, this LTP is marked as a recipient of the
flush completion event. When the asynchronous flush completes, the flush
completion event is dispatched through the event handler associated with
this LTP. An end user should specify either -1 or the LTP obtained
from the ILnkPeerEndpoint.getLtp()
method. This parameter is ignored in case the
user has provided a synchronous blocking or synchronous non-blocking
flush context.packet
- The packet to enqueflushContext
- A context object indicating the IO semantics to
be used in case the link is automatically flushed from within this
method (due to some policy implemented by the endpoint such as auto
flush based on packet queue size) alongwith runtime context information
related to the flushflags
- Flags used to qualify the enque operation. The following
flags are permissible for use here:ILnkEndpoint.IOFLAG_FLUSH_SUPPRESS
ILnkEndpoint.IOFLAG_FLUSH_FORCE
This method serializes and enques a packet at the endpoint for flush at
a later point. Once serialized, the packet queue is conditionally flushed
depending on internal auto flush policies implemented by the endpoint.
See ILnkPeerEndpoint.flush(short, com.neeve.link.ILnkPeerEndpoint.FlushContext)
for more information on how the flushContext
parameter is used and updated by the endpoint in case of an auto flush.
In the event that the enque causes the endpoint to e automatically
flushed and the flush is scheduled for asynchronous completion, the
LTP supplied in the ltp parameter is stored and the flush
completion event dispatched through the handler associated with the
LTP when the flush completes.
In case of an implicit flush, this method may choose to flush only a
part of the set of enqueued packets. The caller should either specify
the use ILnkEndpoint.IOFLAG_FLUSH_FORCE
flags or explicitly
invoke ILnkPeerEndpoint.flush(short, com.neeve.link.ILnkPeerEndpoint.FlushContext)
to ensure that all enqueued packets are flushed.
The sender should assume that the act of enqueuing a packet in an
endpoint transfers ownership of the packet to the endpoint i.e. the
endpoint may choose to hold onto the non-serialized packet
subsequent to return from the method. If the endpoint assumes packet
ownership, it does so by incrementing the packet's reference count.
Although the caller can conditionally decide what to do with the packet
by inspecting the packet's reference count (PktPacket.getOwnerCount()
,
the simplest, consistent and optimal operation to perform post enque
is to PktPacket.dispose()
the packet. If the endpoint did not
assume ownership of the packet, then the packet will be recycled
through its pool (if configured for its type) for the next send by
the caller. If it did assume ownership, then the packet will be
recycled through the pool when the endpoint is done with the packet.
The endpoint never assumes ownership of a packet if this method throws
an exception (checked or unchecked).
ELnkInvalidStateException
- Thrown in case the user is attempting
to enque a packet on a failed or closed endpoint
ELnkNotOwnerException
- Thrown in case this method is invoked
with an async flush context and by a thread that is not the owner of
the dispatcher specified in the context.
ELnkNotJoinedException
- Thrown in case the user with the specified
LTP has not joined the endpoint.
ELnkFlushInProgressException
- Thrown in case a previous implicit
flush during enque or explicit flush could not complete synchronously,
the user elected asynchronous completion of the flush and the flush has
not yet completed. It is illegal to enque a packet into an endpoint
that is attempting to complete a flush asynchronously.
ELnkOpFailedException
- Thrown in case an error was encountered
during the enqueing or, more likely, the automatic flushing of the
endpoint.public final void flush(short ltp, ILnkPeerEndpoint.FlushContext flushContext) throws ELnkInvalidStateException, ELnkNotOwnerException, ELnkNotJoinedException, ELnkFlushInProgressException, ELnkOpFailedException
ILnkPeerEndpoint.flush(short, com.neeve.link.ILnkPeerEndpoint.FlushContext)
flush
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user that is issuing this flush.
This parameter is only used in case (1) the provided flush context
specified in the flushContext parameter in as async flush context
(2) the flush could not be completed synchronously and is scheduled for
asynchronous completion. In this case, this LTP is marked as a recipient
of the flush completion event. When the asynchronous flush completes,
the flush completion event is dispatched through the event handler
associated with this LTP. An end user should either specify -1 or the
LTP obtained from the ILnkPeerEndpoint.getLtp()
method. This parameter is ignored
in case the user has provided a synchronous blocking or synchronous
non-blocking flush context.flushContext
- A context object indicating the IO semantics to
be used in case the link is automatically flushed from within this
method (due to some policy implemented by the endpoint such as auto
flush based on packet queue size) alongwith runtime context information
related to the flush
ELnkInvalidStateException
- Thrown in case the user is attempting
to flush a failed or closed endpoint.
ELnkNotOwnerException
- Thrown in case this method is invoked
with an async flush context and by a thread that is not the owner of
the dispatcher specified in the context.
ELnkNotJoinedException
- Thrown in case the user with the specified
LTP has not joined the endpoint.
ELnkFlushInProgressException
- Thrown in case a previous implicit
flush during enque or explicit flush could not complete synchronously,
the user elected asynchronous completion of the flush and the flush has
not yet completed. It is illegal to flush an endpoint that is attempting
to complete a flush asynchronously.
ELnkOpFailedException
- Thrown in case an error was encountered
during the flushing of the endpoint.
This method flushes enqueued packets to the remote endpoint. The flush
context determines the IO semantics used for the flush operation i.e.
sync blocking, sync non-blocking or async. In case the user has requested
for async flush, the user should check the contents of the flush context
upon return from this method. In case the flush did not complete
synchronously, the user needs to drive the specified dispatcher. That
will asynchronously drive the flush operation. Upon completion of the
flush, the flush context will be updated to indicate that the flush has
completed and an LnkEvents.EVENT_FLUSH_COMPLETE
event will be
dispatched to the user through its registered event handler. It is
illegal to enque packets into or flush the endpoint while an asynchronous
flush is in progress.
For a flush completing asynchronously, in the event that the endpoint fails and the user is dispatched a failure event before the flush completion event is dispatched, the user will never receive a flush completion event.
For a flush completing asynchronously, it is possible for the flush completion event to be dispatched to the user by a thread different from the owner thread of the dispatcher provided in the asynchronous flush context. The user should check for an appropriately process such a case.
public final void fail(Exception e) throws ELnkInvalidStateException, ELnkOpFailedException
ILnkPeerEndpoint.fail(java.lang.Exception)
fail
in interface ILnkPeerEndpoint
e
- The exception that describes the failure. The force failing
of the endpoint will ultimately result in the dispatch of an
LnkEvents.EVENT_FAILURE
event to the user. This exception
object will be attached to that event to describe the failure.
ELnkInvalidStateException
- Thrown in case the user is attempting
to fail a failed or closed endpoint or an endpoint whose read machinery
is not operational.
ELnkOpFailedException
- Thrown in case an error was encountered
during the failing of the endpoint.
This method force fails the endpoint. The successful invocation of this
method causes the endpoint to terminate the underlying connection and
dispatch an LnkEvents.EVENT_FAILURE
event through all
registered event handlers. The event is always dispatched after the
method returns and the state of the endpoint at the time the failure
event is dispatched is identical to its state when a genuine failure
occurs. This method is present to enable the user to force fail a link
connection at strategic points in its execution to test fault handling
and recovery scenrios. It is guaranteed that, after this method returns,
the user will not receive any received packets and all enque and flush
attempts will fail.
A user can only force fail an endpoint that has its read machinery operational. This method will return with an exception indicating an invalid state in case the endpoint is force failed without the read machinery operating.
public final void close(short ltp) throws ELnkOpFailedException
ILnkPeerEndpoint.close(short)
close
in interface ILnkPeerEndpoint
ltp
- Specifies the LTP of the user that is issuing the close.
An end user should specify either -1 or the LTP obtained from the
ILnkPeerEndpoint.getLtp()
method.
ELnkOpFailedException
- Thrown in case an error was encountered
during the closing of the endpoint.
This method first invokes ILnkPeerEndpoint.leave(short, int)
using the specified ltp with
implicit flush suppressed. Then, in case all users have left the
endpoint, this method transitions the endpoint to ILnkPeerEndpoint.State.CLOSING
and kicks off the close machinery. The closure process may need to
be scheduled for asynchronous completion in case it needs to wait for
some async operation to complete or to be cancelled. Once the close
is complete, the endpoint is transitioned to ILnkPeerEndpoint.State.CLOSED
.
The transition from closing to closed state needs to be driven by the
following dispatchers/threads:
- Dispatchers associated with read machinery of the link tree to which
the closing endpoint belongs.
- Dispatchers associated with any flush operation pending asynhronous
completion in the closing endpoint.
- Dispatchers managed and driven internal to the closing endpoint
The user needs to continue to drive any of the above dispatchers that
are under its control.
public final String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |