Search in sources :

Example 1 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project bigbluebutton by bigbluebutton.

the class DeskShareServer method start.

public void start() {
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ScreenCaptureProtocolCodecFactory()));
    acceptor.setHandler(screenCaptureHandler);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    acceptor.setReuseAddress(true);
    try {
        acceptor.bind(new InetSocketAddress(port));
    } catch (IOException e) {
        log.error("IOException while binding to port {}", port);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Example 2 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project bigbluebutton by bigbluebutton.

the class DeskShareServer method start.

public void start() {
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ScreenCaptureProtocolCodecFactory()));
    acceptor.setHandler(screenCaptureHandler);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    acceptor.setReuseAddress(true);
    try {
        acceptor.bind(new InetSocketAddress(port));
    } catch (IOException e) {
        log.error("IOException while binding to port {}", port);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Example 3 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project HeavenMS by ronancpl.

the class Server method run.

@Override
public void run() {
    Properties p = new Properties();
    try {
        p.load(new FileInputStream("world.ini"));
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Please start create_server.bat");
        System.exit(0);
    }
    System.out.println("HeavenMS v" + ServerConstants.VERSION + " starting up.\r\n");
    if (ServerConstants.SHUTDOWNHOOK)
        Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
    Connection c = null;
    try {
        c = DatabaseConnection.getConnection();
        PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
        ps.executeUpdate();
        ps.close();
        ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
        ps.executeUpdate();
        ps.close();
        loadCouponRates(c);
        updateActiveCoupons();
        c.close();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
    IoBuffer.setUseDirectBuffer(false);
    IoBuffer.setAllocator(new SimpleBufferAllocator());
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
    TimerManager tMan = TimerManager.getInstance();
    tMan.start();
    // Purging ftw...
    tMan.register(tMan.purge(), ServerConstants.PURGING_INTERVAL);
    disconnectIdlesOnLoginTask();
    long timeLeft = getTimeLeftForNextHour();
    tMan.register(new CouponWorker(), ServerConstants.COUPON_INTERVAL, timeLeft);
    tMan.register(new RankingWorker(), ServerConstants.RANKING_INTERVAL, timeLeft);
    long timeToTake = System.currentTimeMillis();
    SkillFactory.loadAllSkills();
    System.out.println("Skills loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
    timeToTake = System.currentTimeMillis();
    // MapleItemInformationProvider.getInstance().getAllItems(); //unused, rofl
    CashItemFactory.getSpecialCashItems();
    System.out.println("Items loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
    timeToTake = System.currentTimeMillis();
    MapleQuest.loadAllQuest();
    System.out.println("Quest loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
    NewYearCardRecord.startPendingNewYearCardRequests();
    if (ServerConstants.USE_THREAD_TRACKER)
        ThreadTracker.getInstance().registerThreadTrackerTask();
    try {
        Integer worldCount = Math.min(ServerConstants.WORLD_NAMES.length, Integer.parseInt(p.getProperty("worlds")));
        for (int i = 0; i < worldCount; i++) {
            System.out.println("Starting world " + i);
            World world = new World(i, Integer.parseInt(p.getProperty("flag" + i)), p.getProperty("eventmessage" + i), ServerConstants.EXP_RATE, ServerConstants.DROP_RATE, ServerConstants.MESO_RATE, ServerConstants.QUEST_RATE);
            worldRecommendedList.add(new Pair<>(i, p.getProperty("whyamirecommended" + i)));
            worlds.add(world);
            channels.add(new HashMap<Integer, String>());
            for (int j = 0; j < Integer.parseInt(p.getProperty("channels" + i)); j++) {
                int channelid = j + 1;
                Channel channel = new Channel(i, channelid);
                world.addChannel(channel);
                channels.get(i).put(channelid, channel.getIP());
            }
            world.setServerMessage(p.getProperty("servermessage" + i));
            System.out.println("Finished loading world " + i + "\r\n");
        }
    } catch (Exception e) {
        // For those who get errors
        e.printStackTrace();
        System.out.println("Error in moople.ini, start CreateINI.bat to re-make the file.");
        System.exit(0);
    }
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
    acceptor.setHandler(new MapleServerHandler());
    try {
        acceptor.bind(new InetSocketAddress(8484));
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    System.out.println("Listening on port 8484\r\n\r\n");
    System.out.println("HeavenMS is now online.\r\n");
    online = true;
}
Also used : MapleCodecFactory(net.mina.MapleCodecFactory) SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) SimpleBufferAllocator(org.apache.mina.core.buffer.SimpleBufferAllocator) Properties(java.util.Properties) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) World(net.server.world.World) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) RankingWorker(net.server.worker.RankingWorker) CouponWorker(net.server.worker.CouponWorker) Channel(net.server.channel.Channel) Connection(java.sql.Connection) DatabaseConnection(tools.DatabaseConnection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) TimerManager(server.TimerManager) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) IOException(java.io.IOException) MapleServerHandler(net.MapleServerHandler)

Example 4 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project Openfire by igniterealtime.

the class MINAConnectionAcceptor method buildSocketAcceptor.

private static NioSocketAcceptor buildSocketAcceptor() {
    // Create SocketAcceptor with correct number of processors
    final int processorCount = JiveGlobals.getIntProperty("xmpp.processor.count", Runtime.getRuntime().availableProcessors());
    final NioSocketAcceptor socketAcceptor = new NioSocketAcceptor(processorCount);
    // Set that it will be possible to bind a socket if there is a connection in the timeout state.
    socketAcceptor.setReuseAddress(true);
    // Set the listen backlog (queue) length. Default is 50.
    socketAcceptor.setBacklog(JiveGlobals.getIntProperty("xmpp.socket.backlog", 50));
    // Set default (low level) settings for new socket connections
    final SocketSessionConfig socketSessionConfig = socketAcceptor.getSessionConfig();
    // socketSessionConfig.setKeepAlive();
    final int receiveBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.receive", -1);
    if (receiveBuffer > 0) {
        socketSessionConfig.setReceiveBufferSize(receiveBuffer);
    }
    final int sendBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.send", -1);
    if (sendBuffer > 0) {
        socketSessionConfig.setSendBufferSize(sendBuffer);
    }
    final int linger = JiveGlobals.getIntProperty("xmpp.socket.linger", -1);
    if (linger > 0) {
        socketSessionConfig.setSoLinger(linger);
    }
    socketSessionConfig.setTcpNoDelay(JiveGlobals.getBooleanProperty("xmpp.socket.tcp-nodelay", socketSessionConfig.isTcpNoDelay()));
    return socketAcceptor;
}
Also used : NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) SocketSessionConfig(org.apache.mina.transport.socket.SocketSessionConfig)

Example 5 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project pancm_project by xuwujing.

the class MinaServer method start.

/**
 * Start.
 */
public void start() {
    IoAcceptor ia = null;
    try {
        // 创建一个非堵塞的server端Socket
        ia = new NioSocketAcceptor();
        // 创建 自定义协议编码解码过滤器ProtocolCodecFilter
        ProtocolCodecFilter pf = new ProtocolCodecFilter((new MyTextLineCodecFactory(Charset.forName("utf-8"), "\r\n")));
        // 设置端口
        InetSocketAddress pt = new InetSocketAddress(PORT);
        // 设置过滤器(使用Mina提供的文本换行符编解码器)
        ia.getFilterChain().addLast("codec", pf);
        // 设置读取数据的缓存区大小
        ia.getSessionConfig().setReadBufferSize(2048);
        // 读写通道10秒内无操作进入空闲状态
        ia.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
        // 绑定逻辑处理器
        ia.setHandler(new MinaServerHandler());
        // 绑定端口
        ia.bind(pt);
        logger.info("服务端启动成功...端口号为:" + PORT);
    } catch (Exception e) {
        logger.error("服务器的异常..." + e);
        e.printStackTrace();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IoAcceptor(org.apache.mina.core.service.IoAcceptor) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Aggregations

NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)11 InetSocketAddress (java.net.InetSocketAddress)10 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)9 IOException (java.io.IOException)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)3 IoAcceptor (org.apache.mina.core.service.IoAcceptor)2 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)2 LoggingFilter (org.apache.mina.filter.logging.LoggingFilter)2 SslFilter (org.apache.mina.filter.ssl.SslFilter)2 SocketSessionConfig (org.apache.mina.transport.socket.SocketSessionConfig)2 FileInputStream (java.io.FileInputStream)1 Charset (java.nio.charset.Charset)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MapleServerHandler (net.MapleServerHandler)1 MapleCodecFactory (net.mina.MapleCodecFactory)1 Channel (net.server.channel.Channel)1