use of org.erlide.runtime.rpc.RpcFuture 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;
}
use of org.erlide.runtime.rpc.RpcFuture in project erlide_eclipse by erlang.
the class OtpRpc method sendRpcCall.
private synchronized RpcFuture sendRpcCall(final OtpNode node, final String peer, final boolean logCalls, final OtpErlangObject gleader, final String module, final String fun, final String signature, final Object... args0) throws SignatureException {
final OtpErlangObject[] args = convertArgs(signature, args0);
OtpErlangObject res = null;
final OtpMbox mbox = node.createMbox();
res = buildRpcCall(mbox.self(), gleader, module, fun, args);
if (logCalls) {
final Object[] args01 = { module, fun, argString(args) };
ErlLogger.debug("call -> %s:%s(%s)", args01);
}
//
final OtpErlangRef ref = RpcMonitor.recordRequest(node, peer, module, fun, args, OtpErlang.sizeOf(res));
//
mbox.send("rex", peer, res);
if (OtpRpc.CHECK_RPC) {
ErlLogger.debug("RPC " + mbox.hashCode() + "=> " + res);
}
return new RpcFuture(ref, mbox, module + ":" + fun + "/" + args0.length, logCalls, this);
}
use of org.erlide.runtime.rpc.RpcFuture in project erlide_eclipse by erlang.
the class CallHierarchyAction method run.
@Override
public void run() {
if (module == null) {
return;
}
final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
IErlFunction f = null;
if (el instanceof IErlFunction) {
f = (IErlFunction) el;
} else if (el instanceof IErlFunctionClause) {
f = (IErlFunction) el.getParent();
}
if (f == null) {
return;
}
String name = module.getName();
final int i = name.lastIndexOf('.');
if (i > 0) {
name = name.substring(0, i);
}
final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = dw.getActivePage();
final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {
@Override
protected CallHierarchyView prepare() {
try {
final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
if (cvh == null) {
return null;
}
cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
return cvh;
} catch (final PartInitException e) {
ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
return null;
}
}
@Override
protected RpcFuture call() throws BackendException {
final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
return result;
}
@Override
protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
page.activate(context);
try {
context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
}
};
ac.run();
}
use of org.erlide.runtime.rpc.RpcFuture in project erlide_eclipse by erlang.
the class InternalBuilder method handleErlangFiles.
private void handleErlangFiles(final IErlProject erlProject, @NonNull final IProject project, final BuildKind kind, final IResourceDelta resourceDelta, final BuildNotifier notifier) throws CoreException, BackendException {
final OtpErlangList compilerOptions = CompilerOptions.get(project);
final Set<BuildResource> resourcesToBuild = getResourcesToBuild(kind, project, resourceDelta, notifier);
final int n = resourcesToBuild.size();
if (n == 0) {
return;
}
if (erlProject == null) {
return;
}
// if (BuilderHelper.isDebugging()) {
ErlLogger.debug("Will compile %d resource(s)", n);
// }
final IBackend backend = BackendCore.getBackendManager().getBuildBackend(erlProject);
if (backend == null) {
final String message = "No backend with the required " + "version could be found. Can't build.";
MarkerUtils.createProblemMarker(project, null, message, 0, IMarker.SEVERITY_ERROR);
throw new BackendException(message);
}
final IErlModel model = ErlangEngine.getInstance().getModel();
backend.addProjectPath(model.findProject(project));
notifier.setProgressPerCompilationUnit(1.0f / n);
final Map<RpcFuture, IResource> results = new HashMap<>();
for (final BuildResource bres : resourcesToBuild) {
notifier.checkCancel();
final IResource resource = bres.getResource();
MarkerUtils.deleteMarkers(resource);
notifier.aboutToCompile(resource);
if ("erl".equals(resource.getFileExtension())) {
final String outputDir = erlProject.getProperties().getOutputDir().toString();
final RpcFuture f = helper.startCompileErl(project, bres, outputDir, backend.getOtpRpc(), compilerOptions, kind == BuildKind.FULL);
if (f != null) {
results.put(f, resource);
}
} else if ("yrl".equals(resource.getFileExtension())) {
final RpcFuture f = helper.startCompileYrl(project, resource, backend.getOtpRpc(), compilerOptions);
if (f != null) {
results.put(f, resource);
}
} else {
ErlLogger.warn("Don't know how to compile: %s", resource.getName());
}
}
final List<Entry<RpcFuture, IResource>> done = Lists.newArrayList();
final List<Entry<RpcFuture, IResource>> waiting = Lists.newArrayList(results.entrySet());
// TODO should use some kind of notification!
while (!waiting.isEmpty()) {
for (final Entry<RpcFuture, IResource> result : waiting) {
notifier.checkCancel();
OtpErlangObject r;
try {
r = result.getKey().get(100, TimeUnit.MILLISECONDS);
} catch (final Exception e) {
r = null;
}
if (r != null) {
final IResource resource = result.getValue();
helper.completeCompile(project, resource, r, backend.getOtpRpc(), compilerOptions);
notifier.compiled(resource);
done.add(result);
}
}
waiting.removeAll(done);
done.clear();
}
helper.refreshOutputDir(project);
try {
helper.checkForClashes(backend.getOtpRpc(), project);
} catch (final Exception e) {
}
backend.removeProjectPath(model.findProject(project));
}
Aggregations