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


Java NioSocketAcceptor.setHandler方法代码示例

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


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

示例1: start

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
/**
 * start Mina serversocket
 * @throws Exception
 */
public void start() throws Exception {
	IoBuffer.setUseDirectBuffer(false);
	IoBuffer.setAllocator(new SimpleBufferAllocator());

	acceptor = new NioSocketAcceptor(pool);
	acceptor.setReuseAddress(true);
	acceptor.getSessionConfig().setAll(getSessionConfig());

	int serverPort = GateServerConfig.serverPort;
	logger.info("socket server start at port:{},正在监听客户端的连接...", serverPort);
	DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
	filterChain.addLast("codec", new ProtocolCodecFilter(MessageCodecFactory.getInstance()));
	acceptor.setHandler( new ServerSocketIoHandler() );//指定业务逻辑处理器
	acceptor.setDefaultLocalAddress(new InetSocketAddress(serverPort) );//设置端口号
	acceptor.bind();//启动监听

}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:22,代码来源:SocketServer.java

示例2: SocketServer

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public SocketServer(int port,  int threadPoolSize) {
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		acceptor.setHandler(new ServerHandler());
//		acceptor.getFilterChain().addLast("mychian",new ProtocolCodecFilter(new TextLineCodecFactory()));
//		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
		acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(threadPoolSize)));
		SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
		ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
		ssc.setReceiveBufferSize(10240);// 设置输入缓冲区的大小
		ssc.setSendBufferSize(10240);// 设置输出缓冲区的大小
		ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
		
		try {
			// 绑定端口
			acceptor.bind(new InetSocketAddress(port));
			System.out.println("服务器启动正常,监听端口 " + port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:21,代码来源:SocketServer.java

示例3: Channel

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public Channel(final int world, final int channel) {
    this.world = world;
    this.channel = channel;
    this.mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), world, channel);

    try {
        eventSM = new EventScriptManager(this, ServerConstants.EVENTS.split(" "));
        port = 7575 + this.channel - 1;
        port += (world * 100);
        ip = ServerConstants.HOST + ":" + port;
        IoBuffer.setUseDirectBuffer(false);
        IoBuffer.setAllocator(new SimpleBufferAllocator());
        acceptor = new NioSocketAcceptor();
        TimerManager.getInstance().register(new respawnMaps(), 10000);
        acceptor.setHandler(new MapleServerHandler(world, channel));
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
        acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
        acceptor.bind(new InetSocketAddress(port));
        ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);

        eventSM.init();
        System.out.println("    Channel " + getId() + ": Listening on port " + port);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:27,代码来源:Channel.java

示例4: serverStart

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
@Override
protected void serverStart() throws RemotingException {

    acceptor = new NioSocketAcceptor(); //TCP Acceptor

    // acceptor.getFilterChain().addFirst("logging", new MinaLoggingFilter());
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(getCodec())));
    acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());

    acceptor.setHandler(new MinaHandler(this));
    IoSessionConfig cfg = acceptor.getSessionConfig();
    cfg.setReaderIdleTime(remotingServerConfig.getReaderIdleTimeSeconds());
    cfg.setWriterIdleTime(remotingServerConfig.getWriterIdleTimeSeconds());
    cfg.setBothIdleTime(remotingServerConfig.getServerChannelMaxIdleTimeSeconds());

    bindAddress = new InetSocketAddress(remotingServerConfig.getListenPort());
    try {
        acceptor.bind(bindAddress);
    } catch (IOException e) {
        throw new RemotingException("Start Mina server error", e);
    }
}
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:23,代码来源:MinaRemotingServer.java

示例5: init

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);
    acceptor = new NioSocketAcceptor();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        acceptor.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        acceptor.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    acceptor.setHandler(new MinaServerHandler());
    acceptor.getSessionConfig().setReadBufferSize(config.bufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    acceptor.setReuseAddress(true); //避免重启时提示地址被占用
    //设置主服务监听端口的监听队列的最大值为50,如果当前已经有50个连接,新的连接将被服务器拒绝
    acceptor.setBacklog(50);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:24,代码来源:MinaTcpServerSocket.java

示例6: startServer

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
/**
 * �������
 * @param args
 * @throws IOException 
 */
public  void startServer()  {
	 server = new NioSocketAcceptor();
	//�������ݹ�����
	DefaultIoFilterChainBuilder  filterChain = server.getFilterChain();
	filterChain.addLast("myChin", new ProtocolCodecFilter(  
               new ObjectSerializationCodecFactory()));
	
	//filterChain.addLast("textCode",new ProtocolCodecFilter(
	//			new TextLineCodecFactory(Charset.forName("UTF-8"))));
	
	serverIOHandler = new ServerIOHandler(severFrame);
	server.setHandler(serverIOHandler);
	//�����������˿� --- ����������
	try {
		server.bind(new InetSocketAddress(port));
	} catch (IOException e) {
		Tools.show(severFrame, "�˿��Ѿ�ռ�ã��뻻���˿ڣ�");
	}
}
 
开发者ID:ganhang,项目名称:My-ChatSystem,代码行数:25,代码来源:Server.java

示例7: start

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
protected void start() throws Exception{
		
		buildExecutors();
		IoProcessor<NioSession> processor = new SimpleIoProcessorPool<NioSession>(NioProcessor.class, ioExecutor, coreSize);
		acceptor = new NioSocketAcceptor(acceptorExecutor, processor);
//		acceptor.setBacklog(cfg.getBacklog());
		buildFilterChain();
		acceptor.setHandler(handler);
		try {
			List<SocketAddress> address = new ArrayList<SocketAddress>();
			//可添加多个
			address.add(new InetSocketAddress((String)rule.get("ip"), (Integer)rule.get("port")));
			acceptor.bind(address);
		} catch (IOException e) {
			stop();
			throw e;
		}
		
	}
 
开发者ID:dreajay,项目名称:jcode,代码行数:20,代码来源:TcpAcceptor.java

示例8: startupMinaCore

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
/**
 * 创建 Mina2 Core 服务核心并启动
 *
 * @return
 */
private boolean startupMinaCore() {
	_acceptor = new NioSocketAcceptor();
	// 禁用算法
	_acceptor.getSessionConfig().setTcpNoDelay(true);
	// 添加过滤链处理项
	_acceptor.getFilterChain().addLast("codec",
			new ProtocolCodecFilter(new CodecFactory()));
	// 设置处理器
	_acceptor.setHandler(new FrontendServerHandler(this));
	try {
		_acceptor.bind(new InetSocketAddress(getServerConfig()
				.getFrontendPort()));
	} catch (IOException e) {
		logger.error("启动 Mina Core 监听失败:", e);
		return false;
	}
	logger.error("Mina Core Startup Success On Port:"
			+ getServerConfig().getFrontendPort());
	return true;
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:26,代码来源:FrontendServer.java

示例9: main

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) {
	int port = U.getInt("cleaner.server.port");
	int idleTime = U.getInt("cleaner.server.time");
	NioSocketAcceptor clientAcceptor = new NioSocketAcceptor();
	clientAcceptor.setReuseAddress(true);

	DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
	SocketSessionConfig config = clientAcceptor.getSessionConfig();
	config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 10秒
	config.setReuseAddress(true);
	config.setReadBufferSize(4096);// 默认2048
	config.setKeepAlive(true);
	config.setTcpNoDelay(true);// 开启nagle算法
	// 编解码
	chain.addLast("coder", new ProtocolCodecFilter(new TextLineCodecFactory(U.UTF8)));
	clientAcceptor.setHandler(new CleanerHandler());
	try {
		clientAcceptor.bind(new InetSocketAddress(port));
		log.info("心跳模块启动..");
	} catch (IOException e) {
		log.error("心跳模块启动失败", e);
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:24,代码来源:BeatServer.java

示例10: run_startup_configurations

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void run_startup_configurations() {
    autoPaoDian = Integer.parseInt(ServerProperties.getProperty("autoPaoDian", "1"));
    port = Short.parseShort(ServerProperties.getProperty("cashshop.port", String.valueOf(DEFAULT_PORT)));
    ip = ServerProperties.getProperty("world.host", ServerConstants.IP) + ":" + port;

    IoBuffer.setUseDirectBuffer(false);
    IoBuffer.setAllocator(new SimpleBufferAllocator());

    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
    players = new PlayerStorage(MapleServerHandler.CASH_SHOP_SERVER);
    try {
        acceptor.setHandler(new MapleServerHandler(MapleServerHandler.CASH_SHOP_SERVER));
        acceptor.bind(new InetSocketAddress(port));
        ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);

        FileoutputUtil.log("完成!");
        FileoutputUtil.log("商城伺服器正在监听" + port + "端口\r\n");
    } catch (IOException e) {
        FileoutputUtil.log("失败!");
        System.err.println("无法绑定" + port + "端口");
        throw new RuntimeException("绑定端口失败.", e);
    }
}
 
开发者ID:icelemon1314,项目名称:mapleLemon,代码行数:26,代码来源:CashShopServer.java

示例11: run

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public void run() throws Exception {
	if (start) {
		SimpleIoProcessorPool<NioSession> simpleIoProcessorPool = new SimpleIoProcessorPool(
				NioProcessor.class, LoginServer.ExecutorService);
		acceptor = new NioSocketAcceptor(LoginServer.ExecutorService,
				simpleIoProcessorPool);
		acceptor.getSessionConfig().setTcpNoDelay(true);
		acceptor.getFilterChain().addLast("ThreadPool",
				new ExecutorFilter(LoginServer.ExecutorService));
		acceptor.getFilterChain().addLast("executor",
				new ExecutorFilter(LoginServer.ExecutorService));
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 15);
		acceptor.setHandler(new LoginGatewayHandler(this));
		acceptor.bind(new InetSocketAddress(getPort()));
		log.info("网关端口监听于 " + getPort());
	}
}
 
开发者ID:316181444,项目名称:Hxms,代码行数:18,代码来源:LoginGateway.java

示例12: startListner

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public  void startListner(IoHandler iohandler,int listenPort) throws Exception{
	acceptor = new NioSocketAcceptor();
	acceptor.setBacklog(100);
	acceptor.setReuseAddress(true);
	acceptor.setHandler(iohandler);
	
       DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
       IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory());
       chain.addLast("codec", protocol);
	threadpool = new OrderedThreadPoolExecutor(500);
	threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool"));
	chain.addLast("threadPool", new ExecutorFilter(threadpool));
	
	int recsize = 5120;
	int sendsize = 40480;                                                                                         
	int timeout = 10;
	SocketSessionConfig sc = acceptor.getSessionConfig();
	sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
	sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小
	sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小
	sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出   
	sc.setSoLinger(0);
	sc.setIdleTime(IdleStatus.READER_IDLE, timeout);
	acceptor.bind(new InetSocketAddress(listenPort));
}
 
开发者ID:yongzhidai,项目名称:GameServer,代码行数:26,代码来源:NetManager.java

示例13: run

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
/**
 * 启动HTTP服务端箭筒HTTP请求
 * 
 * @param port要监听的端口号
 * @throws IOException
 */
public void run(int port) throws IOException {
	synchronized (this) {
		if (isRunning) {
			System.out.println("Server is already running.");
			return;
		}
		acceptor = new NioSocketAcceptor();
		acceptor.getFilterChain().addLast(
				"protocolFilter",
				new ProtocolCodecFilter(
						new HttpServerProtocolCodecFactory()));
		// acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		ServerHandler handler = new ServerHandler();
		handler.setHandler(httpHandler);
		acceptor.setHandler(handler);
		acceptor.bind(new InetSocketAddress(port));
		isRunning = true;
		System.out.println("Server now listening on port " + port);
	}
}
 
开发者ID:mklm1525,项目名称:GameServer_demo,代码行数:27,代码来源:HttpServer.java

示例14: start

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public void start()
{
	mAcceptor = new NioSocketAcceptor();
	LoggingFilter loggingFilter = new LoggingFilter();
	loggingFilter.setSessionClosedLogLevel(LogLevel.NONE);
	loggingFilter.setSessionCreatedLogLevel(LogLevel.NONE);
	loggingFilter.setSessionOpenedLogLevel(LogLevel.NONE);
	loggingFilter.setMessageSentLogLevel(LogLevel.NONE);
	mAcceptor.getFilterChain().addLast("logger", loggingFilter);
	
	mAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodec.Encoder(), new MinaCodec.Decoder()));
	mAcceptor.getSessionConfig().setReadBufferSize(4096);
	// macceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	mServerHandler = new MinaServerHandler();
	mAcceptor.setHandler(mServerHandler);
	
	try {
		mAcceptor.bind(new InetSocketAddress(ServerConfig.NET_TCP_IP, ServerConfig.NET_TCP_PORT));
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:AlkaidFang,项目名称:PearlHarbor,代码行数:24,代码来源:TCPConnectionClasser_mina.java

示例15: main

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new WebSocketCodecFactory()));
    // close sessions when the acceptor is stopped
    acceptor.setCloseOnDeactivation(true);
    acceptor.setHandler(new WebSocketHandler());
    SocketSessionConfig sessionConf = acceptor.getSessionConfig();
    sessionConf.setReuseAddress(true);
    acceptor.setReuseAddress(true);
    // loop through the addresses and bind
    Set<InetSocketAddress> socketAddresses = new HashSet<InetSocketAddress>();
    socketAddresses.add(new InetSocketAddress("0.0.0.0", 8888));
    //socketAddresses.add(new InetSocketAddress("localhost", 8888));
    log.debug("Binding to {}", socketAddresses.toString());
    acceptor.bind(socketAddresses);
    System.out.println("WS server started listening");
    listening = true;
    while (true) {
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            System.out.println("WS server stopped listening");
        }
    }
}
 
开发者ID:Red5,项目名称:red5-websocket,代码行数:26,代码来源:WebSocketServerTest.java


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