org.fosstrak.llrp.adaptor
Class AdaptorManagement

java.lang.Object
  extended by org.fosstrak.llrp.adaptor.AdaptorManagement

public class AdaptorManagement
extends java.lang.Object

The AdaptorManagement handles your adaptors, enqueues LLRPMessages, handles errors from the reader site and notifies you about incoming LLRPMessages.

There are some common pitfalls when using the AdaptorManagement:


Below there is some sample-code, how you can use the AdaptorManagement:

// create a message handler
MessageHandler msgHandler = new MessageHandler();

// create an exception handler
ExceptionHandler handler = new ExceptionHandler();

// run the initializer method
String readConfig = Utility.findWithFullPath("/readerDefaultConfig.properties");
String writeConfig = readConfig;
boolean commitChanges = true;
AdaptorManagement.getInstance().initialize(
    readConfig, storeConfig, commitChanges, handler, msgHandler);

// now the management should be initialized and ready to be used

// create an adaptor
String adaptorName = "myAdaptor";
AdaptorManagement.getInstance().define(adaptorName, "localhost");

// create a reader
String readerName = "myReader";
Adaptor adaptor = AdaptorManagement.getAdaptor(adaptorName);
adaptor.define(readerName, "192.168.1.23", 5084, true, true);

//Enqueue some LLRPMessage on the adaptor
AdaptorManagement.enqueueLLRPMessage(adaptorName, readerName, message);

// when you shutdown your application call the shutdown method
AdaptorManagement.getInstance().shutdown();

Author:
sawielan

Field Summary
static java.lang.String DEFAULT_ADAPTOR_NAME
          the name for the default local adaptor.
 
Method Summary
 void checkStatus()
          check whether the AdaptorManagement is ok or not.
 void commit()
          commits the configuration to the properties file.
 boolean containsAdaptor(java.lang.String adaptorName)
          tells whether an adaptorName already exists.
 java.lang.String define(java.lang.String adaptorName, java.lang.String address)
          adds a new adaptor to the adaptor list.
 void deregisterFullHandler(MessageHandler handler)
          remove a handler from the full handler list.
 void deregisterPartialHandler(MessageHandler handler, java.lang.Class clzz)
          remove a handler from the handlers list.
 void disconnectReaders()
          disconnectReaders shuts down all local readers.
 void dispatchHandlers(java.lang.String adaptorName, java.lang.String readerName, org.llrp.ltk.types.LLRPMessage message)
          dispatches an LLRP message to all the registered full handlers.
 void enqueueLLRPMessage(java.lang.String adaptorName, java.lang.String readerName, org.llrp.ltk.types.LLRPMessage message)
          enqueue an LLRPMessage to be sent to a llrp reader. the adaptor will process the message when ready.
 Adaptor getAdaptor(java.lang.String adaptorName)
          returns an adaptor to a given adaptorName.
 java.util.List<java.lang.String> getAdaptorNames()
          returns a list of all the available adaptor names.
 AdaptorImpl getDefaultAdaptor()
          helper to access the default local adaptor more convenient.
 LLRPExceptionHandler getExceptionHandler()
          returns the exception handler.
static AdaptorManagement getInstance()
          returns the singleton of the AdaptorManagement.
 java.lang.String getReadConfig()
          returns the configuration file where to read the settings.
 java.lang.String getStoreConfig()
          returns the configuration file where to store changes.
 boolean hasFullHandler(MessageHandler handler)
          tests whether a given handler is already registered or not.
 boolean hasPartialHandler(MessageHandler handler, java.lang.Class clzz)
          checks whether a given handler is registered at a given selector class.
 boolean initialize(java.lang.String readConfig, java.lang.String storeConfig, boolean commitChanges, LLRPExceptionHandler exceptionHandler, MessageHandler handler)
          initializes the AdaptorManagement.
 boolean initialize(java.lang.String readConfig, java.lang.String storeConfig, boolean commitChanges, LLRPExceptionHandler exceptionHandler, MessageHandler handler, boolean export)
          ATTENTION: initializes the AdaptorManagement.DO NOT USE THIS METHOD as long as you know what you are doing (this method instructs with export=true to export the first local adaptor as a server adaptor.
 boolean isCommitChanges()
          flags whether all changes to the AdaptorManagement get reflected to the configuration file.
 boolean isInitialized()
          flags whether the AdaptorManagement has already been initialized.
 boolean isLocalAdapter(java.lang.String adapterName)
          checks, whether a given adapter is a local adapter or not.
 boolean isReady(java.lang.String adaptorName)
          you can check whether an adaptor is ready to accept messages.
 void loadFromFile()
          loads the adaptorManagement configuration from file (holds the adaptors and the readers for the local adaptor).
 void postException(LLRPRuntimeException e, LLRPExceptionHandlerTypeMap exceptionType, java.lang.String adapterName, java.lang.String readerName)
          posts an exception the the exception handler.
 void registerFullHandler(MessageHandler handler)
          register a handler that will receive all the incoming messages.
 void registerPartialHandler(MessageHandler handler, java.lang.Class clzz)
          register a handler that will receive only a restricted set of messages.
 void reset()
          resets the management to initial state.
 void setCommitChanges(boolean commitChanges)
          sets whether all changes to the AdaptorManagement get reflected to the configuration file.
 void setExceptionHandler(LLRPExceptionHandler exceptionHandler)
          sets the exception handler.
 void setReadConfig(java.lang.String readConfig)
          sets the configuration file.
 void setStoreConfig(java.lang.String storeConfig)
          sets the configuration file where to store changes.
 void shutdown()
          the client leaves the adaptor management. the management makes the cleanup.
 void storeToFile()
          stores the configuration of the adaptor management to file. the remote adaptors get stored and for the local adaptor all readers get stored as well.
 void undefine(java.lang.String adaptorName)
          removes an adaptor from the adaptor list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ADAPTOR_NAME

public static final java.lang.String DEFAULT_ADAPTOR_NAME
the name for the default local adaptor.

See Also:
Constant Field Values
Method Detail

initialize

public boolean initialize(java.lang.String readConfig,
                          java.lang.String storeConfig,
                          boolean commitChanges,
                          LLRPExceptionHandler exceptionHandler,
                          MessageHandler handler)
                   throws LLRPRuntimeException
initializes the AdaptorManagement.

Parameters:
readConfig - where the configuration shall be read from.
storeConfig - where the configuration shall be written to (if changes happen).
commitChanges - if storeConfig is set and commitChanges is true then all the changes to the AdaptorManagement are committed to storeConfig.
exceptionHandler - the exception handler from the GUI.
handler - a handler to dispatch the LLRP messages (can be set to null).
Returns:
returns
  • true if initialization has been performed
  • false if initialization has already been performed and therefore the process was aborted
.
Throws:
LLRPRuntimeException - whenever the AdaptorManagement could not be loaded.

initialize

public boolean initialize(java.lang.String readConfig,
                          java.lang.String storeConfig,
                          boolean commitChanges,
                          LLRPExceptionHandler exceptionHandler,
                          MessageHandler handler,
                          boolean export)
                   throws LLRPRuntimeException
ATTENTION: initializes the AdaptorManagement.DO NOT USE THIS METHOD as long as you know what you are doing (this method instructs with export=true to export the first local adaptor as a server adaptor.

Parameters:
readConfig - where the configuration shall be read from.
storeConfig - where the configuration shall be written to (if changes happen).
commitChanges - if storeConfig is set and commitChanges is true then all the changes to the AdaptorManagement are committed to storeConfig.
exceptionHandler - the exception handler from the GUI.
handler - a handler to dispatch the LLRP messages (can be set to null).
export - if the first local adaptor is to be exported by RMI or not.
Returns:
returns
  • true if initialization has been performed
  • false if initialization has already been performed and therefore the process was aborted
.
Throws:
LLRPRuntimeException - whenever the AdaptorManagement could not be loaded.

isInitialized

public boolean isInitialized()
flags whether the AdaptorManagement has already been initialized.

Returns:
whether the AdaptorManagement has already been initialized.

reset

public void reset()
           throws LLRPRuntimeException
resets the management to initial state.

Throws:
LLRPRuntimeException - if an error occurs during reset.

commit

public void commit()
commits the configuration to the properties file.


checkStatus

public void checkStatus()
                 throws LLRPRuntimeException
check whether the AdaptorManagement is ok or not. if not, an exception is thrown and reported to the exception handler.

Throws:
LLRPRuntimeException

shutdown

public void shutdown()
the client leaves the adaptor management. the management makes the cleanup.


disconnectReaders

public void disconnectReaders()
disconnectReaders shuts down all local readers.


containsAdaptor

public boolean containsAdaptor(java.lang.String adaptorName)
                        throws LLRPRuntimeException
tells whether an adaptorName already exists.

Parameters:
adaptorName - the name of the adaptor to check.
Returns:
true if adaptor exists else false.
Throws:
LLRPRuntimeException - whever something goes wrong ...

isLocalAdapter

public boolean isLocalAdapter(java.lang.String adapterName)
                       throws LLRPRuntimeException
checks, whether a given adapter is a local adapter or not.

Parameters:
adapterName - the name of the adapter to check.
Returns:
true if the adapter is local, false otherwise.
Throws:
LLRPRuntimeException - whenever something goes wrong...

define

public java.lang.String define(java.lang.String adaptorName,
                               java.lang.String address)
                        throws LLRPRuntimeException,
                               java.rmi.RemoteException,
                               java.rmi.NotBoundException
adds a new adaptor to the adaptor list.

Parameters:
adaptorName - the name of the new adaptor.
address - if you are using a client adaptor you have to provide the address of the server stub.
Throws:
LLRPRuntimeException - when either name already exists or when there occurs an error in adaptor creation.
java.rmi.RemoteException - when there is an error during transmition.
java.rmi.NotBoundException - when there is no registry available.

undefine

public void undefine(java.lang.String adaptorName)
              throws LLRPRuntimeException
removes an adaptor from the adaptor list.

Parameters:
adaptorName - the name of the adaptor to remove.
Throws:
LLRPRuntimeException - when either the name does not exist or when an internal runtime error occurs.

getAdaptorNames

public java.util.List<java.lang.String> getAdaptorNames()
                                                 throws LLRPRuntimeException
returns a list of all the available adaptor names.

Returns:
a list of all the available adaptor names.
Throws:
LLRPRuntimeException

getAdaptor

public Adaptor getAdaptor(java.lang.String adaptorName)
                   throws LLRPRuntimeException
returns an adaptor to a given adaptorName.

Parameters:
adaptorName - the name of the requested adaptor.
Returns:
an adaptor to a given adaptorName.
Throws:
LLRPRuntimeException - when the adaptor does not exist.

getDefaultAdaptor

public AdaptorImpl getDefaultAdaptor()
                              throws LLRPRuntimeException
helper to access the default local adaptor more convenient.

Returns:
the default local adaptor.
Throws:
LLRPRuntimeException - this should never occur!

isReady

public boolean isReady(java.lang.String adaptorName)
                throws LLRPRuntimeException
you can check whether an adaptor is ready to accept messages.

Parameters:
adaptorName - the name of the adaptor to check.
Returns:
true when ok, else false.
Throws:
LLRPRuntimeException

enqueueLLRPMessage

public void enqueueLLRPMessage(java.lang.String adaptorName,
                               java.lang.String readerName,
                               org.llrp.ltk.types.LLRPMessage message)
                        throws LLRPRuntimeException
enqueue an LLRPMessage to be sent to a llrp reader. the adaptor will process the message when ready.

Parameters:
adaptorName - the name of the adaptor holding the llrp reader.
readerName - the name of the llrp reader.
message - the LLRPMessage.
Throws:
LLRPRuntimeException - when the queue of the adaptor is full.

registerFullHandler

public void registerFullHandler(MessageHandler handler)
register a handler that will receive all the incoming messages.

Parameters:
handler - the handler.

deregisterFullHandler

public void deregisterFullHandler(MessageHandler handler)
remove a handler from the full handler list.

Parameters:
handler - the handler to be removed.

hasFullHandler

public boolean hasFullHandler(MessageHandler handler)
tests whether a given handler is already registered or not.

Parameters:
handler - the handler to check for.
Returns:
true if the handler is present, false otherwise.

registerPartialHandler

public void registerPartialHandler(MessageHandler handler,
                                   java.lang.Class clzz)
register a handler that will receive only a restricted set of messages.

Parameters:
handler - the handler.
clzz - the type of messages that the handler likes to receive (example KEEPALIVE.class).

deregisterPartialHandler

public void deregisterPartialHandler(MessageHandler handler,
                                     java.lang.Class clzz)
remove a handler from the handlers list.

Parameters:
handler - the handler to remove.
clzz - the class where the handler is registered.

hasPartialHandler

public boolean hasPartialHandler(MessageHandler handler,
                                 java.lang.Class clzz)
checks whether a given handler is registered at a given selector class.

Parameters:
handler - the handler to check.
clzz - the class where to search for the handler.
Returns:
true if the handler is present, false otherwise.

dispatchHandlers

public void dispatchHandlers(java.lang.String adaptorName,
                             java.lang.String readerName,
                             org.llrp.ltk.types.LLRPMessage message)
dispatches an LLRP message to all the registered full handlers. All the handlers that have interest into the class of the message will be informed as well.

Parameters:
adaptorName - the name of the adapter that received the message.
readerName - the reader that received the message.
message - the LLRP message itself.

postException

public void postException(LLRPRuntimeException e,
                          LLRPExceptionHandlerTypeMap exceptionType,
                          java.lang.String adapterName,
                          java.lang.String readerName)
posts an exception the the exception handler.

Parameters:
exceptionType - the type of the exception. see LLRPExceptionHandler for more details.
adapterName - the name of the adaptor that caused the exception.
readerName - the name of the reader that caused the exception.
e - the exception itself.

getInstance

public static AdaptorManagement getInstance()
returns the singleton of the AdaptorManagement.

Returns:
the singleton of the AdaptorManagement.

loadFromFile

public void loadFromFile()
                  throws LLRPRuntimeException
loads the adaptorManagement configuration from file (holds the adaptors and the readers for the local adaptor). all the adaptors defined currently get removed!!! the action is atomic, this means that depending on your setting, the client might get blocked for a short moment!

Throws:
LLRPRuntimeException - whenever there is an exception during restoring.

storeToFile

public void storeToFile()
                 throws LLRPRuntimeException
stores the configuration of the adaptor management to file. the remote adaptors get stored and for the local adaptor all readers get stored as well.

Throws:
LLRPRuntimeException - whenever there occurs an error during storage.

getExceptionHandler

public LLRPExceptionHandler getExceptionHandler()
returns the exception handler.

Returns:
the exception handler.

setExceptionHandler

public void setExceptionHandler(LLRPExceptionHandler exceptionHandler)
sets the exception handler.

Parameters:
exceptionHandler - the exception handler.

isCommitChanges

public boolean isCommitChanges()
flags whether all changes to the AdaptorManagement get reflected to the configuration file.

Returns:
true if yes, false otherwise.

setCommitChanges

public void setCommitChanges(boolean commitChanges)
sets whether all changes to the AdaptorManagement get reflected to the configuration file.

Parameters:
commitChanges -
  • true then the changes get stored back to the configuration immediately
  • false the changes are not stored back

getReadConfig

public java.lang.String getReadConfig()
returns the configuration file where to read the settings.

Returns:
the configuration file where to read the settings.

setReadConfig

public void setReadConfig(java.lang.String readConfig)
sets the configuration file.

Parameters:
readConfig - the configuration file.

getStoreConfig

public java.lang.String getStoreConfig()
returns the configuration file where to store changes.

Returns:
the configuration file where to store changes.

setStoreConfig

public void setStoreConfig(java.lang.String storeConfig)
sets the configuration file where to store changes.

Parameters:
storeConfig - the configuration file where to store changes.


Copyright © 2009. All Rights Reserved.