use of org.eclipse.jetty.websocket.api.Session in project zeppelin by apache.
the class ZeppelinClient method removeAllConnections.
private void removeAllConnections() {
if (watcherSession != null && watcherSession.isOpen()) {
watcherSession.close();
}
Session noteSession = null;
for (Map.Entry<String, Session> note : notesConnection.entrySet()) {
noteSession = note.getValue();
if (isSessionOpen(noteSession)) {
noteSession.close();
}
}
notesConnection.clear();
}
use of org.eclipse.jetty.websocket.api.Session in project zeppelin by apache.
the class ZeppelinClient method send.
public void send(Message msg, String noteId) {
Session noteSession = getZeppelinConnection(noteId);
if (!isSessionOpen(noteSession)) {
LOG.error("Cannot open websocket connection to Zeppelin note {}", noteId);
return;
}
noteSession.getRemote().sendStringByFuture(serialize(msg));
}
use of org.eclipse.jetty.websocket.api.Session in project zeppelin by apache.
the class ZeppelinhubClient method connect.
private ZeppelinhubSession connect() {
ZeppelinhubSession zeppelinSession;
try {
ZeppelinhubWebsocket ws = ZeppelinhubWebsocket.newInstance(zeppelinhubToken);
Future<Session> future = client.connect(ws, zeppelinhubWebsocketUrl, conectionRequest);
Session session = future.get();
zeppelinSession = ZeppelinhubSession.createInstance(session, zeppelinhubToken);
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.info("Couldnt connect to zeppelinhub - {}", e.toString());
zeppelinSession = ZeppelinhubSession.EMPTY;
}
return zeppelinSession;
}
use of org.eclipse.jetty.websocket.api.Session in project zeppelin by apache.
the class ZeppelinClientTest method zeppelinConnectionTest.
@Test
public void zeppelinConnectionTest() {
try {
// Wait for websocket server to start
Thread.sleep(2000);
} catch (InterruptedException e) {
LOG.warn("Cannot wait for websocket server to start, returning");
return;
}
// Initialize and start Zeppelin client
ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "dummy token", null);
client.start();
LOG.info("Zeppelin websocket client started");
// Connection to note AAAA
Session connectionA = client.getZeppelinConnection("AAAA");
assertNotNull(connectionA);
assertTrue(connectionA.isOpen());
assertEquals(client.countConnectedNotes(), 1);
assertEquals(connectionA, client.getZeppelinConnection("AAAA"));
// Connection to note BBBB
Session connectionB = client.getZeppelinConnection("BBBB");
assertNotNull(connectionB);
assertTrue(connectionB.isOpen());
assertEquals(client.countConnectedNotes(), 2);
assertEquals(connectionB, client.getZeppelinConnection("BBBB"));
// Remove connection to note AAAA
client.removeNoteConnection("AAAA");
assertEquals(client.countConnectedNotes(), 1);
assertNotEquals(connectionA, client.getZeppelinConnection("AAAA"));
assertEquals(client.countConnectedNotes(), 2);
client.stop();
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class LargeContainerTest method testEcho.
@Test
public void testEcho() throws Exception {
WSServer wsb = new WSServer(testdir, "app");
wsb.copyWebInf("large-echo-config-web.xml");
wsb.copyEndpoint(LargeEchoDefaultSocket.class);
try {
wsb.start();
URI uri = wsb.getServerBaseURI();
WebAppContext webapp = wsb.createWebAppContext();
wsb.deployWebapp(webapp);
// wsb.dump();
WebSocketClient client = new WebSocketClient(bufferPool);
try {
client.getPolicy().setMaxTextMessageSize(128 * 1024);
client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<Session> foo = client.connect(clientEcho, uri.resolve("echo/large"));
// wait for connect
foo.get(1, TimeUnit.SECONDS);
// The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies
byte[] txt = new byte[100 * 1024];
Arrays.fill(txt, (byte) 'o');
String msg = new String(txt, StandardCharsets.UTF_8);
clientEcho.sendMessage(msg);
Queue<String> msgs = clientEcho.awaitMessages(1);
Assert.assertEquals("Expected message", msg, msgs.poll());
} finally {
client.stop();
}
} finally {
wsb.stop();
}
}
Aggregations