コード例 #1
0
 /**
  * Informs the NetAgent that a new kernel has been connected.
  *
  * @param distantSocket SocketKernel of the distant Kernel
  * @param distantKernel KernelAddress of the distant Kernel
  * @param p2p P2PAgent responsable for the connection.
  */
 protected void sendConnectedKernelInformation(
     SocketKernel distantSocket, KernelAddress distantKernel, AgentAddress p2p, String protocol) {
   AgentAddress addr = getAgentWithRole(community, group, "netagent");
   Vector v = new Vector();
   v.add(distantSocket.getHost() + ":" + distantSocket.getPort());
   v.add(distantKernel);
   v.add(p2p);
   v.add(protocol);
   sendMessage(addr, new NetworkMessage(NetworkMessage.KERNEL_CONNECTED, v));
 }
コード例 #2
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));
   }
 }
コード例 #3
0
 /**
  * Launches a new NetConfigAgent to configure and establish a connection with a distant Kernel.
  *
  * @param distantSocket SocketKernel of the distant kernel.
  */
 private void launchNetConfigConnection(
     SocketKernel distantSocket, Socket socket, KernelAddress dka) {
   try {
     if (socket == null) {
       socket = new Socket(distantSocket.getHost(), distantSocket.getPort());
     }
     NetConfigAgent configa =
         new NetConfigAgent(socket, myInfo, distantSocket, new HashSet(routeTable.values()));
     String name = "netconfigAgent@";
     if (distantSocket != null) {
       name += distantSocket.getHost() + distantSocket.getPort();
     }
     launchAgent(configa, name, false);
     if (dka != null)
       System.err.println("This agent will be connected to me ! " + dka.getInformation());
     pause(500); // Needed unless some agents couldn't be launched when we invoke them
   } catch (UnknownHostException e) {
     debug("UnknownHostException caught " + e);
   } catch (IOException e) {
     debug("IOException caught " + e);
   } catch (Exception e) {
     System.err.println("Connexion failed for this reason : " + e.getMessage());
   }
 }
コード例 #4
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;
  }