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


Java IoHandler类代码示例

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


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

示例1: main

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
public static void main(String[] args) throws Exception{
	int port=9527;
	
	final IoAcceptor acceptor=new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
               							   Executors.newCachedThreadPool());
	acceptor.getFilterChain().addLast("stringserialize", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	IoHandler handler=new IoHandlerAdapter(){

		public void messageReceived(IoSession session, Object message)
				throws Exception {
			if("quit".equalsIgnoreCase(message.toString())){
				acceptor.unbindAll();
				System.out.println("Server has been shutdown!");
				System.exit(0);
			}
			System.out.println("Message from client: "+message);
			session.write("Server response��"+message);
		}
		
	};
	acceptor.bind(new InetSocketAddress(port), handler);
	System.out.println("Server listen on port: "+port);
}
 
开发者ID:java-scott,项目名称:java-project,代码行数:24,代码来源:Server.java

示例2: connectFederation

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

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();
    LOG.info("Binding to server address: {} using acceptor: {}", address, acceptor);
    IoHandler handler = new ReceiveHandler();
    if (protocol.equals("tcp") && clientMode) {
        ConnectFuture future = connector.connect(address, handler, getEndpoint().getConnectorConfig());
        future.join();
        session = future.getSession();
    } else {
        acceptor.bind(address, handler, getEndpoint().getAcceptorConfig());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:MinaConsumer.java

示例4: openConnection

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
private void openConnection() {
    SocketAddress address = getEndpoint().getAddress();
    connector = getEndpoint().getConnector();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating connector to address: {} using connector: {} timeout: {} millis.", new Object[]{address, connector, timeout});
    }
    IoHandler ioHandler = new ResponseHandler(getEndpoint());
    // connect and wait until the connection is established
    ConnectFuture future = connector.connect(address, ioHandler, getEndpoint().getConnectorConfig());
    future.join();
    session = future.getSession();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:MinaProducer.java

示例5: bind

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
/**
 * Bind to a set of URI's. This can be used by plugins to bind to
 * network addresses using the same network setup as the router
 * would, including TLS parameters.
 * 
 * @param uris The URI's to listen to.
 * @param handler The IO handler.
 * @param baseFilters The IO filters used by all connection types.
 * @param authRequired Hosts matched by this filter must be
 *                successfully authenticated via TLS or will be
 *                refused access.
 * 
 * @throws IOException if an error occurred during binding.
 */
public void bind (Set<? extends ElvinURI> uris, IoHandler handler,
                  DefaultIoFilterChainBuilder baseFilters, 
                  Filter<InetAddress> authRequired) 
  throws IOException
{
  SocketAcceptorConfig defaultAcceptorConfig = 
    createAcceptorConfig 
      (createStandardFilters (baseFilters, authRequired));
  SocketAcceptorConfig secureAcceptorConfig = null; // lazy init'ed
  
  for (ElvinURI uri : uris)
  {
    SocketAcceptorConfig bindConfig;
    
    if (uri.isSecure ())
    {
      if (secureAcceptorConfig == null)
      {
        secureAcceptorConfig = 
          createAcceptorConfig 
            (createSecureFilters (baseFilters, authRequired, false));
      }
      
      bindConfig = secureAcceptorConfig;
    } else
    {
      bindConfig = defaultAcceptorConfig;
    }
    
    for (InetSocketAddress address : addressesFor (uri))
      acceptor.bind (address, handler, bindConfig);
  }
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:48,代码来源:Router.java

示例6: connectFederationTLS

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

示例7: connect

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
public void connect (IoHandler acceptorListener, IoHandler connectorListener)
  throws IOException
{
  InetSocketAddress remoteAddress = new InetSocketAddress ("127.0.0.1", 29170);
  
  acceptor.bind (remoteAddress, acceptorListener, acceptorConfig);
  
  ConnectFuture future = 
    connector.connect (remoteAddress, connectorListener, connectorConfig);
  
  future.join ();
  
  session = future.getSession ();
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:15,代码来源:AcceptorConnectorSetup.java

示例8: getHandler

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
/**
 * Does nothing.
 * @return 
 */
@Override
public IoHandler getHandler() {
    return null;
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:9,代码来源:MockIOSession.java

示例9: getHandler

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
public IoHandler getHandler() {
    return null;
}
 
开发者ID:wso2,项目名称:andes,代码行数:4,代码来源:TestIoSession.java

示例10: getHandler

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
public IoHandler getHandler() {
    return null;
}
 
开发者ID:betfair,项目名称:cougar,代码行数:5,代码来源:MyIoSession.java

示例11: createClient

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
public IoSession createClient(NioConfig cfg, IoHandler handler) throws IOException {
    SocketConnector sc = new SocketConnector();
    ConnectFuture cf = sc.connect(new InetSocketAddress("127.0.0.1", 2227), handler, cfg.configureSocketSessionConfig());
    cf.join();
    return cf.getSession();
}
 
开发者ID:betfair,项目名称:cougar,代码行数:7,代码来源:CougarProtocolTest.java

示例12: getHandler

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
public IoHandler getHandler() {
    return mock.getHandler();
}
 
开发者ID:betfair,项目名称:cougar,代码行数:5,代码来源:CougarProtocolTest.java

示例13: getHandler

import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
public IoHandler getHandler() {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
}
 
开发者ID:betfair,项目名称:cougar,代码行数:5,代码来源:MyIoSession.java


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