Search in sources :

Example 56 with Registry

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();
    }
}
Also used : DistributedRMICounter(examples.mvc.rmi.duplex.DistributedRMICounter) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 57 with Registry

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);
}
Also used : Remote(java.rmi.Remote) ServerSocket(java.net.ServerSocket) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AlreadyBoundException(java.rmi.AlreadyBoundException) NotBoundException(java.rmi.NotBoundException) Test(org.junit.Test)

Example 58 with Registry

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++;
    }
}
Also used : Remote(java.rmi.Remote) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) Test(org.junit.Test)

Example 59 with Registry

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);
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 60 with Registry

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");
    }
}
Also used : NotBoundException(java.rmi.NotBoundException) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Aggregations

Registry (java.rmi.registry.Registry)128 LocateRegistry (java.rmi.registry.LocateRegistry)119 RemoteException (java.rmi.RemoteException)43 IOException (java.io.IOException)20 Remote (java.rmi.Remote)16 NodeRegisterRMIStub (org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)14 UnknownHostException (java.net.UnknownHostException)13 JMXServiceURL (javax.management.remote.JMXServiceURL)12 HashMap (java.util.HashMap)10 NotBoundException (java.rmi.NotBoundException)9 JMXConnector (javax.management.remote.JMXConnector)9 DistributedRMICounter (examples.mvc.rmi.duplex.DistributedRMICounter)8 SocketException (java.net.SocketException)8 AlreadyBoundException (java.rmi.AlreadyBoundException)8 MBeanServerConnection (javax.management.MBeanServerConnection)8 JMXConnectorServer (javax.management.remote.JMXConnectorServer)8 Test (org.junit.Test)8 MBeanServer (javax.management.MBeanServer)7 InetAddress (java.net.InetAddress)6 MalformedURLException (java.net.MalformedURLException)6