protected void setupSocketProtocol(String uri) throws Exception { boolean minaLogger = configuration.isMinaLogger(); long timeout = configuration.getTimeout(); List<IoFilter> filters = configuration.getFilters(); address = new InetSocketAddress(configuration.getHost(), configuration.getPort()); final int processorCount = Runtime.getRuntime().availableProcessors() + 1; connector = new NioSocketConnector(processorCount); // connector config connectorConfig = connector.getSessionConfig(); if (configuration.isOrderedThreadPoolExecutor()) { workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize()); } else { workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize()); } connector.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool)); if (minaLogger) { connector.getFilterChain().addLast("logger", new LoggingFilter()); } appendIoFiltersToChain(filters, connector.getFilterChain()); if (configuration.getSslContextParameters() != null) { connector .getFilterChain() .addFirst( "sslFilter", new SslFilter( configuration.getSslContextParameters().createSSLContext(), configuration.isAutoStartTls())); } configureCodecFactory("Mina2Producer", connector); connector.setConnectTimeoutMillis(timeout); }
protected void setupDatagramProtocol(String uri) { boolean minaLogger = configuration.isMinaLogger(); boolean transferExchange = configuration.isTransferExchange(); List<IoFilter> filters = configuration.getFilters(); if (transferExchange) { throw new IllegalArgumentException( "transferExchange=true is not supported for datagram protocol"); } address = new InetSocketAddress(configuration.getHost(), configuration.getPort()); final int processorCount = Runtime.getRuntime().availableProcessors() + 1; connector = new NioDatagramConnector(processorCount); if (configuration.isOrderedThreadPoolExecutor()) { workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize()); } else { workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize()); } connectorConfig = connector.getSessionConfig(); connector.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool)); if (minaLogger) { connector.getFilterChain().addLast("logger", new LoggingFilter()); } appendIoFiltersToChain(filters, connector.getFilterChain()); if (configuration.getSslContextParameters() != null) { LOG.warn( "Using datagram protocol, " + configuration.getProtocol() + ", but an SSLContextParameters instance was provided. SSLContextParameters is only supported on the TCP protocol."); } configureDataGramCodecFactory("Mina2Producer", connector, configuration); // set connect timeout to mina in seconds connector.setConnectTimeoutMillis(timeout); }
private void openConnection() { if (LOG.isDebugEnabled()) { LOG.debug( "Creating connector to address: {} using connector: {} timeout: {} millis.", new Object[] {address, connector, timeout}); } // connect and wait until the connection is established if (connectorConfig != null) { connector.getSessionConfig().setAll(connectorConfig); } connector.setHandler(new ResponseHandler()); ConnectFuture future = connector.connect(address); future.awaitUninterruptibly(); session = future.getSession(); }