Package com.googlecode.protobuf.pro.duplex.server

Examples of com.googlecode.protobuf.pro.duplex.server.DuplexTcpServerBootstrap


        int port = Integer.parseInt(args[1]);
        PeerInfo serverInfo = new PeerInfo(args[0], port);
        //You need then to create a DuplexTcpServerBootstrap and provide it an RpcCallExecutor.


        DuplexTcpServerBootstrap bootstrap = new DuplexTcpServerBootstrap(
                serverInfo,
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool())
        );

        bootstrap.setRpcServerCallExecutor(new ThreadPoolCallExecutor(10, 10));


        // set up request logging
//        final CategoryPerServiceLogger logPolicy = new CategoryPerServiceLogger();
//        logPolicy.setLogRequestProto(true);
//        logPolicy.setLogResponseProto(true);
//        bootstrap.setLogger(logPolicy);

        //Finally binding the bootstrap to the TCP port will start off the socket accepting and clients can start to connect.
        long serverId = new SecureRandom().nextLong();
        String zk_str = props.getProperty("zookeeper.connection.string", ZK_CONNECT_STRING);
        if (args.length == 3) {
            zk_str = args[2];
        }

        List<Client.HostPort> addresses = Lists.newArrayList();
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface ifc = networkInterfaces.nextElement();
            if (!ifc.isLoopback()) {
                for (InterfaceAddress address : ifc.getInterfaceAddresses()) {
                    addresses.add(new Client.HostPort(address.getAddress().getHostAddress(), port));
                }
            }
        }
        ClusterState zkState = new ClusterState(zk_str, FRANZ_BASE, new Info(serverId, addresses));

        bootstrap.getRpcServiceRegistry().registerBlockingService(Catcher.CatcherService.newReflectiveBlockingService(new com.mapr.franz.server.CatcherServiceImpl(serverId, zkState)));

        //If you want to track the RPC peering events with clients, use a RpcClientConnectionRegistry or a TcpConnectionEventListener for TCP connection events. This is the mechanism you can use to "discover" RPC clients before they "call" any service.
        TcpConnectionEventListener listener = new TcpConnectionEventListener() {
            @Override
            public void connectionClosed(RpcClientChannel clientChannel) {
                log.debug("Disconnect from {}", clientChannel.getPeerInfo());
            }

            @Override
            public void connectionOpened(RpcClientChannel clientChannel) {
                log.debug("Connect with {}", clientChannel.getPeerInfo());
            }
        };
        bootstrap.registerConnectionEventListener(listener);

        bootstrap.bind();
    }
View Full Code Here


        } catch (FileNotFoundException e) {
            e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
            return;
        }

        DuplexTcpServerBootstrap bootstrap = startProtoServer(opts.port);
        bootstrap.getRpcServiceRegistry().registerBlockingService(
                Catcher.CatcherService.newReflectiveBlockingService(service));

        try {
            bootstrap.bind();
        } catch (ChannelException e) {
            // releasing resources allows the server to exit
            bootstrap.releaseExternalResources();
            throw e;
        }
    }
View Full Code Here

        }
    }

    private static DuplexTcpServerBootstrap startProtoServer(int port) {
        PeerInfo serverInfo = new PeerInfo("0.0.0.0", port);
        DuplexTcpServerBootstrap bootstrap = new DuplexTcpServerBootstrap(
                serverInfo,
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool())
        );
        ThreadPoolCallExecutor pool = new ThreadPoolCallExecutor(10, 10);
        bootstrap.setRpcServerCallExecutor(pool);
        return bootstrap;
    }
View Full Code Here

    public static void run(Options opts) throws SocketException, FileNotFoundException {
        logger.warn("Starting server {}", opts);

        // start this first so that Hazel has to take second pickings
        DuplexTcpServerBootstrap bootstrap = startProtoServer(opts.port);

        HazelcastInstance instance = setupHazelCast(opts.hosts);
        Server us = recordServerInstance(opts, instance);

        bootstrap.getRpcServiceRegistry().registerBlockingService(
                Catcher.CatcherService.newReflectiveBlockingService(new CatcherImpl(us, instance, opts.basePath)));
        bootstrap.bind();
    }
View Full Code Here

    }


    private static DuplexTcpServerBootstrap startProtoServer(int port) {
        PeerInfo serverInfo = new PeerInfo("0.0.0.0", port);
        DuplexTcpServerBootstrap bootstrap = new DuplexTcpServerBootstrap(
                serverInfo,
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool())
        );
        bootstrap.setRpcServerCallExecutor(new ThreadPoolCallExecutor(10, 10));
        return bootstrap;
    }
View Full Code Here

TOP

Related Classes of com.googlecode.protobuf.pro.duplex.server.DuplexTcpServerBootstrap

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.