Search in sources :

Example 1 with RpcFuture

use of org.erlide.runtime.rpc.RpcFuture 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 RpcFuture

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

the class BuilderHelper method compileErl.

public void compileErl(@NonNull final IProject project, final BuildResource resource, final String outputDir, final IOtpRpc b, final OtpErlangList compilerOptions) {
    final RpcFuture res = startCompileErl(project, resource, outputDir, b, compilerOptions, true);
    if (res == null) {
        ErlLogger.warn("error compiling erl file: " + resource.getResource().getProjectRelativePath());
        return;
    }
    try {
        final OtpErlangObject result = res.checkedGet();
        completeCompile(project, resource.getResource(), result, b, compilerOptions);
    } catch (final RpcException e) {
        ErlLogger.warn(e);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) RpcFuture(org.erlide.runtime.rpc.RpcFuture)

Example 3 with RpcFuture

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

the class ErlTidyCleanupProvider method cleanUp.

@Override
public void cleanUp(final IResource resource) throws Exception {
    // invoke erl_tidy in the background
    final String absolutePathToErlangModule = resource.getLocation().toString();
    final RpcFuture erlTidyFuture = backend.async_call("erl_tidy", "file", "s", absolutePathToErlangModule);
    // wait as long as reasonable for erl_tidy to finish
    erlTidyFuture.get(ErlTidyCleanupProvider.PATIENCE_LIMIT, TimeUnit.MILLISECONDS);
    // refresh the resource so it reflects the altered state on disk
    resource.refreshLocal(IResource.DEPTH_ZERO, null);
}
Also used : RpcFuture(org.erlide.runtime.rpc.RpcFuture)

Example 4 with RpcFuture

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

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

the class OtpRpc method async_call_cb.

@Override
public void async_call_cb(final IRpcCallback cb, final long timeout, final OtpErlangObject gleader, final String module, final String fun, final String signature, final Object... args) throws RpcException {
    checkConnected();
    try {
        final RpcFuture future = sendRpcCall(localNode, nodeName, false, gleader, module, fun, signature, args);
        final Runnable target = new Runnable() {

            @Override
            public void run() {
                OtpErlangObject result;
                try {
                    result = future.checkedGet(timeout, TimeUnit.MILLISECONDS);
                    cb.onSuccess(result);
                } catch (final Exception e) {
                    ErlLogger.error("Could not execute RPC " + module + ":" + fun + " : " + e.getMessage());
                    cb.onFailure(e);
                }
            }
        };
        // We can't use jobs here, it's an Eclipse dependency
        OtpRpc.threadPool.execute(target);
    } catch (final SignatureException e) {
        throw new RpcException(e);
    }
}
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) SignatureException(org.erlide.util.erlang.SignatureException) TimeoutException(java.util.concurrent.TimeoutException) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangDecodeException(com.ericsson.otp.erlang.OtpErlangDecodeException)

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