CS 696 Emerging Technologies: Java Distributed Computing Spring Semester, 1999 Voyager Agent Basics |
||
---|---|---|
© 1999, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 06-May-99 |
Starting Voyager
The Voyager orb can be started on the command line or in a program. In a program you use the Voyager.startup() methods
Program Start up
com.objectspace.voyager.Voyager Static Methods addSystemListener(SystemListener listener) getSystemThreadGroup() getVersion() removeSystemListener(SystemListener listener) shutdown() startup() startup(java.lang.Object object, java.lang.String url) startup(java.lang.String url)
SystemListener Interface shutdown(SystemEvent event) startup(SystemEvent event)
Program Start up Example import com.objectspace.voyager.Voyager; import com.objectspace.voyager.SystemEvent; import com.objectspace.voyager.SystemListener; public class StartupTest implements SystemListener { public static void main(String[] arguments ) { try { System.out.println( "Start program" ); Voyager.addSystemListener( new StartupTest() ); System.out.println( "Call start up" ); Voyager.startup( "tcp://rohan.sdsu.edu:6000" ); System.out.println( "Call shut down" ); Voyager.shutdown( ); System.out.println( "Good by" ); } catch (Exception voyagerProblem ) { voyagerProblem.printStackTrace(); } } public void shutdown( SystemEvent goingDown ) { System.out.println( "Going down" ); } public void startup( SystemEvent starting ) { System.out.println( "Starting up" ); } }
Command Line Arguments
url |
the
url, typically a port, on which to start server
|
-a
<file>
|
process
lines in <file> as arguments
|
-b
<classname>
|
load
and start this application
|
-c
<url>
|
enable
network classloading from specified url
|
-i
<interpreter>
|
use
this interpreter instead of java
|
-l
<string>
|
log
level (silent, exceptions, verbose)
|
-m
<idl> <java>
|
map
idl entity to/from java class
|
-q |
quiet
mode, do not display copyright on startup
|
-r |
enable
resource (class file) serving
|
-s |
install
voyager security manager
|
-t
<int>
|
the
maximum thread pool size
|
-v |
print
version information and exit
|
-x |
pass
remaining parameters to the java interpreter
|
Naming Service
Voyager has its own naming service and also supports RMI registry, CORBA naming service, and JNDI. The latter two are not available in the free version of Voyager.
com.objectspace.voyager.Namespace
Static Methods bind(java.lang.String name, java.lang.Object object) lookup(java.lang.String name) rebind(java.lang.String name, java.lang.Object object) setServerURL(java.lang.Object obj)
unbind(java.lang.String name)
Ifoo aFooStub = (Ifoo) Namespace.lookup( "rmi://eli.sdsu.edu:5645/myFoo" );
Namespace.bind( "rmi://eli.sdsu.edu:5645/myBar", aBarObject );
Modile Code
The of() method in com.objectspace.voyager.mobility.Mobility returns the IMobility facet of an object. The object must be serializable in order to move the object to a different JVM.
com.objectspace.voyager.mobility.Imobility
moveTo(java.lang.Object destination)
public static void mobile() throws Exception { Voyager.startup(); String serverClass = "whitney.voyager.examples.hello.HelloImpl"; Proxy aProxy = Factory.create( serverClass); Hello helloProxy = (Hello) aProxy; System.out.println( helloProxy.sayHello()); IMobility mover = Mobility.of( helloProxy ); mover.moveTo( "//eli.sdsu.edu:8000" ); System.out.println( helloProxy.sayHello()); mover.moveTo( "//fargo.sdsu.edu:8000" ); System.out.println( helloProxy.sayHello()); Voyager.shutdown(); }
moveTo() Explained
This is taken from page 46-47 of Voyager ORB 3.0 Developer Guide.
1 Handling Messages
preDeparture(String source, String destination) throws MobilityException
Mobile Agents
Use the com.objectspace.voyager.agent.Agent class to turn an object into an agent.
com.objectspace.voyager.agent.AgentMethods static IAgent get(java.lang.Object object)
static IAgent of(java.lang.Object object)
getHome() getResourceLoader() isAutonomous() moveTo(Object destination) moveTo(Object destination, String callback) moveTo(Object destination, String callback, Object[] args) moveTo(String destination) moveTo(String destination, String callback) moveTo(String destination, String callback, Object[] args) setAutonomous(boolean flag) setResourceLoader(IResourceLoader resourceLoader)
Agent Example
package whitney.voyager.examples.agent; public interface IHello { String sayHello(); }
HelloAgent
package whitney.voyager.examples.agent; import java.net.InetAddress; import com.objectspace.voyager.agent.*; import com.objectspace.voyager.mobility.*; import com.objectspace.voyager.*; public class HelloAgent implements IHello, java.io.Serializable { private int count = 0; public String sayHello() { return "Hello World from " + getHostName() + " count " + count++; } public void move( String newAddress ) throws MobilityException { System.out.println( "Start move" ); IAgent agentProxy = Agent.of( this ); agentProxy.moveTo( newAddress, "movedDone" ); } public void movedDone() { System.out.println( "I have moved" + sayHello() ); IAgent agentProxy = Agent.of( this ); //rohan host name problem forced this odd check to see if we are home if ( getHostName().startsWith( "local" ); System.out.println( "I am home" ); else try { System.out.println( "Going home" ); move( agentProxy.getHome() ); } catch (MobilityException moveProblem ) { System.out.println( "Trouble moving" ); moveProblem.printStackTrace(); } }
HelloAgent Continued public static void main( String[] arguments) { try { Voyager.startup( "8000" ); String serverClass = "whitney.voyager.examples.agent.HelloAgent"; HelloAgent bond = new HelloAgent(); System.out.println( bond.sayHello()); bond.move( "tcp://fargo.sdsu.edu:8000" ); // No shutdown to make sure the orb will get the return agent } catch (Exception e) { System.out.println("HelloServer err: "); e.printStackTrace(); } } }
protected static String getHostName() { try { return InetAddress.getLocalHost().getHostName(); } catch (java.net.UnknownHostException who) { return "Unknown"; } }
Output on Rohan Hello World from localhost count 0 Start move I have movedHello World from localhost count 2 I am home
Output on Fargo I have movedHello World from fargo.sdsu.edu count 1 Going home Start move
Voyager and Rohan
Voyager is located in /opt/voyager3/ on rohan.
You must add to your path /opt/voyager3/bin
You must add to your classpath /opt/voyager3/lib/voyager.jar to your classpath
Voyager and Rohan’s local host Problems Voyager has the same problem with rohan’s host file setting as RMI. To use voyager on rohan or moria you must always explicitly reference rohan’s name. To state a voyager process on rohan via the command line use:
voyager tcp://rohan.sdsu.eduor
voyager tcp://rohan.sdsu.edu:portNumberTo start a voyager process on rohan from inside a program use:
Voyager.startup( "tcp://rohan.sdsu.edu:6000" );
Copyright ©, All rights reserved.
1999 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 06-May-99    Next