Search in sources :

Example 1 with Inspector

use of com.oracle.truffle.tools.chromeinspector.objects.Inspector 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)

Aggregations

InspectorExecutionContext (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext)1 Inspector (com.oracle.truffle.tools.chromeinspector.objects.Inspector)1 ConnectionWatcher (com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher)1 InspectorServer (com.oracle.truffle.tools.chromeinspector.server.InspectorServer)1 WSInterceptorServer (com.oracle.truffle.tools.chromeinspector.server.WSInterceptorServer)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Supplier (java.util.function.Supplier)1 OptionValues (org.graalvm.options.OptionValues)1