Package net.tomp2p.message

Examples of net.tomp2p.message.CountConnectionOutboundHandler


        Random rnd = new Random(42);
        Peer peer1 = null;
        Peer peer2 = null;
        try {
         
          final CountConnectionOutboundHandler ccohTCP = new CountConnectionOutboundHandler();
          final CountConnectionOutboundHandler ccohUDP = new CountConnectionOutboundHandler();
         
          PipelineFilter pf = new PipelineFilter() {
        @Override
        public Map<String, Pair<EventExecutorGroup, ChannelHandler>> filter(Map<String, Pair<EventExecutorGroup, ChannelHandler>> channelHandlers, boolean tcp,
                boolean client) {
View Full Code Here


        Peer sender = null;
        Peer recv1 = null;
        try {

         
          final CountConnectionOutboundHandler ccohTCP = new CountConnectionOutboundHandler();
          final CountConnectionOutboundHandler ccohUDP = new CountConnectionOutboundHandler();
          PipelineFilter pf = new PipelineFilter() {
        @Override
        public Map<String, Pair<EventExecutorGroup, ChannelHandler>> filter(Map<String, Pair<EventExecutorGroup, ChannelHandler>> channelHandlers, boolean tcp,
                boolean client) {
         
          Map<String, Pair<EventExecutorGroup, ChannelHandler>> retVal = new LinkedHashMap<String, Pair<EventExecutorGroup, ChannelHandler>>();
          retVal.put("counter", new Pair<EventExecutorGroup, ChannelHandler>(null, tcp? ccohTCP:ccohUDP));
          retVal.putAll(channelHandlers);
          return retVal;
        }
      };
      ChannelServerConfiguration csc = PeerBuilder.createDefaultChannelServerConfiguration();
      ChannelClientConfiguration ccc = PeerBuilder.createDefaultChannelClientConfiguration();
      csc.pipelineFilter(pf);
      ccc.pipelineFilter(pf);
            sender = new PeerBuilder(new Number160("0x50")).p2pId(55).enableMaintenance(false).ports(2424).channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
            recv1 = new PeerBuilder(new Number160("0x20")).p2pId(55).enableMaintenance(false).ports(8088).channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
            recv1.objectDataReply(new ObjectDataReply() {
                @Override
                public Object reply(PeerAddress sender, Object request) throws Exception {
                    return "yes";
                }
            });
            FuturePeerConnection peerConnection = sender.createPeerConnection(recv1.peerAddress());
            ccohTCP.reset();
            ccohUDP.reset();

            FutureDirect fd1 = sender.sendDirect(peerConnection).object("test")
                    .connectionTimeoutTCPMillis(2000).idleTCPSeconds(10 * 1000).start();
            fd1.awaitListenersUninterruptibly();
            Assert.assertEquals(true, fd1.isSuccess());
            Assert.assertEquals(1, ccohTCP.total());
            Assert.assertEquals(0, ccohUDP.total());
            Thread.sleep(2000);
            System.err.println("send second with the same connection");
            FutureDirect fd2 = sender.sendDirect(peerConnection).object("test").start();
            fd2.awaitUninterruptibly();
            Assert.assertEquals(1, ccohTCP.total());
            Assert.assertEquals(0, ccohUDP.total());
            Assert.assertEquals(true, fd2.isSuccess());
            peerConnection.close().await();
            System.err.println("done");
        } finally {
            if (sender != null) {
View Full Code Here

    public void testDirect2() throws Exception {
        Peer sender = null;
        Peer recv1 = null;
        try {

          final CountConnectionOutboundHandler ccohTCP = new CountConnectionOutboundHandler();
          final CountConnectionOutboundHandler ccohUDP = new CountConnectionOutboundHandler();
          PipelineFilter pf = new PipelineFilter() {
        @Override
        public Map<String, Pair<EventExecutorGroup, ChannelHandler>> filter(Map<String, Pair<EventExecutorGroup, ChannelHandler>> channelHandlers, boolean tcp,
                boolean client) {
         
          Map<String, Pair<EventExecutorGroup, ChannelHandler>> retVal = new LinkedHashMap<String, Pair<EventExecutorGroup, ChannelHandler>>();
          retVal.put("counter", new Pair<EventExecutorGroup, ChannelHandler>(null, tcp? ccohTCP:ccohUDP));
          retVal.putAll(channelHandlers);
          return retVal;
        }
      };
      ChannelServerConfiguration csc = PeerBuilder.createDefaultChannelServerConfiguration();
      ChannelClientConfiguration ccc = PeerBuilder.createDefaultChannelClientConfiguration();
      csc.pipelineFilter(pf);
      ccc.pipelineFilter(pf);
            sender = new PeerBuilder(new Number160("0x50")).p2pId(55).ports(2424).enableMaintenance(false)
                    .channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
            recv1 = new PeerBuilder(new Number160("0x20")).p2pId(55).ports(8088).enableMaintenance(false)
                .channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
            recv1.objectDataReply(new ObjectDataReply() {
                @Override
                public Object reply(PeerAddress sender, Object request) throws Exception {
                    return "yes";
                }
            });
            FuturePeerConnection peerConnection = sender.createPeerConnection(recv1.peerAddress(), 8000);
            ccohTCP.reset();
            ccohUDP.reset();

            FutureDirect fd1 = sender.sendDirect(peerConnection).object("test")
                    .connectionTimeoutTCPMillis(2000).idleTCPSeconds(5).start();
            fd1.awaitUninterruptibly();
View Full Code Here

TOP

Related Classes of net.tomp2p.message.CountConnectionOutboundHandler

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.