@Override public InetSocketAddress getDefaultLocalAddress() { return (InetSocketAddress) super.getDefaultLocalAddress(); }
@Override public InetSocketAddress getLocalAddress() { return (InetSocketAddress) super.getLocalAddress(); }
@Override public DatagramSessionConfig getSessionConfig() { return (DatagramSessionConfig) super.getSessionConfig(); }
private void readHandle(H handle) throws Exception { IoBuffer readBuf = newReadBuffer(getSessionConfig().getReadBufferSize()); SocketAddress remoteAddress = receive(handle, readBuf); if (remoteAddress != null) { IoSession session = newSessionWithoutLock( remoteAddress, localAddress(handle)); readBuf.flip(); IoBuffer newBuf = newReadBuffer(readBuf.limit()); newBuf.put(readBuf); newBuf.flip(); session.getFilterChain().fireMessageReceived(newBuf); } }
@SuppressWarnings("unchecked") private void processReadySessions(Iterator<H> handles) { while (handles.hasNext()) { H h = handles.next(); handles.remove(); try { if (isReadable(h)) { readHandle(h); } if (isWritable(h)) { for (IoSession session : getManagedSessions().values()) { scheduleFlush((T) session); } } } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t); } } }
private IoSession newSessionWithoutLock( SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { H handle = boundHandles.get(localAddress); if (handle == null) { throw new IllegalArgumentException("Unknown local address: " + localAddress); } IoSession session; IoSessionRecycler sessionRecycler = getSessionRecycler(); synchronized (sessionRecycler) { session = sessionRecycler.recycle(localAddress, remoteAddress); if (session != null) { return session; } // If a new session needs to be created. T newSession = newSession(processor, handle, remoteAddress); getSessionRecycler().put(newSession); session = newSession; } initSession(session, null, null); try { this.getFilterChainBuilder().buildFilterChain(session.getFilterChain()); getListeners().fireSessionCreated(session); } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t); } return session; }
try { for (SocketAddress a: localAddresses) { H handle = open(a); newHandles.put(localAddress(handle), handle); getListeners().fireServiceActivated(); req.setDone(); return newHandles.size(); for (H handle: newHandles.values()) { try { close(handle); } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); wakeup();
/** * Creates a new instance. */ protected AbstractPollingConnectionlessIoAcceptor(IoSessionConfig sessionConfig, Executor executor) { super(sessionConfig, executor); try { init(); selectable = true; } catch (RuntimeException e){ throw e; } catch (Exception e) { throw new RuntimeIoException("Failed to initialize.", e); } finally { if (!selectable) { try { destroy(); } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } }
private int unregisterHandles() { int nHandles = 0; for (;;) { AcceptorOperationFuture request = cancelQueue.poll(); if (request == null) { break; } // close the channels for (SocketAddress a: request.getLocalAddresses()) { H handle = boundHandles.remove(a); if (handle == null) { continue; } try { close(handle); wakeup(); // wake up again to trigger thread death } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e); } finally { nHandles ++; } } request.setDone(); } return nHandles; }
private void flushSessions(long currentTime) { for (; ;) { T session = flushingSessions.poll(); if (session == null) { break; } session.setScheduledForFlush(false); try { boolean flushedAll = flush(session, currentTime); if (flushedAll && !session.getWriteRequestQueue().isEmpty(session) && !session.isScheduledForFlush()) { scheduleFlush(session); } } catch (Exception e) { session.getFilterChain().fireExceptionCaught(e); } } }
/** * Starts the inner Acceptor thread. */ private void startupAcceptor() { if (!selectable) { registerQueue.clear(); cancelQueue.clear(); flushingSessions.clear(); } synchronized (lock) { if (acceptor == null) { acceptor = new Acceptor(); executeWorker(acceptor); } } }
private void notifyIdleSessions(long currentTime) { // process idle sessions if (currentTime - lastIdleCheckTime >= 1000) { lastIdleCheckTime = currentTime; AbstractIoSession.notifyIdleness( getListeners().getManagedSessions().values().iterator(), currentTime); } } }
@Override public InetSocketAddress getDefaultLocalAddress() { return (InetSocketAddress) super.getDefaultLocalAddress(); }
@Override public DatagramSessionConfigEx getSessionConfig() { return (DatagramSessionConfigEx) super.getSessionConfig(); }
@Override public InetSocketAddress getLocalAddress() { return (InetSocketAddress) super.getLocalAddress(); }