Search in sources :

Example 6 with RpcFuture

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

Example 7 with RpcFuture

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);
}
Also used : OtpMbox(com.ericsson.otp.erlang.OtpMbox) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcFuture(org.erlide.runtime.rpc.RpcFuture) OtpErlangRef(com.ericsson.otp.erlang.OtpErlangRef)

Example 8 with RpcFuture

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) IErlElement(org.erlide.engine.model.IErlElement) CallHierarchyView(org.erlide.ui.views.CallHierarchyView) ErlModelException(org.erlide.engine.model.ErlModelException) AsyncCaller(org.erlide.ui.jinterface.AsyncCaller) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RpcFuture(org.erlide.runtime.rpc.RpcFuture) PartInitException(org.eclipse.ui.PartInitException) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 9 with RpcFuture

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));
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BackendException(org.erlide.backend.api.BackendException) BackendException(org.erlide.backend.api.BackendException) Entry(java.util.Map.Entry) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IBackend(org.erlide.backend.api.IBackend) RpcFuture(org.erlide.runtime.rpc.RpcFuture) IResource(org.eclipse.core.resources.IResource)

Aggregations

RpcFuture (org.erlide.runtime.rpc.RpcFuture)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)6 RpcException (org.erlide.runtime.rpc.RpcException)5 TimeoutException (java.util.concurrent.TimeoutException)4 BackendException (org.erlide.backend.api.BackendException)3 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ErlModelException (org.erlide.engine.model.ErlModelException)2 SignatureException (org.erlide.util.erlang.SignatureException)2 OtpErlangDecodeException (com.ericsson.otp.erlang.OtpErlangDecodeException)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangRef (com.ericsson.otp.erlang.OtpErlangRef)1 OtpMbox (com.ericsson.otp.erlang.OtpMbox)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1