Example #1
0
 private void sendAll(Message m) {
   m.setSender(getAddress());
   for (Iterator i = distantKernels.iterator(); i.hasNext(); ) {
     Message m2 = (Message) m.clone();
     AgentAddress distantK = (AgentAddress) i.next();
     m2.setReceiver(distantK);
     sendDistantMessage(m2);
   }
 }
Example #2
0
 final synchronized void updateDistantOrgs(
     AgentAddress initiator, String community, String groupName) {
   AgentAddress[] receivers = communities.getRolePlayers(community, SITE);
   Organization orgOfTheGroup = (Organization) organizations.get(community);
   for (int i = 0; i < receivers.length; i++) {
     if (!receivers[i].equals(getAddress())) {
       Message m =
           new SynchroMessage(initiator, community, orgOfTheGroup.getGroup(groupName), groupName);
       m.setSender(getAddress());
       m.setReceiver(receivers[i]);
       sendDistantMessage(m);
     }
   }
 }
Example #3
0
 final synchronized boolean sendDistantMessage(Message m) {
   if (myCommunicator != null) {
     Message m2 = new KernelMessage(KernelMessage.NO_REQUEST, Kernel.SEND_MESSAGE, m);
     m2.setSender(getAddress());
     m2.setReceiver(myCommunicator);
     try {
       getCurrentKernel().sendLocalMessage(m2);
     } catch (MessageException mexc) {
       if (getDebug()) System.err.println("Unable to send distant message !!" + mexc);
       return false;
     }
     return true;
   }
   return false;
 }
  /** Tests Message class. */
  @Test
  public void messageTest() {
    Message message = new Message();
    message = new Message("xml", this, MessageDirection.OUTBOUND);
    message.setCreationTime(new LocalDateTime());
    message.setSender("sender");
    message.setReceiver("receiver");
    message.setContentHash(null);
    assertNotNull(message.getCreationTime());
    assertEquals("sender", message.getSender());
    assertEquals("receiver", message.getReceiver());
    assertEquals(0, message.getContentHash().length);

    message.setContentHash(new byte[0]);
    assertEquals(0, message.getContentHash().length);
  }
Example #5
0
 final synchronized void updateDistantOrgs(
     int code,
     AgentAddress initiator,
     String community,
     String groupName,
     String roleName,
     Object memberCard) {
   AgentAddress[] receivers = communities.getRolePlayers(community, SITE);
   for (int i = 0; i < receivers.length; i++) {
     if (!receivers[i].equals(getAddress())) {
       Message m = new SynchroMessage(code, initiator, community, groupName, roleName, memberCard);
       m.setSender(getAddress());
       m.setReceiver(receivers[i]);
       sendDistantMessage(m);
     }
   }
 }
  /** Sends a message to a given receiver with a title and content Returns message ID */
  public String send_message(String receiver, String subject, String content, String status) {
    if (receiver != "News_Group") {
      int id = dm.lookupUser(receiver);
      if (id == -1) // User not found
      return "Recepient not found, sending message failed";
    }

    if (receiver == "News_Group" && dm.lookupRights().compareTo("normal") == 0)
      return " You do not have the right to broadcast a message, contact an admin to gain the rights ";
    Message msg = new Message();
    msg.setReceiver(receiver);
    msg.setSubject(subject);
    msg.setContent(content);
    msg.setStatus(status);
    msg.setSender(dm.lookupUserName());
    msg.setDate(new Date().toString());
    em.persist(msg);
    return "Message sent successfully";
  }
Example #7
0
 final synchronized void tryMigration(KernelAddress destination, AgentAddress traveler) {
   AbstractAgent ref = Kernel.getReference(traveler);
   Message message = new SynchroMessage(ref);
   for (Iterator i = distantKernels.iterator(); i.hasNext(); ) {
     AgentAddress potentialReceiver = (AgentAddress) i.next();
     if (potentialReceiver.getKernel().equals(destination)) {
       message.setReceiver(potentialReceiver);
       break;
     }
   }
   if (message.getReceiver() != null && ref != null) {
     // kernelAgent.callshook 	...  updateDistantOrgs(Kernel.MIGRATION,traveler,null,null,null);
     if (ref instanceof Agent) {
       ((Agent) ref).getAgentThread().stop();
       ref.setCurrentKernel(null);
       // ref.messageBox=null;
     }
     getCurrentKernel().removeAgentFromOrganizations(traveler);
     getCurrentKernel().removeReferenceOf(traveler);
     message.setSender(getAddress());
     sendDistantMessage(message);
   }
 }