Example usage for java.rmi RemoteException getCause

List of usage examples for java.rmi RemoteException getCause

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Document

Returns the cause of this exception.

Usage

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

public Object makeObject() throws Exception {
    Vector<String> servantNames = new Vector<String>();

    try {//  w ww  .j a v  a 2s .  c o m

        try {

            _dbLayer.lock();
            servantNames.addAll(_dbLayer.list(_poolData.getPrefixes()));
            // System.out.println("servant Names : " + servantNames);
        } catch (Exception e) {
            e.printStackTrace();
            throw new NoSuchElementException("No R Servant available / No DB ");
        }

        Vector<Integer> order = null;
        if (servantNames.size() > 0)
            order = PoolUtils.getRandomOrder(servantNames.size());

        for (int i = 0; i < servantNames.size(); ++i) {
            try {

                ManagedServant servant = (ManagedServant) _dbLayer
                        .lookup(servantNames.elementAt(order.elementAt(i)));
                PoolUtils.ping(servant);
                _dbLayer.reserve(servantNames.elementAt(order.elementAt(i)));
                return servant;
            } catch (LookUpTimeout e) {
                _dbLayer.registerPingFailure(servantNames.elementAt(order.elementAt(i)));
            } catch (RemoteException re) {

                if (re.getCause() instanceof InitializingException) {
                } else {
                    _dbLayer.registerPingFailure(servantNames.elementAt(order.elementAt(i)));
                }

            }
        }

    } finally {
        _dbLayer.unlock();
        _dbLayer.commit();
    }

    throw new NoSuchElementException("No Servant available");
}

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

public boolean validateObject(Object obj) {
    try {/*from   w ww.ja v  a  2  s  . c  om*/
        PoolUtils.ping((ManagedServant) obj);
        return true;
    } catch (RemoteException re) {

        if (re.getCause() instanceof InitializingException) {
        } else {
            try {

                _dbLayer.lock();
                try {
                    String servantName = _dbLayer.getNameFromStub((ManagedServant) obj);
                    _dbLayer.registerPingFailure(servantName);
                    _dbLayer.unReserve(servantName);
                } finally {
                    _dbLayer.unlock();
                    _dbLayer.commit();
                }

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

        log.info("## Validation failed, couldn't ping");
        return false;
    }
}

From source file:org.ms123.common.rpc.JsonRpcServlet.java

protected Map<String, Object> buildResponse(final Map<String, Object> request,
        final RemoteException exception) {
    final Map<String, Object> response = new HashMap<String, Object>(3);
    final Map<String, Object> error = new HashMap<String, Object>(6);
    error.put("origin", ERROR_FROM_METHOD);
    error.put("code", null);
    error.put("message", exception.getMessage());
    error.put("class", exception.getClass().getName());
    final Throwable cause = exception.getCause();
    if (cause != null) {
    }/*from  w ww.j a  v  a 2s  .c  om*/
    response.put("id", request.get("id"));
    response.put("error", error);
    response.put("result", null);
    return response;
}

From source file:org.springframework.remoting.rmi.RmiClientInterceptorUtils.java

/**
 * Determine whether the given RMI exception indicates a connect failure.
 * <p>Treats RMI's ConnectException, ConnectIOException, UnknownHostException,
 * NoSuchObjectException and StubNotFoundException as connect failure.
 * @param ex the RMI exception to check/*from  w w w  . ja  v a2  s .c  o  m*/
 * @return whether the exception should be treated as connect failure
 * @see java.rmi.ConnectException
 * @see java.rmi.ConnectIOException
 * @see java.rmi.UnknownHostException
 * @see java.rmi.NoSuchObjectException
 * @see java.rmi.StubNotFoundException
 */
public static boolean isConnectFailure(RemoteException ex) {
    return (ex instanceof ConnectException || ex instanceof ConnectIOException
            || ex instanceof UnknownHostException || ex instanceof NoSuchObjectException
            || ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException);
}

From source file:org.taverna.server.localworker.impl.LocalWorker.java

@Override
public RemoteSecurityContext getSecurityContext() throws RemoteException, ImplementationException {
    try {//from   www .j  a  va 2 s  . c o m
        return new SecurityDelegate(masterToken);
    } catch (RemoteException e) {
        if (e.getCause() != null)
            throw new ImplementationException("problem initializing security context", e.getCause());
        throw e;
    } catch (IOException e) {
        throw new ImplementationException("problem initializing security context", e);
    }
}

From source file:org.taverna.server.master.localworker.ForkRunFactory.java

/**
 * Makes the subprocess that manufactures runs.
 * //w w w  . j  av a  2  s. c o  m
 * @throws Exception
 *             If anything goes wrong.
 */
public void initFactory() throws Exception {
    if (factory != null)
        return;
    // Generate the arguments to use when spawning the subprocess
    factoryProcessName = state.getFactoryProcessNamePrefix() + randomUUID();
    ProcessBuilder p = new ProcessBuilder(getJavaBinary());
    p.command().addAll(asList(getExtraArguments()));
    p.command().add("-jar");
    p.command().add(getServerWorkerJar());
    p.command().add(getExecuteWorkflowScript());
    p.command().add(factoryProcessName);
    p.redirectErrorStream(true);
    p.directory(new File(getProperty("javax.servlet.context.tempdir", getProperty("java.io.tmpdir"))));

    // Spawn the subprocess
    log.info("about to create subprocess: " + p.command());
    factoryProcess = p.start();
    Thread logger = new Thread(new OutputLogger(factoryProcessName, factoryProcess),
            factoryProcessName + ".Logger");
    logger.setDaemon(true);
    logger.start();

    // Wait for the subprocess to register itself in the RMI registry
    Calendar deadline = Calendar.getInstance();
    deadline.add(SECOND, state.getWaitSeconds());
    Exception lastException = null;
    lastStartupCheckCount = 0;
    while (deadline.after(Calendar.getInstance())) {
        try {
            sleep(state.getSleepMS());
            lastStartupCheckCount++;
            log.info("about to look up resource called " + factoryProcessName);
            try {
                // Validate registry connection first
                getTheRegistry().list();
            } catch (ConnectException ce) {
                log.warn("connection problems with registry", ce);
            } catch (ConnectIOException e) {
                log.warn("connection problems with registry", e);
            }
            factory = (RemoteRunFactory) getTheRegistry().lookup(factoryProcessName);
            log.info("successfully connected to factory subprocess " + factoryProcessName);
            if (interhost != null)
                factory.setInteractionServiceDetails(interhost, interport, interwebdav, interfeed);
            return;
        } catch (InterruptedException ie) {
            continue;
        } catch (NotBoundException nbe) {
            lastException = nbe;
            log.info("resource \"" + factoryProcessName + "\" not yet registered...");
            continue;
        } catch (RemoteException re) {
            // Unpack a remote exception if we can
            lastException = re;
            try {
                if (re.getCause() != null)
                    lastException = (Exception) re.getCause();
            } catch (Throwable t) {
                // Ignore!
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    throw lastException;
}

From source file:org.taverna.server.master.localworker.RemoteRunDelegate.java

@Override
public void setProperty(String propName, String value) throws NoListenerException, BadPropertyValueException {
    try {/*from   w ww.j  a  v  a2  s  .  com*/
        r.setProperty(propName, value);
    } catch (RemoteException e) {
        log.warn("failed to set property", e);
        if (e.getCause() != null && e.getCause() instanceof RuntimeException)
            throw new NoListenerException("failed to set property", e.getCause());
        if (e.getCause() != null && e.getCause() instanceof Exception)
            throw new BadPropertyValueException("failed to set property", e.getCause());
        throw new BadPropertyValueException("failed to set property", e);
    }
}

From source file:xbird.xquery.expr.ext.BDQExpr.java

public XQExpression staticAnalysis(StaticContext statEnv) throws XQueryException {
    if (!_analyzed) {
        this._analyzed = true;

        XQExpression analyzedEndpoint = _endpoint.staticAnalysis(statEnv);
        this._endpoint = analyzedEndpoint;

        // prepare to ship local variables
        final List<ShippedVariable> shippedVars = new ArrayList<ShippedVariable>(4);
        ParametricVariableDetector detector = new ParametricVariableDetector(shippedVars, statEnv);
        detector.visit(_queryExpr, null);

        final XQExpression compiledExpr;
        if (analyzedEndpoint instanceof LiteralExpr) {// distributed compile                 
            LiteralExpr epLiteral = (LiteralExpr) analyzedEndpoint;
            String endpoint = epLiteral.getValue().stringValue();

            final XQEngineClient client = new XQEngineClient(endpoint);
            final CompileRequest request = new CompileRequest(_queryExpr);

            if (LOG.isInfoEnabled()) {
                LOG.info("Invoking remote compilation at [" + endpoint + "]:\n " + _queryExpr);
            }/*from www . j  a  va  2  s .  c  om*/

            // invokes remote compilation
            final Object result;
            try {
                result = client.execute(request);
            } catch (RemoteException e) {
                throw new XQueryException(e.getMessage(), e.getCause());
            } finally {
                try {
                    client.close();
                } catch (RemoteException e) {
                    LOG.warn("shutdown failed for `" + endpoint + '\'', e);
                }
            }

            compiledExpr = (XQExpression) result;
            // reset local expression
            if (!shippedVars.isEmpty()) {
                ShippedVariableModifier modifier = new ShippedVariableModifier(shippedVars);
                modifier.visit(compiledExpr, null);
            }

            this._parallel = false;

        } else { // compile locally (some access paths such as index access is disabled) 
            boolean prevState = statEnv.isIndicesAccessible();
            statEnv.setIndicesAccessible(false); //TODO remote compilation for static endpoint
            compiledExpr = _queryExpr.staticAnalysis(statEnv);
            statEnv.setIndicesAccessible(prevState);
        }

        this._queryExpr = compiledExpr;
        this._type = compiledExpr.getType();
        final ThreadedVariable threadedVar = new ThreadedVariable(this);
        statEnv.addThreadedVariable(threadedVar);
        return threadedVar;
    }
    return this;
}

From source file:xbird.xquery.expr.ext.BDQExpr.java

private static Sequence invokeRequest(final String endpoint, final PreparedQueryRequest request)
        throws XQueryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Invoking remote execution at [" + endpoint + "]:\n " + request.getCompiledExpression());
    }/*from   www. ja va 2s. co m*/
    final XQEngineClient client = new XQEngineClient(endpoint);
    final Object result;
    try {
        result = client.execute(request);
    } catch (RemoteException e) {
        throw new XQueryException(e.getMessage(), e.getCause());
    } finally {
        try {
            client.close();
        } catch (RemoteException e) {
            LOG.warn("shutdown failed for `" + endpoint + '\'', e);
        }
    }
    Sequence resultSeq = (Sequence) result;
    return resultSeq;
}

From source file:xbird.xquery.func.ext.RemoteEval.java

public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
        throws XQueryException {
    String endpoint = argv.getItem(0).stringValue();
    String query = argv.getItem(1).stringValue();

    if (LOG.isInfoEnabled()) {
        LOG.info("Invoking remote query at [" + endpoint + "]:\n " + query);
    }/*ww w.ja v a 2  s . co  m*/

    XQEngineClient client = new XQEngineClient(endpoint);
    QueryRequest request = new QueryRequest(query, RETURN_TYPE);
    StaticContext statEnv = dynEnv.getStaticContext();
    URI baseUri = statEnv.getBaseURI();
    if (baseUri == null) {
        baseUri = statEnv.getSystemBaseURI();
    }
    request.setBaseUri(baseUri);
    prepareVariablesToShip(request, argv, dynEnv);
    final Object result;
    try {
        result = client.execute(request);
    } catch (RemoteException e) {
        throw new XQueryException(e.getMessage(), e.getCause());
    } finally {
        try {
            client.close();
        } catch (RemoteException e) {
            LOG.warn("shutdown failed for `" + endpoint + '\'', e);
        }
    }
    Sequence resultSeq = (Sequence) result;
    return resultSeq;
}