Java Code Examples for org.eclipse.jetty.websocket.api.Session#setIdleTimeout()

The following examples show how to use org.eclipse.jetty.websocket.api.Session#setIdleTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketProvider.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@OnWebSocketConnect @SuppressWarnings("unused")
public void onWebSocketConnect(final Session session)
{
    SocketAddress localAddress = session.getLocalAddress();
    SocketAddress remoteAddress = session.getRemoteAddress();
    _protocolEngine = _factory.newProtocolEngine(remoteAddress);

    // Let AMQP do timeout handling
    session.setIdleTimeout(0);

    _connectionWrapper = new ConnectionWrapper(session, localAddress, remoteAddress, _protocolEngine, _server.getThreadPool());
    if (session.getUpgradeRequest() instanceof ServletUpgradeRequest)
    {
        ServletUpgradeRequest upgradeRequest = (ServletUpgradeRequest) session.getUpgradeRequest();
        if (upgradeRequest.getCertificates() != null && upgradeRequest.getCertificates().length > 0)
        {
            _connectionWrapper.setPeerCertificate(upgradeRequest.getCertificates()[0]);
        }
    }
    _protocolEngine.setNetworkConnection(_connectionWrapper);
    _protocolEngine.setWorkListener(object -> _server.getThreadPool().execute(() -> _connectionWrapper.doWork()));
    _activeConnections.add(_connectionWrapper);
    _idleTimeoutChecker.wakeup();

}
 
Example 2
Source File: LogWebSocketHandler.java    From android-uiconductor with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
  logger.info("New session connect to log server.");
  session.setIdleTimeout(IDLE_TIMEOUT.toMillis());

  // start new thread to handle log
  TailLogThread thread = new TailLogThread(session);
  thread.start();
}
 
Example 3
Source File: WebSocketHandler.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@Override
public void onWebSocketConnect( final Session session )
{
    session.setIdleTimeout( this.config.getTimeout() );
    this.session = newSession( session );

    final WebSocketEvent event = newEventBuilder().
        openEvent().
        build();

    handleEvent( event );
}
 
Example 4
Source File: RoboconfWebSocket.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void onWebSocketConnect( Session session ) {
	this.session = session;
	session.setIdleTimeout( -1 );
	this.logger.info( "A web socket connection was established. Session origin: " + session.getRemoteAddress());
	WebSocketHandler.addSession( session );
}
 
Example 5
Source File: WebSocketServiceImpl.java    From smockin with Apache License 2.0 4 votes vote down vote up
/**
 *
 * Stores all websocket client sessions in the internal map 'sessionMap'.
 *
 * Note sessions are 'internally' identified using the encrypted handshake 'Sec-WebSocket-Accept' value and
 * 'externally' identified using an allocated UUID.
 *
 */
public void registerSession(final Session session, final boolean isMultiUserMode) {
    logger.debug("registerSession called");

    final String wsPath = session.getUpgradeRequest().getRequestURI().getPath();
    final RestfulMock wsMock = (isMultiUserMode)
            ? restfulMockDAO.findActiveByMethodAndPathPatternAndTypesForMultiUser(
                    RestMethodEnum.GET, wsPath, Arrays.asList(RestMockTypeEnum.PROXY_WS, RestMockTypeEnum.RULE_WS))
            : restfulMockDAO.findActiveByMethodAndPathPatternAndTypesForSingleUser(
                    RestMethodEnum.GET, wsPath, Arrays.asList(RestMockTypeEnum.PROXY_WS, RestMockTypeEnum.RULE_WS));

    if (wsMock == null) {
        if (session.isOpen()) {
            try {
                session.getRemote().sendString("No suitable mock found for " + wsPath);
                session.disconnect();
            } catch(IOException e) {
                logger.error("Error closing non mock matching web socket client connection", e);
            }
        }
        return;
    }

    final String path = mockedRestServerEngineUtils.buildUserPath(wsMock);

    session.setIdleTimeout((wsMock.getWebSocketTimeoutInMillis() > 0) ? wsMock.getWebSocketTimeoutInMillis() : MAX_IDLE_TIMEOUT_MILLIS);

    final Set<SessionIdWrapper> sessions = sessionMap.computeIfAbsent(path, k -> new HashSet<>());
    final String assignedId = GeneralUtils.generateUUID();
    final String traceId = session.getUpgradeResponse().getHeader(GeneralUtils.LOG_REQ_ID);

    sessionMap.merge(
            path, 
            sessions, 
            (k, v) -> {
                v.add(new SessionIdWrapper(assignedId, traceId, session, GeneralUtils.getCurrentDate()));
                return v;
            });

    if (wsMock.isProxyPushIdOnConnect()) {
        sendMessage(assignedId, new WebSocketDTO(path, "clientId: " + assignedId));
    }

    if (wsMock.getMockType() == RestMockTypeEnum.RULE_WS && wsMock.getDefinitions().get(0) != null) {
        RestfulMockDefinitionOrder order = wsMock.getDefinitions().get(0);
        if (order.getResponseBody() != null) {
            sendMessage(assignedId, new WebSocketDTO(path, order.getResponseBody()));
        }

    }

    liveLoggingHandler.broadcast(LiveLoggingUtils.buildLiveLogOutboundDTO(traceId, 101, null,
            "Websocket established (clientId: " + assignedId + ")", false, false));

}
 
Example 6
Source File: DecanterWebSocketAppender.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@OnWebSocketConnect
public void onOpen(Session session) {
    session.setIdleTimeout(-1);
    sessions.add(session);
}