final synchronized void deconnection(String id) { for (Iterator i = distantKernels.iterator(); i.hasNext(); ) { AgentAddress distantK = (AgentAddress) i.next(); if (distantK.getKernel().getID().equals(id)) { debug("disconnected from " + id); for (Iterator j = organizations.entrySet().iterator(); j.hasNext(); ) { Map.Entry e = (Map.Entry) j.next(); Organization org = (Organization) e.getValue(); if (org.removeAgentsFromKernel(distantK.getKernel())) { leaveGroup("communities", (String) e.getKey()); sendAll( new SynchroMessage( Kernel.LEAVE_GROUP, getAddress(), COMMUNITIES, (String) e.getKey(), null, null)); sendAll(new SynchroMessage(Kernel.DELETE_COMMUNITY, (String) e.getKey())); j.remove(); } } kernelAgent.callHooks(Kernel.DISCONNECTED_FROM, distantK.getKernel()); kernelAgent.callHooks(Kernel.REMOVE_MEMBER_ROLE, distantK, COMMUNITIES, PUBLIC, SITE); i.remove(); System.gc(); System.runFinalization(); break; } } if (gui != null) gui.refreshCommunities(); }
synchronized void removeCommunity(String communityName) { System.err.println("removing community : " + communityName); organizations.remove(communityName); kernelAgent.callHooks(Kernel.DELETE_COMMUNITY, communityName); leaveGroup(COMMUNITIES, communityName); sendAll( new SynchroMessage( Kernel.LEAVE_GROUP, getAddress(), COMMUNITIES, communityName, null, null)); sendAll(new SynchroMessage(Kernel.DELETE_COMMUNITY, communityName)); if (gui != null) gui.refreshCommunities(); }
synchronized void joinCommunity(String communityName) { if (!connectedWith(communityName)) { if (createGroup(true, COMMUNITIES, communityName, null, null) > 0) sendAll( new SynchroMessage( getAddress(), COMMUNITIES, communities.getGroup(communityName), communityName)); requestRole(COMMUNITIES, communityName, SITE, null); // must be optimized sendAll( new SynchroMessage( Kernel.ADD_MEMBER_ROLE, getAddress(), COMMUNITIES, communityName, SITE, null)); sendAll(new SynchroMessage(Kernel.NEW_COMMUNITY, communityName)); } }
synchronized Organization createCommunity(String communityName) { if (!organizations.containsKey(communityName)) { Organization org = new Organization(); organizations.put(communityName, org); createGroup(true, COMMUNITIES, communityName, null, null); requestRole(COMMUNITIES, communityName, SITE, null); sendAll( new SynchroMessage( getAddress(), COMMUNITIES, communities.getGroup(communityName), communityName)); sendAll( new SynchroMessage( Kernel.ADD_MEMBER_ROLE, getAddress(), COMMUNITIES, communityName, SITE, null)); sendAll(new SynchroMessage(Kernel.NEW_COMMUNITY, communityName)); kernelAgent.callHooks(Kernel.NEW_COMMUNITY, communityName); if (hasGUI()) gui.refreshCommunities(); return org; } return null; }
synchronized void leaveCommunity(String communityName) { Organization organization = (Organization) organizations.get(communityName); organization.removeDistantAgents(); if (organization.isEmpty()) { leaveGroup("communities", communityName); sendAll( new SynchroMessage( Kernel.LEAVE_GROUP, getAddress(), COMMUNITIES, communityName, null, null)); organizations.remove(communityName); kernelAgent.callHooks(Kernel.DELETE_COMMUNITY, communityName); } else { leaveRole(COMMUNITIES, communityName, SITE); sendAll( new SynchroMessage( Kernel.REMOVE_MEMBER_ROLE, getAddress(), COMMUNITIES, communityName, "site", null)); sendAll(new SynchroMessage(Kernel.DELETE_COMMUNITY, communityName)); } if (gui != null) gui.refreshCommunities(); }