Package net.tomp2p.relay.android

Examples of net.tomp2p.relay.android.AndroidForwarderRPC


      responder.response(createResponseMessage(message, Type.DENIED));
          return;
    }
       
    LOG.debug("Hello Android device! You'll be relayed over GCM. {}", message);
    AndroidForwarderRPC forwarderRPC = new AndroidForwarderRPC(peer, peerConnection.remotePeer(), bufferConfig, authenticationKey, registrationId, mapUpdateInterval);
    registerRelayForwarder(forwarderRPC);
   
        responder.response(createResponseMessage(message, Type.OK));
    }
View Full Code Here


     */
    private void handleBufferRequest(Message message, Responder responder) {
      LOG.debug("Handle buffer request of unreachable peer {}", message.sender());
    BaseRelayForwarderRPC forwarderRPC = forwarders.get(message.sender().peerId());
    if(forwarderRPC instanceof AndroidForwarderRPC) {
      AndroidForwarderRPC androidForwarder = (AndroidForwarderRPC) forwarderRPC;
     
      try {
        Message response = createResponseMessage(message, Type.OK);
        // add all buffered messages
        response.buffer(androidForwarder.getBufferedMessages());
       
        LOG.debug("Responding all buffered messages to Android device {}", message.sender());
        responder.response(response);
      } catch(Exception e) {
        LOG.error("Cannot respond with buffered messages.", e);
View Full Code Here

        continue;
      }

      for (Entry<Integer, DispatchHandler> entry : handlers.entrySet()) {
        if (entry.getValue() instanceof AndroidForwarderRPC && !mockedForwarders.contains(entry.getValue())) {
          final AndroidForwarderRPC forwarderRPC = (AndroidForwarderRPC) entry.getValue();
          // make sure every forwarder only has one of these listeners
          forwarderRPC.addMessageBufferListener(new MessageBufferListener() {

            @Override
            public void bufferFull(List<Message> messageBuffer) {
              for (BaseRelayConnection connection : unreachablePeer.currentRelays()) {
                if (connection instanceof AndroidRelayConnection) {
                  final AndroidRelayConnection androidConnection = (AndroidRelayConnection) connection;
                  if(androidConnection.relayAddress().peerId().equals(forwarderRPC.relayPeerId())) {
                    // start in a new thread
                    new Thread(new Runnable() {
                      @Override
                      public void run() {
                        System.err.println("Caught sending message over GCM from " + forwarderRPC.relayPeerId() + " to unreachable peer");
                        try {
                          Thread.sleep(GCM_MOCK_DELAY_MS);
                        } catch (InterruptedException e) {
                          // ignore
                        }
                        androidConnection.sendBufferRequest();
                      }
                    }, "GCM-Mock").start();
                  }
                }
              }
            }
          });
         
          System.err.println("Mocked Android forwarder at " + forwarderRPC.relayPeerId() + " to " + forwarderRPC.unreachablePeerId());
          mockedForwarders.add(forwarderRPC);
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.relay.android.AndroidForwarderRPC

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.