Esempio n. 1
0
  private void attachImpl(DebugEventListener listener)
      throws IOException, UnsupportedVersionException, MethodIsBlockingException {
    connectionState = ConnectionState.CONNECTING;

    NetListener netListener =
        new NetListener() {
          public void connectionClosed() {}

          public void eosReceived() {
            debugSession.getV8CommandProcessor().processEos();
            onDebuggerDetachedImpl(null);
          }

          public void messageReceived(Message message) {
            JSONObject json;
            try {
              json = JsonUtil.jsonObjectFromJson(message.getContent());
            } catch (ParseException e) {
              LOGGER.log(Level.SEVERE, "Invalid JSON received: {0}", message.getContent());
              return;
            }
            debugSession.getV8CommandProcessor().processIncomingJson(json);
          }
        };
    connection.setNetListener(netListener);

    connection.start();

    connectionState = ConnectionState.EXPECTING_HANDSHAKE;

    Handshaker.StandaloneV8.RemoteInfo remoteInfo;
    try {
      remoteInfo =
          handshaker.getRemoteInfo().get(WAIT_FOR_HANDSHAKE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    } catch (ExecutionException e) {
      throw newIOException("Failed to get version", e);
    } catch (TimeoutException e) {
      throw newIOException("Timed out waiting for handshake", e);
    }

    String versionString = remoteInfo.getProtocolVersion();
    // TODO(peter.rybin): check version here
    if (versionString == null) {
      throw new UnsupportedVersionException(null, null);
    }

    StandaloneVmImpl.this.savedRemoteInfo = remoteInfo;

    StandaloneVmImpl.this.debugEventListener = listener;

    debugSession.startCommunication();

    connectionState = ConnectionState.CONNECTED;
  }
Esempio n. 2
0
    public void send(DebuggerMessage debuggerMessage, boolean immediate) {
      String jsonString = JsonUtil.streamAwareToJson(debuggerMessage);
      Message message = new Message(Collections.<String, String>emptyMap(), jsonString);

      outputConnection.send(message);
      // TODO(peter.rybin): support {@code immediate} in protocol
    }
Esempio n. 3
0
 public boolean detach() {
   boolean res = onDebuggerDetachedImpl(null);
   if (!res) {
     return false;
   }
   connection.close();
   return true;
 }
Esempio n. 4
0
 public void attach(DebugEventListener listener)
     throws IOException, UnsupportedVersionException, MethodIsBlockingException {
   Exception errorCause = null;
   try {
     attachImpl(listener);
   } catch (IOException e) {
     errorCause = e;
     throw e;
   } catch (UnsupportedVersionException e) {
     errorCause = e;
     throw e;
   } finally {
     if (errorCause != null) {
       disconnectReason = errorCause;
       connectionState = ConnectionState.DETACHED;
       connection.close();
     }
   }
 }
Esempio n. 5
0
 public void runInDispatchThread(Runnable callback) {
   outputConnection.runInDispatchThread(callback);
 }