コード例 #1
0
ファイル: SiteAgent.java プロジェクト: Ooya/Robot-Sapiens
 final void handleConnectionMessage(ConnectionMessage m) {
   if (m.isTheFirstMessage()) {
     getCurrentKernel().synchronizeKernel(((ConnectionMessage) m).getOrgs(), true);
     establishConnectionWith(m.getSender(), false);
   } else getCurrentKernel().synchronizeKernel(((ConnectionMessage) m).getOrgs(), false);
   if (distantKernels.add(m.getSender())) {
     // System.out.println("Connecting to "+m.getSender());
     kernelAgent.callHooks(Kernel.CONNECTED_TO, m.getSender().getKernel());
     kernelAgent.callHooks(Kernel.ADD_MEMBER_ROLE, m.getSender(), COMMUNITIES, PUBLIC, SITE);
   }
   System.gc();
   System.runFinalization();
 }
コード例 #2
0
ファイル: SiteAgent.java プロジェクト: Ooya/Robot-Sapiens
 final synchronized void handleNetworkRequest(NetworkRequest m) {
   switch (m.getRequestCode()) {
     case NetworkRequest.INJECT_MESSAGE:
       try {
         Message m2 = (Message) m.getArgument();
         getCurrentKernel().sendLocalMessage(m2);
         if (!(m2 instanceof PrivateMessage))
           kernelAgent.callHooks(Kernel.SEND_MESSAGE, m2.clone());
       } catch (MessageException me) {
         if (getDebug()) System.err.println(me);
       }
       break;
     case NetworkRequest.CONNECTION_REQUEST:
       if (m.getSender().equals(myCommunicator)) {
         establishConnectionWith((AgentAddress) m.getArgument(), true);
         // distantKernels.add(m.getArgument());
       }
       break;
     case NetworkRequest.DECONNECTED_FROM:
       distantKernels.remove(m.getArgument());
       deconnection((String) m.getArgument());
       break;
     case NetworkRequest.BE_COMMUNICATOR:
       if (myCommunicator == null) {
         redisplayMyGUI();
         myCommunicator = m.getSender();
       }
       break;
     case NetworkRequest.STOP_COMMUNICATOR:
       if (myCommunicator != null && myCommunicator.equals(m.getSender())) {
         disposeMyGUI();
         myCommunicator = null;
         for (Iterator i = organizations.entrySet().iterator(); i.hasNext(); ) {
           Map.Entry e = (Map.Entry) i.next();
           Organization org = (Organization) e.getValue();
           if (org.removeDistantAgents()) {
             // communities.leaveGroup(getAddress(), (String) e.getKey());
             leaveGroup("communities", (String) e.getKey());
             i.remove();
           }
         }
         distantKernels.clear();
         System.gc();
         System.runFinalization();
       }
       break;
     case NetworkRequest.GET_AVAILABLE_DESTINATIONS:
       KernelAddress[] destinations = new KernelAddress[distantKernels.size()];
       int j = 0;
       for (Iterator i = distantKernels.iterator(); i.hasNext(); j++)
         destinations[j] = ((AgentAddress) i.next()).getKernel();
       sendMessage(
           m.getSender(),
           new NetworkRequest(NetworkRequest.GET_AVAILABLE_DESTINATIONS, destinations));
       break;
     case NetworkRequest.REQUEST_MIGRATION:
       if (getDebug()) println("receiving a migration request of " + m.getSender());
       // kernelAgent.callsHook(Kernel.MIGRATION...	à rajouter
       tryMigration((KernelAddress) m.getArgument(), m.getSender());
       break;
   }
 }
コード例 #3
0
ファイル: SiteAgent.java プロジェクト: Ooya/Robot-Sapiens
 final void handleSynchroMessage(SynchroMessage m) {
   if (connectedWith(m.community)) {
     if (!organizations.containsKey(m.community)) {
       kernelAgent.callHooks(Kernel.NEW_COMMUNITY, m.community);
       organizations.put(m.community, new Organization());
     }
     Organization localOrg = (Organization) organizations.get(m.community);
     switch (m.code) {
       case Kernel.CREATE_GROUP:
         localOrg.createGroup(
             m.initiator,
             true,
             m.groupName,
             m.newGroup.getDescription(),
             m.newGroup.getGroupIdentifier());
         kernelAgent.callHooks(
             Kernel.CREATE_GROUP, new AGRTrio(m.initiator, m.community, m.groupName, null));
         break;
       case Kernel.ADD_MEMBER_ROLE:
         localOrg.requestRole(m.initiator, m.groupName, m.roleName, m.memberCard);
         kernelAgent.callHooks(
             Kernel.ADD_MEMBER_ROLE,
             new AGRTrio(m.initiator, m.community, m.groupName, m.roleName));
         break;
       case Kernel.LEAVE_GROUP:
         if (localOrg.leaveGroup(m.initiator, m.groupName)) removeCommunity(m.community);
         kernelAgent.callHooks(
             Kernel.LEAVE_GROUP, new AGRTrio(m.initiator, m.community, m.groupName, null));
         break;
       case Kernel.NEW_COMMUNITY:
         establishConnectionWith(m.getSender(), true);
         break;
       case Kernel.DELETE_COMMUNITY:
         localOrg.removeAgentsFromKernel(m.getSender().getKernel());
         if (localOrg.isEmpty()) {
           removeCommunity(m.community);
           kernelAgent.callHooks(Kernel.DELETE_COMMUNITY, m.community);
         }
         break;
       case Kernel.REMOVE_MEMBER_ROLE:
         if (localOrg.leaveRole(m.initiator, m.groupName, m.roleName)) {
           removeCommunity(m.community);
         }
         kernelAgent.callHooks(
             Kernel.REMOVE_MEMBER_ROLE,
             new AGRTrio(m.initiator, m.community, m.groupName, m.roleName));
         break;
       case Kernel.MIGRATION:
         if (getDebug()) System.err.println("receiving a migration " + m.ref.toString());
         getCurrentKernel().receiveAgent(m.ref);
         System.gc();
         System.runFinalization();
         break;
     }
   } else
     switch (m.code) {
       case Kernel.NEW_COMMUNITY:
         kernelAgent.callHooks(Kernel.NEW_COMMUNITY, m.community);
         System.err.println("new community detected");
         if (gui != null)
           gui.refreshCommunities(); // establishConnectionWith(m.getSender(), true);
         break;
       case Kernel.DELETE_COMMUNITY:
         kernelAgent.callHooks(Kernel.DELETE_COMMUNITY, m.community);
         System.err.println("a community has been deleted "); // +organizations);
         if (gui != null)
           gui.refreshCommunities(); // establishConnectionWith(m.getSender(), true);
         break;
     }
 }