@Override protected IoAcceptor initAcceptor() { MulticastAcceptorImpl acceptor = new MulticastAcceptorImpl(); String property = configuration.getProperty("org.kaazing.gateway.transport.udp.READ_BUFFER_SIZE"); if (property != null) { int readBufferSize = Integer.parseInt(property); acceptor.getSessionConfig().setReadBufferSize(readBufferSize); logger.debug("READ_BUFFER_SIZE setting for Multicast acceptor: {}", readBufferSize); } return acceptor; }
@Override public final IoSessionEx newSession(SocketAddress remoteAddress, SocketAddress localAddress) { if (isDisposing()) { throw new IllegalStateException("Already disposed."); } if (remoteAddress == null) { throw new NullPointerException("remoteAddress"); } synchronized (bindLock) { if (!isActive()) { throw new IllegalStateException( "Can't create a session from a unbound service."); } try { return newSessionWithoutLock(remoteAddress, localAddress); } catch (RuntimeException | Error e) { throw e; } catch (Exception e) { throw new RuntimeIoException("Failed to create a session.", e); } } }
private IoSessionEx newSessionWithoutLock( SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { Handle handle = boundHandles.get(localAddress); if (handle == null) { throw new IllegalArgumentException("Unknown local address: " + localAddress); } IoSessionEx session; IoSessionRecycler sessionRecycler = getSessionRecycler(); synchronized (sessionRecycler) { session = (IoSessionEx) sessionRecycler.recycle(localAddress, remoteAddress); if (session != null && !session.isClosing()) { return session; } // If a new session needs to be created. MulticastSession newSession = new MulticastSession(this, processor, handle.socket, handle.localAddress, remoteAddress); sessionRecycler.put(newSession); session = newSession; } initSession(session, null, null); try { this.getFilterChainBuilder().buildFilterChain(session.getFilterChain()); getListeners().fireSessionCreated(session); } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t, session); } return session; }
@Override public void remove(MulticastSession session) { session.getSocket().close(); getSessionRecycler().remove(session); getListeners().fireSessionDestroyed(session); }
IoSessionEx session = newSession(remoteAddress, localAddress); if (socket.isClosed()) { Set<IoSession> managedSessions = new HashSet<>(getManagedSessions().values()); for (IoSession managedSession : managedSessions) { if (localAddress.equals(managedSession.getLocalAddress())) {
@Override protected IoFuture dispose0() throws Exception { // close all recycled sessions that have not yet timed out // this triggers the sessionClosed event for the filter chain Set<IoSession> managedSessions = new HashSet<>(getManagedSessions().values()); for (IoSession managedSession : managedSessions) { managedSession.close(true); } // unbind handles that may not yet have an associated session for (Handle handle : boundHandles.values()) { try { handle.unbind(); } catch (IOException e) { e.printStackTrace(); } } // TODO: remove return for 2.0.0-RCx upgrade return null; }
@Override protected BindFuture bindAsyncInternal(SocketAddress localAddress) { List<? extends SocketAddress> localAddresses = Collections.singletonList(localAddress); try { bindInternal(localAddresses); return DefaultBindFuture.succeededFuture(); } catch (Exception e) { DefaultBindFuture bindFuture = new DefaultBindFuture(); bindFuture.setException(e); return bindFuture; } }