Пример #1
0
 public void setChannel(Channel ch) {
   if (ch == null) return;
   this.channel = ch;
   local_addr = channel.getAddress();
   if (prot_adapter == null) prot_adapter = new ProtocolAdapter();
   // Don't force installing the UpHandler so subclasses can use this
   // method and still integrate with a MuxUpHandler
   installUpHandler(prot_adapter, false);
 }
Пример #2
0
  public void testMergeWithAsymetricViewsCoordIsolated() {
    // Isolate the coord
    Address coord = a.getView().getCreator();
    System.out.println("Isolating coord: " + coord);
    List<Address> members = new ArrayList<>();
    members.add(coord);
    View coord_view = new View(coord, 4, members);
    System.out.println("coord_view: " + coord_view);
    Channel coord_channel = findChannel(coord);
    System.out.println("coord_channel: " + coord_channel.getAddress());

    MutableDigest digest = new MutableDigest(coord_view.getMembersRaw());
    NAKACK2 nakack = (NAKACK2) coord_channel.getProtocolStack().findProtocol(NAKACK2.class);
    digest.merge(nakack.getDigest(coord));

    GMS gms = (GMS) coord_channel.getProtocolStack().findProtocol(GMS.class);
    gms.installView(coord_view, digest);
    System.out.println("gms.getView() " + gms.getView());

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getAddress() + ": " + ch.getView());

    JChannel merge_leader = findChannel(coord);
    MyReceiver receiver = new MyReceiver();
    merge_leader.setReceiver(receiver);

    System.out.println("merge_leader: " + merge_leader.getAddressAsString());

    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(4);
    merge_views.put(a.getAddress(), a.getView());
    merge_views.put(b.getAddress(), b.getView());
    merge_views.put(c.getAddress(), c.getView());
    merge_views.put(d.getAddress(), d.getView());

    gms = (GMS) merge_leader.getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, merge_views));

    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b, c, d);

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      View view = ch.getView();
      System.out.println(ch.getAddress() + ": " + view);
      assert view.size() == 4;
    }
    MergeView merge_view = receiver.getView();
    System.out.println("merge_view = " + merge_view);
    assert merge_view.size() == 4;
    assert merge_view.getSubgroups().size() == 2;

    for (View view : merge_view.getSubgroups())
      assert contains(view, a.getAddress())
          || contains(view, b.getAddress(), c.getAddress(), d.getAddress());
  }
Пример #3
0
 public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2) {
   this.channel = channel;
   prot_adapter = new ProtocolAdapter();
   if (channel != null) {
     local_addr = channel.getAddress();
     channel.addChannelListener(this);
   }
   setMessageListener(l);
   setMembershipListener(l2);
   if (channel != null) installUpHandler(prot_adapter, true);
   start();
 }
Пример #4
0
  protected <T> GroupRequest<T> cast(
      final Collection<Address> dests,
      Message msg,
      RequestOptions options,
      boolean block_for_results,
      FutureListener<RspList<T>> listener)
      throws Exception {
    if (msg.getDest() != null && !(msg.getDest() instanceof AnycastAddress))
      throw new IllegalArgumentException("message destination is non-null, cannot send message");

    if (options != null) {
      msg.setFlag(options.getFlags()).setTransientFlag(options.getTransientFlags());
      if (options.getScope() > 0) msg.setScope(options.getScope());
    }

    List<Address> real_dests;
    // we need to clone because we don't want to modify the original
    if (dests != null) {
      real_dests = new ArrayList<Address>();
      for (Address dest : dests) {
        if (dest instanceof SiteAddress || this.members.contains(dest)) {
          if (!real_dests.contains(dest)) real_dests.add(dest);
        }
      }
    } else real_dests = new ArrayList<Address>(members);

    // if local delivery is off, then we should not wait for the message from the local member.
    // therefore remove it from the membership
    Channel tmp = channel;
    if ((tmp != null && tmp.getDiscardOwnMessages())
        || msg.isTransientFlagSet(Message.TransientFlag.DONT_LOOPBACK)) {
      if (local_addr == null) local_addr = tmp != null ? tmp.getAddress() : null;
      if (local_addr != null) real_dests.remove(local_addr);
    }

    if (options != null && options.hasExclusionList()) {
      Address[] exclusion_list = options.exclusionList();
      for (Address excluding : exclusion_list) real_dests.remove(excluding);
    }

    // don't even send the message if the destination list is empty
    if (log.isTraceEnabled()) log.trace("real_dests=" + real_dests);

    if (real_dests.isEmpty()) {
      if (log.isTraceEnabled()) log.trace("destination list is empty, won't send message");
      return null;
    }

    if (options != null) {
      boolean async = options.getMode() == ResponseMode.GET_NONE;
      if (options.getAnycasting()) {
        if (async) async_anycasts.incrementAndGet();
        else sync_anycasts.incrementAndGet();
      } else {
        if (async) async_multicasts.incrementAndGet();
        else sync_multicasts.incrementAndGet();
      }
    }

    GroupRequest<T> req = new GroupRequest<T>(msg, corr, real_dests, options);
    if (listener != null) req.setListener(listener);
    if (options != null) {
      req.setResponseFilter(options.getRspFilter());
      req.setAnycasting(options.getAnycasting());
    }
    req.setBlockForResults(block_for_results);
    req.execute();
    return req;
  }