@Override public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception { // We close idle sessions to make sure we don't consume // too many client resources. // Note closing the session here will create the // appropriate event handlers to clean up all mappings // and references. session.close(); }
/** * {@inheritDoc} */ @Override public boolean isClosed() { return !this.m_ioSession.isConnected(); }
private Object generateKey(IoSession session) { return generateKey(session.getLocalAddress(), session .getRemoteAddress()); }
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 Context getContext(final IoSession session) { Context ctx = (Context) session.getAttribute(CONTEXT); if (ctx == null) { ctx = new Context(); session.setAttribute(CONTEXT, ctx); } return ctx; }
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); } }
(InetSocketAddress) this.m_ioSession.getLocalAddress(); final InetSocketAddress remoteAddress = (InetSocketAddress) this.m_ioSession.getRemoteAddress(); if (this.m_ioSession.isConnected()) { LOG.info("Writing binding request: {} on {}", bindingRequest, this.m_ioSession); this.m_ioSession.write(bindingRequest); || this.m_ioSession.isClosing()) { LOG.debug("The transaction was canceled!"); return new CanceledStunMessage();
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); } }
private void write(final SipMessage message, final IoSession io, final boolean listen) { final WriteFuture wf = io.write(message); if (listen) { wf.addListener(this); } }
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); } };
(InetSocketAddress) this.m_ioSession.getLocalAddress(); (InetSocketAddress) this.m_ioSession.getRemoteAddress(); m_log.debug("Using normal remote address: {}", remoteAddress); this.m_ioSession.write(response); final TransportType type = this.m_ioSession.getTransportType(); final boolean isUdp = type.isConnectionless(); final IceCandidate remoteCandidate;
private void removeSession(IoSession session) { // remove the session from the list of polled sessions polledSessions.remove(session); // add the bytes processed between last polling and session closing // prevent non seen byte with non-connected protocols like HTTP and datagrams IoSessionStat sessStat = (IoSessionStat) session.getAttribute(KEY); // computing with time between polling and closing long currentTime = System.currentTimeMillis(); synchronized (calcLock) { bytesReadThroughput += (session.getReadBytes() - sessStat.lastByteRead) / ((currentTime - sessStat.lastPollingTime) / 1000f); bytesWrittenThroughput += (session.getWrittenBytes() - sessStat.lastByteWrite) / ((currentTime - sessStat.lastPollingTime) / 1000f); msgReadThroughput += (session.getReadMessages() - sessStat.lastMessageRead) / ((currentTime - sessStat.lastPollingTime) / 1000f); msgWrittenThroughput += (session.getWrittenMessages() - sessStat.lastMessageWrite) / ((currentTime - sessStat.lastPollingTime) / 1000f); } session.removeAttribute(KEY); }
if (this.m_ioSession.isClosing() || !this.m_ioSession.isConnected()) { m_log.info("Ignoring binding request for closed session"); return null; this.m_ioSession.write(response); this.m_ioSession.write(errorResponse); this.m_bindingRequestTracker.addResponse(request, errorResponse);
public Object visitBindingRequest(final BindingRequest binding) { LOG.debug("STUN server visiting binding request..."); final InetSocketAddress address = (InetSocketAddress) m_session.getRemoteAddress(); final UUID transactionId = binding.getTransactionId(); final StunMessage response = new BindingSuccessResponse(transactionId.getRawBytes(), address); this.m_session.write(response); return null; } }
/** * {@inheritDoc} */ @Override public SocketAddress getRemoteSocketAddress() { return this.m_ioSession.getRemoteAddress(); }
/** * 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 onData(final InetSocketAddress remoteAddress, final IoSession session, final byte[] data) { m_log.debug("Received data message"); final IoSession localSession = onRemoteAddressOpened(remoteAddress, session); final ByteBuffer dataBuf = ByteBuffer.wrap(data); localSession.write(dataBuf); m_log.debug("Local bytes written: {}", localSession.getWrittenBytes()); }
@SuppressWarnings("unchecked") private Queue<WriteRequest> getWriteRequestQueue(IoSession session) { return (Queue<WriteRequest>) session.getAttribute(WRITE_REQUEST_QUEUE); }
protected synchronized void write(final T message) throws IOException { m_log.debug("Writing message: {}", message); checkClosed(); m_lastWriteFuture = m_ioSession.write(message); m_lastWriteFuture.join(m_ioSession.getWriteTimeoutInMillis()); m_log.debug("Finshing writing message..."); }
/** * {@inheritDoc} */ @Override public SocketAddress getLocalSocketAddress() { return this.m_ioSession.getLocalAddress(); }