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


Java ThreadModel类代码示例

本文整理汇总了Java中org.apache.mina.common.ThreadModel的典型用法代码示例。如果您正苦于以下问题:Java ThreadModel类的具体用法?Java ThreadModel怎么用?Java ThreadModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: configureProtocol

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
protected void configureProtocol(BaseIoServiceConfig config, boolean isServer) throws IOException {

        ByteBuffer.setUseDirectBuffers(useDirectBuffersInMina);

        config.getFilterChain().addLast("slowHandling", new SessionWriteQueueMonitoring(nioLogger, maxWriteQueueSize));
        config.getFilterChain().addLast("codec",
                new ProtocolCodecFilter(new CougarProtocolEncoder(nioLogger), new CougarProtocolDecoder(nioLogger)));
        if (isServer) {
            config.getFilterChain().addLast("protocol", CougarProtocol.getServerInstance(nioLogger, keepAliveInterval, keepAliveTimeout, null, false, false));
        }
        else {
            config.getFilterChain().addLast("protocol", CougarProtocol.getClientInstance(nioLogger, keepAliveInterval, keepAliveTimeout, null, false, false, rpcTimeoutMillis));
        }

        config.setThreadModel(ThreadModel.MANUAL);
    }
 
开发者ID:betfair,项目名称:cougar,代码行数:17,代码来源:NioConfig.java

示例2: connectFederation

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例3: doOpen

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
@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));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:15,代码来源:MinaServer.java

示例4: createClient

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例5: createClient

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例6: doOpen

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
@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));
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:15,代码来源:MinaServer.java

示例7: SocketAcceptorConfig

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
/**
 * Create default MINA config for incoming connections.
 * 
 * @param filters The base set of common filters.
 * @param authRequired The set of hosts that must connect via
 *                authenticated connections and should be
 *                blacklisted from non authenticated access.
 */
private SocketAcceptorConfig createAcceptorConfig 
  (DefaultIoFilterChainBuilder filters)
{
  SocketAcceptorConfig defaultAcceptorConfig = new SocketAcceptorConfig ();
  
  defaultAcceptorConfig.setReuseAddress (true);
  defaultAcceptorConfig.setThreadModel (ThreadModel.MANUAL);
  defaultAcceptorConfig.setFilterChainBuilder (filters);
  
  return defaultAcceptorConfig;
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:20,代码来源:Router.java

示例8: connectFederationTLS

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例9: connect

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例10: createStandardConfig

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例11: AcceptorConnectorSetup

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例12: MinaServer

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
public MinaServer() {
  acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
      Executors.newCachedThreadPool(new NamedThreadFactory(ACCEPTOR_THREADNAME)));
  acceptor.getDefaultConfig().setThreadModel(ThreadModel.MANUAL);
  acceptor.getDefaultConfig().getFilterChain().addLast("objectserialize", new MinaProtocolCodecFilter());
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:7,代码来源:MinaServer.java

示例13: createSocketEndpoint

import org.apache.mina.common.ThreadModel; //导入依赖的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

示例14: createDatagramEndpoint

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
protected MinaEndpoint createDatagramEndpoint(String uri, MinaConfiguration configuration) {
    boolean minaLogger = configuration.isMinaLogger();
    long timeout = configuration.getTimeout();
    boolean transferExchange = configuration.isTransferExchange();
    boolean sync = configuration.isSync();
    List<IoFilter> filters = configuration.getFilters();

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

    IoAcceptor acceptor = new DatagramAcceptor(acceptorPool);
    IoConnector connector = new DatagramConnector(connectorPool);
    SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

    if (transferExchange) {
        throw new IllegalArgumentException("transferExchange=true is not supported for datagram protocol");
    }

    DatagramConnectorConfig connectorConfig = new DatagramConnectorConfig();
    // must use manual thread model according to Mina documentation
    connectorConfig.setThreadModel(ThreadModel.MANUAL);
    configureDataGramCodecFactory("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));

    DatagramAcceptorConfig acceptorConfig = new DatagramAcceptorConfig();
    // must use manual thread model according to Mina documentation
    acceptorConfig.setThreadModel(ThreadModel.MANUAL);
    configureDataGramCodecFactory("MinaConsumer", acceptorConfig, configuration);
    acceptorConfig.setDisconnectOnUnbind(true);
    // reuse address is default true for datagram
    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,代码行数:66,代码来源:MinaComponent.java

示例15: createClientSSLListeners

import org.apache.mina.common.ThreadModel; //导入依赖的package包/类
private void createClientSSLListeners() {
    // Start clients SSL unless it's been disabled.
    if (isClientSSLListenerEnabled()) {
        int port = getClientSSLListenerPort();
        String algorithm = JiveGlobals.getProperty("xmpp.socket.ssl.algorithm");
        if ("".equals(algorithm) || algorithm == null) {
            algorithm = "TLS";
        }
        try {
            // Create SocketAcceptor with correct number of processors
            sslSocketAcceptor = buildSocketAcceptor();
            // Customize Executor that will be used by processors to process incoming stanzas
            int eventThreads = JiveGlobals.getIntProperty("xmpp.client_ssl.processing.threads", 16);
            ExecutorFilter executorFilter = new ExecutorFilter();
            ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor();
            final ThreadFactory originalThreadFactory = eventExecutor.getThreadFactory();
            ThreadFactory newThreadFactory = new ThreadFactory()
            {
                private final AtomicInteger threadId = new AtomicInteger( 0 );

                public Thread newThread( Runnable runnable )
                {
                    Thread t = originalThreadFactory.newThread( runnable );
                    t.setName("Old SSL executor thread - " + threadId.incrementAndGet() );
                    t.setDaemon( true );
                    return t;
                }
            };
            eventExecutor.setThreadFactory( newThreadFactory );
            eventExecutor.setCorePoolSize(eventThreads + 1);
            eventExecutor.setMaximumPoolSize(eventThreads + 1);
            eventExecutor.setKeepAliveTime(60, TimeUnit.SECONDS);

            sslSocketAcceptor.getDefaultConfig().setThreadModel(ThreadModel.MANUAL);
            // Add the XMPP codec filter
            sslSocketAcceptor.getFilterChain().addFirst("xmpp", new ProtocolCodecFilter(new XMPPCodecFactory()));
            sslSocketAcceptor.getFilterChain().addFirst("threadModel", executorFilter);
            // Kill sessions whose outgoing queues keep growing and fail to send traffic
            sslSocketAcceptor.getFilterChain().addAfter("xmpp", "outCap", new StalledSessionsFilter());

            // Add the SSL filter now since sockets are "borned" encrypted in the old ssl method
            SSLContext sslContext = SSLContext.getInstance(algorithm);
            KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyFactory.init(SSLConfig.getKeyStore(), SSLConfig.getKeyPassword().toCharArray());
            TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustFactory.init(SSLConfig.getc2sTrustStore());

            sslContext.init(keyFactory.getKeyManagers(),
                    trustFactory.getTrustManagers(),
                    new java.security.SecureRandom());

            SSLFilter sslFilter = new SSLFilter(sslContext);
            if (JiveGlobals.getProperty("xmpp.client.cert.policy","disabled").equals("needed")) {
                sslFilter.setNeedClientAuth(true);
            }
            else if(JiveGlobals.getProperty("xmpp.client.cert.policy","disabled").equals("wanted")) {
                sslFilter.setWantClientAuth(true);
            }
            sslSocketAcceptor.getFilterChain().addFirst("tls", sslFilter);

        }
        catch (Exception e) {
            System.err.println("Error starting SSL XMPP listener on port " + port + ": " +
                    e.getMessage());
            Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e);
        }
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:69,代码来源:ConnectionManagerImpl.java


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