+RMITests & put remote classes in package
This commit is contained in:
parent
13a6e2c5e6
commit
6df70d51b3
@ -4,6 +4,8 @@
|
|||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Uses remote object PerfectTime
|
// Uses remote object PerfectTime
|
||||||
// {ValidateByHand}
|
// {ValidateByHand}
|
||||||
|
package remote;
|
||||||
|
|
||||||
import java.rmi.registry.*;
|
import java.rmi.registry.*;
|
||||||
|
|
||||||
public class DisplayPerfectTime {
|
public class DisplayPerfectTime {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// The PerfectTime remote interface
|
// The PerfectTime remote interface
|
||||||
|
package remote;
|
||||||
|
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
|
|
||||||
public interface PerfectTime extends Remote {
|
public interface PerfectTime extends Remote {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Implementing the PerfectTime remote object
|
// Implementing the PerfectTime remote object
|
||||||
|
package remote;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
|
|
||||||
public class PerfectTimeImpl implements PerfectTime {
|
public class PerfectTimeImpl implements PerfectTime {
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Server for the PerfectTime remote object
|
// Server for the PerfectTime remote object
|
||||||
// {ValidateByHand}
|
// {ValidateByHand}
|
||||||
|
package remote;
|
||||||
|
|
||||||
import java.rmi.registry.Registry;
|
import java.rmi.registry.Registry;
|
||||||
import java.rmi.registry.LocateRegistry;
|
import java.rmi.registry.LocateRegistry;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
|
25
remote/tests/RMITests.java
Normal file
25
remote/tests/RMITests.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// remote/tests/RMITests.java
|
||||||
|
// (c)2016 MindView LLC: see Copyright.txt
|
||||||
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
|
package remote;
|
||||||
|
|
||||||
|
import java.rmi.registry.*;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.TestInfo;
|
||||||
|
|
||||||
|
public class RMITests {
|
||||||
|
@Test
|
||||||
|
void test_remote_time() throws Exception {
|
||||||
|
LocateRegistry.createRegistry(1099);
|
||||||
|
PerfectTimeServer timeServer = new PerfectTimeServer();
|
||||||
|
timeServer.main(null);
|
||||||
|
Registry reg =
|
||||||
|
LocateRegistry.getRegistry("localhost");
|
||||||
|
PerfectTime pt =
|
||||||
|
(PerfectTime) reg.lookup("PerfectTime");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
System.out.println("Time: " + pt.getPerfectTime());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user