예제 #1
0
  /**
   * Block the given sourceToBlock address for the given multicastAddress on the given
   * networkInterface
   */
  @Override
  public ChannelFuture block(
      InetAddress multicastAddress,
      NetworkInterface networkInterface,
      InetAddress sourceToBlock,
      ChannelPromise promise) {
    checkJavaVersion();

    if (multicastAddress == null) {
      throw new NullPointerException("multicastAddress");
    }
    if (sourceToBlock == null) {
      throw new NullPointerException("sourceToBlock");
    }

    if (networkInterface == null) {
      throw new NullPointerException("networkInterface");
    }
    synchronized (this) {
      if (memberships != null) {
        List<MembershipKey> keys = memberships.get(multicastAddress);
        for (MembershipKey key : keys) {
          if (networkInterface.equals(key.networkInterface())) {
            try {
              key.block(sourceToBlock);
            } catch (IOException e) {
              promise.setFailure(e);
            }
          }
        }
      }
    }
    promise.setSuccess();
    return promise;
  }
예제 #2
0
  @Override
  public ChannelFuture leaveGroup(
      InetAddress multicastAddress,
      NetworkInterface networkInterface,
      InetAddress source,
      ChannelPromise promise) {
    if (PlatformDependent.javaVersion() < 7) {
      throw new UnsupportedOperationException();
    }
    if (multicastAddress == null) {
      throw new NullPointerException("multicastAddress");
    }
    if (networkInterface == null) {
      throw new NullPointerException("networkInterface");
    }

    synchronized (this) {
      if (memberships != null) {
        List<MembershipKey> keys = memberships.get(multicastAddress);
        if (keys != null) {
          Iterator<MembershipKey> keyIt = keys.iterator();

          while (keyIt.hasNext()) {
            MembershipKey key = keyIt.next();
            if (networkInterface.equals(key.networkInterface())) {
              if (source == null && key.sourceAddress() == null
                  || source != null && source.equals(key.sourceAddress())) {
                key.drop();
                keyIt.remove();
              }
            }
          }
          if (keys.isEmpty()) {
            memberships.remove(multicastAddress);
          }
        }
      }
    }

    promise.setSuccess();
    return promise;
  }