Difference between revisions of "Engine RMI Interface"

From RifidiWiki

Jump to: navigation, search
(Rifidi RMI Implementation)
(Reader Server Components)
Line 111: Line 111:
 
===Reader Server Components===
 
===Reader Server Components===
 
;RifidiManager
 
;RifidiManager
:The rifidiManager is the object that manages readers on a specific machine.  There is exactly one RifidiManager per machine.  It is in charge of keeping track of the readers (i.e. creating and destroying).
+
:The rifidiManager is the object that manages readers on a specific machine.  There is exactly one RifidiManager per machine.  It is in charge of keeping track of the readers (i.e. creating and destroying).  There are two distinct ways to start the manager, depending on how it is to be used.
 +
# '''Remotely''' If you wish to start the server on a remote machine, you must use the RifidiManager's main method to start it running.  The client will now need to know the RifidiManager's IP and port (normally the port is cajo's default port of .
 +
# '''Locally''' If the RifidiManger is to be started locally, a method is provided so that the client can do it programmaticly.  This method is provided for convenience, so that  It is simpler for the user when he just wants to start up the IDE and play around with a reader.
 
;RifidiManagerInterface
 
;RifidiManagerInterface
 
:The RifidiManagerInterface is the set of method calls that the RifidiManager exposes to the client.
 
:The RifidiManagerInterface is the set of method calls that the RifidiManager exposes to the client.
 +
 
===Reader Components===
 
===Reader Components===
 
;ReaderModuleManager
 
;ReaderModuleManager

Revision as of 16:06, 26 November 2007

RMI (Remote Method Invocation) is an architecture that allows clients to invoke methods on remote machines. Rifidi uses this architecture to allow the IDE (and the Tag Streamer) to communicate with the reader. It uses the cajo library to provide the RMI functionality.

Purpose of RMI Architecture

The basic goal of implementing RMI in Rifidi is so that one client (i.e. the IDE or Tag Streamer) can transparently control multiple readers on different machines, if need be. This enables a distributed architecture that will allow rifidi to drive performance testing of edge servers, because multiple machines can run rifidi readers, thus distributing the load across a network of computer. At the same time, however, it should be easy to start up one or two readers on a local machine for compatibility testing or to simply experiment with a reader.

Architecture Diagram

A figure depicting the purpose of RMI in Rifidi

Architecture Components

Client
The client (such as the IDE, Tag Streamer, or Designer) runs on a local machine. Its purpose is to allow the user to manipulate readers (i.e. start, stop, add tags, etc).
Reader Server
The Reader Server manages one or more readers on a particular machine by creating and destroying readers. There is one instance of a reader manager per machine.
Reader
A reader is the program that emulates a particular reader, such as an LLRP Reader. There can be multiple instances of a reader on a single machine.

One important aspect of this architecture is that The client doesn't care if a Reader Server is local or remote. That fact is transparent to the client.

Rifidi RMI Implementation

This section describes how RMI is implemented in Rifidi.

Using Cajo

Cajo is "a small, free library, enabling powerful dynamic multi-machine cooperation; both within and between, both free and proprietary Java applications. It provides a surprisingly easy to use, yet completely understandable framework to dramatically simplify the use of RMI; whilst at the same time harnessing its full potential." (https://cajo.dev.java.net/). If you are not familiar with cajo and/or RMI, you should read through the examples on cajo's website and wiki.

Remote Interfaces

One of the advantages of cajo is that it allows an object to easily expose functionality through an interface that another object can get and use. The advantage to using an interface as opposed to invoking calls using text is that typechecking can be done at compile time.

For example, suppose Object_A looked like this:

public class Object_A implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private int value=0;
	
	public void incrementValue(){
		value ++;
	}
	
	public String getValue(){
		return "object A's value is: " +Integer.toString( value);
	}

}

A simple way that a client could access Object_A's functionality is like this:

Object object = Remote.getItem("//serverHost:1198/obj_a");
Remote.invoke(object, "incrementValue", null);
String s = (String)Remote.invoke(object, "getValue", null);

However, another way that the client could access Object_A's functionality is if Object_A implemented an interface that exposed its methods that are available via RMI. For example, suppose there was an interface that looked like this:

public interface Object_A_Interface {

	public abstract void incrementValue();

	public abstract String getValue();

}

Now Object_A looks like this:

public class Object_A implements Serializable, Object_A_Interface{
	
	private static final long serialVersionUID = 1L;
	
	private int value=0;
	
	/* (non-Javadoc)
	 * @see org.rifidi.sandbox.cajo.test.Object_A_Interface#incrementValue()
	 */
	public void incrementValue(){
		value ++;
	}
	
	/* (non-Javadoc)
	 * @see org.rifidi.sandbox.cajo.test.Object_A_Interface#getValue()
	 */
	public String getValue(){
		return "object A's value is: " +Integer.toString( value);
	}

}

A client can now access Object_A's functionality by getting an interface and calling the methods. This enables the compiler to throw errors if something is wrong.

Object_A_Interface obja = (Object_A_Interface) TransparentItemProxy.getItem(
                                               "//serverHost:1198/obj_a",
                                               new Class[] { Object_A_Interface.class });
obja.incrementValue()
String s = obja.getValue();
System.out.println(s);

Callbacks

Another advantage of using RMI and cajo is that it allows for callbacks. This means that a client can call methods on a server using the method above, and the server can also invoke methods on the client using a similar method. This is important for Rifidi in situations with the GUI needs to be updated based on changes in the reader, such as when a TagID changes or when a GPO line goes high.

RMI Class Diagram

A UML Class Diagram depicting the components of the RMI Architecture in Rifidi

RMI Class Diagram Components

Client Components

RifidiClient
The client is the program that the user controls the reader with (such as the IDE, Tag Streamer, or Designer).
ClientCallbackManager
The callback manager is the object that handles callbacks from the readers. Callbacks happen when something on the reader changes that the IDE needs to know about to update a GUI component, such as a Tag ID changing or a GPO line toggle. There is one callback manager per reader in the IDE.
RifidiClientInterface
The client Interface is the set of method calls that the client callback manager exposes to the readers.

Reader Server Components

RifidiManager
The rifidiManager is the object that manages readers on a specific machine. There is exactly one RifidiManager per machine. It is in charge of keeping track of the readers (i.e. creating and destroying). There are two distinct ways to start the manager, depending on how it is to be used.
  1. Remotely If you wish to start the server on a remote machine, you must use the RifidiManager's main method to start it running. The client will now need to know the RifidiManager's IP and port (normally the port is cajo's default port of .
  2. Locally If the RifidiManger is to be started locally, a method is provided so that the client can do it programmaticly. This method is provided for convenience, so that It is simpler for the user when he just wants to start up the IDE and play around with a reader.
RifidiManagerInterface
The RifidiManagerInterface is the set of method calls that the RifidiManager exposes to the client.

Reader Components

ReaderModuleManager
The ReaderModuleManager is the wrapper around a reader on a machine. There is one ReaderModuleManager per instantiated reader.
ReaderModuleInterface
The ReaderModuleInterface represents the methods that a reader exposes to the client.

RMI in action: An example

Timing Diagram

A UML Class Diagram depicting the components of the RMI Architecture in Rifidi

Explanation of Diagram

Reference Client