private void addSession(IoSession session) { IoSessionStat sessionStats = new IoSessionStat(); session.setAttribute(KEY, sessionStats); totalProcessedSessions.incrementAndGet(); polledSessions.add(session); }
private void add(IoSession session, int size) { synchronized (session) { int counter = getCounter(session) + size; session.setAttribute(COUNTER, new Integer(counter)); if (counter >= maximumConnectionBufferSize && session.getTrafficMask().isReadable()) { session.suspendRead(); session.setAttribute(SUSPENDED_READS); } } }
private ProtocolDecoderOutput getDecoderOut(IoSession session, NextFilter nextFilter) { ProtocolDecoderOutput out = (ProtocolDecoderOutput) session.getAttribute(DECODER_OUT); if (out == null) { out = new SimpleProtocolDecoderOutput(session, nextFilter); session.setAttribute(DECODER_OUT, out); } return out; }
public void execute(NextCommand next, IoSession session, Object message) throws Exception { if (next != null) { session.setAttribute(NEXT_COMMAND, next); } try { callNextCommand(head, session, message); } finally { session.removeAttribute(NEXT_COMMAND); } }
/** * Creates a new instance with the factory passed to the constructor of * this class. The created handler is stored as a session * attribute named {@link #HANDLER}. * * @see org.littleshoot.mina.common.IoHandler#sessionCreated(org.littleshoot.mina.common.IoSession) */ public void sessionCreated(IoSession session) throws Exception { SingleSessionIoHandler handler = factory.getHandler(session); session.setAttribute(HANDLER, handler); handler.sessionCreated(); }
private Context getContext(final IoSession session) { Context ctx = (Context) session.getAttribute(CONTEXT); if (ctx == null) { ctx = new Context(); session.setAttribute(CONTEXT, ctx); } return ctx; }
private ProtocolEncoder getEncoder(IoSession session) throws Exception { ProtocolEncoder encoder = (ProtocolEncoder) session .getAttribute(ENCODER); if (encoder == null) { encoder = factory.getEncoder(); session.setAttribute(ENCODER, encoder); } return encoder; }
private ProtocolDecoder getDecoder(IoSession session) throws Exception { ProtocolDecoder decoder = (ProtocolDecoder) session .getAttribute(DECODER); if (decoder == null) { decoder = factory.getDecoder(); session.setAttribute(DECODER, decoder); } return decoder; }
private Context getContext(IoSession session) { Context ctx = (Context) session.getAttribute(CONTEXT); if (ctx == null) { ctx = new Context(); session.setAttribute(CONTEXT, ctx); } return ctx; }
private static Logger getLogger(IoSession session) { Logger log = (Logger) session.getAttribute(LOGGER); if (log == null) { log = LoggerFactory.getLogger(getClass(session)); String prefix = (String) session.getAttribute(PREFIX); if (prefix == null) { prefix = "[" + session.getRemoteAddress() + "] "; session.setAttribute(PREFIX, prefix); } session.setAttribute(LOGGER, log); } return log; } }
private static SessionBuffer getSessionBuffer(IoSession session) { synchronized (session) { SessionBuffer buf = (SessionBuffer) session.getAttribute(KEY); if (buf == null) { buf = new SessionBuffer(session); session.setAttribute(KEY, buf); } return buf; } }
/** * Initializes streams and timeout settings. */ @Override public void sessionOpened(final IoSession session) { // Set timeouts session.setWriteTimeout(m_writeTimeout); session.setIdleTime(IdleStatus.READER_IDLE, m_readTimeout); // Create streams final InputStream in = new IoSessionInputStream(session, m_readTimeout); final OutputStream out = this.m_osFactory.newStream(session); session.setAttribute(KEY_IN, in); session.setAttribute(KEY_OUT, out); final Socket ioSocket = new IoSessionSocket(session, in, out); session.setAttribute("SOCKET", ioSocket); //onSocket(ioSocket); }
private void release(IoSession session, int size) { synchronized (session) { int counter = Math.max(0, getCounter(session) - size); session.setAttribute(COUNTER, new Integer(counter)); if (counter < maximumConnectionBufferSize && isSuspendedReads(session)) { session.resumeRead(); session.removeAttribute(SUSPENDED_READS); } } }
/** * Initializes streams and timeout settings. */ public void sessionOpened(IoSession session) { // Set timeouts session.setWriteTimeout(writeTimeout); session.setIdleTime(IdleStatus.READER_IDLE, readTimeout); // Create streams InputStream in = new IoSessionInputStream(); OutputStream out = new IoSessionOutputStream(session); session.setAttribute(KEY_IN, in); session.setAttribute(KEY_OUT, out); processStreamIo(session, in, out); }
public void operationComplete(final IoFuture ioFuture) { if (!ioFuture.isReady()) { m_log.warn("Future not ready?"); return; } try { m_ioSession = ioFuture.getSession(); } catch (final RuntimeIOException e) { // This seems to get thrown when we can't connect at all. m_log.warn("Could not connect to TURN server at: " + stunServerAddress, e); // m_connectionListener.connectionFailed(); return; } if (m_ioSession == null || !m_ioSession.isConnected()) { m_log.error("Could not create session"); throw new RuntimeIoException("Could not get session"); } // TODO: We should not need this. final TurnStunMessageMapper mapper = new TurnStunMessageMapperImpl(); m_ioSession.setAttribute("REMOTE_ADDRESS_MAP", mapper); final AllocateRequest msg = new AllocateRequest(); m_log.debug("Sending allocate request to write handler..."); m_ioSession.write(msg); } };
if (queue == null) { queue = new ConcurrentLinkedQueue<WriteRequest>(); session.setAttribute(WRITE_REQUEST_QUEUE, queue); nextFilter.messageSent(session, message); } else { session.setAttribute(CURRENT_STREAM, inputStream); session.setAttribute(INITIAL_WRITE_FUTURE, writeRequest .getFuture());
public void sessionCreated(final IoSession session) { m_log.debug("Setting media stream on session"); if (m_closed) { m_log.info("Already closed. Closing session."); session.close(); return; } session.setAttribute(IceMediaStream.class.getSimpleName(), this); final InetSocketAddress localAddress = (InetSocketAddress) session .getLocalAddress(); final InetSocketAddress remoteAddress = (InetSocketAddress) session .getRemoteAddress(); final boolean isUdp = MinaUtils.isUdp(session); final IceCandidatePair pair = getPair(localAddress, remoteAddress, isUdp); if (pair == null) { return; } if (pair.getIoSession() == null) { pair.setIoSession(session); } }
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER); if (encoder == null) { encoder = charset.newEncoder(); session.setAttribute(ENCODER, encoder); } String value = message.toString(); ByteBuffer buf = ByteBuffer.allocate(value.length()) .setAutoExpand(true); buf.putString(value, encoder); if (buf.position() > maxLineLength) { throw new IllegalArgumentException("Line length: " + buf.position()); } buf.putString(delimiter.getValue(), encoder); buf.flip(); out.write(buf); }
private void storeRemainingInSession(ByteBuffer buf, IoSession session) { ByteBuffer remainingBuf = ByteBuffer.allocate(buf.capacity()); remainingBuf.setAutoExpand(true); remainingBuf.order(buf.order()); remainingBuf.put(buf); session.setAttribute(BUFFER, remainingBuf); } }