public ConnectFuture connect(SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer) { MulticastAddress multicastAddress = (MulticastAddress) localAddress; String uri = format("udp://%s:%d", multicastAddress.getGroupAddress().getHostAddress(), multicastAddress.getBindPort()); ResourceAddress resourceAddress = resourceAddressFactory.newResourceAddress(uri); final MulticastSession newSession = new MulticastSession(MulticastConnectorImpl.this, processor, socket, resourceAddress, remoteAddress); DefaultConnectFuture connectFuture = new DefaultConnectFuture(); initSession(newSession, connectFuture, sessionInitializer); newSession.getProcessor().add(newSession); dispatchSessions.add(newSession); newSession.getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { dispatchSessions.remove(newSession); } }); return connectFuture; }
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; }