Search in sources :

Example 1 with NotBoundException

use of java.rmi.NotBoundException in project jdk8u_jdk by JetBrains.

the class Main method setupServer.

/**
     * Setup benchmark server.
     */
static void setupServer() {
    switch(runmode) {
        case SAMEVM:
            try {
                serverImpl = new BenchServerImpl();
                server = (BenchServer) RemoteObject.toStub(serverImpl);
            } catch (RemoteException e) {
                die("Error: failed to create local server: " + e);
            }
            if (verbose)
                System.out.println("Benchmark server created locally");
            break;
        case CLIENT:
            try {
                Registry reg = LocateRegistry.getRegistry(host, port);
                server = (BenchServer) reg.lookup(REGNAME);
            } catch (NotBoundException | RemoteException e) {
                die("Error: failed to connect to server: " + e);
            }
            if (server == null) {
                die("Error: server not found");
            }
            if (verbose) {
                System.out.println("Connected to benchmark server on " + host + ":" + port);
            }
            break;
        case SERVER:
            try {
                Registry reg = LocateRegistry.createRegistry(port);
                serverImpl = new BenchServerImpl();
                reg.bind(REGNAME, serverImpl);
            } catch (AlreadyBoundException | RemoteException e) {
                die("Error: failed to initialize server: " + e);
            }
            if (verbose) {
                System.out.println("Benchmark server started on port " + port);
            }
            break;
        default:
            throw new InternalError("illegal runmode");
    }
}
Also used : AlreadyBoundException(java.rmi.AlreadyBoundException) NotBoundException(java.rmi.NotBoundException) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteException(java.rmi.RemoteException)

Example 2 with NotBoundException

use of java.rmi.NotBoundException in project yyl_example by Relucent.

the class HelloClient method main.

public static void main(String[] args) {
    try {
        // 在RMI服务注册表中查找名称为RHello的对象,并调用其上的方法
        HelloService service = (HelloService) Naming.lookup("rmi://localhost:8888/hello");
        System.out.println(service.hello());
        System.out.println(service.hello("I'm the king of the world!"));
    } catch (NotBoundException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NotBoundException(java.rmi.NotBoundException) HelloService(yyl.example.basic.rmi.api.HelloService) RemoteException(java.rmi.RemoteException)

Example 3 with NotBoundException

use of java.rmi.NotBoundException in project intellij-community by JetBrains.

the class DebuggerConnector method connect.

@Nullable
private Debugger connect() {
    Throwable lastException = null;
    for (int i = 0; i < 10; i++) {
        if (myProcess.isProcessTerminated())
            return null;
        try {
            final Debugger realClient = EDTGuard.create(new RemoteDebuggerClient(myPort), myProcess);
            myProcess.notifyTextAvailable("Connected to XSLT debugger on port " + myPort + "\n", ProcessOutputTypes.SYSTEM);
            return realClient;
        } catch (ConnectException e) {
            lastException = e;
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
                break;
            }
        } catch (NotBoundException e) {
            lastException = e;
            try {
                Thread.sleep(200);
            } catch (InterruptedException e1) {
                break;
            }
        } catch (IOException e) {
            lastException = e;
            break;
        }
    }
    if (lastException != null) {
        Logger.getInstance(getClass().getName()).info("Could not connect to debugger", lastException);
        if (lastException.getMessage() != null) {
            myProcess.notifyTextAvailable("Connection error: " + lastException.getMessage() + "\n", ProcessOutputTypes.SYSTEM);
        }
    }
    return null;
}
Also used : Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) NotBoundException(java.rmi.NotBoundException) RemoteDebuggerClient(org.intellij.plugins.xsltDebugger.rt.engine.remote.RemoteDebuggerClient) IOException(java.io.IOException) ConnectException(java.rmi.ConnectException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with NotBoundException

use of java.rmi.NotBoundException in project jmeter by apache.

the class RemoteJMeterEngineImpl method rexit.

/*
     * Called by:
     * - ClientJMeterEngine.exe() which is called on remoteStop 
     */
@Override
public void rexit() throws RemoteException {
    log.info("Exiting");
    // Bug 59400 - allow rexit() to return
    Thread et = new Thread() {

        @Override
        public void run() {
            log.info("Stopping the backing engine");
            backingEngine.exit();
        }
    };
    et.setDaemon(false);
    // Tidy up any objects we created
    Registry reg = LocateRegistry.getRegistry(this.rmiPort);
    try {
        reg.unbind(JMETER_ENGINE_RMI_NAME);
    } catch (NotBoundException e) {
        log.warn("{} is not bound", JMETER_ENGINE_RMI_NAME, e);
    }
    log.info("Unbound from registry");
    // Help with garbage control
    JMeterUtils.helpGC();
    et.start();
}
Also used : NotBoundException(java.rmi.NotBoundException) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry)

Example 5 with NotBoundException

use of java.rmi.NotBoundException in project spring-framework by spring-projects.

the class RmiClientInterceptor method lookupStub.

/**
	 * Create the RMI stub, typically by looking it up.
	 * <p>Called on interceptor initialization if "cacheStub" is "true";
	 * else called for each invocation by {@link #getStub()}.
	 * <p>The default implementation looks up the service URL via
	 * {@code java.rmi.Naming}. This can be overridden in subclasses.
	 * @return the RMI stub to store in this interceptor
	 * @throws RemoteLookupFailureException if RMI stub creation failed
	 * @see #setCacheStub
	 * @see java.rmi.Naming#lookup
	 */
protected Remote lookupStub() throws RemoteLookupFailureException {
    try {
        Remote stub = null;
        if (this.registryClientSocketFactory != null) {
            // RMIClientSocketFactory specified for registry access.
            // Unfortunately, due to RMI API limitations, this means
            // that we need to parse the RMI URL ourselves and perform
            // straight LocateRegistry.getRegistry/Registry.lookup calls.
            URL url = new URL(null, getServiceUrl(), new DummyURLStreamHandler());
            String protocol = url.getProtocol();
            if (protocol != null && !"rmi".equals(protocol)) {
                throw new MalformedURLException("Invalid URL scheme '" + protocol + "'");
            }
            String host = url.getHost();
            int port = url.getPort();
            String name = url.getPath();
            if (name != null && name.startsWith("/")) {
                name = name.substring(1);
            }
            Registry registry = LocateRegistry.getRegistry(host, port, this.registryClientSocketFactory);
            stub = registry.lookup(name);
        } else {
            // Can proceed with standard RMI lookup API...
            stub = Naming.lookup(getServiceUrl());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Located RMI stub with URL [" + getServiceUrl() + "]");
        }
        return stub;
    } catch (MalformedURLException ex) {
        throw new RemoteLookupFailureException("Service URL [" + getServiceUrl() + "] is invalid", ex);
    } catch (NotBoundException ex) {
        throw new RemoteLookupFailureException("Could not find RMI service [" + getServiceUrl() + "] in RMI registry", ex);
    } catch (RemoteException ex) {
        throw new RemoteLookupFailureException("Lookup of RMI stub failed", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NotBoundException(java.rmi.NotBoundException) Remote(java.rmi.Remote) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException) URL(java.net.URL)

Aggregations

NotBoundException (java.rmi.NotBoundException)5 RemoteException (java.rmi.RemoteException)3 LocateRegistry (java.rmi.registry.LocateRegistry)3 Registry (java.rmi.registry.Registry)3 MalformedURLException (java.net.MalformedURLException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 ConnectException (java.rmi.ConnectException)1 Remote (java.rmi.Remote)1 Debugger (org.intellij.plugins.xsltDebugger.rt.engine.Debugger)1 RemoteDebuggerClient (org.intellij.plugins.xsltDebugger.rt.engine.remote.RemoteDebuggerClient)1 Nullable (org.jetbrains.annotations.Nullable)1 RemoteLookupFailureException (org.springframework.remoting.RemoteLookupFailureException)1 HelloService (yyl.example.basic.rmi.api.HelloService)1