Search in sources :

Example 16 with RpcException

use of org.erlide.runtime.rpc.RpcException 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 17 with RpcException

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

the class ErlSearchQuery method run.

@Override
public IStatus run(final IProgressMonitor monitor) throws OperationCanceledException {
    final Object locker = new Object();
    final IRpcResultCallback callback = new IRpcResultCallback() {

        @Override
        public void start(final OtpErlangObject msg) {
            if (fSearchResult != null) {
                fSearchResult.removeAll();
            }
            final OtpErlangLong progressMaxL = (OtpErlangLong) msg;
            int progressMax;
            try {
                progressMax = progressMaxL.intValue();
            } catch (final OtpErlangRangeException e) {
                progressMax = 10;
            }
            monitor.beginTask("Searching", progressMax);
        }

        @Override
        public void stop(final OtpErlangObject msg) {
            monitor.done();
            stopped = true;
            synchronized (locker) {
                locker.notifyAll();
            }
        }

        @Override
        public void progress(final OtpErlangObject msg) {
            final OtpErlangTuple t = (OtpErlangTuple) msg;
            final OtpErlangPid backgroundSearchPid = (OtpErlangPid) t.elementAt(0);
            final OtpErlangLong progressL = (OtpErlangLong) t.elementAt(1);
            final OtpErlangObject resultO = t.elementAt(2);
            int progress = 1;
            try {
                progress = progressL.intValue();
                final List<ModuleLineFunctionArityRef> result = Lists.newArrayList();
                SearchUtil.addSearchResult(result, resultO);
                addMatches(result);
            } catch (final OtpErlangRangeException e) {
            }
            monitor.worked(progress);
            if (monitor.isCanceled()) {
                try {
                    ErlangEngine.getInstance().getSearchServerService().cancelSearch(backgroundSearchPid);
                } catch (final RpcException e) {
                }
            }
        }
    };
    try {
        final ErlSearchScope reducedScope = pattern.reduceScope(scope);
        ErlangEngine.getInstance().getSearchServerService().startFindRefs(pattern, reducedScope, ErlangEngine.getInstance().getStateDir(), callback, false);
    } catch (final RpcException e) {
        return new Status(IStatus.ERROR, ErlideUIPlugin.PLUGIN_ID, "Search error", e);
    }
    while (!stopped) {
        synchronized (locker) {
            try {
                if (!stopped) {
                    locker.wait();
                }
            } catch (final InterruptedException e) {
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IRpcResultCallback(org.erlide.runtime.rpc.IRpcResultCallback) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 18 with RpcException

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

the class AsyncCaller method run.

@Override
public void run() {
    final T context = prepare();
    try {
        final RpcFuture result = call();
        if (result == null) {
            return;
        }
        final Job job = new UIJob("async call updater") {

            @Override
            public IStatus runInUIThread(final IProgressMonitor monitor) {
                try {
                    if (result.checkedGet(1, TimeUnit.MILLISECONDS) == null) {
                        schedule(interval);
                    }
                } catch (final RpcException e) {
                    ErlLogger.error(e);
                } catch (final TimeoutException e) {
                    ErlLogger.error(e);
                }
                handleResult(context, result);
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                return new Status(IStatus.OK, ErlideUIPlugin.PLUGIN_ID, "done");
            }
        };
        job.schedule(interval);
    } catch (final BackendException e) {
        ErlLogger.error(e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RpcException(org.erlide.runtime.rpc.RpcException) UIJob(org.eclipse.ui.progress.UIJob) RpcFuture(org.erlide.runtime.rpc.RpcFuture) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob) TimeoutException(java.util.concurrent.TimeoutException) BackendException(org.erlide.backend.api.BackendException)

Example 19 with RpcException

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

the class TraceBackend method loadDataFromFile.

/**
 * Loads traces from active result set (
 * {@link #setActiveResultSet(TracingResultsNode)}). Index of last trace
 * which will be loaded is <code>max(number_of_traces, endIndex)</code>.
 *
 * @param theStartIndex
 *            number of first trace
 * @param endIndex
 *            number of last trace
 */
public void loadDataFromFile(final long theStartIndex, final long endIndex) {
    if (!tracing && !loading) {
        synchronized (this) {
            if (!tracing && !loading) {
                try {
                    loading = true;
                    loadingFileInfo = false;
                    startIndex = theStartIndex;
                    handler = new TraceEventHandler();
                    getBackend(true);
                    TraceCollections.getTracesList().clear();
                    tracerBackend.getRuntime().registerEventListener(handler);
                    final OtpErlangLong start = new OtpErlangLong(theStartIndex);
                    final OtpErlangLong stop = new OtpErlangLong(endIndex);
                    tracerBackend.getOtpRpc().call(Constants.ERLANG_HELPER_MODULE, TraceBackend.FUN_LOAD, "sii", new OtpErlangString(activeResultSet.getFileName()), start, stop);
                } catch (final RpcException e) {
                    ErlLogger.error(e);
                    errorObject = e;
                    finishLoading(TracingStatus.EXCEPTION_THROWN);
                }
            }
        }
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 20 with RpcException

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

the class ProcessHelper method getProcsOnTracedNodes.

/**
 * Returns list of processes on all traced nodes.
 *
 * @return list of processes
 */
public static TracedProcess[] getProcsOnTracedNodes() {
    try {
        final IOtpRpc backend = TraceBackend.getInstance().getBackend(true).getOtpRpc();
        final List<OtpErlangAtom> nodeAtoms = new ArrayList<>();
        for (final Object o : TraceBackend.getInstance().getTracedNodesArray()) {
            final TracedNode tracedNode = (TracedNode) o;
            if (tracedNode.isEnabled()) {
                nodeAtoms.add(new OtpErlangAtom(tracedNode.getNodeName()));
            }
        }
        final OtpErlangList nodesList = new OtpErlangList(nodeAtoms.toArray(new OtpErlangAtom[nodeAtoms.size()]));
        final OtpErlangList procList = (OtpErlangList) backend.call(ProcessHelper.MODULE_NAME, ProcessHelper.FUNCTION_NAME, "x", nodesList);
        final TracedProcess[] processes = new TracedProcess[procList.arity()];
        for (int i = 0; i < procList.arity(); i++) {
            final OtpErlangTuple tuple = (OtpErlangTuple) procList.elementAt(i);
            processes[i] = new TracedProcess(tuple);
        }
        return processes;
    } catch (final RpcException e) {
        ErlLogger.error(e);
    }
    return null;
}
Also used : TracedProcess(org.erlide.tracing.core.mvc.model.TracedProcess) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Aggregations

RpcException (org.erlide.runtime.rpc.RpcException)37 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)30 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)15 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)12 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)8 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)7 ArrayList (java.util.ArrayList)7 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)6 RpcFuture (org.erlide.runtime.rpc.RpcFuture)5 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)4 TimeoutException (java.util.concurrent.TimeoutException)4 CoverException (org.erlide.cover.api.CoverException)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)4 Test (org.junit.Test)4 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)3 IPath (org.eclipse.core.runtime.IPath)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3