use of org.dartlang.vm.service.consumer.VMConsumer in project flutter-intellij by flutter.
the class FlutterTestRunner method run.
protected RunContentDescriptor run(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// Poll, waiting for "flutter run" to give us a websocket.
// This is adapted from DartVmServiceDebugProcess::scheduleConnect.
String url = connector.getWebSocketUrl();
while (url == null) {
if (launcher.isTerminated()) {
return;
}
TimeoutUtil.sleep(100);
url = connector.getWebSocketUrl();
}
if (launcher.isTerminated()) {
return;
}
final VmService vmService;
try {
vmService = VmService.connect(url);
} catch (IOException | RuntimeException e) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Failed to connect to the VM service at: " + url + "\n" + e.toString() + "\n", ProcessOutputTypes.STDERR);
}
return;
}
// Listen for debug 'PauseStart' events for isolates after the initial connect and resume those isolates.
vmService.streamListen(VmService.DEBUG_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
if (EventKind.PauseStart.equals(event.getKind())) {
resumePausedAtStartIsolate(launcher, vmService, event.getIsolate());
}
}
});
// Resume any isolates paused at the initial connect.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM response) {
final ElementList<IsolateRef> isolates = response.getIsolates();
for (IsolateRef isolateRef : isolates) {
resumePausedAtStartIsolate(launcher, vmService, isolateRef);
}
}
@Override
public void onError(RPCError error) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Error connecting to VM: " + error.getCode() + " " + error.getMessage() + "\n", ProcessOutputTypes.STDERR);
}
}
});
});
return new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
use of org.dartlang.vm.service.consumer.VMConsumer in project flutter-intellij by flutter.
the class RenderThread method performReload.
/**
* Attempt to perform hot reload.
*
* @return true if successful, or false if unsuccessful or timeout.
*/
private boolean performReload() {
final CountDownLatch reloadLatch = new CountDownLatch(1);
final AtomicBoolean reloadSuccess = new AtomicBoolean(false);
myVmService.getVM(new VMConsumer() {
@Override
public void received(VM vm) {
final ElementList<IsolateRef> isolates = vm.getIsolates();
if (!isolates.isEmpty()) {
final String isolateId = isolates.get(0).getId();
myVmService.reloadSources(isolateId, new ReloadReportConsumer() {
@Override
public void received(ReloadReport report) {
reloadSuccess.set(report.getSuccess());
reloadLatch.countDown();
}
@Override
public void onError(RPCError error) {
reloadLatch.countDown();
}
});
}
}
@Override
public void onError(RPCError error) {
reloadLatch.countDown();
}
});
return Uninterruptibles.awaitUninterruptibly(reloadLatch, 2000, TimeUnit.MILLISECONDS) && reloadSuccess.get();
}
use of org.dartlang.vm.service.consumer.VMConsumer in project flutter-intellij by flutter.
the class DartVmServiceDebugProcess method onConnectSucceeded.
private void onConnectSucceeded(VmService vmService) {
final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
final DartVmServiceBreakpointHandler breakpointHandler = (DartVmServiceBreakpointHandler) myBreakpointHandlers[0];
myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, breakpointHandler);
final ScriptProvider provider = (isolateId, scriptId) -> myVmServiceWrapper.getScriptSync(isolateId, scriptId);
mapper.onConnect(provider, myConnector.getRemoteBaseUrl());
final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(executionEnvironment);
if (launchMode.supportsDebugConnection()) {
myVmServiceWrapper.handleDebuggerConnected();
// TODO(jacobr): the following code is a workaround for issues
// auto-resuming isolates paused at their creation while running in
// debug mode.
// The ideal fix would by to fix VMServiceWrapper so that it checks
// for already running isolates like we do here or to refactor where we
// create our VmServiceWrapper so we can listen for isolate creation soon
// enough that we never miss an isolate creation message.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM vm) {
final ElementList<IsolateRef> isolates = vm.getIsolates();
// to handleDebuggerConnected was made and so
for (IsolateRef isolateRef : isolates) {
vmService.getIsolate(isolateRef.getId(), new VmServiceConsumers.GetIsolateConsumerWrapper() {
public void received(Isolate isolate) {
final Event event = isolate.getPauseEvent();
final EventKind eventKind = event.getKind();
if (eventKind == EventKind.PauseStart) {
ApplicationManager.getApplication().invokeLater(() -> {
// We are assuming it is safe to call handleIsolate multiple times.
myVmServiceWrapper.handleIsolate(isolateRef, true);
});
} else if (eventKind == EventKind.Resume) {
// Currently true if we got here via 'flutter attach'
ApplicationManager.getApplication().invokeLater(() -> {
myVmServiceWrapper.attachIsolate(isolateRef, isolate);
});
}
}
});
}
}
@Override
public void onError(RPCError error) {
FlutterUtils.warn(LOG, error.toString());
}
});
}
vmService.addVmServiceListener(vmServiceListener);
myVmConnected = true;
getSession().rebuildViews();
onVmConnected(vmService);
}
Aggregations