Difference between revisions of "RMI Interface"
From RifidiWiki
(→Creating a Client) |
(→Using native RMI) |
||
Line 14: | Line 14: | ||
==Using native RMI== | ==Using native RMI== | ||
+ | <pre> | ||
+ | import java.rmi.NotBoundException; | ||
+ | import java.rmi.Remote; | ||
+ | import java.rmi.RemoteException; | ||
+ | import java.rmi.registry.LocateRegistry; | ||
+ | import java.rmi.registry.Registry; | ||
+ | |||
+ | import org.rifidi.edge.core.api.rmi.EdgeServerStub; | ||
+ | |||
+ | /** | ||
+ | * An example Edge Server RMI Client | ||
+ | * | ||
+ | * @author Kyle Neumeier - kyle@pramari.com | ||
+ | * | ||
+ | */ | ||
+ | public class RMITest { | ||
+ | |||
+ | /** | ||
+ | * Main method. Looks up stub and makes a call | ||
+ | * | ||
+ | * @param args | ||
+ | * - none | ||
+ | */ | ||
+ | public static void main(String[] args) { | ||
+ | try { | ||
+ | // obtain a reference to the RMI registry | ||
+ | Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1098); | ||
+ | // look up the stub on the regsitry | ||
+ | Remote remoteObject = registry.lookup("EdgeServerStub"); | ||
+ | if (remoteObject instanceof EdgeServerStub) { | ||
+ | // if the stub is the correct type, make the call | ||
+ | EdgeServerStub stub = (EdgeServerStub) remoteObject; | ||
+ | System.out.println(stub.getStartupTime()); | ||
+ | } | ||
+ | } catch (RemoteException e) { | ||
+ | e.printStackTrace(); | ||
+ | } catch (NotBoundException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
==Using Rifidi RMI Utils== | ==Using Rifidi RMI Utils== |
Revision as of 18:42, 18 May 2009
The Rifidi Edge Server exposes its functionality to clients via Remote Method Invocation (RMI). From the RMI homepage:
Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based applications, in which the methods of remote Java objects can be invoked from other Java virtual machines*, possibly on different hosts. RMI uses object serialization to marshal and unmarshal parameters and does not truncate types, supporting true object-oriented polymorphism.
Contents
Available RMI Stubs
RMI stubs are objects that the server creates to handle remote method calls. The Rifidi Edge Server creates three stubs when it starts up, registers them under a given name in the RMI Registry, and registers the objects as services in the OSGi registry.
EdgeServerStub
This stub handles global Edge server functionality, such as saving configurations. It is registered in the RMI registry under the name EdgeServerStub. For more information see <link to Javadoc>
ReaderStub
This stub handles all calls related to Readers, such as creating and deleting readers, changing reader properties, and managing session lifecycle. It is registered in the RMI registry under the name ReaderStub. For more information see <link to Javadoc>
CommandStub
This stub handles all calls related to commands, such as creating and deleting CommandConfigurations and changing CommandConfiguration properties. It is registered in the RMI registry under the name CommandStub. For more information see <link to Javadoc>
Creating a Client
Using native RMI
import java.rmi.NotBoundException; import java.rmi.Remote; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import org.rifidi.edge.core.api.rmi.EdgeServerStub; /** * An example Edge Server RMI Client * * @author Kyle Neumeier - kyle@pramari.com * */ public class RMITest { /** * Main method. Looks up stub and makes a call * * @param args * - none */ public static void main(String[] args) { try { // obtain a reference to the RMI registry Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1098); // look up the stub on the regsitry Remote remoteObject = registry.lookup("EdgeServerStub"); if (remoteObject instanceof EdgeServerStub) { // if the stub is the correct type, make the call EdgeServerStub stub = (EdgeServerStub) remoteObject; System.out.println(stub.getStartupTime()); } } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } } }