Java Code Examples for sun.management.jmxremote.LocalRMIServerSocketFactory

Following code examples demonstrate how to use sun.management.jmxremote.LocalRMIServerSocketFactoryfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use sun.management.jmxremote.LocalRMIServerSocketFactoryand various code implementation of this class.

	public synchronized void start() throws Exception {
		if (rmiServer != null) {
			return;
		}

		final RMIServerSocketFactory serverFactory;

		if (address.isLoopbackAddress()) {
			serverFactory = new LocalRMIServerSocketFactory();
		} else {
			serverFactory = new RMIServerSocketFactoryImpl(address);
		}

		registry = LocateRegistry.createRegistry(namingPort, null, serverFactory);

		final Map<String,Object> env = new HashMap<String,Object>();
		env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverFactory);

		final StringBuffer serviceUrl = new StringBuffer();
		serviceUrl.append("service:jmx:");
		url = serviceUrl.toString();

		rmiServer = new RMIConnectorServer(
				new JMXServiceURL(url),
				env,
				ManagementFactory.getPlatformMBeanServer()
				);

		rmiServer.start();
	} 


    public static void main(String[] args) throws Exception {
        final LocalRMIServerSocketFactory f =
                new LocalRMIServerSocketFactory();
        final ServerSocket s = f.createServerSocket(0);
        final int port = s.getLocalPort();
        Thread t = new Thread() {

            public void run() {
                while (isRunning) {
                    Exception error = Result.SUCCESS;
                    try {
                        System.err.println("Accepting: ");
                        final Socket ss = s.accept();
                        System.err.println(ss.getInetAddress() + " accepted");
                    } catch (Exception x) {
                        if (isRunning) {
                            x.printStackTrace();
                        }
                        error = x;
                    } finally {
                        try {
                            if (isRunning) {
                                queue.put(error);
                            }
                        } catch (Exception x) {
                            System.err.println("Could't send result to client!");
                            x.printStackTrace();
                            return;
                        }
                    }
                }
            }
        };

        try {
            t.start();

            System.err.println("new Socket((String)null, port)");
            final Socket s1 = new Socket((String) null, port);
            checkError("new Socket((String)null, port)");
            s1.close();
            System.err.println("new Socket((String)null, port): PASSED");

            System.err.println("new Socket(InetAddress.getByName(null), port)");
            final Socket s2 = new Socket(InetAddress.getByName(null), port);
            checkError("new Socket(InetAddress.getByName(null), port)");
            s2.close();
            System.err.println("new Socket(InetAddress.getByName(null), port): PASSED");

            System.err.println("new Socket(localhost, port)");
            final Socket s3 = new Socket("localhost", port);
            checkError("new Socket(localhost, port)");
            s3.close();
            System.err.println("new Socket(localhost, port): PASSED");

            System.err.println("new Socket(127.0.0.1, port)");
            final Socket s4 = new Socket("127.0.0.1", port);
            checkError("new Socket(127.0.0.1, port)");
            s4.close();
            System.err.println("new Socket(127.0.0.1, port): PASSED");
        }
        finally {
            isRunning = false;
            s.close();
            t.join();
        }
    } 

    protected boolean prerun() {
        
        if(!ActionDebugger.getInstance().isEnabled())
            return false;

        groupDelegates = ActionDebugger.getInstance().getGroupDelegates();
        try {
            sourceDir = IOUtils.createTempDirectory("lsfusiondebug");

            DebuggerService stub = (DebuggerService) UnicastRemoteObject.exportObject(ActionDebugger.getInstance(), 0, new LocalhostClientSocketFactory(), new LocalRMIServerSocketFactory());
            int port = getRmiManager().getDebuggerPort();
            Registry registry = LocateRegistry.createRegistry(port);
            registry.bind("lsfDebuggerService", stub);

        } catch (Exception e) {
            Throwables.propagate(e);
        }

        return true;
    } 

Advertisement
Javadoc
This RMI server socket factory creates server sockets that will only accept connection requests from

clients running on the host where the RMI remote objects have been exported.

Read More
Related Classes
Advertisement