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;
}
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;
}
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);
}
}
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);
}
}
}
}
}
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;
}
Aggregations