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