com.neeve.link
Class LnkContinuousConnector

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

public class LnkContinuousConnector
extends LnkObject

Class that continuously retries link establishment till successful or stopped.

This class continuously attempts to establish a link connection until successful or stopped by the user. The user provides the link descriptor and associated information needed for link establishment at creation time. The user then starts the link establishment via start(com.neeve.emx.IEmxDispatcher) that kicks off the connection establishment. The connection establishment is retried at the specified interval until successful or stopped (stop()) by the user. The completion (whether that be due to a successful connect, an error internal to the connector or because the user has stopped the connect) is communicated to the user via the provided event handler.

LnkContinuousConnector.State enumerates the various states that a connector can be in. The user can use the getState() method to query the state of a connector. 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 LnkContinuousConnector.State
          States of a connector.
 
Method Summary
static LnkContinuousConnector create(RootConfig.ObjectConfig config, String descriptor, int retryInterval, ILnkEventHandler userHandler)
          Create a continuous link connector.
static LnkContinuousConnector create(RootConfig.ObjectConfig config, com.neeve.util.UtlAddressDescriptor descriptor, int retryInterval, ILnkEventHandler userHandler)
          Create a continuous link connector.
 LnkContinuousConnector.State getState()
          Get the current state of the connector
 void start(IEmxDispatcher dispatcher)
          Start the connector.
 void stop()
          Stop the connector.
 
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 LnkContinuousConnector create(RootConfig.ObjectConfig config,
                                            com.neeve.util.UtlAddressDescriptor descriptor,
                                            int retryInterval,
                                            ILnkEventHandler userHandler)
Create a continuous link connector.

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 link descriptor to use.
retryInterval - Interval (in seconds) at which failed connection attempts will be retried.
userHandler - The handler to which the completion event will be dispatched.
Returns:
Returns the created continuous link connector.
Threading:
This method is safe for concurrent access by multiple threads.

create

public static LnkContinuousConnector create(RootConfig.ObjectConfig config,
                                            String descriptor,
                                            int retryInterval,
                                            ILnkEventHandler userHandler)
Create a continuous link connector.

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 link descriptor to use.
retryInterval - Interval (in seconds) at which failed connection attempts will be retried.
userHandler - The handler to which the completion event will be dispatched.
Returns:
Returns the created continuous link connector.
Threading:
This method is safe for concurrent access by multiple threads.

start

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

Parameters:
dispatcher - The dispatcher in whose context the connect 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 connector is not in the LnkContinuousConnector.State.STOPPED state.
ELnkNotOwnerException - Thrown in case the calling thread is not the owner of the dispatcher provided at the time the connector was created.
ELnkOpFailedException - Thrown in case the connector could not be started.

This method kicks off the connection establishment. The user will be dispatched an LnkEvents.EVENT_CONTINUOUS_CONNECT_COMPLETE event when either the connection is successfully established, an internal error occurs that prevents the connector from continuing or the user issues a stop() call.

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 connector was created.

getState

public final LnkContinuousConnector.State getState()
Get the current state of the connector

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 connector.

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

This method schedules a stop on a started connector. It does so by setting the state of the connector to LnkContinuousConnector.State.STOPPING. At the time this method is invoked, the connector either has a connect pending completion or has an alarm scheduled to retry the connect. The changing of the state by this method is basically an indication to the alarm event to not reschedule the connect but to dispatch a cancellation event. In such as case the user will receive the LnkEvents.EVENT_CONTINUOUS_CONNECT_COMPLETE event with the event data containing a ELnkOpCancelledException. In case there was a connect pending at this time this method was called, the result of the connect will be dispatched to the user as the completion 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.