/** {@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); } } }
/** {@inheritDoc} */ @Override public void sessionClosed(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session closed: {} id: {}", session.getId(), sessionId); if (log.isTraceEnabled()) { log.trace("Session attributes: {}", session.getAttributeKeys()); } if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { // fire-off closed event handler.connectionClosed(conn); // clear any session attributes we may have previously set // TODO: verify this cleanup code is necessary. The session is over and will be garbage collected surely? if (session.containsAttribute(RTMPConnection.RTMP_HANDSHAKE)) { session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); } if (session.containsAttribute(RTMPConnection.RTMPE_CIPHER_IN)) { session.removeAttribute(RTMPConnection.RTMPE_CIPHER_IN); session.removeAttribute(RTMPConnection.RTMPE_CIPHER_OUT); } } else { log.warn("Connection was not found for {}", sessionId); } cleanSession(session, false); } else { log.debug("Connections session id was null in session, may already be closed"); } }
String sessionId = null; if (!session.containsAttribute(RTMPConnection.RTMP_SESSION_ID)) {
/** * @see IoSession#containsAttribute(Object) */ public boolean containsAttribute(Object key) { return wrappedSession.containsAttribute(key); }
public static boolean isLittleEndian ( final IoSession session ) { return session.containsAttribute ( ATTR_LITTLE_ENDIAN ); }
public boolean exists(IoSession session) { return session.containsAttribute(this); }
/** * get session's playerId * @param session * @return */ public long getPlayerIdBy(IoSession session) { if (session != null) { if (session.containsAttribute(SessionProperties.PLAYER_ID)) { return getSessionAttr(session, SessionProperties.PLAYER_ID, Long.class); } } return 0; }
private CharsetEncoder getCharsetEncoder ( final IoSession session ) { if ( session.containsAttribute ( "charsetEncoder" ) ) { return (CharsetEncoder)session.getAttribute ( "charsetEncoder" ); } final CharsetEncoder encoder = Charset.forName ( "UTF-8" ).newEncoder (); session.setAttribute ( "charsetEncoder", encoder ); return encoder; }
private CharsetEncoder getCharsetEncoder ( final IoSession session ) { if ( session.containsAttribute ( "charsetEncoder" ) ) { return (CharsetEncoder)session.getAttribute ( "charsetEncoder" ); } final CharsetEncoder encoder = Charset.forName ( "UTF-8" ).newEncoder (); session.setAttribute ( "charsetEncoder", encoder ); return encoder; }
private CharsetDecoder getCharsetDecoder ( final IoSession session ) { if ( session.containsAttribute ( "charsetDecoder" ) ) { return (CharsetDecoder)session.getAttribute ( "charsetDecoder" ); } final CharsetDecoder decoder = Charset.forName ( "UTF-8" ).newDecoder (); session.setAttribute ( "charsetDecoder", decoder ); return decoder; }
private CharsetDecoder getCharsetDecoder ( final IoSession session ) { if ( session.containsAttribute ( "charsetDecoder" ) ) { return (CharsetDecoder)session.getAttribute ( "charsetDecoder" ); } final CharsetDecoder decoder = Charset.forName ( "UTF-8" ).newDecoder (); session.setAttribute ( "charsetDecoder", decoder ); return decoder; }
/** * @see FtpSession#getSessionId() */ public UUID getSessionId() { synchronized (wrappedSession) { if (!wrappedSession.containsAttribute(ATTRIBUTE_SESSION_ID)) { wrappedSession.setAttribute(ATTRIBUTE_SESSION_ID, UUID.randomUUID()); } return (UUID) wrappedSession.getAttribute(ATTRIBUTE_SESSION_ID); } }
/** {@inheritDoc} */ public void connectionClosed(RTMPConnection conn) { log.debug("connectionClosed: {}", conn.getSessionId()); if (conn.getStateCode() != RTMP.STATE_DISCONNECTED) { // inform any callbacks for pending calls that the connection is closed conn.sendPendingServiceCallsCloseError(); // close the connection if (conn.getStateCode() != RTMP.STATE_DISCONNECTING) { conn.close(); } // set as disconnected conn.setStateCode(RTMP.STATE_DISCONNECTED); } IoSession session = conn.getIoSession(); if (session != null && session.containsAttribute(RTMPConnection.RTMP_CONN_MANAGER)) { @SuppressWarnings("unchecked") IConnectionManager<RTMPConnection> connManager = (IConnectionManager<RTMPConnection>) ((WeakReference<?>) session.getAttribute(RTMPConnection.RTMP_CONN_MANAGER)).get(); if (connManager != null) { connManager.removeConnection(conn.getSessionId()); } else { log.debug("Connection manager was not found in the session"); } } log.trace("connectionClosed: {}", conn); }
/** {@inheritDoc} */ public void connectionClosed(RTMPConnection conn) { log.debug("connectionClosed: {}", conn.getSessionId()); if (conn.getStateCode() != RTMP.STATE_DISCONNECTED) { // inform any callbacks for pending calls that the connection is closed conn.sendPendingServiceCallsCloseError(); // close the connection if (conn.getStateCode() != RTMP.STATE_DISCONNECTING) { conn.close(); } // set as disconnected conn.setStateCode(RTMP.STATE_DISCONNECTED); } IoSession session = conn.getIoSession(); if (session != null && session.containsAttribute(RTMPConnection.RTMP_CONN_MANAGER)) { @SuppressWarnings("unchecked") IConnectionManager<RTMPConnection> connManager = (IConnectionManager<RTMPConnection>) ((WeakReference<?>) session.getAttribute(RTMPConnection.RTMP_CONN_MANAGER)).get(); if (connManager != null) { connManager.removeConnection(conn.getSessionId()); } else { log.debug("Connection manager was not found in the session"); } } log.trace("connectionClosed: {}", conn); }
/** * {@inheritDoc} */ @Override public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception { @SuppressWarnings("unchecked") LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer = ( LdapMessageContainer<MessageDecorator<? extends Message>> ) session.getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR ); if ( session.containsAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ) ) { int maxPDUSize = ( Integer ) session.getAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ); messageContainer.setMaxPDUSize( maxPDUSize ); } List<Message> decodedMessages = new ArrayList<>(); ByteBuffer buf = in.buf(); decode( buf, messageContainer, decodedMessages ); for ( Message message : decodedMessages ) { out.write( message ); } }
/** * {@inheritDoc} */ @Override public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception { @SuppressWarnings("unchecked") LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer = ( LdapMessageContainer<MessageDecorator<? extends Message>> ) session.getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR ); if ( session.containsAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ) ) { int maxPDUSize = ( Integer ) session.getAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ); messageContainer.setMaxPDUSize( maxPDUSize ); } List<Message> decodedMessages = new ArrayList<>(); ByteBuffer buf = in.buf(); decode( buf, messageContainer, decodedMessages ); for ( Message message : decodedMessages ) { out.write( message ); } }
@Override protected boolean doDecode(IoSession session, IoBuffer msg, ProtocolDecoderOutput out) throws Exception { /** * 消息已经解析 * 谷歌浏览器一次请求存在多次收到消息,还额外请求了/favicon.ico路径 */ if (session.containsAttribute(HTTP_REQUEST)) { return false; } msg.mark(); HttpRequestImpl rq = parseHttpRequestHead(msg.buf(), msg); if (rq != null) { out.write(rq); session.setAttribute(HTTP_REQUEST, rq); // LOG.info("解析成功"); return true; } msg.reset(); return false; }
private WriteFuture initiateClosure(NextFilter nextFilter, IoSession session) throws SSLException { SslHandler handler = getSslSessionHandler(session); // if already shut down if (!handler.closeOutbound()) { return DefaultWriteFuture.newNotWrittenFuture( session, new IllegalStateException("SSL session is shut down already.")); } // there might be data to write out here? WriteFuture future = handler.writeNetBuffer(nextFilter); if (future == null) { future = DefaultWriteFuture.newWrittenFuture(session); } if (handler.isInboundDone()) { handler.destroy(); } if (session.containsAttribute(USE_NOTIFICATION)) { handler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED); } return future; }
private WriteFuture initiateClosure(NextFilter nextFilter, IoSession session) throws SSLException { SslHandler handler = getSslSessionHandler(session); // if already shut down if (!handler.closeOutbound()) { return DefaultWriteFuture.newNotWrittenFuture( session, new IllegalStateException("SSL session is shut down already.")); } // there might be data to write out here? WriteFuture future = handler.writeNetBuffer(nextFilter); if (future == null) { future = DefaultWriteFuture.newWrittenFuture(session); } if (handler.isInboundDone()) { handler.destroy(); } if (session.containsAttribute(USE_NOTIFICATION)) { handler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED); } return future; }
if (session.containsAttribute(USE_NOTIFICATION)) { sslHandler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED);