org.fosstrak.llrp.adaptor
Class ReaderImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by org.fosstrak.llrp.adaptor.ReaderImpl
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, Reader, org.llrp.ltk.net.LLRPEndpoint

public class ReaderImpl
extends java.rmi.server.UnicastRemoteObject
implements org.llrp.ltk.net.LLRPEndpoint, Reader

This class implements the ReaderInterface. The Reader implementation maintains two queues to decouple the user interface from the actual message delivery over the network.
1. from the user to the LLRP reader: the message to be sent is put into a queue. a queue watch-dog awakes as soon as there are messages in the queue and delivers them via LTK.
2. from the LLRP reader to user: the incoming message from the reader is stored into a queue. a queue watch-dog awakes as soon as there are messages in the queue and delivers them to the user.

Author:
sawielan
See Also:
Serialized Form

Nested Class Summary
static class ReaderImpl.QueuePolicy
          queue policies.
 
Field Summary
static int DEFAULT_KEEPALIVE_PERIOD
          the default keep-alive interval for the reader.
static int DEFAULT_MISS_KEEPALIVE
          default how many times a keep-alive can be missed.
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ReaderImpl(Adaptor adaptor, java.lang.String readerName, java.lang.String readerAddress)
          constructor for a local reader stub. the stub maintains connection to the llrp reader.
ReaderImpl(Adaptor adaptor, java.lang.String readerName, java.lang.String readerAddress, int port)
          constructor for a local reader stub. the stub maintains connection to the llrp reader.
 
Method Summary
 void connect(boolean clientInitiatedConnection)
          connects this reader to the real physical llrp reader.
 void deregisterFromAsynchronous(AsynchronousNotifiable receiver)
          deregister from the asynchronous messages. the receiver will no more receive asynchronous llrp messages.
 void disconnect()
          disconnect the reader stub from the physical reader.
 void errorOccured(java.lang.String message)
          when there is an error, the ltk will call this method.
 int getKeepAlivePeriod()
          returns the keepalive period set for this reader.
 ReaderMetaData getMetaData()
          the reader meta-data contains information about the reader, the settings, etc.
 int getPort()
          return the port of this reader.
 java.lang.String getReaderAddress()
          return the ip address of this reader.
 java.lang.String getReaderName()
          return the name of this reader.
 boolean isClientInitiated()
          tell if this reader maintains a client initiated connection or if the reader accepts a connection from a llrp reader.
 boolean isConnected()
          tells if the reader is connected or not.
 boolean isConnectImmediate()
          tells whether this reader connects immediately after creation.
 boolean isReportKeepAlive()
           
 void messageReceived(org.llrp.ltk.types.LLRPMessage message)
          when a message arrives through ltk, this method is called.
 void reconnect()
          try to reconnect the reader.
 void registerForAsynchronous(AsynchronousNotifiable receiver)
          register for asynchronous messages from the physical reader.
 void send(byte[] message)
          send a message to the llrp reader.
 void setClientInitiated(boolean clientInitiated)
          sets the connect behavior to the specified value.
 void setConnectImmediate(boolean value)
          tells whether this reader connects immediately after creation.
 void setKeepAlivePeriod(int keepAlivePeriod, int times, boolean report, boolean throwException)
          sets the connection timeout period for the reader. if the times * keepAlivePeriod has passed by without a notification from the reader the reader gets disconnected.
 void setReportKeepAlive(boolean report)
          if set to true, the reader will report all the keep-alive messages exchanged between the reader and the driver stub.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_KEEPALIVE_PERIOD

public static final int DEFAULT_KEEPALIVE_PERIOD
the default keep-alive interval for the reader.

See Also:
Constant Field Values

DEFAULT_MISS_KEEPALIVE

public static final int DEFAULT_MISS_KEEPALIVE
default how many times a keep-alive can be missed.

See Also:
Constant Field Values
Constructor Detail

ReaderImpl

public ReaderImpl(Adaptor adaptor,
                  java.lang.String readerName,
                  java.lang.String readerAddress)
           throws java.rmi.RemoteException
constructor for a local reader stub. the stub maintains connection to the llrp reader.

Parameters:
adaptor - the adaptor responsible for this reader.
readerName - the name of this reader.
readerAddress - the address where to connect.
Throws:
java.rmi.RemoteException - whenever there is an RMI exception

ReaderImpl

public ReaderImpl(Adaptor adaptor,
                  java.lang.String readerName,
                  java.lang.String readerAddress,
                  int port)
           throws java.rmi.RemoteException
constructor for a local reader stub. the stub maintains connection to the llrp reader.

Parameters:
adaptor - the adaptor responsible for this reader.
readerName - the name of this reader.
readerAddress - the address where to connect.
port - the port where to connect.
Throws:
java.rmi.RemoteException - whenever there is an RMI exception
Method Detail

connect

public void connect(boolean clientInitiatedConnection)
             throws LLRPRuntimeException,
                    java.rmi.RemoteException
Description copied from interface: Reader
connects this reader to the real physical llrp reader.

Specified by:
connect in interface Reader
Parameters:
clientInitiatedConnection - if the connection is initiated by the client then you should pass true. if the physical reader initiates the connection then provide false.
Throws:
LLRPRuntimeException - whenever an error occurs.
java.rmi.RemoteException - whenever there is an rmi error.

disconnect

public void disconnect()
                throws java.rmi.RemoteException
Description copied from interface: Reader
disconnect the reader stub from the physical reader.

Specified by:
disconnect in interface Reader
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

reconnect

public void reconnect()
               throws LLRPRuntimeException,
                      java.rmi.RemoteException
Description copied from interface: Reader
try to reconnect the reader.

Specified by:
reconnect in interface Reader
Throws:
LLRPRuntimeException - whenever there is a exception during connection setup.
java.rmi.RemoteException - whenever there is an rmi error.

send

public void send(byte[] message)
          throws java.rmi.RemoteException
Description copied from interface: Reader
send a message to the llrp reader.

Specified by:
send in interface Reader
Parameters:
message - the message to be sent.
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

isConnected

public boolean isConnected()
                    throws java.rmi.RemoteException
Description copied from interface: Reader
tells if the reader is connected or not.

Specified by:
isConnected in interface Reader
Returns:
true if the reader is connected.
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

errorOccured

public void errorOccured(java.lang.String message)
when there is an error, the ltk will call this method.

Specified by:
errorOccured in interface org.llrp.ltk.net.LLRPEndpoint
Parameters:
message - the error message from ltk.

messageReceived

public void messageReceived(org.llrp.ltk.types.LLRPMessage message)
when a message arrives through ltk, this method is called.

Specified by:
messageReceived in interface org.llrp.ltk.net.LLRPEndpoint
Parameters:
message - the llrp message delivered by ltk.

getReaderAddress

public java.lang.String getReaderAddress()
                                  throws java.rmi.RemoteException
Description copied from interface: Reader
return the ip address of this reader.

Specified by:
getReaderAddress in interface Reader
Returns:
the ip address of this reader.
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

getPort

public int getPort()
            throws java.rmi.RemoteException
Description copied from interface: Reader
return the port of this reader.

Specified by:
getPort in interface Reader
Returns:
the port of this reader.
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

isClientInitiated

public boolean isClientInitiated()
                          throws java.rmi.RemoteException
Description copied from interface: Reader
tell if this reader maintains a client initiated connection or if the reader accepts a connection from a llrp reader.

Specified by:
isClientInitiated in interface Reader
Returns:
  • true if client initiated connection
  • false if llrp reader initiated connection
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

setClientInitiated

public void setClientInitiated(boolean clientInitiated)
                        throws java.rmi.RemoteException
Description copied from interface: Reader
sets the connect behavior to the specified value.

Specified by:
setClientInitiated in interface Reader
Parameters:
clientInitiated - if true then the client issues the connect.
Throws:
java.rmi.RemoteException - whever there is an RMI error.

registerForAsynchronous

public void registerForAsynchronous(AsynchronousNotifiable receiver)
                             throws java.rmi.RemoteException
Description copied from interface: Reader
register for asynchronous messages from the physical reader.

Specified by:
registerForAsynchronous in interface Reader
Parameters:
receiver - the receiver that shall be notified with the message.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

deregisterFromAsynchronous

public void deregisterFromAsynchronous(AsynchronousNotifiable receiver)
                                throws java.rmi.RemoteException
Description copied from interface: Reader
deregister from the asynchronous messages. the receiver will no more receive asynchronous llrp messages.

Specified by:
deregisterFromAsynchronous in interface Reader
Parameters:
receiver - the receiver to deregister.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

getReaderName

public java.lang.String getReaderName()
                               throws java.rmi.RemoteException
Description copied from interface: Reader
return the name of this reader.

Specified by:
getReaderName in interface Reader
Returns:
the name of this reader.
Throws:
java.rmi.RemoteException - whenever there is an rmi error.

isConnectImmediate

public boolean isConnectImmediate()
                           throws java.rmi.RemoteException
Description copied from interface: Reader
tells whether this reader connects immediately after creation.

Specified by:
isConnectImmediate in interface Reader
Returns:
whether this reader connects immediately after creation.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

setConnectImmediate

public void setConnectImmediate(boolean value)
                         throws java.rmi.RemoteException
Description copied from interface: Reader
tells whether this reader connects immediately after creation.

Specified by:
setConnectImmediate in interface Reader
Parameters:
value - whether this reader connects immediately after creation.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

getKeepAlivePeriod

public int getKeepAlivePeriod()
                       throws java.rmi.RemoteException
Description copied from interface: Reader
returns the keepalive period set for this reader.

Specified by:
getKeepAlivePeriod in interface Reader
Returns:
the keepalive period set for this reader.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

setKeepAlivePeriod

public void setKeepAlivePeriod(int keepAlivePeriod,
                               int times,
                               boolean report,
                               boolean throwException)
                        throws java.rmi.RemoteException
Description copied from interface: Reader
sets the connection timeout period for the reader. if the times * keepAlivePeriod has passed by without a notification from the reader the reader gets disconnected.

Specified by:
setKeepAlivePeriod in interface Reader
Parameters:
keepAlivePeriod - the reader must send in this period a keepalive message. time in ms.
times - how many missed keepalive messages are ok.
report - whether to report the keepalive messages to the repo or not.
throwException - whether to throw an exception upon disconnection.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

setReportKeepAlive

public void setReportKeepAlive(boolean report)
                        throws java.rmi.RemoteException
Description copied from interface: Reader
if set to true, the reader will report all the keep-alive messages exchanged between the reader and the driver stub.

Specified by:
setReportKeepAlive in interface Reader
Parameters:
report - if true report the status messages. if false not.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

isReportKeepAlive

public boolean isReportKeepAlive()
                          throws java.rmi.RemoteException
Specified by:
isReportKeepAlive in interface Reader
Returns:
whether the reader stub delivers the keep-alive messages to the repo or not.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.

getMetaData

public final ReaderMetaData getMetaData()
                                 throws java.rmi.RemoteException
Description copied from interface: Reader
the reader meta-data contains information about the reader, the settings, etc.

Specified by:
getMetaData in interface Reader
Returns:
a meta-data structure.
Throws:
java.rmi.RemoteException - whenever there is an RMI error.


Copyright © 2009. All Rights Reserved.