コード例 #1
0
ファイル: Discovery.java プロジェクト: DevFactory/JGroups
  /**
   * Disseminates cache information (UUID/IP adddress/port/name) to the given members
   *
   * @param current_mbrs The current members. Guaranteed to be non-null. This is a copy and can be
   *     modified.
   * @param left_mbrs The members which left. These are excluded from dissemination. Can be null if
   *     no members left
   * @param new_mbrs The new members that we need to disseminate the information to. Will be all
   *     members if null.
   */
  protected void disseminateDiscoveryInformation(
      List current_mbrs, List<Address> left_mbrs, List<Address> new_mbrs) {
    if (new_mbrs == null || new_mbrs.isEmpty()) return;

    if (local_addr != null) current_mbrs.remove(local_addr);
    if (left_mbrs != null) current_mbrs.removeAll(left_mbrs);

    // 1. Send information about <everyone - self - left_mbrs> to new_mbrs
    Set<Address> info = new HashSet<>(current_mbrs);
    for (Address addr : info) {
      PhysicalAddress phys_addr =
          (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, addr));
      if (phys_addr == null) continue;
      boolean is_coordinator = isCoord(addr);
      for (Address target : new_mbrs)
        sendDiscoveryResponse(addr, phys_addr, UUID.get(addr), target, is_coordinator);
    }

    // 2. Send information about new_mbrs to <everyone - self - left_mbrs - new_mbrs>
    Set<Address> targets = new HashSet<>(current_mbrs);
    targets.removeAll(new_mbrs);

    if (!targets.isEmpty()) {
      for (Address addr : new_mbrs) {
        PhysicalAddress phys_addr =
            (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, addr));
        if (phys_addr == null) continue;
        boolean is_coordinator = isCoord(addr);
        for (Address target : targets)
          sendDiscoveryResponse(addr, phys_addr, UUID.get(addr), target, is_coordinator);
      }
    }
  }
コード例 #2
0
ファイル: UtilTest.java プロジェクト: Sk464036801/JGroups
 public static void testAll() {
   List<String> l = new ArrayList<>();
   l.add("one");
   l.add("two");
   l.add("one");
   System.out.println("-- list is " + l);
   assert !(Util.all(l, "one"));
   l.remove("two");
   System.out.println("-- list is " + l);
   assert Util.all(l, "one");
 }
コード例 #3
0
ファイル: Discovery.java プロジェクト: randythomas/JGroups
    public void addResponse(PingData rsp, boolean overwrite) {
      if (rsp == null) return;
      promise.getLock().lock();
      try {
        if (overwrite) ping_rsps.remove(rsp);

        // https://jira.jboss.org/jira/browse/JGRP-1179
        int index = ping_rsps.indexOf(rsp);
        if (index == -1) {
          ping_rsps.add(rsp);
          promise.getCond().signalAll();
        } else if (rsp.isCoord()) {
          PingData pr = ping_rsps.get(index);

          // Check if the already existing element is not server
          if (!pr.isCoord()) {
            ping_rsps.set(index, rsp);
            promise.getCond().signalAll();
          }
        }
      } finally {
        promise.getLock().unlock();
      }
    }
コード例 #4
0
ファイル: JChannel.java プロジェクト: schaebo/JGroups
 public boolean removeAddressGenerator(AddressGenerator address_generator) {
   return address_generator != null
       && address_generators != null
       && address_generators.remove(address_generator);
 }
コード例 #5
0
  /** @return true if the channel was removed indeed. */
  public boolean removeChannelListener(ChannelListener l) {

    synchronized (additionalChannelListeners) {
      return additionalChannelListeners.remove(l);
    }
  }
コード例 #6
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;
  }