本文整理汇总了Java中org.apache.mina.core.service.IoAcceptor.bind方法的典型用法代码示例。如果您正苦于以下问题:Java IoAcceptor.bind方法的具体用法?Java IoAcceptor.bind怎么用?Java IoAcceptor.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.service.IoAcceptor
的用法示例。
在下文中一共展示了IoAcceptor.bind方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
// 这个过滤器用来记录所有的信息,比如创建session(会话),接收消息,发送消息,关闭会话等
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
// 用来转换二进制或协议的专用数据到消息对象中
acceptor.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
// 实时处理客户端的连接和请求
acceptor.setHandler(new TimeServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
// 方法将定时调用一次会话,保持空闲状态。来设定时间间隔。
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
acceptor.bind(new InetSocketAddress(PORT));
}
示例2: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// 创建服务器端的监听器对象
IoAcceptor acceptor = new NioSocketAcceptor();
// 增加日志过滤器:用于日志存储
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
// 增加消息编码过滤器,采用UTF-8编码
acceptor.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
// 设置具体的事物逻辑处理器
acceptor.setHandler(new TimeServerHandler());
// 设置IoSession的一些属性
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
// 设置服务器监听的端口
acceptor.bind(new InetSocketAddress(PORT));
}
示例3: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
// acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, IDELTIMEOUT);
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast("myfliter", new MyFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CommandCodecFactory("UTF-8")));
KeepAliveMessageFactoryImpl kamfi = new KeepAliveMessageFactoryImpl();
KeepAliveFilter kaf = new KeepAliveFilter(kamfi, IdleStatus.BOTH_IDLE);
/** 是否回发 */
kaf.setForwardEvent(true);
acceptor.getFilterChain().addLast("heart", kaf);
acceptor.setHandler(new CalculatorHandler());
acceptor.bind(new InetSocketAddress(PORT));
log.debug("socket通信服务端已启动,端口是" + PORT);
}
示例4: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));// 指定编码过滤器
acceptor.setHandler(new TimeServerHandler());// 指定业务逻辑处理器
//读写 通道均在3 秒内无任何操作就进入空闲状态
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 3);
acceptor.setDefaultLocalAddress(new InetSocketAddress(PORT));// 设置端口号
acceptor.bind();// 启动监听
}
示例5: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.setHandler(new Mina2TesterServerHandler());
try {
acceptor.bind(new InetSocketAddress(7890));
} catch (Exception e) {
System.out.println("Config Error:" + e);
}
System.out.println("监听中...");
}
示例6: tryToInitializeAndBindSensorAcceptor
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
private void tryToInitializeAndBindSensorAcceptor(String protocol, InetSocketAddress s, Map<String, String> aAcceptors, Executor aExecutor) throws IOException, Exception {
if (acceptorsFactory != null && acceptorsFactory.isSupported(protocol)) {
String acceptorModuleName = aAcceptors.get(protocol);
if (acceptorModuleName == null) {
acceptorModuleName = aAcceptors.get(null);
}
if (acceptorModuleName != null) {
Integer sessionIdleTime = portsSessionIdleTimeouts != null ? portsSessionIdleTimeouts.get(s.getPort()) : null;
if (sessionIdleTime == null || sessionIdleTime == 0) {
sessionIdleTime = 360;
}
Integer sessionIdleCheckInterval = portsSessionIdleCheckIntervals != null ? portsSessionIdleCheckIntervals.get(s.getPort()) : null;
if (sessionIdleCheckInterval == null || sessionIdleCheckInterval == 0) {
sessionIdleCheckInterval = 360;
}
IoAcceptor sensorAcceptor = acceptorsFactory.create(protocol, aExecutor, sessionIdleTime, sessionIdleCheckInterval, new com.eas.server.handlers.PositioningPacketReciever(this, acceptorModuleName, retranslateFactory));
if (sensorAcceptor != null) {
sensorAcceptor.bind(s);
Logger.getLogger(PlatypusServer.class.getName()).log(Level.INFO, "Listening {0} protocol on {1}", new Object[]{protocol, s.toString()});
}
} else {
Logger.getLogger(PlatypusServer.class.getName()).log(Level.INFO, "Acceptor module was not found for {0} protocol", protocol);
}
} else {
Logger.getLogger(PlatypusServer.class.getName()).log(Level.INFO, "{0} protocol is not supported", protocol);
}
}
示例7: initializeAndBindPlatypusAcceptor
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
private void initializeAndBindPlatypusAcceptor(InetSocketAddress s) throws IOException, Exception {
//final SslFilter sslFilter = new SslFilter(sslContext); commented out until MINA Sslfilter bugs will be fixed
ThreadPoolExecutor connectionsPollerExecutor = new ThreadPoolExecutor(1, 1,
3L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
new PlatypusThreadFactory("nio-polling-", false));
final IoAcceptor acceptor = new NioSocketAcceptor(connectionsPollerExecutor, new NioProcessor(executor));
//acceptor.getFilterChain().addLast("encryption", sslFilter); commented out until MINA Sslfilter bugs will be fixed
acceptor.getFilterChain().addLast("platypusCodec", new ProtocolCodecFilter(new ResponseEncoder(), new RequestDecoder()));
/*
acceptor.getFilterChain().addLast("executor", new ExecutorFilter(executor, IoEventType.EXCEPTION_CAUGHT,
IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT, IoEventType.SESSION_CLOSED, IoEventType.SESSION_IDLE, IoEventType.CLOSE, IoEventType.WRITE));
*/
PlatypusRequestsHandler handler = new PlatypusRequestsHandler(this);
acceptor.setHandler(handler);
Integer sessionIdleTime = portsSessionIdleTimeouts != null ? portsSessionIdleTimeouts.get(s.getPort()) : null;
if (sessionIdleTime == null || sessionIdleTime == 0) {
sessionIdleTime = PlatypusRequestsHandler.SESSION_TIME_OUT;
}
Integer sessionIdleCheckInterval = portsSessionIdleCheckIntervals != null ? portsSessionIdleCheckIntervals.get(s.getPort()) : null;
if (sessionIdleCheckInterval == null || sessionIdleCheckInterval == 0) {
sessionIdleCheckInterval = PlatypusRequestsHandler.IDLE_TIME_EVENT;
}
handler.setSessionIdleCheckInterval(sessionIdleCheckInterval);
handler.setSessionIdleTime(sessionIdleTime);
acceptor.bind(s);
Logger.getLogger(ServerMain.class.getName()).log(Level.INFO, "Listening platypus protocol on {0}", s.toString());
}
示例8: main
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor
acceptor.getFilterChain().addLast("logging", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
acceptor.setHandler(new HelloServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
acceptor.bind(new InetSocketAddress(PORT));
}
示例9: ResetConnection
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
/**
* Cierra el socket actual y crea uno nuevo con en mismo handler
* @throws IOException
*/
public static void ResetConnection() throws IOException{
IoAcceptor newAcceptor = new NioSocketAcceptor();
newAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
newAcceptor.setHandler( _acceptor.getHandler() );
_acceptor.dispose();
newAcceptor.getSessionConfig().setReadBufferSize(65536);
newAcceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
newAcceptor.bind( new InetSocketAddress( PORT ) );
LOGGER.info("Mina Server Socket ReInitiated");
}
示例10: scoketMain
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public void scoketMain(){
//构造接收器 创建非阻塞的server端的Socket连接
IoAcceptor acceptor = new NioSocketAcceptor();
//创建业务处理类
//ServerHandler handler = new ServerHandler();
DemuxingServerHandler handler = new DemuxingServerHandler();
//设置业务处理类
acceptor.setHandler(handler);
SocketSessionConfig cfg = (SocketSessionConfig) acceptor.getSessionConfig();
//设置读取数据的缓冲区大小
cfg.setReadBufferSize(1024);
//MINA在调用了close()方法后,不会再进入TIME_WAIT状态了,而直接Close掉了
cfg.setSoLinger(0);
cfg.getBothIdleTimeInMillis();
//读写通道30秒内无操作进入空闲状态
cfg.setIdleTime(IdleStatus.BOTH_IDLE, 220);
//将NioProcessor的IO操作线程和TimeServerHandler的业务处理线程分开
acceptor.getFilterChain().addLast("executor", new ExecutorFilter());
//过滤器 自定义混合解码器 采用DemuxingProtocolCodecFactory混合解码器协议
acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(new DemuxingAppqyProtocolCodecFactory(true,0)));
//acceptor.getFilterChain().addLast("StringCodec", new ProtocolCodecFilter(new StringProtocalCodecFactory(Charset.forName("UTF-8"))));
//添加编码过滤器 这个过滤器的作用是将来自客户端输入的信息转换成一行行的文本后传递给 IoHandler ; ps:将指定名称的过滤器添加到过滤器链的末尾。
//acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
//添加时间过滤器 默认间隔1秒同IP发送的连接请求将被拒绝(包括同IP下的其他端口,网上说不包含,测试之后是包含)
//acceptor.getFilterChain().addFirst("tcpTime", new ConnectionThrottleFilter(5000));
//添加日志组件
acceptor.getFilterChain().addLast("logging", new LoggingFilter());
//为NioSocketAcceptor增加一个线程的处理池 java运行分配少量内存的情况下 加了线程池容易内存溢出
//acceptor.getFilterChain().addFirst("ThreadPool",new ExecutorFilter(Executors.newCachedThreadPool()));
// 启动服务
try {
acceptor.bind(new InetSocketAddress(this.PORT));
Date now = new Date();
log.info(Language.eServerStar + this.PORT + " "+DateFormat.getDateTimeInstance().format(now));
} catch (IOException e) {
e.printStackTrace();
log.error(Language.ePortUse);
log.error(Language.eServerExit);
log.error("StackTrace:" + e.getStackTrace().toString());
//结束程序
System.exit(-1);
}
}
示例11: init
import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public void init() throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
acceptor.setHandler(new MinaChatServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 600);
acceptor.bind(new InetSocketAddress(port));
}