Search in sources :

Example 1 with DelayTask

use of com.firenio.collection.DelayedQueue.DelayTask in project baseio by generallycloud.

the class TestDelayedWorkQueue method main.

public static void main(String[] args) {
    DelayedQueue q = new DelayedQueue();
    q.offer(new TestDelayTask(10));
    q.offer(new TestDelayTask(5));
    q.offer(new TestDelayTask(15));
    q.offer(new TestDelayTask(1));
    q.offer(new TestDelayTask(2));
    q.offer(new TestDelayTask(18));
    q.offer(new TestDelayTask(12));
    q.offer(new TestDelayTask(2));
    for (; ; ) {
        DelayTask t = q.poll();
        if (t == null) {
            break;
        }
        t.run();
    }
}
Also used : DelayTask(com.firenio.collection.DelayedQueue.DelayTask) DelayedQueue(com.firenio.collection.DelayedQueue)

Example 2 with DelayTask

use of com.firenio.collection.DelayedQueue.DelayTask in project baseio by generallycloud.

the class TestShowMemoryServlet method doAccept.

@Override
protected void doAccept(Channel ch, HttpFrame f) throws Exception {
    TestWebSocketChatServlet chatServlet = context.getBean(TestWebSocketChatServlet.class);
    TestWebSocketRumpetrollServlet rumpetrollServlet = context.getBean(TestWebSocketRumpetrollServlet.class);
    WebSocketMsgAdapter chatMsgAdapter = chatServlet.getMsgAdapter();
    WebSocketMsgAdapter rumpetrollMsgAdapter = rumpetrollServlet.getMsgAdapter();
    ChannelContext context = ch.getContext();
    String kill = f.getRequestParam("kill");
    if (!Util.isNullOrBlank(kill)) {
        Integer id = Integer.valueOf(kill, 16);
        Channel close_ch = CountChannelListener.chs.get(id);
        if (close_ch != null) {
            close_ch.getEventLoop().schedule(new DelayTask(10) {

                @Override
                public void run() {
                    Util.close(close_ch);
                }
            });
        }
    }
    BigDecimal time = new BigDecimal(Util.now_f() - context.getStartupTime());
    BigDecimal anHour = new BigDecimal(60 * 60 * 1000);
    BigDecimal hour = time.divide(anHour, 3, RoundingMode.HALF_UP);
    NioEventLoopGroup group = ch.getEventLoop().getGroup();
    ByteBufAllocatorGroup allocator = group.getAllocatorGroup();
    String allocatorDes = "unpooled";
    if (allocator != null) {
        StringBuilder builder = new StringBuilder();
        String[] res = allocator.toDebugString();
        for (int i = 0; i < res.length; i++) {
            builder.append("<BR/>\n");
            builder.append(res[i]);
        }
        allocatorDes = builder.toString();
    }
    int M = 1024 * 1024;
    int eventLoopSize = group.getEventLoopSize();
    int SERVER_MEMORY_POOL_UNIT = group.getMemoryUnit();
    long SERVER_MEMORY_POOL_CAPACITY = group.getMemoryCapacity();
    double MEMORY_POOL_SIZE = SERVER_MEMORY_POOL_CAPACITY / (M * 1d);
    MEMORY_POOL_SIZE = new BigDecimal(MEMORY_POOL_SIZE).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    Runtime runtime = Runtime.getRuntime();
    StringBuilder builder = new StringBuilder(HttpUtil.HTML_HEADER);
    builder.append("		<div style=\"margin-left:20px;\">\n");
    builder.append("服务器内存使用情况:</BR>\n");
    builder.append("虚拟机占用内存:");
    builder.append(runtime.totalMemory() / M);
    builder.append("M;\n</BR>已占用内存:");
    builder.append((runtime.totalMemory() - runtime.freeMemory()) / M);
    builder.append("M;\n</BR>空闲内存:");
    builder.append(runtime.freeMemory() / M);
    builder.append("M;\n</BR>内存池大小:");
    builder.append(MEMORY_POOL_SIZE);
    builder.append("M;\n</BR>内存池状态:");
    builder.append(allocatorDes);
    builder.append("\n</BR>聊天室(WebSocket)客户端数量:");
    builder.append(chatMsgAdapter.getClientSize());
    builder.append("\n</BR>小蝌蚪(WebSocket)客户端数量:");
    builder.append(rumpetrollMsgAdapter.getClientSize());
    builder.append("\n</BR>服务器当前连接数(io-channel):");
    builder.append(CountChannelListener.chs.size());
    for (Channel s : CountChannelListener.chs.values()) {
        builder.append("\n</BR>");
        builder.append(s);
        builder.append(", opened: ");
        builder.append(DateUtil.get().formatYyyy_MM_dd_HH_mm_ss(new Date(s.getCreationTime())));
    }
    builder.append(";\n</BR>服务运行时间:");
    builder.append(hour + "H;");
    builder.append("		</div>\n");
    builder.append(HttpUtil.HTML_POWER_BY);
    builder.append(HttpUtil.HTML_BOTTOM);
    f.setString(builder.toString(), ch);
    f.setContentType(HttpContentType.text_html_utf8);
    ch.writeAndFlush(f);
}
Also used : ByteBufAllocatorGroup(com.firenio.buffer.ByteBufAllocatorGroup) Channel(com.firenio.component.Channel) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ChannelContext(com.firenio.component.ChannelContext) DelayTask(com.firenio.collection.DelayedQueue.DelayTask) NioEventLoopGroup(com.firenio.component.NioEventLoopGroup)

Aggregations

DelayTask (com.firenio.collection.DelayedQueue.DelayTask)2 ByteBufAllocatorGroup (com.firenio.buffer.ByteBufAllocatorGroup)1 DelayedQueue (com.firenio.collection.DelayedQueue)1 Channel (com.firenio.component.Channel)1 ChannelContext (com.firenio.component.ChannelContext)1 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1