Пример #1
0
 public void removeMessagesOfType(int type) {
   Iterator<Message> it = iterator();
   while (it.hasNext()) {
     Message message = it.next();
     if (message.getMessageType() == type) it.remove();
   }
 }
Пример #2
0
  public void testRegularAndOOBMulticasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class);
    a.setDiscardOwnMessages(true);

    Address dest = null; // send to all
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownMulticasts(1);
    a.send(m2);
    a.send(m3);

    Util.sleep(500);
    Collection<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 10; i++) {
      System.out.println("list = " + list);
      if (list.size() == 3) break;
      Util.sleep(1000); // give the asynchronous msgs some time to be received
      sendStableMessages(a, b);
    }
    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
Пример #3
0
  /** Tests https://jira.jboss.org/jira/browse/JGRP-1079 for unicast messages */
  public void testOOBUnicastMessageLoss() throws Exception {
    MyReceiver receiver = new MySleepingReceiver("C2", 1000);
    b.setReceiver(receiver);

    a.getProtocolStack().getTransport().setOOBRejectionPolicy("discard");

    final int NUM = 10;
    final Address dest = b.getAddress();
    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(dest, null, i);
      msg.setFlag(Message.OOB);
      a.send(msg);
    }

    Collection<Integer> msgs = receiver.getMsgs();

    for (int i = 0; i < 20; i++) {
      if (msgs.size() == NUM) break;
      Util.sleep(1000);
      // sendStableMessages(c1,c2); // not needed for unicasts !
    }

    assert msgs.size() == NUM
        : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs);
    for (int i = 1; i <= NUM; i++) {
      assert msgs.contains(i);
    }
  }
Пример #4
0
  protected void sendStableMessage(Address dest, short conn_id, long low, long high) {
    Message stable_msg = new Message(dest, null, null);
    Unicast2Header hdr = Unicast2Header.createStableHeader(conn_id, low, high);
    stable_msg.putHeader(this.id, hdr);
    stable_msg.setFlag(Message.OOB);
    if (log.isTraceEnabled()) {
      StringBuilder sb = new StringBuilder();
      sb.append(local_addr)
          .append(" --> STABLE(")
          .append(dest)
          .append(": ")
          .append(low)
          .append("-")
          .append(high)
          .append(", conn_id=")
          .append(conn_id)
          .append(")");
      log.trace(sb.toString());
    }
    down_prot.down(new Event(Event.MSG, stable_msg));

    ReceiverEntry entry = recv_table.get(dest);
    NakReceiverWindow win = entry != null ? entry.received_msgs : null;
    if (win != null) win.stable(win.getHighestDelivered());
  }
Пример #5
0
  /**
   * Processes a packet read from either the multicast or unicast socket. Needs to be synchronized
   * because mcast or unicast socket reads can be concurrent
   */
  void handleIncomingUdpPacket(byte[] data) {
    ByteArrayInputStream inp_stream;
    ObjectInputStream inp;
    Message msg = null;
    List l; // used if bundling is enabled

    try {
      // skip the first n bytes (default: 4), this is the version info
      inp_stream = new ByteArrayInputStream(data, VERSION_LENGTH, data.length - VERSION_LENGTH);
      inp = new ObjectInputStream(inp_stream);
      if (enable_bundling) {
        l = new List();
        l.readExternal(inp);
        for (Enumeration en = l.elements(); en.hasMoreElements(); ) {
          msg = (Message) en.nextElement();
          try {
            handleMessage(msg);
          } catch (Throwable t) {
            Trace.error("UDP.handleIncomingUdpPacket()", "failure: " + t.toString());
          }
        }
      } else {
        msg = new Message();
        msg.readExternal(inp);
        handleMessage(msg);
      }
    } catch (Throwable e) {
      Trace.error("UDP.handleIncomingUdpPacket()", "exception=" + Trace.getStackTrace(e));
    }
  }
  public static long getEventGenerationDate(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_GENERATION_DATE)) {
      return 0L;
    }

    return message.getLongProperty(MessagePropertyNames.EVENT_GENERATION_DATE);
  }
  public static String getEventCategory(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_CATEGORY)) {
      return EVENT_MODULE_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.EVENT_CATEGORY);
  }
  public static String getPortName(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.PORT_NAME)) {
      return PORT_NAME_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.PORT_NAME);
  }
  public static String getDocumentID(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.DOCUMENT_ID)) {
      return DOCUMENT_ID_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.DOCUMENT_ID);
  }
  public static long getTotalTime(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.TOTAL_TIME)) {
      return TOTAL_TIME_DEF;
    }

    return message.getLongProperty(MessagePropertyNames.TOTAL_TIME);
  }
  public static String getSourceFPSName(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.SOURCE)) {
      return SOURCE_FPS_NAME_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.SOURCE);
  }
  public static int getEventID(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_ID)) {
      return EVENT_ID_DEF;
    }

    return message.getIntProperty(MessagePropertyNames.EVENT_ID);
  }
  public static String getEventDescription(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_DESCRIPTION)) {
      return EVENT_DESCRIPTION_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.EVENT_DESCRIPTION);
  }
Пример #14
0
  /**
   * We need to resend our first message with our conn_id
   *
   * @param sender
   * @param seqno Resend the non null messages in the range [lowest .. seqno]
   */
  protected void handleResendingOfFirstMessage(Address sender, long seqno) {
    if (log.isTraceEnabled())
      log.trace(local_addr + " <-- SEND_FIRST_SEQNO(" + sender + "," + seqno + ")");
    SenderEntry entry = send_table.get(sender);
    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win == null) {
      if (log.isErrorEnabled())
        log.error(local_addr + ": sender window for " + sender + " not found");
      return;
    }

    boolean first_sent = false;
    for (long i = win.getLow() + 1; i <= seqno; i++) {
      Message rsp = win.get(i);
      if (rsp == null) continue;
      if (first_sent) {
        down_prot.down(new Event(Event.MSG, rsp));
      } else {
        first_sent = true;
        // We need to copy the UnicastHeader and put it back into the message because Message.copy()
        // doesn't copy
        // the headers and therefore we'd modify the original message in the sender retransmission
        // window
        // (https://jira.jboss.org/jira/browse/JGRP-965)
        Message copy = rsp.copy();
        Unicast2Header hdr = (Unicast2Header) copy.getHeader(this.id);
        Unicast2Header newhdr = hdr.copy();
        newhdr.first = true;
        copy.putHeader(this.id, newhdr);
        down_prot.down(new Event(Event.MSG, copy));
      }
    }
  }
  public static String getEventProcessVersion(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_PROCESS_VERSION)) {
      return EVENT_PROCESS_VERSION_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.EVENT_PROCESS_VERSION);
  }
  public static boolean getIsAlert(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.IS_ALERT)) {
      return false;
    }

    return message.getBooleanProperty(MessagePropertyNames.IS_ALERT);
  }
  public static Hashtable getDataTable(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.DATA_TABLE)) {
      return DATA_TABLE_DEF;
    }

    return (Hashtable) message.getObjectProperty(MessagePropertyNames.DATA_TABLE);
  }
  public static String getComment(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.COMMENT)) {
      return COMMENT_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.COMMENT);
  }
  public static String getEventStatus(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_STATUS)) {
      return EVENT_STATUS_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.EVENT_STATUS);
  }
  public static String getUserDefinedId(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.USER_DEFINED_DOC_ID)) {
      return USER_DEFINED_DOC_ID_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.USER_DEFINED_DOC_ID);
  }
  public static int getEventType(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_TYPE)) {
      return 0;
    }

    return message.getIntProperty(MessagePropertyNames.EVENT_TYPE);
  }
  public static String getWorkFlowInstId(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.WORK_FLOW_INST_ID)) {
      return WORK_FLOW_INST_ID_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.WORK_FLOW_INST_ID);
  }
Пример #23
0
 public void retransmit(long first_seqno, long last_seqno, Address sender) {
   if (last_seqno < first_seqno) return;
   Unicast2Header hdr = Unicast2Header.createXmitReqHeader(first_seqno, last_seqno);
   Message xmit_req = new Message(sender, null, null);
   xmit_req.putHeader(this.id, hdr);
   down_prot.down(new Event(Event.MSG, xmit_req));
 }
  public static String getSink(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.SINK)) {
      return null;
    }

    return message.getStringProperty(MessagePropertyNames.SINK);
  }
Пример #25
0
  /**
   * set up the connection socket for the first connection
   *
   * @param sedMsg the message to send
   */
  public void setupCommunication(Message sedMsg) {
    /* get the configuration item in the configuration file */
    ArrayList<HashMap<String, String>> configLst = map.get(CONFIG_HEADER);
    String dest = sedMsg.get_dest();

    boolean findName = false;

    /* find the ip address and port of the target node */
    for (HashMap<String, String> configItem : configLst) {
      if (configItem.get("name").equals(dest)) {
        String ip = configItem.get("ip");
        Object val = configItem.get("port");
        Integer tmp = (Integer) val;
        int port = tmp.intValue();

        sedMsg.set_ip(ip);
        sedMsg.set_portNum(port);

        setupTCPConnection(ip, port);

        findName = true;
      }
    }

    /* if cannot find target node exit */
    if (!findName) {
      System.err.println("cannot find the dest machine, exit...");
      System.exit(1);
    }
  }
  public static String getCompInstName(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.COMP_INST_NAME)) {
      return COMP_INST_NAME_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.COMP_INST_NAME);
  }
Пример #27
0
  /** Tests https://jira.jboss.org/jira/browse/JGRP-1079 */
  public void testOOBMessageLoss() throws Exception {
    Util.close(b); // we only need 1 channel
    MyReceiver receiver = new MySleepingReceiver("C1", 1000);
    a.setReceiver(receiver);

    TP transport = a.getProtocolStack().getTransport();
    transport.setOOBRejectionPolicy("discard");

    final int NUM = 10;

    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(null, null, i);
      msg.setFlag(Message.OOB);
      a.send(msg);
    }
    STABLE stable = (STABLE) a.getProtocolStack().findProtocol(STABLE.class);
    if (stable != null) stable.runMessageGarbageCollection();
    Collection<Integer> msgs = receiver.getMsgs();

    for (int i = 0; i < 20; i++) {
      if (msgs.size() == NUM) break;
      Util.sleep(1000);
      sendStableMessages(a, b);
    }

    System.out.println("msgs = " + Util.print(msgs));

    assert msgs.size() == NUM
        : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs);
    for (int i = 1; i <= NUM; i++) {
      assert msgs.contains(i);
    }
  }
  public static String getEventProcessName(Message message) throws JMSException {
    if (!message.propertyExists(MessagePropertyNames.EVENT_PROCESS_NAME)) {
      return EVENT_PROCESS_NAME_DEF;
    }

    return message.getStringProperty(MessagePropertyNames.EVENT_PROCESS_NAME);
  }
Пример #29
0
  /**
   * Tests sending 1, 2 (OOB) and 3, where they are received in the order 1, 3, 2. Message 3 should
   * not get delivered until message 4 is received (http://jira.jboss.com/jira/browse/JGRP-780)
   */
  public void testRegularAndOOBUnicasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class);

    Address dest = b.getAddress();
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownUnicasts(1);
    a.send(m2);
    a.send(m3);

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 3 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(a, b);
    }

    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
Пример #30
0
 /**
  * Retrieves from the list of messages those elements that produces the specified message code.
  *
  * @param messageCode The message code.
  * @return A list of Message instances.
  */
 public List<Message> getMessagesWithCode(String messageCode) {
   List<Message> results = new ArrayList<Message>();
   for (Message message : this) {
     if (message.getMessageCode().equals(messageCode)) results.add(message);
   }
   return results;
 }