当前位置: 首页>>代码示例>>Java>>正文


Java SocketConnectorConfig.setThreadModel方法代码示例

本文整理汇总了Java中org.apache.mina.transport.socket.nio.SocketConnectorConfig.setThreadModel方法的典型用法代码示例。如果您正苦于以下问题:Java SocketConnectorConfig.setThreadModel方法的具体用法?Java SocketConnectorConfig.setThreadModel怎么用?Java SocketConnectorConfig.setThreadModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.transport.socket.nio.SocketConnectorConfig的用法示例。


在下文中一共展示了SocketConnectorConfig.setThreadModel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectFederation

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
/**
 * Create a connection to federation listener.
 */
private static IoSession connectFederation (Router router,
                                            EwafURI uri,
                                            IoHandler listener)
{
  SocketConnector connector = new SocketConnector (1, router.executor ());
  SocketConnectorConfig connectorConfig = new SocketConnectorConfig ();
  
  connector.setWorkerTimeout (0);
  
  connectorConfig.setThreadModel (ThreadModel.MANUAL);
  connectorConfig.setConnectTimeout (20);
  
  connectorConfig.getFilterChain ().addLast   
    ("codec", FederationFrameCodec.FILTER);
  
  ConnectFuture future = 
    connector.connect (new InetSocketAddress (uri.host, uri.port),
                       listener, connectorConfig);
  
  future.join ();
  
  return future.getSession ();
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:27,代码来源:JUTestFederation.java

示例2: createClient

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
  if (isDebugEnabled) {
    LOGGER.debug("create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key);
  }
  SocketConnectorConfig cfg = new SocketConnectorConfig();
  cfg.setThreadModel(ThreadModel.MANUAL);
  if (connectTimeout > 1000) {
    cfg.setConnectTimeout((int) connectTimeout / 1000);
  } else {
    cfg.setConnectTimeout(1);
  }
  cfg.getSessionConfig().setTcpNoDelay(Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
  cfg.getFilterChain().addLast("objectserialize", new MinaProtocolCodecFilter());
  SocketAddress targetAddress = new InetSocketAddress(targetIP, targetPort);
  MinaClientProcessor processor = new MinaClientProcessor(this, key);
  ConnectFuture connectFuture = ioConnector.connect(targetAddress, null, processor, cfg);
  // wait for connection established
  connectFuture.join();

  IoSession ioSession = connectFuture.getSession();
  if ((ioSession == null) || (!ioSession.isConnected())) {
    String targetUrl = targetIP + ":" + targetPort;
    LOGGER.error("create connection error,targetaddress is " + targetUrl);
    throw new Exception("create connection error,targetaddress is " + targetUrl);
  }
  if (isDebugEnabled) {
    LOGGER.debug(
        "create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key + " successed");
  }
  MinaClient client = new MinaClient(ioSession, key, connectTimeout);
  processor.setClient(client);
  return client;
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:34,代码来源:MinaClientFactory.java

示例3: createClient

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
private synchronized TairClient createClient(String targetUrl, int connectionTimeout, PacketStreamer pstreamer)
		throws Exception {
	SocketConnectorConfig cfg = new SocketConnectorConfig();
	cfg.setThreadModel(ThreadModel.MANUAL);
	if (connectionTimeout < MIN_CONN_TIMEOUT)
		connectionTimeout = MIN_CONN_TIMEOUT;
	cfg.setConnectTimeout((int) connectionTimeout / 1000);
	cfg.getSessionConfig().setTcpNoDelay(true);
	cfg.getFilterChain().addLast("objectserialize",
			new TairProtocolCodecFilter(pstreamer));
	String address = TairUtil.getHost(targetUrl);
	int port = TairUtil.getPort(targetUrl);
	SocketAddress targetAddress = new InetSocketAddress(address, port);
	TairClientProcessor processor = new TairClientProcessor();
	ConnectFuture connectFuture = ioConnector.connect(targetAddress, null,
			processor, cfg);

	connectFuture.join();
	
	IoSession ioSession = connectFuture.getSession();
	if ((ioSession == null) || (!ioSession.isConnected())) {
		throw new Exception(
				"create tair connection error,targetaddress is "
						+ targetUrl);
	}
	if (LOGGER.isTraceEnabled()) {
		LOGGER.trace("create tair connection success,targetaddress is "
				+ targetUrl);
	}
	TairClient client = new TairClient(this, ioSession,targetUrl);
	processor.setClient(client);
	processor.setFactory(this, targetUrl);
	return client;
}
 
开发者ID:alibaba,项目名称:tair-java-client,代码行数:35,代码来源:TairClientFactory.java

示例4: connectFederationTLS

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
/**
 * Create a connection to federation listener.
 */
private static IoSession connectFederationTLS (Router router,
                                               EwafURI uri,
                                               IoHandler listener)
  throws Exception
{
  SocketConnector connector = new SocketConnector (1, router.executor ());
  SocketConnectorConfig connectorConfig = new SocketConnectorConfig ();
  
  connector.setWorkerTimeout (0);
  
  connectorConfig.setThreadModel (ThreadModel.MANUAL);
  connectorConfig.setConnectTimeout (20);
  
  SSLFilter filter = new SSLFilter (defaultSSLContext ());
  
  filter.setUseClientMode (true);
  
  connectorConfig.getFilterChain ().addFirst ("ssl", filter);   
  
  connectorConfig.getFilterChain ().addLast   
    ("codec", FederationFrameCodec.FILTER);
  
  ConnectFuture future = 
    connector.connect (new InetSocketAddress (uri.host, uri.port),
                       listener, connectorConfig);
  
  future.join ();
  
  return future.getSession ();
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:34,代码来源:JUTestFederationTLS.java

示例5: connect

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
private IoSession connect ()
{
  SocketConnectorConfig connectorConfig = new SocketConnectorConfig ();
  
  connectorConfig.setThreadModel (ThreadModel.MANUAL);
  connectorConfig.setConnectTimeout (20);
  
  ConnectFuture future = 
    connector.connect (remoteAddress, new IoHandlerAdapter (),
                       connectorConfig);
  
  future.join ();
  
  return future.getSession ();
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:16,代码来源:Fuzz.java

示例6: createStandardConfig

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
private static SocketConnectorConfig createStandardConfig () 
  throws Exception
{
  SocketConnectorConfig connectorConfig = new SocketConnectorConfig ();
  connectorConfig.setThreadModel (ThreadModel.MANUAL);
  connectorConfig.setConnectTimeout (10);
  
  connectorConfig.getFilterChain ().addLast 
    ("codec", ClientFrameCodec.FILTER);
  
  return connectorConfig;
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:13,代码来源:JUTestRouterTLS.java

示例7: AcceptorConnectorSetup

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
public AcceptorConnectorSetup ()
  throws IOException
{
  executor = newCachedThreadPool ();
  
  // listener
  acceptor = new SocketAcceptor (1, executor);
  acceptorConfig = new SocketAcceptorConfig ();
  
  acceptorConfig.setReuseAddress (true);
  acceptorConfig.setThreadModel (ThreadModel.MANUAL);
  
  DefaultIoFilterChainBuilder filterChainBuilder =
    acceptorConfig.getFilterChain ();

  filterChainBuilder.addLast ("codec", ClientFrameCodec.FILTER);
  
  // connector
  connector = new SocketConnector (1, executor);
  connectorConfig = new SocketConnectorConfig ();
  
  connector.setWorkerTimeout (0);
  
  connectorConfig.setThreadModel (ThreadModel.MANUAL);
  connectorConfig.setConnectTimeout (20);
  
  connectorConfig.getFilterChain ().addLast   
    ("codec", ClientFrameCodec.FILTER);
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:30,代码来源:AcceptorConnectorSetup.java

示例8: createSocketEndpoint

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
protected MinaEndpoint createSocketEndpoint(String uri, MinaConfiguration configuration) {
    boolean minaLogger = configuration.isMinaLogger();
    long timeout = configuration.getTimeout();
    boolean sync = configuration.isSync();
    List<IoFilter> filters = configuration.getFilters();
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;

    ExecutorService acceptorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaSocketAcceptor");
    ExecutorService connectorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaSocketConnector");
    ExecutorService workerPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaThreadPool");

    IoAcceptor acceptor = new SocketAcceptor(processorCount, acceptorPool);
    IoConnector connector = new SocketConnector(processorCount, connectorPool);
    SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

    // connector config
    SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
    // must use manual thread model according to Mina documentation
    connectorConfig.setThreadModel(ThreadModel.MANUAL);
    configureCodecFactory("MinaProducer", connectorConfig, configuration);
    connectorConfig.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        connectorConfig.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connectorConfig.getFilterChain());

    // set connect timeout to mina in seconds
    connectorConfig.setConnectTimeout((int) (timeout / 1000));

    // acceptor connectorConfig
    SocketAcceptorConfig acceptorConfig = new SocketAcceptorConfig();
    // must use manual thread model according to Mina documentation
    acceptorConfig.setThreadModel(ThreadModel.MANUAL);
    configureCodecFactory("MinaConsumer", acceptorConfig, configuration);
    acceptorConfig.setReuseAddress(true);
    acceptorConfig.setDisconnectOnUnbind(true);
    acceptorConfig.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        acceptorConfig.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, acceptorConfig.getFilterChain());

    MinaEndpoint endpoint = new MinaEndpoint(uri, this);
    endpoint.setAddress(address);
    endpoint.setAcceptor(acceptor);
    endpoint.setAcceptorConfig(acceptorConfig);
    endpoint.setConnector(connector);
    endpoint.setConnectorConfig(connectorConfig);
    endpoint.setConfiguration(configuration);

    // enlist threads pools in use on endpoint
    endpoint.addThreadPool(acceptorPool);
    endpoint.addThreadPool(connectorPool);
    endpoint.addThreadPool(workerPool);

    // set sync or async mode after endpoint is created
    if (sync) {
        endpoint.setExchangePattern(ExchangePattern.InOut);
    } else {
        endpoint.setExchangePattern(ExchangePattern.InOnly);
    }

    return endpoint;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:65,代码来源:MinaComponent.java

示例9: connect

import org.apache.mina.transport.socket.nio.SocketConnectorConfig; //导入方法依赖的package包/类
public NetworkConnection connect(Receiver<java.nio.ByteBuffer> receiver, ConnectionSettings settings, SSLContextFactory sslFactory)
{
    final IoConnector ioConnector = _ioConnectorFactory.newConnector();
    final SocketAddress address;
    final String protocol = settings.getProtocol();
    final int port = settings.getPort();

    if (Transport.TCP.equalsIgnoreCase(protocol))
    {
        address = new InetSocketAddress(settings.getHost(), port);
    }
    else
    {
        throw new TransportException("Unknown transport: " + protocol);
    }

    LOGGER.debug("Attempting connection to " + address);

    if (ioConnector instanceof SocketConnector)
    {
        SocketConnectorConfig cfg = (SocketConnectorConfig) ioConnector.getDefaultConfig();
        cfg.setThreadModel(ExecutorThreadModel.getInstance("MinaNetworkTransport(Client)"));

        SocketSessionConfig scfg = (SocketSessionConfig) cfg.getSessionConfig();
        scfg.setTcpNoDelay(true);
        scfg.setSendBufferSize(CLIENT_DEFAULT_BUFFER_SIZE);
        scfg.setReceiveBufferSize(CLIENT_DEFAULT_BUFFER_SIZE);

        // Don't have the connector's worker thread wait around for other
        // connections (we only use one SocketConnector per connection
        // at the moment anyway). This allows short-running
        // clients (like unit tests) to complete quickly.
        ((SocketConnector) ioConnector).setWorkerTimeout(0);
    }

    if (settings.isUseSSL()){
        try {
            SSLContext sslContext = SSLUtil.createSSLContext(settings);
            SSLFilter sslFilter = new SSLFilter(sslContext);
            sslFilter.setUseClientMode(true);
            ioConnector.getFilterChain().addFirst("sslFilter", sslFilter);
        } catch (Exception e) {
            Exception ex = new Exception("An exception occurred in creating SSLContext: ", e);
            ex.printStackTrace();
        }
    }

    ConnectFuture future = ioConnector.connect(address, new MinaNetworkHandler(null), ioConnector.getDefaultConfig());
    future.join();
    if (!future.isConnected())
    {
        throw new TransportException("Could not open connection");
    }
    IoSession session = future.getSession();
    session.setAttachment(receiver);

    return new MinaNetworkConnection(session);
}
 
开发者ID:wso2,项目名称:andes,代码行数:59,代码来源:MinaNetworkTransport.java


注:本文中的org.apache.mina.transport.socket.nio.SocketConnectorConfig.setThreadModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。