Search in sources :

Example 1 with ActivationSystem

use of java.rmi.activation.ActivationSystem in project jdk8u_jdk by JetBrains.

the class PipeWriter method main.

/**
     * Main program to start the activation system. <br>
     * The usage is as follows: rmid [-port num] [-log dir].
     */
public static void main(String[] args) {
    boolean stop = false;
    // already.
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }
    try {
        int port = ActivationSystem.SYSTEM_PORT;
        RMIServerSocketFactory ssf = null;
        /*
             * If rmid has an inherited channel (meaning that it was
             * launched from inetd), set the server socket factory to
             * return the inherited server socket.
             **/
        Channel inheritedChannel = AccessController.doPrivileged(new PrivilegedExceptionAction<Channel>() {

            public Channel run() throws IOException {
                return System.inheritedChannel();
            }
        });
        if (inheritedChannel != null && inheritedChannel instanceof ServerSocketChannel) {
            /*
                 * Redirect System.err output to a file.
                 */
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

                public Void run() throws IOException {
                    File file = Files.createTempFile("rmid-err", null).toFile();
                    PrintStream errStream = new PrintStream(new FileOutputStream(file));
                    System.setErr(errStream);
                    return null;
                }
            });
            ServerSocket serverSocket = ((ServerSocketChannel) inheritedChannel).socket();
            port = serverSocket.getLocalPort();
            ssf = new ActivationServerSocketFactory(serverSocket);
            System.err.println(new Date());
            System.err.println(getTextResource("rmid.inherited.channel.info") + ": " + inheritedChannel);
        }
        String log = null;
        List<String> childArgs = new ArrayList<>();
        /*
             * Parse arguments
             */
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-port")) {
                if (ssf != null) {
                    bomb(getTextResource("rmid.syntax.port.badarg"));
                }
                if ((i + 1) < args.length) {
                    try {
                        port = Integer.parseInt(args[++i]);
                    } catch (NumberFormatException nfe) {
                        bomb(getTextResource("rmid.syntax.port.badnumber"));
                    }
                } else {
                    bomb(getTextResource("rmid.syntax.port.missing"));
                }
            } else if (args[i].equals("-log")) {
                if ((i + 1) < args.length) {
                    log = args[++i];
                } else {
                    bomb(getTextResource("rmid.syntax.log.missing"));
                }
            } else if (args[i].equals("-stop")) {
                stop = true;
            } else if (args[i].startsWith("-C")) {
                childArgs.add(args[i].substring(2));
            } else {
                bomb(MessageFormat.format(getTextResource("rmid.syntax.illegal.option"), args[i]));
            }
        }
        if (log == null) {
            if (ssf != null) {
                bomb(getTextResource("rmid.syntax.log.required"));
            } else {
                log = "log";
            }
        }
        debugExec = AccessController.doPrivileged(new GetBooleanAction("sun.rmi.server.activation.debugExec"));
        /**
             * Determine class name for activation exec policy (if any).
             */
        String execPolicyClassName = AccessController.doPrivileged(new GetPropertyAction("sun.rmi.activation.execPolicy", null));
        if (execPolicyClassName == null) {
            if (!stop) {
                DefaultExecPolicy.checkConfiguration();
            }
            execPolicyClassName = "default";
        }
        /**
             * Initialize method for activation exec policy.
             */
        if (!execPolicyClassName.equals("none")) {
            if (execPolicyClassName.equals("") || execPolicyClassName.equals("default")) {
                execPolicyClassName = DefaultExecPolicy.class.getName();
            }
            try {
                Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
                execPolicy = execPolicyClass.newInstance();
                execPolicyMethod = execPolicyClass.getMethod("checkExecCommand", ActivationGroupDesc.class, String[].class);
            } catch (Exception e) {
                if (debugExec) {
                    System.err.println(getTextResource("rmid.exec.policy.exception"));
                    e.printStackTrace();
                }
                bomb(getTextResource("rmid.exec.policy.invalid"));
            }
        }
        if (stop == true) {
            final int finalPort = port;
            AccessController.doPrivileged(new PrivilegedAction<Void>() {

                public Void run() {
                    System.setProperty("java.rmi.activation.port", Integer.toString(finalPort));
                    return null;
                }
            });
            ActivationSystem system = ActivationGroup.getSystem();
            system.shutdown();
            System.exit(0);
        }
        /*
             * Fix for 4173960: Create and initialize activation using
             * a static method, startActivation, which will build the
             * Activation state in two ways: if when rmid is run, no
             * log file is found, the ActLogHandler.recover(...)
             * method will create a new Activation instance.
             * Alternatively, if a logfile is available, a serialized
             * instance of activation will be read from the log's
             * snapshot file.  Log updates will be applied to this
             * Activation object until rmid's state has been fully
             * recovered.  In either case, only one instance of
             * Activation is created.
             */
        startActivation(port, ssf, log, childArgs.toArray(new String[childArgs.size()]));
        // prevent activator from exiting
        while (true) {
            try {
                Thread.sleep(Long.MAX_VALUE);
            } catch (InterruptedException e) {
            }
        }
    } catch (Exception e) {
        System.err.println(MessageFormat.format(getTextResource("rmid.unexpected.exception"), e));
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : ArrayList(java.util.ArrayList) ActivationSystem(java.rmi.activation.ActivationSystem) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) ServerSocketChannel(java.nio.channels.ServerSocketChannel) PrintStream(java.io.PrintStream) GetBooleanAction(sun.security.action.GetBooleanAction) Channel(java.nio.channels.Channel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ServerSocket(java.net.ServerSocket) ConnectIOException(java.rmi.ConnectIOException) IOException(java.io.IOException) Date(java.util.Date) ActivationException(java.rmi.activation.ActivationException) UnknownGroupException(java.rmi.activation.UnknownGroupException) ConnectIOException(java.rmi.ConnectIOException) NotBoundException(java.rmi.NotBoundException) MissingResourceException(java.util.MissingResourceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) AccessControlException(java.security.AccessControlException) UnknownObjectException(java.rmi.activation.UnknownObjectException) NoSuchObjectException(java.rmi.NoSuchObjectException) AccessException(java.rmi.AccessException) SocketException(java.net.SocketException) ConnectException(java.rmi.ConnectException) IOException(java.io.IOException) AlreadyBoundException(java.rmi.AlreadyBoundException) GetPropertyAction(sun.security.action.GetPropertyAction) FileOutputStream(java.io.FileOutputStream) ActivationGroupDesc(java.rmi.activation.ActivationGroupDesc) PolicyFile(sun.security.provider.PolicyFile) File(java.io.File)

Example 2 with ActivationSystem

use of java.rmi.activation.ActivationSystem in project jdk8u_jdk by JetBrains.

the class InheritedChannelNotServerSocket method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6261402\n");
    System.setProperty("java.rmi.activation.port", Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
        /*
             * Export callback object and bind in registry.
             */
        System.err.println("export callback object and bind in registry");
        obj = new CallbackImpl();
        Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0);
        Registry registry = LocateRegistry.createRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
        registry.bind("Callback", proxy);
        /*
             * Start rmid.
             */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, true, TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
        rmid.addOptions(new String[] { "-Djava.nio.channels.spi.SelectorProvider=" + "InheritedChannelNotServerSocket$SP" });
        rmid.start();
        /*
             * Get activation system and wait to be notified via callback
             * from rmid's selector provider.
             */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");
    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
Also used : ActivationSystem(java.rmi.activation.ActivationSystem) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry)

Example 3 with ActivationSystem

use of java.rmi.activation.ActivationSystem in project jdk8u_jdk by JetBrains.

the class Callback method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.rmi.activation.port", Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
        /*
             * Export callback object and bind in registry.
             */
        System.err.println("export callback object and bind in registry");
        obj = new RmidViaInheritedChannel();
        Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0);
        Registry registry = LocateRegistry.createRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
        registry.bind("Callback", proxy);
        /*
             * Start rmid.
             */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, false, TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
        rmid.addOptions(new String[] { "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider" });
        if (System.getProperty("os.name").startsWith("Windows") && System.getProperty("os.version").startsWith("5.")) {
            /* Windows XP/2003 or older
                 * Need to expand ephemeral range to include RMI test ports
                 */
            rmid.addOptions(new String[] { "-Djdk.net.ephemeralPortRange.low=1024", "-Djdk.net.ephemeralPortRange.high=64000" });
        }
        rmid.start();
        /*
             * Get activation system and wait to be notified via callback
             * from rmid's selector provider.
             */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");
    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
Also used : ActivationSystem(java.rmi.activation.ActivationSystem) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry)

Example 4 with ActivationSystem

use of java.rmi.activation.ActivationSystem in project jdk8u_jdk by JetBrains.

the class IdempotentActiveGroup method main.

public static void main(String[] args) {
    System.err.println("\nRegression test for bug 4720528\n");
    TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
    RMID rmid = null;
    ActivationInstantiator inst1 = null;
    ActivationInstantiator inst2 = null;
    try {
        RMID.removeLog();
        rmid = RMID.createRMID();
        rmid.start();
        System.err.println("Create group descriptor");
        ActivationGroupDesc groupDesc = new ActivationGroupDesc(null, null);
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("Register group descriptor");
        ActivationGroupID groupID = system.registerGroup(groupDesc);
        inst1 = new FakeInstantiator();
        inst2 = new FakeInstantiator();
        System.err.println("Invoke activeGroup with inst1");
        system.activeGroup(groupID, inst1, 0);
        try {
            System.err.println("Invoke activeGroup with inst2");
            system.activeGroup(groupID, inst2, 0);
            throw new RuntimeException("TEST FAILED: activeGroup with unequal groups succeeded!");
        } catch (ActivationException expected) {
            System.err.println("Caught expected ActivationException");
            System.err.println("Test 1 (of 2) passed");
        }
        try {
            System.err.println("Invoke activeGroup with inst1");
            system.activeGroup(groupID, inst1, 0);
            System.err.println("activeGroup call succeeded");
            System.err.println("Test 2 (of 2) passed");
        } catch (ActivationException unexpected) {
            throw new RuntimeException("TEST FAILED: activeGroup with equal groups failed!", unexpected);
        }
    } catch (Exception e) {
        TestLibrary.bomb("test failed", e);
    } finally {
        try {
            if (inst1 != null) {
                UnicastRemoteObject.unexportObject(inst1, true);
            }
            if (inst2 != null) {
                UnicastRemoteObject.unexportObject(inst2, true);
            }
        } catch (NoSuchObjectException unexpected) {
            throw new AssertionError(unexpected);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
Also used : ActivationSystem(java.rmi.activation.ActivationSystem) ActivationGroupID(java.rmi.activation.ActivationGroupID) ActivationInstantiator(java.rmi.activation.ActivationInstantiator) ActivationException(java.rmi.activation.ActivationException) ActivationGroupDesc(java.rmi.activation.ActivationGroupDesc) NoSuchObjectException(java.rmi.NoSuchObjectException) NoSuchObjectException(java.rmi.NoSuchObjectException) ActivationException(java.rmi.activation.ActivationException) RemoteException(java.rmi.RemoteException)

Aggregations

ActivationSystem (java.rmi.activation.ActivationSystem)4 NoSuchObjectException (java.rmi.NoSuchObjectException)2 RemoteException (java.rmi.RemoteException)2 ActivationException (java.rmi.activation.ActivationException)2 ActivationGroupDesc (java.rmi.activation.ActivationGroupDesc)2 LocateRegistry (java.rmi.registry.LocateRegistry)2 Registry (java.rmi.registry.Registry)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ServerSocket (java.net.ServerSocket)1 SocketException (java.net.SocketException)1 Channel (java.nio.channels.Channel)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 AccessException (java.rmi.AccessException)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 ConnectException (java.rmi.ConnectException)1 ConnectIOException (java.rmi.ConnectIOException)1