private static void initializeFallbackDefaultSocketParameters() { Socket unconnectedSocket = new Socket(); // Use a unconnected socket. try { initializeDefaultSocketParameters(unconnectedSocket); } catch (SocketException se) { ExceptionMonitor.getInstance().exceptionCaught(se); try { unconnectedSocket.close(); } catch (IOException ioe) { ExceptionMonitor.getInstance().exceptionCaught(ioe); } } }
private static void initializeTestAddresses() { try { // These two tests were disabled due to DIRMINA-560 // (IPv4 localhost TEST_ADDRESS causes server to hang) // IPv6 localhost //TEST_ADDRESSES.put(new InetSocketAddress(InetAddress // .getByAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 1 }), 0), InetAddress // .getByAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 1 })); // IPv4 localhost //TEST_ADDRESSES.put(new InetSocketAddress(InetAddress // .getByAddress(new byte[] { 127, 0, 0, 1 }), 0), InetAddress // .getByAddress(new byte[] { 127, 0, 0, 1 })); // Bind to wildcard interface and connect to IPv6 localhost TEST_ADDRESSES.put(new InetSocketAddress(0), InetAddress .getByAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 })); // Bind to wildcard interface and connect to IPv4 localhost TEST_ADDRESSES.put(new InetSocketAddress(0), InetAddress .getByAddress(new byte[] { 127, 0, 0, 1 })); } catch (UnknownHostException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } }
private void processTimedOutSessions(Set<SelectionKey> keys) { long currentTime = System.currentTimeMillis(); for (SelectionKey key : keys) { if (!key.isValid()) { continue; } ConnectionRequest entry = (ConnectionRequest) key.attachment(); if (currentTime >= entry.deadline) { entry.setException(new ConnectException()); try { key.channel().close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } finally { key.cancel(); } } } }
private void registerNew() { if (connectQueue.isEmpty()) { return; } Selector selector = this.selector; for (;;) { ConnectionRequest req = connectQueue.poll(); if (req == null) { break; } SocketChannel ch = req.channel; try { ch.register(selector, SelectionKey.OP_CONNECT, req); } catch (IOException e) { req.setException(e); try { ch.close(); } catch (IOException e2) { ExceptionMonitor.getInstance().exceptionCaught(e2); } } } }
} catch (IOException e) { ExceptionMonitor.getInstance() .exceptionCaught(e); } finally { SocketAcceptor.this.selector = null; ExceptionMonitor.getInstance().exceptionCaught(e); ExceptionMonitor.getInstance().exceptionCaught(e1);
@SuppressWarnings("unchecked") private void notifyListener(IoFutureListener l) { try { l.operationComplete(this); } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t); } } }
/** * Calls {@link IoServiceListener#serviceActivated(IoService, SocketAddress, IoHandler, IoServiceConfig)} * for all registered listeners. */ public void fireServiceActivated(IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config) { if (!managedServiceAddresses.add(serviceAddress)) { return; } for (IoServiceListener listener : listeners) { try { listener.serviceActivated(service, serviceAddress, handler, config); } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } }
private void processReadySessions(Set<SelectionKey> keys) { Iterator<SelectionKey> it = keys.iterator(); while (it.hasNext()) { SelectionKey key = it.next(); it.remove(); DatagramChannel ch = (DatagramChannel) key.channel(); RegistrationRequest req = (RegistrationRequest) key.attachment(); try { if (key.isReadable()) { readSession(ch, req); } if (key.isWritable()) { for (Object o : getManagedSessions(req.address)) { scheduleFlush((DatagramSessionImpl) o); } } } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t); } } }
socket.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e); ss.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e);
private void processSessions(Set<SelectionKey> keys) { for (SelectionKey key : keys) { if (!key.isConnectable()) { continue; } SocketChannel ch = (SocketChannel) key.channel(); ConnectionRequest entry = (ConnectionRequest) key.attachment(); boolean success = false; try { if (ch.finishConnect()) { key.cancel(); newSession(ch, entry.handler, entry.config, entry); } success = true; } catch (Throwable e) { entry.setException(e); } finally { if (!success) { key.cancel(); try { ch.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } } keys.clear(); }
public void unbind(SocketAddress address) { if (address == null) { throw new NullPointerException("address"); } CancellationRequest request = new CancellationRequest(address); synchronized (lock) { try { startupWorker(); } catch (IOException e) { // IOException is thrown only when Worker thread is not // running and failed to open a selector. We simply throw // IllegalArgumentException here because we can simply // conclude that nothing is bound to the selector. throw new IllegalArgumentException("Address not bound: " + address); } cancelQueue.add(request); selector.wakeup(); } try { request.done.await(); } catch (InterruptedException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } if (request.exception != null) { request.exception.fillInStackTrace(); throw request.exception; } }
request.done.await(); } catch (InterruptedException e) { ExceptionMonitor.getInstance().exceptionCaught(e);
/** * Calls {@link IoServiceListener#serviceDeactivated(IoService, SocketAddress, IoHandler, IoServiceConfig)} * for all registered listeners. */ public synchronized void fireServiceDeactivated(IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config) { if (!managedServiceAddresses.remove(serviceAddress)) { return; } try { for (IoServiceListener listener : listeners) { try { listener.serviceDeactivated(service, serviceAddress, handler, config); } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } finally { disconnectSessions(serviceAddress, config); } }
/** * Creates a new instance. * * @throws RuntimeIOException if failed to get the default configuration */ public SocketAcceptorConfig() { ServerSocket s = null; try { s = new ServerSocket(); reuseAddress = s.getReuseAddress(); } catch (IOException e) { throw new RuntimeIOException( "Failed to get the default configuration.", e); } finally { if (s != null) { try { s.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } sessionConfig.setReuseAddress(true); }
ExceptionMonitor.getInstance().exceptionCaught(t); } finally { synchronized (request) {
private void cancelKeys() { if (cancelQueue.isEmpty()) return; Selector selector = this.selector; for (;;) { DatagramSessionImpl session = cancelQueue.poll(); if (session == null) break; else { SelectionKey key = session.getSelectionKey(); DatagramChannel ch = (DatagramChannel) key.channel(); try { ch.disconnect(); ch.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e); } getListeners().fireSessionDestroyed(session); session.getCloseFuture().setClosed(); key.cancel(); selector.wakeup(); // wake up again to trigger thread death } } }
success = true; } catch (Throwable t) { ExceptionMonitor.getInstance().exceptionCaught(t); } finally { if (!success) {
listener.sessionDestroyed(session); } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e);
listener.sessionCreated(session); } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e);
req.channel.close(); } catch (IOException e) { ExceptionMonitor.getInstance().exceptionCaught(e);