use of java.rmi.registry.Registry in project GIPC by pdewan.
the class ASimpleRMICounterClient method main.
public static void main(String[] args) {
try {
Registry rmiRegistry = LocateRegistry.getRegistry(SERVER_HOST_NAME, SERVER_PORT);
DistributedRMICounter counter = (DistributedRMICounter) rmiRegistry.lookup(COUNTER_NAME);
counter.increment(1);
System.out.println(counter.getValue());
} catch (Exception e) {
e.printStackTrace();
}
}
use of java.rmi.registry.Registry in project mlib by myshzzx.
the class RMITest2 method server.
@Test
public void server() throws RemoteException, AlreadyBoundException, InterruptedException {
Registry registry = LocateRegistry.createRegistry(port);
BlockingQueue<Socket> socks = new LinkedBlockingQueue<>();
RIImpl ro = new RIImpl();
Remote expRO = UnicastRemoteObject.exportObject(ro, port + 1, null, p -> new ServerSocket(p) {
@Override
public Socket accept() throws IOException {
final Socket accept = super.accept();
socks.offer(accept);
return accept;
}
});
registry.bind("ro", expRO);
new Thread() {
@Override
public void run() {
Socket sock;
while (true) {
try {
Thread.sleep(500);
sock = socks.take();
if (sock.isClosed())
System.out.println("sock closed");
else
socks.offer(sock);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}.start();
Thread.sleep(100000000);
}
use of java.rmi.registry.Registry in project mlib by myshzzx.
the class RMITest method server.
@Test
public void server() throws RemoteException, AlreadyBoundException, InterruptedException {
int port = 8030;
Registry registry = LocateRegistry.createRegistry(port);
RIImpl ro = new RIImpl();
Remote expRO = UnicastRemoteObject.exportObject(ro, port + 1);
registry.bind("ro", expRO);
registry.bind("po", (PureObj) () -> {
System.out.println("PureObj getValue");
return 1;
});
int i = 1;
while (true) {
Thread.sleep(1_000);
ro.v = i++;
}
}
use of java.rmi.registry.Registry in project tutorials by eugenp.
the class MessengerServiceImpl method createStubAndBind.
public void createStubAndBind() throws RemoteException {
MessengerService stub = (MessengerService) UnicastRemoteObject.exportObject((MessengerService) this, 0);
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind("MessengerService", stub);
}
use of java.rmi.registry.Registry in project tutorials by eugenp.
the class JavaRMIIntegrationTest method whenClientSendsMessageToServer_thenServerSendsResponseMessage.
@Test
public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() {
try {
Registry registry = LocateRegistry.getRegistry();
MessengerService server = (MessengerService) registry.lookup("MessengerService");
String responseMessage = server.sendMessage("Client Message");
String expectedMessage = "Server Message";
assertEquals(responseMessage, expectedMessage);
} catch (RemoteException e) {
fail("Exception Occurred");
} catch (NotBoundException nb) {
fail("Exception Occurred");
}
}
Aggregations