@Override protected void doOpen() throws Throwable { // set thread pool. acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config SocketAcceptorConfig cfg = acceptor.getDefaultConfig(); cfg.setThreadModel(ThreadModel.MANUAL); // set codec. acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this)); }
@Override public Collection<Channel> getChannels() { Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress()); Collection<Channel> channels = new HashSet<Channel>(); for (IoSession session : sessions) { if (session.isConnected()) { channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this)); } } return channels; }
@Override protected void doClose() throws Throwable { try { if (acceptor != null) { acceptor.unbind(getBindAddress()); } } catch (Throwable e) { logger.warn(e.getMessage(), e); } }
public synchronized void start() throws IOException { register(); if (serverHandler != null) { if (socketAcceptor == null) { socketAcceptor = new SocketAcceptor(socketAcceptorProcessors, serverExecutor); } SocketAcceptorConfig config = socketAcceptor.getDefaultConfig(); nioConfig.configureSocketAcceptorConfig(config); socketAcceptor.bind(nioConfig.getServerSocketAddress(), serverHandler, config); socketAddress = (InetSocketAddress) socketAcceptor.getManagedServiceAddresses().iterator().next(); LOGGER.info("ExecutionVenueNioServer started on " + socketAcceptor.getManagedServiceAddresses()); // Create a shutdown hook to close the Socket Server cleanly Runtime.getRuntime().addShutdownHook(new Thread("EV Socket Server Shutdown Thread") { @Override public void run() { LOGGER.info("Gracefully shutting down ExecutionVenueNioServer"); try { ExecutionVenueNioServer.this.stop(); } catch (Exception e) { LOGGER.warn("Failed to shutdown ExecutionVenueNioServer", e); } } }); running = true; } }
/** * {@inheritDoc} */ public Acceptor<SocketAddress> createAcceptor() { IoAcceptor minaAcceptor; if (transportType.equals(TransportType.RELIABLE)) { org.apache.mina.transport.socket.nio.SocketAcceptor minaSocketAcceptor = new org.apache.mina.transport.socket.nio.SocketAcceptor( numProcessors, executor); SocketAcceptorConfig socketConfig = minaSocketAcceptor.getDefaultConfig(); socketConfig.setReuseAddress(Boolean.parseBoolean( System.getProperty(REUSE_ADDRESS_PROPERTY, DEFAULT_REUSE_ADDRESS))); minaAcceptor = minaSocketAcceptor; } else { minaAcceptor = new DatagramAcceptor(executor); } SocketAcceptor acceptor = new SocketAcceptor(this, minaAcceptor); logger.log(Level.FINE, "returning {0}", acceptor); return acceptor; } }
private void shutdownSessions(boolean blockUntilComplete) { CougarProtocol cougarProtocol = (CougarProtocol) socketAcceptor.getDefaultConfig().getFilterChain().get("protocol"); sessionManager.shutdownSessions(socketAcceptor.getManagedSessions(socketAddress), cougarProtocol, this.serverHandler, blockUntilComplete); }
@Override public boolean isBound() { return acceptor.isManaged(getBindAddress()); }
@ManagedAttribute public synchronized void setHealthState(boolean isHealthy) { if (LOGGER.isInfoEnabled()) { LOGGER.info("setting protocol to " + (isHealthy ? "enabled" : "disabled")); } if (socketAcceptor != null) { CougarProtocol cougarProtocol = (CougarProtocol) socketAcceptor.getDefaultConfig().getFilterChain().get("protocol"); cougarProtocol.setEnabled(isHealthy); if (!isHealthy) { shutdownSessions(false); } } }
private void startNetworking() throws Exception { registry = new SocketAcceptor(); SocketAcceptorConfig config = new SocketAcceptorConfig(); config.setReuseAddress( true ); config.getFilterChain().addLast( "protocol", new ProtocolCodecFilter( new ReplicationServerProtocolCodecFactory() ) ); config.getFilterChain().addLast( "logger", new LoggingFilter() ); // bind server protocol provider registry.bind( new InetSocketAddress( configuration.getServerPort() ), new ReplicationServerProtocolHandler( this ), config ); clientConnectionManager.start( configuration ); }
cfg = ( SocketAcceptorConfig ) getDefaultConfig(); getListeners().fireServiceActivated( this, req.address, req.handler, req.config );
@Override public boolean isBound() { return acceptor.isManaged(getBindAddress()); }
@ManagedAttribute public boolean isEnabled() { final CougarProtocol protocol = (CougarProtocol) socketAcceptor.getDefaultConfig().getFilterChain().get("protocol"); if (protocol != null) { return protocol.isEnabled(); } return false; }
File workingDirectory = ...; Partition partition = new JdbmPartition(); partition.setId(...); partition.setSuffix(...); DirectoryService directoryService = new DefaultDirectoryService(); directoryService.setWorkingDirectory(workingDirectory); directoryService.addPartition(partition); LdapService ldapService = new LdapService(); ldapService.setSocketAcceptor(new SocketAcceptor(null)); ldapService.setIpPort(...); ldapService.setDirectoryService(directoryService); directoryService.startup(); ldapService.start();
@Override protected void doOpen() throws Throwable { // set thread pool. acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config SocketAcceptorConfig cfg = acceptor.getDefaultConfig(); cfg.setThreadModel(ThreadModel.MANUAL); // set codec. acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this)); }
@Override public Collection<Channel> getChannels() { Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress()); Collection<Channel> channels = new HashSet<Channel>(); for (IoSession session : sessions) { if (session.isConnected()) { channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this)); } } return channels; }
@Override protected void doClose() throws Throwable { try { if (acceptor != null) { acceptor.unbind(getBindAddress()); } } catch (Throwable e) { logger.warn(e.getMessage(), e); } }
@Override public boolean isBound() { return acceptor.isManaged(getBindAddress()); }
@ManagedAttribute public synchronized Boolean isHealthState() { if (socketAcceptor != null) { CougarProtocol cougarProtocol = (CougarProtocol) socketAcceptor.getDefaultConfig().getFilterChain().get("protocol"); return cougarProtocol.isEnabled(); } return null; }
@Override protected void doOpen() throws Throwable { // set thread pool. acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig(); cfg.setThreadModel(ThreadModel.MANUAL); // set codec. acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this)); }