Search in sources :

Example 1 with RpcTimeoutException

use of org.erlide.runtime.rpc.RpcTimeoutException in project erlide_eclipse by erlang.

the class DialyzerUtils method doDialyze.

public static void doDialyze(final IProgressMonitor monitor, final Set<IErlModule> modules, final Set<IErlProject> projects, final IBackend backend) throws InvocationTargetException, DialyzerErrorException {
    if (backend == null) {
        ErlLogger.warn("Trying to dialyze with null backend");
        return;
    }
    try {
        for (final IErlModule module : modules) {
            DialyzerMarkerUtils.removeDialyzerMarkersFor(module.getResource());
        }
        // TODO handle preferences from multiple projects
        final DialyzerPreferences prefs = DialyzerPreferences.get(null);
        final Collection<String> pltPaths = prefs.getPltPaths();
        // prefs.getFromSource();
        final boolean fromSource = false;
        // prefs.getNoCheckPLT();
        final boolean noCheckPLT = true;
        final List<String> files = Lists.newArrayList();
        final List<IPath> includeDirs = Lists.newArrayList();
        final List<String> names = Lists.newArrayList();
        DialyzerUtils.collectFilesAndIncludeDirs(modules, projects, files, names, includeDirs, fromSource);
        if (names.isEmpty()) {
            return;
        }
        final String fileNames = names.size() + " modules [" + DialyzerUtils.getFileNames(names) + "]";
        monitor.subTask(fileNames);
        ErlLogger.trace("dialyzer", "run %s", fileNames);
        final IOtpRpc b = backend.getOtpRpc();
        final RpcFuture future = ErlideDialyze.dialyze(b, files, pltPaths, includeDirs, fromSource, noCheckPLT);
        while (!future.isDone()) {
            // check cancellation
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            // check backend down
            if (!backend.isRunning()) {
                throw new BackendException("Dialyzer: backend " + backend.getName() + " is down");
            }
            OtpErlangObject r = null;
            try {
                r = future.checkedGet(500, TimeUnit.MILLISECONDS);
            } catch (final TimeoutException e) {
            } catch (final RpcTimeoutException e) {
            }
            if (r != null) {
                DialyzerUtils.processResult(b, r);
            }
        }
    } catch (final RpcException e) {
        throw new InvocationTargetException(e);
    } catch (final BackendException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) BackendException(org.erlide.backend.api.BackendException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) IErlModule(org.erlide.engine.model.root.IErlModule) RpcFuture(org.erlide.runtime.rpc.RpcFuture) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with RpcTimeoutException

use of org.erlide.runtime.rpc.RpcTimeoutException in project erlide_eclipse by erlang.

the class OtpRpc method getRpcResult.

/**
 * Retrieve the result of a RPC.
 *
 * @param mbox
 * @param timeout
 * @param env
 * @return
 * @throws RpcException
 */
@Override
public OtpErlangObject getRpcResult(final OtpMbox mbox, final long timeout, final String env) throws RpcException {
    assert mbox != null;
    OtpErlangObject res = null;
    try {
        try {
            if (timeout == OtpRpc.INFINITY) {
                res = mbox.receive();
            } else {
                res = mbox.receive(timeout);
            }
            if (OtpRpc.CHECK_RPC) {
                ErlLogger.debug("RPC " + mbox.hashCode() + "<= " + res);
            }
        } finally {
            if (res != null) {
                mbox.close();
            }
        }
        if (res == null) {
            final String msg = env != null ? env : "??";
            throw new RpcTimeoutException(msg);
        }
        if (!(res instanceof OtpErlangTuple)) {
            throw new RpcException(res.toString());
        }
        final OtpErlangTuple t = (OtpErlangTuple) res;
        if (t.arity() != 2) {
            throw new RpcException(res.toString());
        }
        res = t.elementAt(1);
    } catch (final OtpErlangExit e) {
        throw new RpcException(e);
    } catch (final OtpErlangDecodeException e) {
        throw new RpcException(e);
    }
    return res;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangDecodeException(com.ericsson.otp.erlang.OtpErlangDecodeException) OtpErlangExit(com.ericsson.otp.erlang.OtpErlangExit) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 3 with RpcTimeoutException

use of org.erlide.runtime.rpc.RpcTimeoutException in project erlide_eclipse by erlang.

the class OtpRpc method call.

@Override
public OtpErlangObject call(final long timeout, final OtpErlangObject gleader, final String module, final String fun, final String signature, final Object... args0) throws RpcException {
    checkConnected();
    OtpErlangObject result = null;
    try {
        final RpcFuture future = sendRpcCall(localNode, nodeName, false, gleader, module, fun, signature, args0);
        result = future.checkedGet(timeout, TimeUnit.MILLISECONDS);
        if (OtpRpc.CHECK_RPC) {
            ErlLogger.debug("RPC result:: " + result);
        }
        if (isBadRpc(result)) {
            throw new RpcException("Bad RPC: " + result);
        }
    } catch (final SignatureException e) {
        throw new RpcException(e);
    } catch (final TimeoutException e) {
        throw new RpcTimeoutException(e.getMessage());
    }
    return result;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) RpcFuture(org.erlide.runtime.rpc.RpcFuture) SignatureException(org.erlide.util.erlang.SignatureException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 RpcException (org.erlide.runtime.rpc.RpcException)3 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)3 TimeoutException (java.util.concurrent.TimeoutException)2 RpcFuture (org.erlide.runtime.rpc.RpcFuture)2 OtpErlangDecodeException (com.ericsson.otp.erlang.OtpErlangDecodeException)1 OtpErlangExit (com.ericsson.otp.erlang.OtpErlangExit)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IPath (org.eclipse.core.runtime.IPath)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 BackendException (org.erlide.backend.api.BackendException)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)1 SignatureException (org.erlide.util.erlang.SignatureException)1