Search in sources :

Example 1 with ConnectionWatcher

use of com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher in project graal by oracle.

the class Session method connect.

private Object connect() {
    if (iss != null) {
        throw new InspectorStateException("The inspector session is already connected");
    }
    InspectorExecutionContext execContext = contextSupplier.get();
    iss = InspectServerSession.create(execContext, false, new ConnectionWatcher());
    iss.open(getListeners());
    execContext.setSynchronous(true);
    // Enable the Runtime by default
    iss.sendCommand(new Command("{\"id\":0,\"method\":\"Runtime.enable\"}"));
    return undefinedProvider.get();
}
Also used : Command(com.oracle.truffle.tools.chromeinspector.commands.Command) InspectorExecutionContext(com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext) ConnectionWatcher(com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher)

Example 2 with ConnectionWatcher

use of com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher in project graal by oracle.

the class InspectorInstrument method onCreate.

@Override
protected void onCreate(Env env) {
    OptionValues options = env.getOptions();
    if (options.hasSetOptions()) {
        HostAndPort hostAndPort = options.get(Inspect);
        connectionWatcher = new ConnectionWatcher();
        try {
            server = new Server(env, "Main Context", hostAndPort, options.get(Attach), options.get(Suspend), options.get(WaitAttached), options.get(HideErrors), options.get(Internal), options.get(Initialization), options.get(Path), options.hasBeenSet(Secure), options.get(Secure), new KeyStoreOptions(options), options.get(SourcePath), connectionWatcher);
        } catch (IOException e) {
            throw new InspectorIOException(hostAndPort.getHostPort(), e);
        }
    }
    env.registerService(new Inspector(env, server != null ? server.getConnection() : null, new InspectorServerConnection.Open() {

        @Override
        // The parameters port and host should not be assigned
        @SuppressWarnings("all")
        public synchronized InspectorServerConnection open(int port, String host, boolean wait) {
            if (server != null && server.wss != null) {
                return null;
            }
            HostAndPort hostAndPort = options.get(Inspect);
            if (port < 0) {
                port = hostAndPort.port;
            }
            if (host == null) {
                host = hostAndPort.host;
            }
            connectionWatcher = new ConnectionWatcher();
            hostAndPort = new HostAndPort(host, port);
            try {
                server = new Server(env, "Main Context", hostAndPort, false, false, wait, options.get(HideErrors), options.get(Internal), options.get(Initialization), null, options.hasBeenSet(Secure), options.get(Secure), new KeyStoreOptions(options), options.get(SourcePath), connectionWatcher);
            } catch (IOException e) {
                PrintWriter info = new PrintWriter(env.err());
                info.println(new InspectorIOException(hostAndPort.getHostPort(), e).getLocalizedMessage());
                info.flush();
            }
            return server != null ? server.getConnection() : null;
        }
    }, new Supplier<InspectorExecutionContext>() {

        @Override
        public InspectorExecutionContext get() {
            if (server != null) {
                return server.getConnection().getExecutionContext();
            } else {
                PrintWriter err = (options.get(HideErrors)) ? null : new PrintWriter(env.err(), true);
                return new InspectorExecutionContext("Main Context", options.get(Internal), options.get(Initialization), env, Collections.emptyList(), err);
            }
        }
    }));
}
Also used : OptionValues(org.graalvm.options.OptionValues) InspectorServer(com.oracle.truffle.tools.chromeinspector.server.InspectorServer) WSInterceptorServer(com.oracle.truffle.tools.chromeinspector.server.WSInterceptorServer) InspectorExecutionContext(com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext) IOException(java.io.IOException) ConnectionWatcher(com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher) Inspector(com.oracle.truffle.tools.chromeinspector.objects.Inspector) Supplier(java.util.function.Supplier) PrintWriter(java.io.PrintWriter)

Example 3 with ConnectionWatcher

use of com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher in project graal by oracle.

the class InspectSessionInfo method onCreate.

@Override
protected void onCreate(final Env env) {
    env.registerService(new InspectSessionInfoProvider() {

        @Override
        public InspectSessionInfo getSessionInfo(final boolean suspend, final boolean inspectInternal, final boolean inspectInitialization, final List<URI> sourcePath) {
            return new InspectSessionInfo() {

                private InspectServerSession iss;

                private InspectorExecutionContext context;

                private ConnectionWatcher connectionWatcher;

                private long id;

                InspectSessionInfo init() {
                    this.context = new InspectorExecutionContext("test", inspectInternal, inspectInitialization, env, sourcePath, new PrintWriter(env.err(), true));
                    this.connectionWatcher = new ConnectionWatcher();
                    this.iss = InspectServerSession.create(context, suspend, connectionWatcher);
                    lastServerSession = new WeakReference<>(iss);
                    this.id = context.getId();
                    // Fake connection open
                    ReflectionUtils.invoke(connectionWatcher, "notifyOpen");
                    return this;
                }

                @Override
                public InspectServerSession getInspectServerSession() {
                    return iss;
                }

                @Override
                public InspectorExecutionContext getInspectorContext() {
                    return context;
                }

                @Override
                public ConnectionWatcher getConnectionWatcher() {
                    return connectionWatcher;
                }

                @Override
                public long getId() {
                    return id;
                }
            }.init();
        }
    });
}
Also used : InspectServerSession(com.oracle.truffle.tools.chromeinspector.server.InspectServerSession) InspectorExecutionContext(com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext) URI(java.net.URI) ConnectionWatcher(com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher) PrintWriter(java.io.PrintWriter)

Aggregations

InspectorExecutionContext (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext)3 ConnectionWatcher (com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher)3 PrintWriter (java.io.PrintWriter)2 Command (com.oracle.truffle.tools.chromeinspector.commands.Command)1 Inspector (com.oracle.truffle.tools.chromeinspector.objects.Inspector)1 InspectServerSession (com.oracle.truffle.tools.chromeinspector.server.InspectServerSession)1 InspectorServer (com.oracle.truffle.tools.chromeinspector.server.InspectorServer)1 WSInterceptorServer (com.oracle.truffle.tools.chromeinspector.server.WSInterceptorServer)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Supplier (java.util.function.Supplier)1 OptionValues (org.graalvm.options.OptionValues)1