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);
}
}
}
}