org.apache.mina.core.buffer.SimpleBufferAllocator Java Examples
The following examples show how to use
org.apache.mina.core.buffer.SimpleBufferAllocator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrossServer.java From jforgame with Apache License 2.0 | 6 votes |
/** * start Mina serversocket * @throws Exception */ @Override public void start() throws Exception { final int serverPort = ServerConfig.getInstance().getCrossPort(); IoBuffer.setUseDirectBuffer(false); IoBuffer.setAllocator(new SimpleBufferAllocator()); acceptor = new NioSocketAcceptor(pool); acceptor.setReuseAddress(true); acceptor.getSessionConfig().setAll(getSessionConfig()); logger.info("cross server start at port:{},正在监听服务器点对点的连接...", serverPort); DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain(); filterChain.addLast("codec", new ProtocolCodecFilter(SerializerHelper.getInstance().getCodecFactory())); //指定业务逻辑处理器 acceptor.setHandler(new Game2GameIoHandler(BaseCrossMessageDispatcher.getInstance())); //设置端口号 acceptor.setDefaultLocalAddress(new InetSocketAddress(serverPort)); //启动监听 acceptor.bind(); }
Example #2
Source File: MinaSocketServer.java From jforgame with Apache License 2.0 | 6 votes |
/** * start Mina serversocket * @throws Exception */ @Override public void start() throws Exception { int serverPort = ServerConfig.getInstance().getServerPort(); IoBuffer.setUseDirectBuffer(false); IoBuffer.setAllocator(new SimpleBufferAllocator()); acceptor = new NioSocketAcceptor(pool); acceptor.setReuseAddress(true); acceptor.getSessionConfig().setAll(getSessionConfig()); logger.info("mina socket server start at port:{},正在监听客户端的连接...", serverPort); DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain(); filterChain.addLast("codec", new ProtocolCodecFilter(SerializerHelper.getInstance().getCodecFactory())); filterChain.addLast("moduleEntrance", new ModuleEntranceFilter()); filterChain.addLast("msgTrace", new MessageTraceFilter()); filterChain.addLast("flood", new FloodFilter()); //指定业务逻辑处理器 acceptor.setHandler(new ServerSocketIoHandler(new MessageDispatcher())); //设置端口号 acceptor.setDefaultLocalAddress(new InetSocketAddress(serverPort)); //启动监听 acceptor.bind(); }
Example #3
Source File: CashShopServer.java From mapleLemon with GNU General Public License v2.0 | 6 votes |
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); } }
Example #4
Source File: SslHandler.java From jane with GNU Lesser General Public License v3.0 | 6 votes |
/** * Start SSL shutdown process. * * @return <tt>true</tt> if shutdown process is started. * <tt>false</tt> if shutdown process is already finished. * @throws SSLException on errors */ boolean closeOutbound() throws SSLException { if (sslEngine == null || sslEngine.isOutboundDone()) return false; sslEngine.closeOutbound(); createOutNetBuffer(0); for (;;) { SSLEngineResult result = sslEngine.wrap(SimpleBufferAllocator.emptyBuffer.buf(), outNetBuffer.buf()); if (result.getStatus() != Status.BUFFER_OVERFLOW) { if (result.getStatus() != Status.CLOSED) throw new SSLException("improper close state: " + result); break; } outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1); outNetBuffer.limit(outNetBuffer.capacity()); } outNetBuffer.flip(); return true; }
Example #5
Source File: LoginServer.java From mapleLemon with GNU General Public License v2.0 | 5 votes |
public static void run_startup_configurations() { userLimit = ServerProperties.getProperty("userlimit", 140); serverName = ServerProperties.getProperty("serverName", "MapleStory"); flag = ServerProperties.getProperty("flag", (byte) 3); adminOnly = Boolean.parseBoolean(ServerProperties.getProperty("admin", "false")); maxCharacters = ServerProperties.getProperty("maxCharacters", 30); autoReg = Boolean.parseBoolean(ServerProperties.getProperty("autoReg", "false")); checkMacs = Boolean.parseBoolean(ServerProperties.getProperty("checkMacs", "false")); port = Short.parseShort(ServerProperties.getProperty("world.port", String.valueOf(DEFAULT_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); try { acceptor.setHandler(new MapleServerHandler(MapleServerHandler.LOGIN_SERVER)); acceptor.bind(new InetSocketAddress(port)); ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true); FileoutputUtil.log("\"登入\"伺服器正在监听" + port + "端口\r\n"); } catch (IOException e) { System.err.println("无法绑定" + port + "端口: " + e); } }
Example #6
Source File: ConnectionManagerImpl.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void initialize(XMPPServer server) { super.initialize(server); // Check if we need to configure MINA to use Direct or Heap Buffers // Note: It has been reported that heap buffers are 50% faster than direct buffers if (JiveGlobals.getBooleanProperty("xmpp.socket.heapBuffer", true)) { IoBuffer.setUseDirectBuffer(false); IoBuffer.setAllocator(new SimpleBufferAllocator()); } }
Example #7
Source File: CachedIoBufferAllocator.java From jane with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IoBuffer allocate(int requestedCapacity, boolean direct) { if (requestedCapacity <= 0) return direct ? SimpleBufferAllocator.emptyDirectBuffer : SimpleBufferAllocator.emptyBuffer; int actualCapacity = Integer.highestOneBit(requestedCapacity); if (actualCapacity < requestedCapacity) { actualCapacity += actualCapacity; if (actualCapacity < 0) actualCapacity = requestedCapacity; // must be > 0x4000_0000 } IoBuffer buf; if (actualCapacity <= maxCachedBufferSize) { buf = (direct ? directBuffers : heapBuffers).get()[getIdx(actualCapacity)].pollFirst(); if (buf != null) { buf.clear(); buf.buf().order(ByteOrder.BIG_ENDIAN); reuseCount.getAndIncrement(); } else { buf = new CachedBuffer(actualCapacity, direct); allocCount.getAndIncrement(); } } else buf = SimpleBufferAllocator.instance.allocate(actualCapacity, direct); buf.limit(requestedCapacity); return buf; }
Example #8
Source File: Channel.java From HeavenMS with GNU Affero General Public License v3.0 | 4 votes |
public Channel(final int world, final int channel, long startTime) { this.world = world; this.channel = channel; this.ongoingStartTime = startTime + 10000; // rude approach to a world's last channel boot time, placeholder for the 1st wedding reservation ever this.mapManager = new MapleMapManager(null, world, channel); try { port = 7575 + this.channel - 1; port += (world * 100); ip = YamlConfig.config.server.HOST + ":" + port; IoBuffer.setUseDirectBuffer(false); IoBuffer.setAllocator(new SimpleBufferAllocator()); acceptor = new NioSocketAcceptor(); 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); for (MapleExpeditionType exped : MapleExpeditionType.values()) { expedType.add(exped); } if (Server.getInstance().isOnline()) { // postpone event loading to improve boot time... thanks Riizade, daronhudson for noticing slow startup times eventSM = new EventScriptManager(this, getEvents()); eventSM.init(); } else { String[] ev = {"0_EXAMPLE"}; eventSM = new EventScriptManager(this, ev); } dojoStage = new int[20]; dojoFinishTime = new long[20]; dojoTask = new ScheduledFuture<?>[20]; for(int i = 0; i < 20; i++) { dojoStage[i] = 0; dojoFinishTime[i] = 0; dojoTask[i] = null; } services = new ServicesManager(ChannelServices.OVERALL); System.out.println(" Channel " + getId() + ": Listening on port " + port); } catch (Exception e) { e.printStackTrace(); } }
Example #9
Source File: CachedIoBufferAllocator.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
public static void globalSet(boolean useDirectBuffer, int maxPoolSize, int maxCachedBufferSize) { IoBuffer.setUseDirectBuffer(useDirectBuffer); IoBuffer.setAllocator( maxPoolSize > 0 && maxCachedBufferSize > 0 ? new CachedIoBufferAllocator(maxPoolSize, maxCachedBufferSize) : SimpleBufferAllocator.instance); }
Example #10
Source File: CachedIoBufferAllocator.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IoBuffer wrap(ByteBuffer bb) { return SimpleBufferAllocator.instance.wrap(bb); }
Example #11
Source File: CachedIoBufferAllocator.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IoBuffer duplicate() { return SimpleBufferAllocator.instance.wrap(buf.duplicate()); }
Example #12
Source File: SslHandler.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
/** * Perform any handshaking processing. */ void handshake(NextFilter nextFilter) throws Exception { for (;;) { switch (handshakeStatus) { case FINISHED: // LOGGER.debug("{} processing the FINISHED state", SslFilter.getSessionInfo(session)); handshakeComplete = true; // Send the SECURE message only if it's the first SSL handshake if (firstSSLNegociation) { firstSSLNegociation = false; if (session.containsAttribute(SslFilter.USE_NOTIFICATION)) scheduleMessageReceived(nextFilter, SslFilter.SESSION_SECURED); } // if (!isOutboundDone()) { // LOGGER.debug("{} is now secured", SslFilter.getSessionInfo(session)); // } else { // LOGGER.debug("{} is not secured yet", SslFilter.getSessionInfo(session)); // } return; case NEED_TASK: // LOGGER.debug("{} processing the NEED_TASK state", SslFilter.getSessionInfo(session)); handshakeStatus = doTasks(); break; case NEED_UNWRAP: // LOGGER.debug("{} processing the NEED_UNWRAP state", SslFilter.getSessionInfo(session)); // we need more data read if (unwrapHandshake(nextFilter) == Status.BUFFER_UNDERFLOW && handshakeStatus != HandshakeStatus.FINISHED || isInboundDone()) return; // We need more data or the session is closed break; case NEED_WRAP: case NOT_HANDSHAKING: // LOGGER.debug("{} processing the NEED_WRAP state", SslFilter.getSessionInfo(session)); // First make sure that the out buffer is completely empty. // Since we cannot call wrap with data left on the buffer if (outNetBuffer != null && outNetBuffer.hasRemaining()) return; createOutNetBuffer(0); for (;;) { //NOSONAR SSLEngineResult result = sslEngine.wrap(SimpleBufferAllocator.emptyBuffer.buf(), outNetBuffer.buf()); if (result.getStatus() != Status.BUFFER_OVERFLOW) { handshakeStatus = result.getHandshakeStatus(); break; } outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1); outNetBuffer.limit(outNetBuffer.capacity()); } outNetBuffer.flip(); writeNetBuffer(nextFilter, false); break; default: String msg = "invalid handshaking state" + handshakeStatus + " while processing the handshake for session " + session.getId(); ExceptionMonitor.getInstance().error(msg); throw new IllegalStateException(msg); } } }