/** * 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)); }
/** * 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()); } }
/** 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; }