private void addSession( IoSession session ) { IoSessionStat sessionStats = new IoSessionStat(); sessionStats.lastPollingTime = System.currentTimeMillis(); session.setAttribute( KEY, sessionStats ); totalProcessedSessions.incrementAndGet(); polledSessions.add( session ); }
@Override public void sessionCreated(IoSession session) { logger.info("Session created: {}", session); // Allocate saved buffer when session is created. // This allows us to parse an incomplete message and use it on // the next request. session.setAttribute(SAVED_BUF, IoBuffer.allocate(maxEventSize, false)); }
/** Constructs a new RTMPTConnection */ RTMPTConnection() { super(IConnection.Type.POLLING.name().toLowerCase()); // create a DummySession for the HTTP-based connection to allow our Mina based system happy ioSession = new DummySession(); ioSession.setAttribute(RTMPConnection.RTMP_SESSION_ID, sessionId); }
@Override public void sessionOpened(IoSession session) throws Exception { // Create a new XML parser for the new connection. The parser will be used by the XMPPDecoder filter. final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8); session.setAttribute(XML_PARSER, parser); // Create a new NIOConnection for the new session final NIOConnection connection = createNIOConnection(session); session.setAttribute(CONNECTION, connection); session.setAttribute(HANDLER, createStanzaHandler(connection)); // Set the max time a connection can be idle before closing it. This amount of seconds // is divided in two, as Openfire will ping idle clients first (at 50% of the max idle time) // before disconnecting them (at 100% of the max idle time). This prevents Openfire from // removing connections without warning. final int idleTime = getMaxIdleTime() / 2; if (idleTime > 0) { session.getConfig().setIdleTime(IdleStatus.READER_IDLE, idleTime); } }
/** {@inheritDoc} */ @Override public void sessionOpened(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session opened: {} id: {}", session.getId(), sessionId); RTMPConnManager connManager = (RTMPConnManager) RTMPConnManager.getInstance(); session.setAttribute(RTMPConnection.RTMP_CONN_MANAGER, new WeakReference<IConnectionManager<RTMPConnection>>(connManager)); RTMPMinaConnection conn = (RTMPMinaConnection) connManager.getConnectionBySessionId(sessionId); handler.connectionOpened(conn); }
/** {@inheritDoc} */ @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { log.debug("Filter chain: {}", session.getFilterChain()); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isDebugEnabled()) { log.warn("Exception caught on session: {} id: {}", session.getId(), sessionId, cause); } if (cause instanceof IOException) { // Mina states that the connection will be automatically closed when an IOException is caught log.debug("IOException caught on {}", sessionId); } else { log.debug("Non-IOException caught on {}", sessionId); if (session.containsAttribute("FORCED_CLOSE")) { log.info("Close already forced on this session: {}", session.getId()); } else { // set flag session.setAttribute("FORCED_CLOSE", Boolean.TRUE); //session.suspendRead(); cleanSession(session, true); } } }
/** * Updates the system counter of read bytes. This information is used by the incoming * bytes statistic. * * @param session the session that read more bytes from the socket. */ private void updateReadBytesCounter(IoSession session) { long currentBytes = session.getReadBytes(); Long prevBytes = (Long) session.getAttribute("_read_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_read_bytes", currentBytes); ServerTrafficCounter.incrementIncomingCounter(delta); }
/** * Updates the system counter of written bytes. This information is used by the outgoing * bytes statistic. * * @param session the session that wrote more bytes to the socket. */ private void updateWrittenBytesCounter(IoSession session) { long currentBytes = session.getWrittenBytes(); Long prevBytes = (Long) session.getAttribute("_written_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_written_bytes", currentBytes); ServerTrafficCounter.incrementOutgoingCounter(delta); } }
client.setAttribute(ProxyFilter.FORWARD_KEY, session); session.setAttribute(ProxyFilter.FORWARD_KEY, client);
session.setAttribute(SslFilter.USE_NOTIFICATION, Boolean.TRUE); log.debug("isSslStarted: {}", sslFilter.isSslStarted(session)); session.setAttribute(RTMPConnection.RTMP_SESSION_ID, conn.getSessionId()); session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake);
session.setAttribute(RTMPConnection.RTMP_SESSION_ID, sessionId); session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake); log.debug("Created: {}", sessionId); } else {
public void startTLS(boolean clientMode, boolean directTLS) throws Exception { final EncryptionArtifactFactory factory = new EncryptionArtifactFactory( configuration ); final SslFilter filter; if ( clientMode ) { filter = factory.createClientModeSslFilter(); } else { filter = factory.createServerModeSslFilter(); } ioSession.getFilterChain().addBefore(EXECUTOR_FILTER_NAME, TLS_FILTER_NAME, filter); if (!directTLS) { ioSession.setAttribute( SslFilter.DISABLE_ENCRYPTION_ONCE, Boolean.TRUE ); } if ( !clientMode && !directTLS ) { // Indicate the client that the server is ready to negotiate TLS deliverRawText( "<proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" ); } }
log.debug("Using encrypted communications, adding ciphers to the session"); rtmp.setEncrypted(true); session.setAttribute(RTMPConnection.RTMPE_CIPHER_IN, handshake.getCipherIn()); session.setAttribute(RTMPConnection.RTMPE_CIPHER_OUT, handshake.getCipherOut());
session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake);
@Override public void sessionCreated(IoSession session) throws Exception { super.sessionCreated(session); Line line = state.getOrCreateLine((InetSocketAddress)session.getRemoteAddress()); session.setAttribute("line", line); logger.debug("Session[{}] created", session.getId()); }
IoSession session = acceptor.newSession(telex.getTo(), acceptor.getLocalAddress()); line.setSession(session); session.setAttribute("line", line); logger.debug("SEND[{}]: {} bytes: {}", new Object[]{ session.getId(), bytes.length, msg});
@Override public void disconnect() { // We cannot call join() on the CloseFuture returned // by the following call. We are using a minimal // threading model and calling join will prevent the // close event from being processed by this thread (if // this thread is the MINA IO processor thread. ioSession.closeOnFlush(); ioSession.setAttribute(SessionConnector.QFJ_RESET_IO_CONNECTOR, Boolean.TRUE); }
@Override public void initializeSession(final IoSession session, ConnectFuture future) { LOGGER.debug("Initializing new session: {}", session); session.setAttribute(ProxyIoSession.PROXY_SESSION, proxyIoSession); proxyIoSession.setSession(session); LOGGER.debug(" setting up proxyIoSession: {}", proxyIoSession); // Reconnection is done so we send the // request to the proxy proxyIoSession.setReconnectionNeeded(false); writeRequest0(nextFilter, request); } });
private ProtocolEncoderOutput getEncoderOut(IoSession session, NextFilter nextFilter, WriteRequest writeRequest) { ProtocolEncoderOutput out = (ProtocolEncoderOutput) session.getAttribute(ENCODER_OUT); if (out == null) { // Create a new instance, and stores it into the session out = new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest); session.setAttribute(ENCODER_OUT, out); } return out; }
@Override public void sessionOpened(IoSession session) { super.sessionOpened(session); UserSession userSession = new UserSession(session); session.setAttribute(Config.USER_SESSION, userSession); }