Example usage for java.rmi RemoteException RemoteException

List of usage examples for java.rmi RemoteException RemoteException

Introduction

In this page you can find the example usage for java.rmi RemoteException RemoteException.

Prototype

public RemoteException(String s) 

Source Link

Document

Constructs a RemoteException with the specified detail message.

Usage

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public String[] getS3ClassAttribute(final long rObjectId, final String slotsPath) throws RemoteException {
    final String[][] result = new String[1][];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                String[] comment = null;
                long commentId = e.rniEval(e.rniParse("class(" + rootvar + slotsPath + ")", 1), 0);
                if (commentId != 0 && e.rniExpType(commentId) == STRSXP) {
                    comment = e.rniGetStringArray(commentId);
                }/*from  www .  j  a  va2  s.  c o m*/
                result[0] = comment;
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });

    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long setS3ClassAttribute(final long rObjectId, final String slotsPath, final String[] classAttribute)
        throws RemoteException {
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {

                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                String ca = "c(";
                for (int i = 0; i < classAttribute.length; ++i) {
                    ca += "'" + classAttribute[i] + "'" + (i == classAttribute.length - 1 ? "" : ",");
                }/*from  ww w .  j a  v a2s .c  o m*/
                ca += ")";
                e.rniEval(e.rniParse(
                        "class(" + rootvar + slotsPath + ")<-" + (classAttribute == null ? "NULL" : ca), 1), 0);
                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.RServantImpl.java

public void init() throws RemoteException {
    try {//ww w  .  j a v  a 2s . co  m
        //System.setProperty("wks.persitent", "false");

        DirectJNI.init(getServantName());

        _assignInterface = new AssignInterfaceImpl(this);
        DirectJNI.getInstance()
                .setAssignInterface((AssignInterface) java.rmi.server.RemoteObject.toStub(_assignInterface));

        _remoteRni = new RNIImpl(_log);

        _graphicNotifier = new GraphicNotifierImpl();

        _rim = new HashMap<String, RPackage>();

        for (String className : DirectJNI._rPackageInterfacesHash.keySet()) {
            String shortClassName = className.substring(className.lastIndexOf('.') + 1);
            log.info(shortClassName);
            System.out.println("Going to load : " + className + "ImplRemote");
            _rim.put(shortClassName,
                    (RPackage) DirectJNI._mappingClassLoader.loadClass(className + "ImplRemote").newInstance());
        }

        if (System.getProperty("preprocess.help") == null || System.getProperty("preprocess.help").equals("")
                || System.getProperty("preprocess.help").equalsIgnoreCase("true")) {
            String[] packNames = ((RChar) DirectJNI.getInstance().getRServices().getObject(".packages(all=T)"))
                    .getValue();
            DirectJNI.getInstance().preprocessHelp(packNames, true);
        }

        if (System.getProperty("apply.sandbox") != null
                && System.getProperty("apply.sandbox").equalsIgnoreCase("true")) {
            DirectJNI.getInstance().applySandbox();
        }

        RListener.setRClusterInterface(new RClustserInterface() {
            public Vector<RServices> createRs(int n, String nodeName) throws Exception {
                System.out.println(" create Rs");

                ExecutorService exec = Executors.newFixedThreadPool(5);
                Future<RServices>[] futures = new Future[n];

                for (int i = 0; i < n; ++i) {

                    futures[i] = exec.submit(new Callable<RServices>() {
                        public RServices call() {
                            try {
                                RServices w = cloneServer();
                                return w;
                            } catch (Exception e) {
                                e.printStackTrace();
                                return _rCreationPb;
                            }
                        }
                    });

                }
                while (countCreated(futures) < n) {
                    try {
                        Thread.sleep(20);
                    } catch (Exception e) {
                    }
                }

                for (int i = 0; i < n; ++i) {
                    if (futures[i].get() == _rCreationPb)
                        return null;
                }

                Vector<RServices> workers = new Vector<RServices>();
                for (int i = 0; i < n; ++i)
                    if (futures[i].get() != _rCreationPb)
                        workers.add(futures[i].get());

                for (int i = 0; i < n; ++i) {
                    rserverProcessId.put(workers.elementAt(i), workers.elementAt(i).getProcessId());
                }
                return workers;
            }

            private HashMap<RServices, String> rserverProcessId = new HashMap<RServices, String>();

            public void releaseRs(Vector<RServices> rs, int n, String nodeName) throws Exception {
                for (int i = 0; i < n; ++i) {
                    try {
                        String processId = rserverProcessId.get(rs.elementAt(i));
                        if (processId != null) {
                            if (PoolUtils.isWindowsOs()) {
                                PoolUtils.killLocalWinProcess(processId, true);
                            } else {
                                PoolUtils.killLocalUnixProcess(processId, true);
                            }
                            rserverProcessId.remove(rs.elementAt(i));
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        });

        RServices rstub = (RServices) java.rmi.server.RemoteObject.toStub(this);
        R._instance = rstub;

        DirectJNI.getInstance().setStub(PoolUtils.stubToHex(rstub));

        // to be removed
        try {
            File mainlog = new File(
                    DirectJNI.getInstance().getRServices().getWorkingDirectory() + "/" + "main.log");
            if (mainlog.exists())
                mainlog.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }

        _isReady = true;

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RemoteException("<" + Utils.getStackTraceAsString(ex) + ">");
    }
}

From source file:org.kchine.r.server.impl.RServantImpl.java

public void startHttpServer(final int port) throws RemoteException {
    if (_virtualizationServer != null) {
        throw new RemoteException("Server Already Running");
    } else if (ServerManager.isPortInUse("127.0.0.1", port)) {
        throw new RemoteException("Port already in use");
    } else {/*from w  ww . java  2  s.c  o m*/

        try {
            log.info("!! Request to run virtualization server on port " + port);
            RKit rkit = new RKit() {
                RServices _r = (RServices) UnicastRemoteObject.toStub(RServantImpl.this);
                ReentrantLock _lock = new ExtendedReentrantLock() {
                    public void rawLock() {
                        super.lock();
                    }

                    public void rawUnlock() {
                        super.unlock();
                    }
                };

                public RServices getR() {
                    return _r;
                }

                public ReentrantLock getRLock() {
                    return _lock;
                }
            };

            _virtualizationServer = new Server(port);

            _virtualizationServer.setStopAtShutdown(true);

            Context root = new Context(_virtualizationServer, "/rvirtual",
                    Context.SESSIONS | Context.NO_SECURITY);

            final HttpSessionListener sessionListener = new FreeResourcesListener();
            root.getSessionHandler().setSessionManager(new HashSessionManager() {
                @Override
                protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session,
                        boolean arg1) {
                    super.addSession(session, arg1);
                    sessionListener.sessionCreated(new HttpSessionEvent(session.getSession()));
                }

                @Override
                protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session) {
                    super.addSession(session);
                }

                @Override
                public void removeSession(HttpSession session, boolean invalidate) {
                    super.removeSession(session, invalidate);
                    sessionListener.sessionDestroyed(new HttpSessionEvent(session));
                }

                @Override
                public void removeSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session,
                        boolean arg1) {
                    super.removeSession(session, arg1);
                    sessionListener.sessionDestroyed(new HttpSessionEvent(session));
                }

                @Override
                protected void removeSession(String clusterId) {
                    super.removeSession(clusterId);
                }
            });

            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.GraphicsServlet(rkit)),
                    "/graphics/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.RESTServlet(rkit)),
                    "/rest/*");
            root.addServlet(
                    new ServletHolder(new org.kchine.r.server.http.frontend.CommandServlet(rkit, false)),
                    "/cmd/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.local.LocalHelpServlet(rkit)),
                    "/helpme/*");
            root.addServlet(new ServletHolder(
                    new org.kchine.r.server.http.frontend.WWWDirectoryServlet(new DiretoryProvider() {
                        public String getDirectory() throws Exception {
                            return DirectJNI.getInstance().getRServices().getWorkingDirectory();
                        }
                    }, "/wd")), "/wd/*");
            root.addServlet(new ServletHolder(
                    new org.kchine.r.server.http.frontend.WWWDirectoryServlet(ServerManager.WWW_DIR, "/www")),
                    "/www/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.WWWDirectoryServlet(
                    ServerManager.WWW_DIR, "/appletlibs")), "/appletlibs/*");

            System.out.println("+ going to start virtualization http server port : " + port);

            _virtualizationServer.start();

            log.info("HTTP R URL :" + "http://" + PoolUtils.getHostIp() + ":" + port + "/rvirtual/cmd");

        } catch (Exception e) {
            log.info(PoolUtils.getStackTraceAsString(e));
            e.printStackTrace();
        }
    }

}

From source file:org.kchine.rpf.db.DBLayer.java

public String getNameFromStub(Remote stub) throws RemoteException, AccessException {

    ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
    try {//from w  ww .  j av a2s. co  m
        new ObjectOutputStream(baoStream).writeObject(stub);
    } catch (Exception e) {
        e.printStackTrace();
    }
    String stub_hex = bytesToHex(baoStream.toByteArray());

    Statement stmt = null;
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        rset = stmt.executeQuery("select NAME from SERVANTS where STUB_HEX='" + stub_hex + "'");
        if (!rset.next())
            throw new RemoteException("no corresponding servant in DB");
        return rset.getString(1);

    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            return getNameFromStub(stub);
        } else {
            throw new RemoteException("", (sqle));
        }
    } finally {
        if (rset != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }

}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public ManagedServantAbstract(String name, String prefix, Registry registry, int port) throws RemoteException {
    super(port);//from   w  w w  .  j  av a2s.  co m

    _registry = registry;
    try {
        registry.list();
        log.info("ping registry:ok");
    } catch (ConnectException ce) {
        String message = "can't connect to the naming server, make sure an instance of rmiregistry is running";
        log.info(message);
        throw new RemoteException(message);
    } catch (Exception e) {
        e.printStackTrace();
    }

    String newname = null;
    if (name == null) {
        while (true) {
            newname = makeName(prefix, registry);
            try {
                registry.bind(newname, java.rmi.server.RemoteObject.toStub(this));
                break;
            } catch (AlreadyBoundException e) {
            }
        }
    } else {

        // if (!name.startsWith(prefix)) throw new
        // RemoteException("The server name must start with :" + prefix);
        ManagedServant oldServant = null;

        try {
            oldServant = ((ManagedServant) registry.lookup(name));
        } catch (NotBoundException e) {

        }

        if (oldServant != null) {
            log.info("Found an old servant with this name. Killing old servant.");

            try {
                PoolUtils.die(oldServant);
            } catch (RemoteException re) {
                log.info("Old servant wouldn't die! ");
            }
        }

        registry.rebind(name, java.rmi.server.RemoteObject.toStub(this));
    }

    _servantName = name == null ? newname : name;

    final Registry reg = registry;
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            try {
                log.info("Shutting Down");
                reg.unbind(_servantName);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }));

}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public String consoleSubmit(String cmd) throws RemoteException {
    throw new RemoteException("console mode not supported");
}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public String consoleSubmit(String cmd, HashMap<String, Object> clientProperties) throws RemoteException {
    throw new RemoteException("console mode not supported");
}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public String getStatus() throws RemoteException {
    throw new RemoteException("console mode not supported");
}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public void push(String symbol, Serializable object) throws RemoteException {
    throw new RemoteException("push/pop mode not supported");
}