Ejemplo n.º 1
0
 /**
  * Handles a request of a P2PAgent.<br>
  * The vector must contain:<br>
  * the KernelAddress<br>
  * the Distant SocketKernel<br>
  * the AgentAdress of the distant Kernel<br>
  * the Connection protocol<br>
  * the Kernels known by the distant kernel.This can be either the DistantKernelInFormation (used
  * by netcomm) or just the socketKernel. (for compatibility with 3.1)<br>
  *
  * @param address AgentAddress of the P2PAgent requesting the Sync
  * @param vec Information to sync
  */
 private void handleSynchRequest(AgentAddress sender, Vector vec) {
   Enumeration a = vec.elements();
   KernelAddress distantK = (KernelAddress) a.nextElement();
   SocketKernel distantSI = (SocketKernel) a.nextElement();
   AgentAddress distantKernel = (AgentAddress) a.nextElement();
   String protocol = (String) a.nextElement();
   Collection otherKernels = (Collection) a.nextElement();
   if (addRoute(distantK, sender, distantSI, protocol)) // el de ack
   {
     replyConnect(sender);
     for (Iterator i = otherKernels.iterator(); i.hasNext(); ) {
       Object o = i.next();
       if (o instanceof DistantKernelInformation) {
         DistantKernelInformation distantInfo = (DistantKernelInformation) o;
         if (!(myKernel.getKernel().getID().equals(distantInfo.getDistantKernelAddress().getID())
             || isConfiguring(distantInfo.getDistantKernelAddress())
             || isKnownKernelSocket(distantInfo.getSocketKernel()))) {
           launchNetConfigConnection(
               distantInfo.getSocketKernel(), null, distantInfo.getDistantKernelAddress());
         }
       } else if (o instanceof SocketKernel) {
         SocketKernel distantSocket = (SocketKernel) o;
         if (!(myInfo.equals(distantSocket) || isKnownKernelSocket(distantSocket))) {
           launchNetConfigConnection(distantSocket, null, null);
         }
       }
     }
   } else {
     debug("Adding Route failed");
     if (!sender.equals(
         getP2PAddress(distantK))) // kill the agent.. the route is handled by someone else
     sendMessage(sender, new NetworkMessage(NetworkMessage.DIE, null));
   }
 }
Ejemplo n.º 2
0
 /**
  * Checks if the the kenel listening on the SocketKernel has already been added to the routing
  * Table.
  *
  * @param distantKernel SocketKernel of the distant Kernel
  * @return true iff the kenel listening on the SocketKernel <code>distantKernel</code> is known
  */
 private boolean isKnownKernelSocket(SocketKernel distantKernel) {
   Iterator it = routeTable.values().iterator();
   while (it.hasNext()) {
     DistantKernelInformation element = (DistantKernelInformation) it.next();
     if (element.getSocketKernel().equals(distantKernel)) return true;
   }
   return false;
 }
Ejemplo n.º 3
0
  /** Create a Vector Compatible with Madkit 3.1 */
  private Vector buildSynch(char s, HashSet dKernels) {
    Vector v = new Vector();

    if (s == 'c') v.addElement("TRANSMIT_SOCKET_INFO");
    else if (s == 'r') v.addElement("ACK_SOCKET_INFO");

    v.addElement(getAddress().getKernel());
    madkit.communicator.SocketKernel sktemp =
        new madkit.communicator.SocketKernel(myInfo.getHost(), myInfo.getPort());
    v.addElement(sktemp); // need to change the socketKernel object to keep backwards comp
    v.addElement(myKernel);
    Collection scks = new Vector();
    for (Iterator iter = dKernels.iterator(); iter.hasNext(); ) {
      DistantKernelInformation info = (DistantKernelInformation) iter.next();
      madkit.communicator.SocketKernel sk =
          new madkit.communicator.SocketKernel(
              info.getSocketKernel().getHost(),
              info.getSocketKernel()
                  .getPort()); // need to change the socketKernel object to keep backwards comp
      scks.add(sk);
    }
    v.addElement(new HashSet(scks));
    return v;
  }