public static String print(List<Message> list) {
   StringBuilder sb = new StringBuilder();
   for (Message msg : list) {
     sb.append(msg.getSrc()).append(": ").append(msg.getObject()).append(" ");
   }
   return sb.toString();
 }
Exemplo n.º 2
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   if (sent_msgs != null) sb.append(sent_msgs).append(", ");
   sb.append("send_conn_id=" + send_conn_id);
   sb.append(" (" + age() + " ms old)");
   return sb.toString();
 }
Exemplo n.º 3
0
  public static void testDetermineMergeParticipantsAndMergeCoords4() {
    Address a = Util.createRandomAddress(),
        b = Util.createRandomAddress(),
        c = Util.createRandomAddress(),
        d = Util.createRandomAddress();
    org.jgroups.util.UUID.add(a, "A");
    org.jgroups.util.UUID.add(b, "B");
    org.jgroups.util.UUID.add(c, "C");
    org.jgroups.util.UUID.add(d, "D");

    View v1 = View.create(a, 1, a, b);
    View v2 = View.create(c, 1, c, d);

    Map<Address, View> map = new HashMap<>();
    map.put(a, v1);
    map.put(b, v1);
    map.put(d, v2);

    StringBuilder sb = new StringBuilder("map:\n");
    for (Map.Entry<Address, View> entry : map.entrySet())
      sb.append(entry.getKey() + ": " + entry.getValue() + "\n");
    System.out.println(sb);

    Collection<Address> merge_participants = Util.determineMergeParticipants(map);
    System.out.println("merge_participants = " + merge_participants);
    assert merge_participants.size() == 3;
    assert merge_participants.contains(a)
        && merge_participants.contains(c)
        && merge_participants.contains(d);

    Collection<Address> merge_coords = Util.determineMergeCoords(map);
    System.out.println("merge_coords = " + merge_coords);
    assert merge_coords.size() == 2;
    assert merge_coords.contains(a) && merge_coords.contains(c);
  }
Exemplo n.º 4
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   if (received_msgs != null) sb.append(received_msgs).append(", ");
   sb.append("recv_conn_id=" + recv_conn_id);
   sb.append(" (" + age() + " ms old)");
   return sb.toString();
 }
Exemplo n.º 5
0
 public String toString() {
   StringBuilder sb = new StringBuilder(64);
   sb.append(printType());
   if (seqno >= 0) sb.append(" seqno=" + seqno);
   if (flush_ack) sb.append(" (flush_ack)");
   return sb.toString();
 }
Exemplo n.º 6
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(type2Str(type)).append(", seqno=").append(seqno);
   if (conn_id != 0) sb.append(", conn_id=").append(conn_id);
   if (first) sb.append(", first");
   return sb.toString();
 }
Exemplo n.º 7
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());
  }
Exemplo n.º 8
0
 @ManagedOperation
 public String printPreviousViews() {
   StringBuilder sb = new StringBuilder();
   for (Tuple<View, Long> tmp : prev_views)
     sb.append(new Date(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
   return sb.toString();
 }
Exemplo n.º 9
0
 public String dumpHistory() {
   StringBuilder sb = new StringBuilder();
   for (String line : history) {
     sb.append(line + "\n");
   }
   return sb.toString();
 }
Exemplo n.º 10
0
 public String dumpQueue() {
   StringBuilder sb = new StringBuilder();
   List v = queue.values();
   for (Iterator it = v.iterator(); it.hasNext(); ) {
     sb.append(it.next() + "\n");
   }
   return sb.toString();
 }
Exemplo n.º 11
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("receiver " + name).append(":\n");
   for (Map.Entry<Address, Collection<Long>> entry : msgs.entrySet()) {
     sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
   }
   return sb.toString();
 }
Exemplo n.º 12
0
 @ManagedOperation(description = "Runs the discovery protocol to find initial members")
 public String findInitialMembersAsString() {
   Responses rsps = findMembers(null, false, false);
   if (!rsps.isDone()) rsps.waitFor(300);
   if (rsps.isEmpty()) return "<empty>";
   StringBuilder sb = new StringBuilder();
   for (PingData rsp : rsps) sb.append(rsp).append("\n");
   return sb.toString();
 }
Exemplo n.º 13
0
 @ManagedOperation(description = "Prints the contents of the send windows for all members")
 public String printSendWindowMessages() {
   StringBuilder ret = new StringBuilder(local_addr + ":\n");
   for (Map.Entry<Address, SenderEntry> entry : send_table.entrySet()) {
     Address addr = entry.getKey();
     Table<Message> buf = entry.getValue().sent_msgs;
     ret.append(addr).append(": ").append(buf.toString()).append('\n');
   }
   return ret.toString();
 }
Exemplo n.º 14
0
 @ManagedOperation(description = "Runs the discovery protocol to find initial members")
 public String findInitialMembersAsString() {
   List<PingData> results = findInitialMembers(null);
   if (results == null || results.isEmpty()) return "<empty>";
   StringBuilder sb = new StringBuilder();
   for (PingData rsp : results) {
     sb.append(rsp).append("\n");
   }
   return sb.toString();
 }
Exemplo n.º 15
0
 @ManagedOperation
 public String printPreviousMembers() {
   StringBuilder sb = new StringBuilder();
   if (prev_members != null) {
     for (Address addr : prev_members) {
       sb.append(addr).append("\n");
     }
   }
   return sb.toString();
 }
Exemplo n.º 16
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(current_owner);
   if (!queue.isEmpty()) {
     sb.append(", queue: ");
     for (Request req : queue) {
       sb.append(req.toStringShort()).append(" ");
     }
   }
   return sb.toString();
 }
Exemplo n.º 17
0
 @ManagedOperation(description = "Runs the discovery protocol to find all views")
 public String findAllViewsAsString() {
   List<PingData> rsps = findAllViews(null);
   if (rsps == null || rsps.isEmpty()) return "<empty>";
   StringBuilder sb = new StringBuilder();
   for (PingData data : rsps) {
     View v = data.getView();
     if (v != null) sb.append(v).append("\n");
   }
   return sb.toString();
 }
Exemplo n.º 18
0
  /**
   * Check whether the hashtable contains an entry e for <code>sender</code> (create if not). If
   * e.received_msgs is null and <code>first</code> is true: create a new AckReceiverWindow(seqno)
   * and add message. Set e.received_msgs to the new window. Else just add the message.
   */
  protected void handleDataReceived(
      Address sender, long seqno, short conn_id, boolean first, Message msg, Event evt) {
    if (log.isTraceEnabled()) {
      StringBuilder sb = new StringBuilder();
      sb.append(local_addr).append(" <-- DATA(").append(sender).append(": #").append(seqno);
      if (conn_id != 0) sb.append(", conn_id=").append(conn_id);
      if (first) sb.append(", first");
      sb.append(')');
      log.trace(sb);
    }

    ReceiverEntry entry = getReceiverEntry(sender, seqno, first, conn_id);
    if (entry == null) return;
    if (conn_expiry_timeout > 0) entry.update();
    Table<Message> win = entry.received_msgs;
    boolean added = win.add(seqno, msg); // win is guaranteed to be non-null if we get here
    num_msgs_received++;

    // An OOB message is passed up immediately. Later, when remove() is called, we discard it. This
    // affects ordering !
    // http://jira.jboss.com/jira/browse/JGRP-377
    if (msg.isFlagSet(Message.OOB) && added) {
      try {
        up_prot.up(evt);
      } catch (Throwable t) {
        log.error("couldn't deliver OOB message " + msg, t);
      }
    }

    final AtomicBoolean processing = win.getProcessing();
    if (!processing.compareAndSet(false, true)) {
      return;
    }

    // try to remove (from the AckReceiverWindow) as many messages as possible as pass them up

    // Prevents concurrent passing up of messages by different threads
    // (http://jira.jboss.com/jira/browse/JGRP-198);
    // this is all the more important once we have a concurrent stack
    // (http://jira.jboss.com/jira/browse/JGRP-181),
    // where lots of threads can come up to this point concurrently, but only 1 is allowed to pass
    // at a time
    // We *can* deliver messages from *different* senders concurrently, e.g. reception of P1, Q1,
    // P2, Q2 can result in
    // delivery of P1, Q1, Q2, P2: FIFO (implemented by UNICAST) says messages need to be delivered
    // only in the
    // order in which they were sent by their senders
    int num_msgs = removeAndDeliver(processing, win);
    if (num_msgs > 0) {
      long hd = win.getHighestDelivered();
      sendAck(sender, hd);
    }
  }
Exemplo n.º 19
0
  protected void handleBatchReceived(Address sender, Map<Short, List<Message>> map) {
    for (Map.Entry<Short, List<Message>> element : map.entrySet()) {
      final List<Message> msg_list = element.getValue();
      if (log.isTraceEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append(local_addr)
            .append(" <-- DATA(")
            .append(sender)
            .append(": " + printMessageList(msg_list))
            .append(')');
        log.trace(sb);
      }

      short conn_id = element.getKey();
      ReceiverEntry entry = null;
      for (Message msg : msg_list) {
        UnicastHeader hdr = (UnicastHeader) msg.getHeader(id);
        entry = getReceiverEntry(sender, hdr.seqno, hdr.first, conn_id);
        if (entry == null) continue;
        Table<Message> win = entry.received_msgs;
        boolean msg_added =
            win.add(hdr.seqno, msg); // win is guaranteed to be non-null if we get here
        num_msgs_received++;

        if (hdr.first && msg_added)
          sendAck(
              sender, hdr.seqno,
              conn_id); // send an ack immediately when we received the first message of a conn

        // An OOB message is passed up immediately. Later, when remove() is called, we discard it.
        // This affects ordering !
        // http://jira.jboss.com/jira/browse/JGRP-377
        if (msg.isFlagSet(Message.Flag.OOB) && msg_added) {
          try {
            up_prot.up(new Event(Event.MSG, msg));
          } catch (Throwable t) {
            log.error("couldn't deliver OOB message " + msg, t);
          }
        }
      }
      if (entry != null && conn_expiry_timeout > 0) entry.update();
    }

    ReceiverEntry entry = recv_table.get(sender);
    Table<Message> win = entry != null ? entry.received_msgs : null;
    if (win != null) {
      final AtomicBoolean processing = win.getProcessing();
      if (processing.compareAndSet(false, true)) {
        removeAndDeliver(processing, win, sender);
        sendAck(sender, win.getHighestDeliverable(), entry.recv_conn_id);
      }
    }
  }
Exemplo n.º 20
0
 @ManagedOperation(description = "Returns the sizes of all NakReceiverWindow.RetransmitTables")
 public String printRetransmitTableSizes() {
   StringBuilder sb = new StringBuilder();
   for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) {
     NakReceiverWindow win = entry.getValue().received_msgs;
     sb.append(entry.getKey() + ": ")
         .append(win.getRetransmitTableSize())
         .append(" (capacity=" + win.getRetransmitTableCapacity())
         .append(", fill factor=" + win.getRetransmitTableFillFactor() + "%)\n");
   }
   return sb.toString();
 }
Exemplo n.º 21
0
 protected String printMessageList(List<Message> list) {
   StringBuilder sb = new StringBuilder();
   int size = list.size();
   Message first = size > 0 ? list.get(0) : null, second = size > 1 ? list.get(size - 1) : first;
   UnicastHeader hdr;
   if (first != null) {
     hdr = (UnicastHeader) first.getHeader(id);
     if (hdr != null) sb.append("#" + hdr.seqno);
   }
   if (second != null) {
     hdr = (UnicastHeader) second.getHeader(id);
     if (hdr != null) sb.append(" - #" + hdr.seqno);
   }
   return sb.toString();
 }
Exemplo n.º 22
0
  /**
   * We need to resend our first message with our conn_id
   *
   * @param sender
   * @param seqno Resend messages in the range [lowest .. seqno]
   */
  private void handleResendingOfFirstMessage(Address sender, long seqno) {
    if (log.isTraceEnabled())
      log.trace(local_addr + " <-- SEND_FIRST_SEQNO(" + sender + "," + seqno + ")");
    SenderEntry entry = send_table.get(sender);
    AckSenderWindow win = entry != null ? entry.sent_msgs : null;
    if (win == null) {
      if (log.isErrorEnabled())
        log.error(local_addr + ": sender window for " + sender + " not found");
      return;
    }
    long lowest = win.getLowest();
    Message rsp = win.get(lowest);
    if (rsp == null) return;

    // 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);

    if (log.isTraceEnabled()) {
      StringBuilder sb = new StringBuilder();
      sb.append(local_addr)
          .append(" --> DATA(")
          .append(copy.getDest())
          .append(": #")
          .append(newhdr.seqno)
          .append(", conn_id=")
          .append(newhdr.conn_id);
      if (newhdr.first) sb.append(", first");
      sb.append(')');
      log.trace(sb);
    }
    down_prot.down(new Event(Event.MSG, copy));

    if (++lowest > seqno) return;
    for (long i = lowest; i <= seqno; i++) {
      rsp = win.get(i);
      if (rsp != null) down_prot.down(new Event(Event.MSG, rsp));
    }
  }
Exemplo n.º 23
0
  /**
   * Try to remove as many messages as possible from the table as pass them up. Prevents concurrent
   * passing up of messages by different threads (http://jira.jboss.com/jira/browse/JGRP-198); lots
   * of threads can come up to this point concurrently, but only 1 is allowed to pass at a time. We
   * *can* deliver messages from *different* senders concurrently, e.g. reception of P1, Q1, P2, Q2
   * can result in delivery of P1, Q1, Q2, P2: FIFO (implemented by UNICAST) says messages need to
   * be delivered in the order in which they were sent
   */
  protected int removeAndDeliver(
      final AtomicBoolean processing, Table<Message> win, Address sender) {
    int retval = 0;
    boolean released_processing = false;
    try {
      while (true) {
        List<Message> list = win.removeMany(processing, true, max_msg_batch_size);
        if (list == null) {
          released_processing = true;
          return retval;
        }

        MessageBatch batch = new MessageBatch(local_addr, sender, null, false, list);
        for (Message msg_to_deliver : batch) {
          // discard OOB msg: it has already been delivered
          // (http://jira.jboss.com/jira/browse/JGRP-377)
          if (msg_to_deliver.isFlagSet(Message.Flag.OOB)) batch.remove(msg_to_deliver);
        }

        try {
          if (log.isTraceEnabled()) {
            Message first = batch.first(), last = batch.last();
            StringBuilder sb = new StringBuilder(local_addr + ": delivering");
            if (first != null && last != null) {
              UnicastHeader hdr1 = (UnicastHeader) first.getHeader(id),
                  hdr2 = (UnicastHeader) last.getHeader(id);
              sb.append(" #").append(hdr1.seqno).append(" - #").append(hdr2.seqno);
            }
            sb.append(" (" + batch.size()).append(" messages)");
            log.trace(sb);
          }
          up_prot.up(batch);
        } catch (Throwable t) {
          log.error("failed to deliver batch " + batch, t);
        }
      }
    } finally {
      // processing is always set in win.remove(processing) above and never here ! This code is just
      // a
      // 2nd line of defense should there be an exception before win.remove(processing) sets
      // processing
      if (!released_processing) processing.set(false);
    }
  }
Exemplo n.º 24
0
 protected void sendStableMessage(Address dest, short conn_id, long hd, long hr) {
   Message stable_msg = new Message(dest, null, null);
   Unicast2Header hdr = Unicast2Header.createStableHeader(conn_id, hd, hr);
   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(hd)
         .append("-")
         .append(hr)
         .append(", conn_id=")
         .append(conn_id)
         .append(")");
     log.trace(sb.toString());
   }
   down_prot.down(new Event(Event.MSG, stable_msg));
 }
Exemplo n.º 25
0
  private void handleXmitRequest(Address sender, long low, long high) {
    if (log.isTraceEnabled())
      log.trace(
          new StringBuilder()
              .append(local_addr)
              .append(" <-- XMIT(")
              .append(sender)
              .append(": #")
              .append(low)
              .append("-")
              .append(high)
              .append(')'));

    SenderEntry entry = send_table.get(sender);
    AckSenderWindow win = entry != null ? entry.sent_msgs : null;
    if (win != null) {
      for (long i = low; i <= high; i++) {
        Message msg = win.get(i);
        if (msg == null) {
          if (log.isWarnEnabled() && !local_addr.equals(sender)) {
            StringBuilder sb = new StringBuilder();
            sb.append("(requester=").append(sender).append(", local_addr=").append(this.local_addr);
            sb.append(") message ").append(sender).append("::").append(i);
            sb.append(" not found in retransmission table of ")
                .append(sender)
                .append(":\n")
                .append(win);
            log.warn(sb.toString());
          }
          continue;
        }

        down_prot.down(new Event(Event.MSG, msg));
        num_xmits++;
      }
    }
  }
Exemplo n.º 26
0
  protected void handleXmitRequest(Address sender, SeqnoList missing) {
    if (log.isTraceEnabled())
      log.trace(
          new StringBuilder()
              .append(local_addr)
              .append(" <-- XMIT(")
              .append(sender)
              .append(": #")
              .append(missing)
              .append(')'));

    SenderEntry entry = send_table.get(sender);
    xmit_reqs_received.addAndGet(missing.size());
    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win != null) {
      for (long seqno : missing) {
        Message msg = win.get(seqno);
        if (msg == null) {
          if (log.isWarnEnabled() && !local_addr.equals(sender)) {
            StringBuilder sb = new StringBuilder();
            sb.append("(requester=").append(sender).append(", local_addr=").append(this.local_addr);
            sb.append(") message ").append(sender).append("::").append(seqno);
            sb.append(" not found in retransmission table of ")
                .append(sender)
                .append(":\n")
                .append(win);
            log.warn(sb.toString());
          }
          continue;
        }

        down_prot.down(new Event(Event.MSG, msg));
        xmit_rsps_sent.incrementAndGet();
      }
    }
  }
Exemplo n.º 27
0
 public String toStringShort() {
   StringBuilder sb = new StringBuilder();
   switch (type) {
     case RELEASE_LOCK:
       sb.append("U");
       break;
     case GRANT_LOCK:
       sb.append(is_trylock ? "TL" : "L");
       break;
     default:
       sb.append("N/A");
       break;
   }
   sb.append("(").append(lock_name).append(",").append(owner);
   if (timeout > 0) sb.append(",").append(timeout);
   sb.append(")");
   return sb.toString();
 }
Exemplo n.º 28
0
  @ManagedOperation
  public String printConnections() {
    StringBuilder sb = new StringBuilder();
    if (!send_table.isEmpty()) {
      sb.append("send connections:\n");
      for (Map.Entry<Address, SenderEntry> entry : send_table.entrySet()) {
        sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
      }
    }

    if (!recv_table.isEmpty()) {
      sb.append("\nreceive connections:\n");
      for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) {
        sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
      }
    }
    return sb.toString();
  }
Exemplo n.º 29
0
 public void viewAccepted(View new_view) {
   events.append('v');
 }
Exemplo n.º 30
0
 public String getEventSequence() {
   return events.toString();
 }