Package com.taobao.gecko.service

Examples of com.taobao.gecko.service.RemotingServer


    @Test
    public void testGetStats() throws Exception {
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setWireFormatType(new MetamorphosisWireFormatType());
        serverConfig.setPort(8199);
        RemotingServer server = RemotingFactory.bind(serverConfig);
        try {
            server.registerProcessor(StatsCommand.class, new RequestProcessor<StatsCommand>() {

                @Override
                public void handleRequest(StatsCommand request, Connection conn) {
                    String rt = "pid 34947\r\n" + //
                            "port 8123\r\n" + //
                            "uptime 3168\r\n" + //
                            "version 1.4.0.3-SNAPSHOT\r\n" + //
                            "curr_connections 1\r\n" + //
                            "threads 34\r\n" + //
                            "cmd_put 0\r\n" + //
                            "cmd_get 0\r\n" + //
                            "cmd_offset 0\r\n" + //
                            "tx_begin 0\r\n" + //
                            "tx_xa_begin 0\r\n" + //
                            "tx_commit 0\r\n" + //
                            "tx_rollback 0\r\n" + //
                            "get_miss 0\r\n" + //
                            "put_failed 0\r\n" + //
                            "total_messages 100051\r\n" + //
                            "topics 1";
                    rt += "\r\nitem " + (StringUtils.isBlank(request.getItem()) ? "null" : request.getItem()) + "\r\n";
                    System.out.println(rt);
                    try {
                        conn.response(new BooleanCommand(200, rt, request.getOpaque()));
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                    }
                }


                @Override
                public ThreadPoolExecutor getExecutor() {
                    return null;
                }

            });

            String uri = server.getConnectURI().toString();
            this.messageSessionFactory.getRemotingClient().connect(uri);
            this.messageSessionFactory.getRemotingClient().awaitReadyInterrupt(uri);
            Map<InetSocketAddress, StatsResult> rt = this.messageSessionFactory.getStats();
            assertNotNull(rt);
            assertEquals(1, rt.size());
            InetSocketAddress sockAddr =
                    new InetSocketAddress(server.getConnectURI().getHost(), server.getConnectURI().getPort());
            StatsResult sr = rt.get(sockAddr);
            this.assertStatsResult(sr);
            assertEquals("null", sr.getValue("item"));

            rt = this.messageSessionFactory.getStats("topics");
            assertNotNull(rt);
            assertEquals(1, rt.size());
            sr = rt.get(sockAddr);
            this.assertStatsResult(sr);
            assertEquals("topics", sr.getValue("item"));

            sr = this.messageSessionFactory.getStats(sockAddr);
            this.assertStatsResult(sr);
            assertEquals("null", sr.getValue("item"));

            sr = this.messageSessionFactory.getStats(sockAddr, "topics");
            this.assertStatsResult(sr);
            assertEquals("topics", sr.getValue("item"));
        }
        finally {
            if (server != null) {
                server.stop();
            }
        }
    }
View Full Code Here


    private static RemotingServer newRemotingServer(final MetaConfig metaConfig) {
        final ServerConfig serverConfig = new ServerConfig();
        serverConfig.setWireFormatType(new MetamorphosisWireFormatType());
        serverConfig.setPort(metaConfig.getServerPort());
        final RemotingServer server = RemotingFactory.newRemotingServer(serverConfig);
        return server;
    }
View Full Code Here

TOP

Related Classes of com.taobao.gecko.service.RemotingServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.