Example #1
0
 /** Broadcast the event to all connected parties. */
 public void sendEvent(NetworkEvent event) {
   if (!myReceivedMsgs.contains(event.getMsgId())) {
     // Only set the host id if we are initiating the event
     event.setHostId(myServerHash);
     myReceivedMsgs.add(event.getMsgId());
   }
   for (NetworkConnection conn : myConnections.values()) {
     try {
       System.out.println("Sending to " + conn + ": " + event);
       conn.write(event);
     } catch (IOException ioe) {
       System.out.println("Could not send event to " + conn);
     }
   }
 }
Example #2
0
    public void run() {
      while (running) {
        NetworkEvent e = null;
        try {
          e = queue.take();
        } catch (InterruptedException ie) {
        }

        if (e != null && !myReceivedMsgs.contains(e.getMsgId())) {
          if (myReceivedMsgs.size() >= RECEIVED_MSG_BUFFER_SIZE) myReceivedMsgs.clear();
          myReceivedMsgs.add(e.getMsgId());
          eventReceived(e);
        }
      }
      queue.clear();
      myReceivedMsgs.clear();
    }
Example #3
0
 /** Send the event to the host. If we don't know how to reach the host, returns false. */
 public boolean sendEvent(Long host, NetworkEvent event) {
   NetworkConnection conn = myConnections.get(host);
   try {
     if (conn != null) {
       if (!myReceivedMsgs.contains(event.getMsgId())) {
         // Only set the host id if we are initiating the event
         event.setHostId(myServerHash);
         myReceivedMsgs.add(event.getMsgId());
       }
       System.out.println("Sending to " + conn + ": " + event);
       conn.write(event);
       return true;
     } else {
       System.out.println("Unrecognized host: " + host);
     }
   } catch (IOException e) {
     System.out.println("Could not send event to " + conn);
   }
   return false;
 }