com.neeve.link
Class LnkContinuousAcceptor

java.lang.Object
  extended by com.neeve.root.RootObject
      extended by com.neeve.link.LnkObject
          extended by com.neeve.link.LnkContinuousAcceptor

public class LnkContinuousAcceptor
extends LnkObject

Class that continuously retries link acceptance until a failure or stopped.

This class continuously attempts to accept link connections until a failure is encountered or it is stopped by the user. The user provides the link descriptor and associated information needed for link acceptance at creation time. The user then starts the acceptor via start(com.neeve.emx.IEmxDispatcher). Accepted links are dispatched to the user via a provided event handler until either the accept operation encounters an error or the user stops the acceptor. An event dispatched to the user indicating an unsuccessful accept (whether that be due to an error or due to stoppage by the user) indicates that the acceptor has stopped accepting additional links.

LnkContinuousAcceptor.State enumerates the various states that a acceptor can be in. The user can use the getState() method to query the state of an acceptor. Refer to the method documentation for the states in which the methods can be invoked.

Threading:
This class is safe for concurrent access by multiple threads.

Nested Class Summary
static class LnkContinuousAcceptor.State
          States of a acceptor.
 
Method Summary
static LnkContinuousAcceptor create(RootConfig.ObjectConfig config, String descriptor, ILnkEventHandler userHandler)
          Create a continuous link acceptor.
static LnkContinuousAcceptor create(RootConfig.ObjectConfig config, com.neeve.util.UtlAddressDescriptor descriptor, ILnkEventHandler userHandler)
          Create a continuous link acceptor.
 LnkContinuousAcceptor.State getState()
          Get the current state of the acceptor.
 void start(IEmxDispatcher dispatcher)
          Start the acceptor.
 void stop()
          Stop the acceptor.
 
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, toString, wait, wait, wait
 

Method Detail

create

public static LnkContinuousAcceptor create(RootConfig.ObjectConfig config,
                                           com.neeve.util.UtlAddressDescriptor descriptor,
                                           ILnkEventHandler userHandler)
Create a continuous link acceptor.

Parameters:
config - The package configuration object to use in the creation of this object. The allows the parameters used to configure the package that is using this class to be automatically applied to this object too.
descriptor - The descriptor to use to accept incoming links.
userHandler - The handler to which the completion events will be dispatched.
Returns:
Returns the created continuous link acceptor.
Threading:
This method is safe for concurrent access by multiple threads.

create

public static LnkContinuousAcceptor create(RootConfig.ObjectConfig config,
                                           String descriptor,
                                           ILnkEventHandler userHandler)
Create a continuous link acceptor.

Parameters:
config - The package configuration object to use in the creation of this object. The allows the parameters used to configure the package that is using this class to be automatically applied to this object too.
descriptor - The descriptor to use to accept incoming links.
userHandler - The handler to which the completion events will be dispatched.
Returns:
Returns the created continuous link acceptor.
Threading:
This method is safe for concurrent access by multiple threads.

start

public final void start(IEmxDispatcher dispatcher)
                 throws ELnkInvalidStateException,
                        ELnkNotOwnerException,
                        ELnkOpFailedException
Start the acceptor.

Parameters:
dispatcher - The dispatcher in whose context the accept should be run. The caller is responsible for driving this dispatcher upon return from this method until the completion event is dispatched.
Throws:
ELnkInvalidStateException - Thrown in case the acceptor is not in the LnkContinuousAcceptor.State.STOPPED state.
ELnkNotOwnerException - Thrown in case the calling thread is not the owner of the provided dispatcher.
ELnkOpFailedException - Thrown in case the acceptor could not be started.

This method kicks off the link acceptance. The user will be dispatched an LnkEvents.EVENT_CONTINUOUS_ACCEPT_COMPLETE event for each link successfully accepted by the acceptor. This will continue till an error occurs or the user issues a stop() call at which point the user will be dispatched one last event containing an exception. That event is the indication that the acceptor has stopped accepting any more links.

Threading:
This method is not safe for concurrent access by multiple threads and must be invoked by the owner thread of the dispatcher provided at the time the acceptor was created.

getState

public final LnkContinuousAcceptor.State getState()
Get the current state of the acceptor.

Threading:
This method is safe for concurrent access by multiple threads and can be invoked by any thread.

stop

public final void stop()
                throws ELnkInvalidStateException,
                       ELnkOpFailedException
Stop the acceptor.

Throws:
ELnkInvalidStateException - Thrown in case the acceptor is not in the LnkContinuousAcceptor.State.STARTED state.
ELnkOpFailedException - Thrown in case the a stop could not be scheduled on the acceptor.

This method schedules a stop on a started acceptor. It does so by setting the state of the acceptor to LnkContinuousAcceptor.State.STOPPING. At the time this method is invoked, the acceptor has an accept pending with a timeout. When the accept completes (either due to a successful accept or timeout), the state will indicate that the accept should not be reposted and the user be dispatched a cancellation event i.e. LnkEvents.EVENT_CONTINUOUS_ACCEPT_COMPLETE with the event data containing a ELnkOpCancelledException. The user should note that, in case a link is accepted between the time this method was invoked and the scheduled timeout of the accept call, the user will receive the accepted link followed by a cancellation event.

Threading:
This method is not safe for concurrent access by multiple threads and can be invoked by any thread.


Copyright © 2015 Neeve Research, LLC. All Rights Reserved.