| OHSWG | 12.15.97 |

Open Hypermedia Systems Working Group
Beans, RMI, Voyager
These examples are, just as the RMI example, based on Client/Server Programming with Java and CORBA by Robert Orfali and Dan Harkey. As the purpose of the example program has been described previously, I will restrict myself to highlighting the difference between RMI and Voyager.
Voyager program does not need definition of interfaces to create remote objects, so we'll just define the CountVoyager program directly:
public class CountVoyager {
String name;
int sum;
public CountVoyager(String name) {
this.name = name;
System.out.println("CountYoyager " + name + " created.");
}
public int sum() {
return sum;
}
public void sum(int _val) {
this.sum = _val;
}
public int increment() {
return ++sum;
}
}
As can be seen, the implementation of CountVoyager is somewhat simpler than in the RMI case, as the handling of exception etc., is added by the Voyager tool vcc.
In order to remote enable CountVoyager, we need to create a virtual version of it:
$ vcc CountVoyager Symantec Java! JustInTime Compiler Version 210.063 for JDK 1.1.3 Copyright (C) 1996-97 Symantec Corporation vcc 2.0 beta 1, copyright objectspace 1997 $ dir VCountVoyager.java -rw-r--r-- 1 544 everyone 4764 Dec 15 02:35 VCountVoyager.java
Having created the virtual object, we are going to use, we turn our attention to the client:
import com.objectspace.voyager.*;
public class CountVoyagerClient
{
public static void main(String args[]) {
try {
// create account with initial balance of 1000 in a remote application
VCountVoyager myCount = new VCountVoyager("my CountVoyager", args[0]);
// Set Sum to initial value of 0
System.out.println("Setting Sum to 0");
myCount.sum(0);
// Calculate Start time
long startTime = System.currentTimeMillis();
// Increment 1000 times
System.out.println("Incrementing");
for (int i = 0 ; i < 1000 ; i++) {
myCount.increment();
}
// Calculate stop time; print out statistics
long stopTime = System.currentTimeMillis();
System.out.println("Avg Ping = "
+ ((stopTime - startTime)/1000f)
+ " msecs");
System.out.println("Sum = " + myCount.sum());
Voyager.shutdown();
}
catch(VoyagerException exception) {
System.err.println(exception);
}
}
}
First the instantiation of the VCountVoyager object is the most interesting line in the program. Rather than already having an instance of CountVoyager running on the Voyager server, this line actually uploads the CountVoyager to the server, where it is installed with the alias 'my CountVoyager'.
We now have everything we need to run the example:
$ start voyager 8000 -s $ java CountVoyagerClient talisker:8000 Symantec Java! JustInTime Compiler Version 210.063 for JDK 1.1.3 Copyright (C) 1996-97 Symantec Corporation voyager(tm) 2.0 beta 1, copyright objectspace 1997 address = 130.225.16.3:4151 Setting Sum to 0 Incrementing Avg Ping = 1.39 msecs Sum = 1000
The first command launches the Voyager server listening on port 8000 and with the Voyager security manager installed.
As is plain to see, Voyager is not as fast as RMI. The following example will solve the same problem in a more native Voyager way:
public class CountMobile implements java.io.Serializable {
String name;
int sum;
public CountMobile() {
}
public int sum() {
return sum;
}
public void sum(int _val) {
this.sum = _val;
}
public int increment() {
return ++sum;
}
public float test() {
// Set Sum to initial value of 0
this.sum(0);
// Calculate Start time
long startTime = System.currentTimeMillis();
// Increment 100000] times
for (int i=0 ; i<100000 ; i++) {
this.increment();
}
// Calculate stop time; print out statistics
long stopTime = System.currentTimeMillis();
return (stopTime - startTime)/100000f;
}
}
The most apparent difference between CountVoyager.java and CountMobile.java is that the latter implements java.io.Serializable, so that it can be shipped over the network. Also a method test has been added to do the calculations and return the average time of one iteration.
The client has also been changed:
import com.objectspace.voyager.*;
public class CountMobileClient {
public static void main(String args[]) {
try {
VCountMobile myMCount = new VCountMobile("localhost/my CountMobile");
myMCount.moveTo(args[0]);
System.out.println("Avg Ping = "
+ myMCount.test()
+ " msecs");
Voyager.shutdown();
} catch (VoyagerException exception) {
System.err.println(exception);
}
}
}
The program starts by instantiating the Mobile at the local machine. Having been created, the Mobile to told to move to a Voyager server. Once it has arrived at the Voyager server, it is told to perform the calculation test. The result is returned from the remote object and printed.
The result of running the program looks like this:
$ start voyager 8000 -s $ java CountMobileClient talisker:8000 Symantec Java! JustInTime Compiler Version 210.063 for JDK 1.1.3 Copyright (C) 1996-97 Symantec Corporation voyager(tm) 2.0 beta 1, copyright objectspace 1997 address = 130.225.16.3:4228 Avg Ping = 6.3E-4 msecs
It is of course no big surprise that it is much faster do local (in this case at the server) method invocation rather than remote method invocation, and in this sense this is a very unfair comparison. However Voyager has the ability to ship objects who are about to engage in heavy network traffic to the server, and that could certainly be useful in other cases than this toy example.
This concludes the Voyager example.
| Home | Description | Example | Availability | Recommendations | References |
Please send feedback to Niels Olof Bouvin. Last modified: Mon Dec 15 07:06:17 1997
Niels Olof Bouvin