WebSocket implements WebSocketListener, WebsocketEncoder { @Override public void onWebSocketConnect(final Session session) { try { if (!session.isOpen()) throw new IllegalStateException("Session already closed"); this.session = session; this.websocketPusher = new WebSocketPusher(session, 1 << 20, 1 << 12, TimeUnit.SECONDS.toMillis(60)); uiContext = new UIContext(this, context, applicationManager.getConfiguration(), request); log.info("Creating a new {}", uiContext); final CommunicationSanityChecker communicationSanityChecker = new CommunicationSanityChecker(uiContext); context.registerUIContext(uiContext); uiContext.acquire(); try { beginObject(); final ApplicationConfiguration configuration = uiContext.getConfiguration(); final boolean enableClientToServerHeartBeat = configuration.isEnableClientToServerHeartBeat(); final TimeUnit heartBeatPeriodTimeUnit = configuration.getHeartBeatPeriodTimeUnit(); final int heartBeatPeriod = enableClientToServerHeartBeat ? (int) heartBeatPeriodTimeUnit.toSeconds(configuration.getHeartBeatPeriod()) : 0; encode(ServerToClientModel.CREATE_CONTEXT, uiContext.getID()); encode(ServerToClientModel.OPTION_FORMFIELD_TABULATION, configuration.isTabindexOnlyFormField()); encode(ServerToClientModel.HEARTBEAT_PERIOD, heartBeatPeriod); endObject(); if (isAlive()) flush0(); } catch (final Throwable e) { log.error("Cannot send server heart beat to client", e); } finally { uiContext.release(); } applicationManager.startApplication(uiContext); communicationSanityChecker.start(); } catch (final Exception e) { log.error("Cannot process WebSocket instructions", e); e.printStackTrace(); } } WebSocket(); @Override void onWebSocketConnect(final Session session); @Override void onWebSocketError(final Throwable throwable); @Override void onWebSocketClose(final int statusCode, final String reason); @Override void onWebSocketText(final String message); @Override void onWebSocketBinary(final byte[] payload, final int offset, final int len); void sendRoundTrip(); void flush(); void close(); void disconnect(); @Override void beginObject(); @Override void endObject(); @Override void encode(final ServerToClientModel model, final Object value); ServletUpgradeRequest getRequest(); void setRequest(final ServletUpgradeRequest request); void setApplicationManager(final ApplicationManager applicationManager); void setMonitor(final WebsocketMonitor monitor); void setContext(final TxnContext context); void setListener(final Listener listener);  }
@Test public void testOnWebSocketConnect() { assertEquals(encodedValues.get(0), new Pair<>(ServerToClientModel.CREATE_CONTEXT, uiContext.getID())); assertEquals(encodedValues.get(1), new Pair<>(ServerToClientModel.OPTION_FORMFIELD_TABULATION, false)); assertEquals(encodedValues.get(2), new Pair<>(ServerToClientModel.HEARTBEAT_PERIOD, 0)); }