本文整理汇总了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);
}
示例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 ();
}
示例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());
}
}
示例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();
}
示例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);
}
}
示例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 ();
}
示例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 ();
}
示例8: getHandler
import org.apache.mina.common.IoHandler; //导入依赖的package包/类
/**
* Does nothing.
* @return
*/
@Override
public IoHandler getHandler() {
return null;
}
示例9: getHandler
import org.apache.mina.common.IoHandler; //导入依赖的package包/类
public IoHandler getHandler() {
return null;
}
示例10: getHandler
import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
public IoHandler getHandler() {
return null;
}
示例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();
}
示例12: getHandler
import org.apache.mina.common.IoHandler; //导入依赖的package包/类
@Override
public IoHandler getHandler() {
return mock.getHandler();
}
示例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.
}