Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Package Functions | Package Attributes | List of all members
org.dartlang.vm.service.VmServiceBase Class Referenceabstract
Inheritance diagram for org.dartlang.vm.service.VmServiceBase:
org.dartlang.vm.service.internal.VmServiceConst

Public Member Functions

void addVmServiceListener (VmServiceListener listener)
 
void removeVmServiceListener (VmServiceListener listener)
 
void addServiceRunner (String service, RemoteServiceRunner runner)
 
void removeServiceRunner (String service)
 
Version getRuntimeVersion ()
 
void disconnect ()
 
void getInstance (String isolateId, String instanceId, final GetInstanceConsumer consumer)
 
void getLibrary (String isolateId, String libraryId, final GetLibraryConsumer consumer)
 
abstract void getObject (String isolateId, String objectId, GetObjectConsumer consumer)
 
void callServiceExtension (String isolateId, String method, ServiceExtensionConsumer consumer)
 
void callServiceExtension (String isolateId, String method, JsonObject params, ServiceExtensionConsumer consumer)
 
void connectionOpened ()
 
void connectionClosed ()
 

Static Public Member Functions

static VmService connect (final String url) throws IOException
 
static VmService localConnect (int port) throws IOException
 

Protected Member Functions

void request (String method, JsonObject params, Consumer consumer)
 
String removeNewLines (String str)
 

Package Functions

abstract void forwardResponse (Consumer consumer, String type, JsonObject json)
 
void logUnknownResponse (Consumer consumer, JsonObject json)
 
void processMessage (String jsonText)
 
void processRequest (JsonObject json)
 
void processNotification (JsonObject json)
 
void processResponse (JsonObject json)
 

Package Attributes

RequestSink requestSink
 
Version runtimeVersion
 

Additional Inherited Members

- Static Public Attributes inherited from org.dartlang.vm.service.internal.VmServiceConst
static final String CODE = "code"
 
static final String ERROR = "error"
 
static final String EVENT = "event"
 
static final String ID = "id"
 
static final String MESSAGE = "message"
 
static final String METHOD = "method"
 
static final String PARAMS = "params"
 
static final String RESULT = "result"
 
static final String STREAM_ID = "streamId"
 
static final String TYPE = "type"
 
static final String JSONRPC = "jsonrpc"
 
static final String JSONRPC_VERSION = "2.0"
 
static final String DATA = "data"
 
static final int PARSE_ERROR = -32700
 
static final int INVALID_REQUEST = -32600
 
static final int METHOD_NOT_FOUND = -32601
 
static final int INVALID_PARAMS = -32602
 
static final int SERVER_ERROR = -32000
 

Detailed Description

Internal VmService base class containing non-generated code.

Definition at line 45 of file VmServiceBase.java.

Member Function Documentation

◆ addServiceRunner()

void org.dartlang.vm.service.VmServiceBase.addServiceRunner ( String  service,
RemoteServiceRunner  runner 
)
inline

Add a VM RemoteServiceRunner.

Definition at line 217 of file VmServiceBase.java.

217 {
218 remoteServiceRunners.put(service, runner);
219 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm service
Definition: switches.h:99

◆ addVmServiceListener()

void org.dartlang.vm.service.VmServiceBase.addVmServiceListener ( VmServiceListener  listener)
inline

Add a listener to receive Events from the VM.

Definition at line 203 of file VmServiceBase.java.

203 {
204 vmListeners.add(listener);
205 }

◆ callServiceExtension() [1/2]

void org.dartlang.vm.service.VmServiceBase.callServiceExtension ( String  isolateId,
String  method,
JsonObject  params,
ServiceExtensionConsumer  consumer 
)
inline

Invoke a specific service protocol extension method.

See https://api.dart.dev/stable/dart-developer/dart-developer-library.html.

Definition at line 314 of file VmServiceBase.java.

314 {
315 params.addProperty("isolateId", isolateId);
316 request(method, params, consumer);
317 }
void request(String method, JsonObject params, Consumer consumer)
const EmbeddedViewParams * params

◆ callServiceExtension() [2/2]

void org.dartlang.vm.service.VmServiceBase.callServiceExtension ( String  isolateId,
String  method,
ServiceExtensionConsumer  consumer 
)
inline

Invoke a specific service protocol extension method.

See https://api.dart.dev/stable/dart-developer/dart-developer-library.html.

Definition at line 303 of file VmServiceBase.java.

303 {
304 JsonObject params = new JsonObject();
305 params.addProperty("isolateId", isolateId);
306 request(method, params, consumer);
307 }

◆ connect()

static VmService org.dartlang.vm.service.VmServiceBase.connect ( final String  url) throws IOException
inlinestatic

Connect to the VM observatory service via the specified URI

Returns
an API object for interacting with the VM service (not null).

Definition at line 51 of file VmServiceBase.java.

51 {
52 // Validate URL
53 URI uri;
54 try {
55 uri = new URI(url);
56 } catch (URISyntaxException e) {
57 throw new IOException("Invalid URL: " + url, e);
58 }
59 String wsScheme = uri.getScheme();
60 if (!"ws".equals(wsScheme) && !"wss".equals(wsScheme)) {
61 throw new IOException("Unsupported URL scheme: " + wsScheme);
62 }
63
64 // Create web socket and observatory
65 WebSocket webSocket;
66 try {
67 webSocket = new WebSocket(uri);
68 } catch (WebSocketException e) {
69 throw new IOException("Failed to create websocket: " + url, e);
70 }
71 final VmService vmService = new VmService();
72
73 // Setup event handler for forwarding responses
74 webSocket.setEventHandler(new WebSocketEventHandler() {
75 @Override
76 public void onClose() {
77 Logging.getLogger().logInformation("VM connection closed: " + url);
78
79 vmService.connectionClosed();
80 }
81
82 @Override
83 public void onMessage(WebSocketMessage message) {
84 Logging.getLogger().logInformation("VM message: " + message.getText());
85 try {
86 vmService.processMessage(message.getText());
87 } catch (Exception e) {
88 Logging.getLogger().logError(e.getMessage(), e);
89 }
90 }
91
92 @Override
93 public void onOpen() {
94 vmService.connectionOpened();
95
96 Logging.getLogger().logInformation("VM connection open: " + url);
97 }
98
99 @Override
100 public void onPing() {
101 }
102
103 @Override
104 public void onPong() {
105 }
106 });
107
108 // Establish WebSocket Connection
109 //noinspection TryWithIdenticalCatches
110 try {
111 webSocket.connect();
112 } catch (WebSocketException e) {
113 throw new IOException("Failed to connect: " + url, e);
114 } catch (ArrayIndexOutOfBoundsException e) {
115 // The weberknecht can occasionally throw an array index exception if a connect terminates on initial connect
116 // (de.roderick.weberknecht.WebSocket.connect, WebSocket.java:126).
117 throw new IOException("Failed to connect: " + url, e);
118 }
119 vmService.requestSink = new WebSocketRequestSink(webSocket);
120
121 // Check protocol version
122 final CountDownLatch latch = new CountDownLatch(1);
123 final String[] errMsg = new String[1];
124 vmService.getVersion(new VersionConsumer() {
125 @Override
126 public void onError(RPCError error) {
127 String msg = "Failed to determine protocol version: " + error.getCode() + "\n message: "
128 + error.getMessage() + "\n details: " + error.getDetails();
129 Logging.getLogger().logInformation(msg);
130 errMsg[0] = msg;
131 }
132
133 @Override
134 public void received(Version version) {
135 vmService.runtimeVersion = version;
136
137 latch.countDown();
138 }
139 });
140
141 try {
142 if (!latch.await(5, TimeUnit.SECONDS)) {
143 throw new IOException("Failed to determine protocol version");
144 }
145 if (errMsg[0] != null) {
146 throw new IOException(errMsg[0]);
147 }
148 } catch (InterruptedException e) {
149 throw new RuntimeException("Interrupted while waiting for response", e);
150 }
151
152 return vmService;
153 }
Version
bool equals(SkDrawable *a, SkDrawable *b)
const uint8_t uint32_t uint32_t GError ** error
Win32Message message

◆ connectionClosed()

void org.dartlang.vm.service.VmServiceBase.connectionClosed ( )
inline

Definition at line 362 of file VmServiceBase.java.

362 {
363 for (VmServiceListener listener : new ArrayList<>(vmListeners)) {
364 try {
365 listener.connectionClosed();
366 } catch (Exception e) {
367 Logging.getLogger().logError("Exception notifying listener", e);
368 }
369 }
370 }

◆ connectionOpened()

void org.dartlang.vm.service.VmServiceBase.connectionOpened ( )
inline

Definition at line 342 of file VmServiceBase.java.

342 {
343 for (VmServiceListener listener : new ArrayList<>(vmListeners)) {
344 try {
345 listener.connectionOpened();
346 } catch (Exception e) {
347 Logging.getLogger().logError("Exception notifying listener", e);
348 }
349 }
350 }

◆ disconnect()

void org.dartlang.vm.service.VmServiceBase.disconnect ( )
inline

Disconnect from the VM observatory service.

Definition at line 238 of file VmServiceBase.java.

◆ forwardResponse()

abstract void org.dartlang.vm.service.VmServiceBase.forwardResponse ( Consumer  consumer,
String  type,
JsonObject  json 
)
abstractpackage

◆ getInstance()

void org.dartlang.vm.service.VmServiceBase.getInstance ( String  isolateId,
String  instanceId,
final GetInstanceConsumer  consumer 
)
inline

Return the instance with the given identifier.

Definition at line 245 of file VmServiceBase.java.

245 {
246 getObject(isolateId, instanceId, new GetObjectConsumer() {
247
248 @Override
249 public void onError(RPCError error) {
250 consumer.onError(error);
251 }
252
253 @Override
254 public void received(Obj response) {
255 if (response instanceof Instance) {
256 consumer.received((Instance) response);
257 } else {
258 onError(RPCError.unexpected("Instance", response));
259 }
260 }
261
262 @Override
263 public void received(Sentinel response) {
264 onError(RPCError.unexpected("Instance", response));
265 }
266 });
267 }
abstract void getObject(String isolateId, String objectId, GetObjectConsumer consumer)
static RPCError unexpected(String expectedType, Response response)
Definition: RPCError.java:62

◆ getLibrary()

void org.dartlang.vm.service.VmServiceBase.getLibrary ( String  isolateId,
String  libraryId,
final GetLibraryConsumer  consumer 
)
inline

Return the library with the given identifier.

Definition at line 272 of file VmServiceBase.java.

272 {
273 getObject(isolateId, libraryId, new GetObjectConsumer() {
274
275 @Override
276 public void onError(RPCError error) {
277 consumer.onError(error);
278 }
279
280 @Override
281 public void received(Obj response) {
282 if (response instanceof Library) {
283 consumer.received((Library) response);
284 } else {
285 onError(RPCError.unexpected("Library", response));
286 }
287 }
288
289 @Override
290 public void received(Sentinel response) {
291 onError(RPCError.unexpected("Library", response));
292 }
293 });
294 }

◆ getObject()

abstract void org.dartlang.vm.service.VmServiceBase.getObject ( String  isolateId,
String  objectId,
GetObjectConsumer  consumer 
)
abstract

◆ getRuntimeVersion()

Version org.dartlang.vm.service.VmServiceBase.getRuntimeVersion ( )
inline

Return the VM service protocol version supported by the current debug connection.

Definition at line 231 of file VmServiceBase.java.

231 {
232 return runtimeVersion;
233 }

◆ localConnect()

static VmService org.dartlang.vm.service.VmServiceBase.localConnect ( int  port) throws IOException
inlinestatic

Connect to the VM observatory service on the given local port.

Returns
an API object for interacting with the VM service (not null).
Deprecated:
prefer the Url based constructor VmServiceBase#connect

Definition at line 163 of file VmServiceBase.java.

163 {
164 return connect("ws://localhost:" + port + "/ws");
165 }
static VmService connect(final String url)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition: switches.h:87

◆ logUnknownResponse()

void org.dartlang.vm.service.VmServiceBase.logUnknownResponse ( Consumer  consumer,
JsonObject  json 
)
inlinepackage

Definition at line 374 of file VmServiceBase.java.

374 {
375 Class<? extends Consumer> consumerClass = consumer.getClass();
376 StringBuilder msg = new StringBuilder();
377 msg.append("Expected response for ").append(consumerClass).append("\n");
378 for (Class<?> interf : consumerClass.getInterfaces()) {
379 msg.append(" implementing ").append(interf).append("\n");
380 }
381 msg.append(" but received ").append(json);
382 Logging.getLogger().logError(msg.toString());
383 }

◆ processMessage()

void org.dartlang.vm.service.VmServiceBase.processMessage ( String  jsonText)
inlinepackage

Process the response from the VM service and forward that response to the consumer associated with the response id.

Definition at line 389 of file VmServiceBase.java.

389 {
390 if (jsonText == null || jsonText.isEmpty()) {
391 return;
392 }
393
394 // Decode the JSON
395 JsonObject json;
396 try {
397 json = (JsonObject) new JsonParser().parse(jsonText);
398 } catch (Exception e) {
399 Logging.getLogger().logError("Parse message failed: " + jsonText, e);
400 return;
401 }
402
403 if (json.has("method")) {
404 if (!json.has(PARAMS)) {
405 final String message = "Missing " + PARAMS;
406 Logging.getLogger().logError(message);
407 final JsonObject response = new JsonObject();
408 response.addProperty(JSONRPC, JSONRPC_VERSION);
409 final JsonObject error = new JsonObject();
410 error.addProperty(CODE, INVALID_REQUEST);
411 error.addProperty(MESSAGE, message);
412 response.add(ERROR, error);
413 requestSink.add(response);
414 return;
415 }
416 if (json.has("id")) {
417 processRequest(json);
418 } else {
420 }
421 } else if (json.has("result") || json.has("error")) {
422 processResponse(json);
423 } else {
424 Logging.getLogger().logError("Malformed message");
425 }
426 }
void processNotification(JsonObject json)

◆ processNotification()

void org.dartlang.vm.service.VmServiceBase.processNotification ( JsonObject  json)
inlinepackage

Definition at line 529 of file VmServiceBase.java.

529 {
530 String method;
531 try {
532 method = json.get(METHOD).getAsString();
533 } catch (Exception e) {
534 Logging.getLogger().logError("Request malformed " + METHOD, e);
535 return;
536 }
537 JsonObject params;
538 try {
539 params = json.get(PARAMS).getAsJsonObject();
540 } catch (Exception e) {
541 Logging.getLogger().logError("Event missing " + PARAMS, e);
542 return;
543 }
544 if ("streamNotify".equals(method)) {
545 String streamId;
546 try {
547 streamId = params.get(STREAM_ID).getAsString();
548 } catch (Exception e) {
549 Logging.getLogger().logError("Event missing " + STREAM_ID, e);
550 return;
551 }
552 Event event;
553 try {
554 event = new Event(params.get(EVENT).getAsJsonObject());
555 } catch (Exception e) {
556 Logging.getLogger().logError("Event missing " + EVENT, e);
557 return;
558 }
559 forwardEvent(streamId, event);
560 } else {
561 if (!remoteServiceRunners.containsKey(method)) {
562 Logging.getLogger().logError("Unknown service " + method);
563 return;
564 }
565
566 final RemoteServiceRunner runner = remoteServiceRunners.get(method);
567 try {
568 runner.run(params, ignoreCallback);
569 } catch (Exception e) {
570 Logging.getLogger().logError("Internal Server Error", e);
571 }
572 }
573 }
GrAATriangulator::Event Event
FlKeyEvent * event

◆ processRequest()

void org.dartlang.vm.service.VmServiceBase.processRequest ( JsonObject  json)
inlinepackage

Definition at line 428 of file VmServiceBase.java.

428 {
429 final JsonObject response = new JsonObject();
430 response.addProperty(JSONRPC, JSONRPC_VERSION);
431
432 // Get the consumer associated with this request
433 String id;
434 try {
435 id = json.get(ID).getAsString();
436 } catch (Exception e) {
437 final String message = "Request malformed " + ID;
438 Logging.getLogger().logError(message, e);
439 final JsonObject error = new JsonObject();
440 error.addProperty(CODE, INVALID_REQUEST);
441 error.addProperty(MESSAGE, message);
442 response.add(ERROR, error);
443 requestSink.add(response);
444 return;
445 }
446
447 response.addProperty(ID, id);
448
449 String method;
450 try {
451 method = json.get(METHOD).getAsString();
452 } catch (Exception e) {
453 final String message = "Request malformed " + METHOD;
454 Logging.getLogger().logError(message, e);
455 final JsonObject error = new JsonObject();
456 error.addProperty(CODE, INVALID_REQUEST);
457 error.addProperty(MESSAGE, message);
458 response.add(ERROR, error);
459 requestSink.add(response);
460 return;
461 }
462
463 JsonObject params;
464 try {
465 params = json.get(PARAMS).getAsJsonObject();
466 } catch (Exception e) {
467 final String message = "Request malformed " + METHOD;
468 Logging.getLogger().logError(message, e);
469 final JsonObject error = new JsonObject();
470 error.addProperty(CODE, INVALID_REQUEST);
471 error.addProperty(MESSAGE, message);
472 response.add(ERROR, error);
473 requestSink.add(response);
474 return;
475 }
476
477 if (!remoteServiceRunners.containsKey(method)) {
478 final String message = "Unknown service " + method;
479 Logging.getLogger().logError(message);
480 final JsonObject error = new JsonObject();
481 error.addProperty(CODE, METHOD_NOT_FOUND);
482 error.addProperty(MESSAGE, message);
483 response.add(ERROR, error);
484 requestSink.add(response);
485 return;
486 }
487
488 final RemoteServiceRunner runner = remoteServiceRunners.get(method);
489 try {
490 runner.run(params, new RemoteServiceCompleter() {
491 public void result(JsonObject result) {
492 response.add(RESULT, result);
493 requestSink.add(response);
494 }
495
496 public void error(int code, String message, JsonObject data) {
497 final JsonObject error = new JsonObject();
498 error.addProperty(CODE, code);
499 error.addProperty(MESSAGE, message);
500 if (data != null) {
501 error.add(DATA, data);
502 }
503 response.add(ERROR, error);
504 requestSink.add(response);
505 }
506 });
507 } catch (Exception e) {
508 final String message = "Internal Server Error";
509 Logging.getLogger().logError(message, e);
510 final JsonObject error = new JsonObject();
511 error.addProperty(CODE, SERVER_ERROR);
512 error.addProperty(MESSAGE, message);
513 response.add(ERROR, error);
514 requestSink.add(response);
515 }
516 }
GAsyncResult * result
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
const uintptr_t id

◆ processResponse()

void org.dartlang.vm.service.VmServiceBase.processResponse ( JsonObject  json)
inlinepackage

Definition at line 579 of file VmServiceBase.java.

579 {
580 JsonElement idElem = json.get(ID);
581 if (idElem == null) {
582 Logging.getLogger().logError("Response missing " + ID);
583 return;
584 }
585
586 // Get the consumer associated with this response
587 String id;
588 try {
589 id = idElem.getAsString();
590 } catch (Exception e) {
591 Logging.getLogger().logError("Response missing " + ID, e);
592 return;
593 }
594 Consumer consumer = consumerMap.remove(id);
595 if (consumer == null) {
596 Logging.getLogger().logError("No consumer associated with " + ID + ": " + id);
597 return;
598 }
599
600 // Forward the response if the request was successfully executed
601 JsonElement resultElem = json.get(RESULT);
602 if (resultElem != null) {
603 JsonObject result;
604 try {
605 result = resultElem.getAsJsonObject();
606 } catch (Exception e) {
607 Logging.getLogger().logError("Response has invalid " + RESULT, e);
608 return;
609 }
610 String responseType = "";
611 if (result.has(TYPE)) {
612 responseType = result.get(TYPE).getAsString();
613 }
614 // ServiceExtensionConsumers do not care about the response type.
615 else if (!(consumer instanceof ServiceExtensionConsumer)) {
616 Logging.getLogger().logError("Response missing " + TYPE + ": " + result.toString());
617 return;
618 }
619 forwardResponse(consumer, responseType, result);
620 return;
621 }
622
623 // Forward an error if the request failed
624 resultElem = json.get(ERROR);
625 if (resultElem != null) {
626 JsonObject error;
627 try {
628 error = resultElem.getAsJsonObject();
629 } catch (Exception e) {
630 Logging.getLogger().logError("Response has invalid " + RESULT, e);
631 return;
632 }
633 consumer.onError(new RPCError(error));
634 return;
635 }
636
637 Logging.getLogger().logError("Response missing " + RESULT + " and " + ERROR);
638 }
abstract void forwardResponse(Consumer consumer, String type, JsonObject json)

◆ removeNewLines()

String org.dartlang.vm.service.VmServiceBase.removeNewLines ( String  str)
inlineprotected

Definition at line 575 of file VmServiceBase.java.

575 {
576 return str.replaceAll("\r\n", " ").replaceAll("\n", " ");
577 }

◆ removeServiceRunner()

void org.dartlang.vm.service.VmServiceBase.removeServiceRunner ( String  service)
inline

Remove a VM RemoteServiceRunner.

Definition at line 224 of file VmServiceBase.java.

224 {
225 remoteServiceRunners.remove(service);
226 }

◆ removeVmServiceListener()

void org.dartlang.vm.service.VmServiceBase.removeVmServiceListener ( VmServiceListener  listener)
inline

Remove the given listener from the VM.

Definition at line 210 of file VmServiceBase.java.

210 {
211 vmListeners.remove(listener);
212 }

◆ request()

void org.dartlang.vm.service.VmServiceBase.request ( String  method,
JsonObject  params,
Consumer  consumer 
)
inlineprotected

Sends the request and associates the request with the passed Consumer.

Definition at line 322 of file VmServiceBase.java.

322 {
323
324 // Assemble the request
325 String id = Integer.toString(nextId.incrementAndGet());
326 JsonObject request = new JsonObject();
327
328 request.addProperty(JSONRPC, JSONRPC_VERSION);
329 request.addProperty(ID, id);
330 request.addProperty(METHOD, method);
331 request.add(PARAMS, params);
332
333 // Cache the consumer to receive the response
334 synchronized (consumerMapLock) {
335 consumerMap.put(id, consumer);
336 }
337
338 // Send the request
340 }

Member Data Documentation

◆ requestSink

RequestSink org.dartlang.vm.service.VmServiceBase.requestSink
package

The channel through which observatory requests are made.

Definition at line 196 of file VmServiceBase.java.

◆ runtimeVersion

Version org.dartlang.vm.service.VmServiceBase.runtimeVersion
package

Definition at line 198 of file VmServiceBase.java.


The documentation for this class was generated from the following file: