Search in sources :

Example 1 with WebSocketClient

use of com.oracle.truffle.tools.utils.java_websocket.client.WebSocketClient in project graal by oracle.

the class MultiEngineTest method checkSuspendAndResume.

private static void checkSuspendAndResume(String path) throws Exception {
    CountDownLatch closed = new CountDownLatch(1);
    AtomicBoolean paused = new AtomicBoolean(false);
    AtomicReference<Exception> exception = new AtomicReference<>(null);
    final String url = "ws://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + PORT + "/" + path;
    WebSocketClient wsc = new WebSocketClient(new URI(url)) {

        @Override
        public void onOpen(ServerHandshake sh) {
        }

        @Override
        public void onMessage(String message) {
            JSONObject msg = new JSONObject(message);
            if ("Debugger.paused".equals(msg.opt("method"))) {
                paused.set(true);
                send("{\"id\":5,\"method\":\"Debugger.resume\"}");
            }
        }

        @Override
        public void onClose(int i, String message, boolean bln) {
            closed.countDown();
        }

        @Override
        public void onError(Exception excptn) {
            excptn.printStackTrace();
            exception.set(excptn);
        }
    };
    final boolean connectionSucceeded = wsc.connectBlocking();
    assertTrue("Connection has not succeeded: " + url, connectionSucceeded);
    for (String message : INITIAL_MESSAGES) {
        wsc.send(message);
    }
    closed.await();
    wsc.close();
    if (exception.get() != null) {
        throw exception.get();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerHandshake(com.oracle.truffle.tools.utils.java_websocket.handshake.ServerHandshake) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketClient(com.oracle.truffle.tools.utils.java_websocket.client.WebSocketClient) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

WebSocketClient (com.oracle.truffle.tools.utils.java_websocket.client.WebSocketClient)1 ServerHandshake (com.oracle.truffle.tools.utils.java_websocket.handshake.ServerHandshake)1 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1