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, Throwable cause) 

Source Link

Document

Constructs a RemoteException with the specified detail message and cause.

Usage

From source file:org.jvnet.hudson.update_center.ConfluencePluginList.java

public WikiPage getPage(String url) throws IOException {
    Matcher tinylink = TINYLINK_PATTERN.matcher(url);
    if (tinylink.matches()) {
        String id = tinylink.group(1);

        File cache = new File(cacheDir, id + ".link");
        if (cache.exists()) {
            url = FileUtils.readFileToString(cache);
        } else {/*from w  w  w .  j  av a2  s. com*/
            try {
                // Avoid creating lots of sessions on wiki server.. get a session and reuse it.
                if (wikiSessionId == null)
                    wikiSessionId = initSession(WIKI_URL);
                url = checkRedirect(WIKI_URL + "pages/tinyurl.action?urlIdentifier=" + id, wikiSessionId);
                FileUtils.writeStringToFile(cache, url);
            } catch (IOException e) {
                throw new RemoteException("Failed to lookup tinylink redirect", e);
            }
        }
    }

    for (String p : WIKI_PREFIXES) {
        if (!url.startsWith(p))
            continue;

        String pageName = url.substring(p.length()).replace('+', ' '); // poor hack for URL escape

        // trim off the trailing '/'
        if (pageName.endsWith("/"))
            pageName = pageName.substring(0, pageName.length() - 1);

        return loadPage(pageName);
    }
    throw new IllegalArgumentException("** Failed to resolve " + url);
}

From source file:org.kchine.r.server.graphics.GDContainerBag.java

public byte[] popAllGraphicObjectsSerialized(int maxNbrGraphicPrimitives) throws RemoteException {
    try {//  w w w  .j av a 2 s .  c o m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(popAllGraphicObjects(maxNbrGraphicPrimitives));
        return baos.toByteArray();
    } catch (Exception e) {
        throw new RemoteException("", e);
    }
}

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

public void reset() throws RemoteException {
    if (isResetEnabled()) {

        System.out.println(".....reset called");
        runR(new ExecutionUnit() {
            public void run(Rengine e) {

                String[] allobj = e
                        .rniGetStringArray(e.rniEval(e.rniParse(".PrivateEnv$ls(all.names=TRUE)", 1), 0));
                if (allobj != null) {
                    for (int i = 0; i < allobj.length; ++i)
                        if (DirectJNI.getInstance().getBootStrapRObjects().contains(allobj[i])) {
                        } else
                            e.rniEval(e.rniParse("rm(" + allobj[i] + ")", 1), 0);
                }/*  w  w  w .j av a2s  .  co m*/

                DirectJNI.getInstance().unprotectAll();
                _log.setLength(0);

            }
        });

        Vector<Integer> devices = new Vector<Integer>();
        for (Integer d : _deviceHashMap.keySet())
            devices.add(d);

        System.out.println("devices before reset:" + devices);

        for (Integer d : devices) {
            try {
                _deviceHashMap.get(d).dispose();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        RListener.stopAllClusters();
        DirectJNI.getInstance().removeAllRCallbacks();
        try {
            DirectJNI.getInstance().regenerateWorkingDirectory(true);
        } catch (Exception e) {
            throw new RemoteException("", e);
        }
    }

}

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

public void stopHttpServer() throws RemoteException {
    if (_virtualizationServer != null) {
        try {//from   w w  w. ja  v  a2 s  . c o  m
            _virtualizationServer.stop();
        } catch (Exception e) {
            _virtualizationServer = null;
            throw new RemoteException("", e);
        }
        _virtualizationServer = null;
    }
}

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

synchronized public RServices cloneServer() throws RemoteException {
    System.out.println("cloneServer");
    try {//from   w w w .j a  va 2  s.  co m
        RServices w = ServerManager.createR(null, false, false, PoolUtils.getHostIp(),
                LocalHttpServer.getLocalHttpServerPort(),
                ServerManager.getRegistryNamingInfo(PoolUtils.getHostIp(),
                        LocalRmiRegistry.getLocalRmiRegistryPort()),
                256, 256, "", false, null, null, System.getProperty("application_type"), null, null);
        return w;
    } catch (Exception e) {
        throw new RemoteException("", e);
    }

}

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

public void bind(String name, Remote obj, HashMap<String, Object> options)
        throws RemoteException, AlreadyBoundException, AccessException {

    Statement stmt = null;// w ww .ja v a 2  s.co  m
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        lock(stmt);
        rset = stmt.executeQuery("select count(*) from SERVANTS where NAME='" + name + "'");
        rset.next();
        if (rset.getInt(1) > 0) {
            throw new AlreadyBoundException();
        }
    } catch (AlreadyBoundException abe) {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } catch (Exception e) {
            throw new RemoteException("", e);
        }
        throw abe;
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            bind(name, obj);
        } 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);
            }
    }

    stmt = null;
    String stub_hex = stubToHex(obj);
    try {
        stmt = _connection.createStatement();
        stmt.execute(
                "Insert into SERVANTS (NAME,STUB_HEX,IN_USE,PING_FAILURES,REGISTER_TIME,PROCESS_ID,HOST_NAME,HOST_IP,OS,CODEBASE,JOB_ID,JOB_NAME,NOTIFY_EMAIL,NOTIFIED) "
                        + "values ('" + name + "','" + stub_hex + "',0,0," + sysdateFunctionName() + ",'"
                        + options.get("process.id") + "','" + options.get("host.name") + "','"
                        + options.get("host.ip") + "','" + options.get("os.name") + "',"
                        + (options.get("java.rmi.server.codebase") == null ? "NULL"
                                : "'" + options.get("java.rmi.server.codebase") + "',")
                        + (options.get("job.id") == null ? "NULL" : "'" + options.get("job.id") + "'") + ","
                        + (options.get("job.name") == null ? "NULL" : "'" + options.get("job.name") + "'") + ","
                        + (options.get("notify.email") == null ? "NULL"
                                : "'" + options.get("notify.email") + "'")
                        + ",0)");
    } catch (SQLException sqle) {
        sqle.printStackTrace();
        if (isConstraintViolationError(sqle))
            throw new AlreadyBoundException();
        else
            throw new RemoteException("", (sqle));
    } finally {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } 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.db.DBLayer.java

public String[] list() throws RemoteException, AccessException {
    Vector<String> result = new Vector<String>();
    Statement stmt = null;/*  w  ww .  j a v a 2 s . c o  m*/
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        rset = stmt.executeQuery("select NAME from SERVANTS");
        while (rset.next()) {
            result.add(rset.getString(1));
        }
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            return list();
        } 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));
            }
    }

    return result.toArray(new String[0]);

}

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

public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException {
    Statement stmt = null;/*from w  w w  .  ja  va2  s.c  o  m*/
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        rset = stmt.executeQuery("select STUB_HEX,CODEBASE from SERVANTS where NAME='" + name + "'");
        if (rset.next()) {

            final String stubHex = rset.getString(1);
            final String codeBaseStr = rset.getString(2);
            final ClassLoader cl = (codeBaseStr != null
                    ? new URLClassLoader(PoolUtils.getURLS(codeBaseStr), DBLayer.class.getClassLoader())
                    : DBLayer.class.getClassLoader());
            System.out.println("codeBaseStr ::" + codeBaseStr);

            final Object[] resultHolder = new Object[1];
            Runnable lookupRunnable = new Runnable() {
                public void run() {
                    try {
                        resultHolder[0] = hexToStub(stubHex, cl);
                    } catch (Exception e) {
                        final boolean wasInterrupted = Thread.interrupted();
                        if (wasInterrupted) {
                            resultHolder[0] = new LookUpInterrupted();
                        } else {
                            resultHolder[0] = e;
                        }
                    }
                }
            };

            Thread lookupThread = InterruptibleRMIThreadFactory.getInstance().newThread(lookupRunnable);
            lookupThread.start();

            long t1 = System.currentTimeMillis();
            while (resultHolder[0] == null) {
                if ((System.currentTimeMillis() - t1) > PoolUtils.LOOKUP_TIMEOUT_MILLISEC) {
                    lookupThread.interrupt();
                    resultHolder[0] = new LookUpTimeout();
                    registerPingFailure(name);
                    break;
                }
                Thread.sleep(10);
            }

            if (resultHolder[0] instanceof Throwable) {
                if (resultHolder[0] instanceof NotBoundException)
                    throw (NotBoundException) resultHolder[0];
                else
                    throw (RemoteException) resultHolder[0];
            }

            return (Remote) resultHolder[0];

        } else {
            throw new NotBoundException();
        }
    } catch (NotBoundException nbe) {
        throw nbe;
    } catch (AccessException ae) {
        throw ae;
    } catch (LookUpTimeout lue) {
        throw lue;
    } catch (LookUpInterrupted lui) {
        throw lui;
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            return lookup(name);
        } else {
            throw new RemoteException("", (sqle));
        }
    } catch (Exception e) {
        throw new RemoteException("", (e));
    } 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.db.DBLayer.java

public void rebind(String name, Remote obj, HashMap<String, Object> options)
        throws RemoteException, AccessException {
    Statement stmt = null;//from ww  w .  ja  va2 s .  co m
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        lock(stmt);
        rset = stmt.executeQuery("select count(*) from SERVANTS where NAME='" + name + "'");
        rset.next();
        if (rset.getInt(1) > 0) {
            stmt.execute("DELETE FROM SERVANTS WHERE NAME='" + name + "'");
        }
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            rebind(name, obj);
        } 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));
            }
    }

    stmt = null;
    String stub_hex = stubToHex(obj);

    try {

        stmt = _connection.createStatement();
        stmt.execute(
                "Insert into SERVANTS (NAME,STUB_HEX,IN_USE,PING_FAILURES,REGISTER_TIME,PROCESS_ID,HOST_NAME,HOST_IP,OS,CODEBASE,JOB_ID,JOB_NAME,NOTIFY_EMAIL,NOTIFIED) "
                        + "values ('" + name + "','" + stub_hex + "',0,0," + sysdateFunctionName() + ",'"
                        + options.get("process.id") + "','" + options.get("host.name") + "','"
                        + options.get("host.ip") + "','" + options.get("os.name") + "',"
                        + (options.get("java.rmi.server.codebase") == null ? "NULL"
                                : "'" + options.get("java.rmi.server.codebase") + "',")
                        + (options.get("job.id") == null ? "NULL" : "'" + options.get("job.id") + "'") + ","
                        + (options.get("job.name") == null ? "NULL" : "'" + options.get("job.name") + "'") + ","
                        + (options.get("notify.email") == null ? "NULL"
                                : "'" + options.get("notify.email") + "'")
                        + ",0)");

    } catch (SQLException sqle) {
        throw new RemoteException("", (sqle));
    } finally {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } 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.db.DBLayer.java

public void unbind(String name) throws RemoteException, NotBoundException, AccessException {

    Statement stmt = null;//  www  .j  a v a  2 s  . c o m
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        lock(stmt);
        stmt.execute("DELETE FROM SERVANTS WHERE NAME='" + name + "'");
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            unbind(name);
        } else {
            throw new RemoteException("", (sqle));
        }
    } finally {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } catch (Exception e) {
            throw new RemoteException("", (e));
        }
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
        if (rset != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }
}