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();
 }
 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);
 }
  public void stop() {
    if (corr != null) corr.stop();

    if (channel instanceof JChannel) {
      TP transport = channel.getProtocolStack().getTransport();
      transport.unregisterProbeHandler(probe_handler);
      corr.unregisterProbeHandler(transport);
    }
  }
 @Deprecated
 public RpcDispatcher(
     Channel channel,
     MessageListener l,
     MembershipListener l2,
     Object server_obj,
     boolean deadlock_detection) {
   super(channel, l, l2);
   channel.addChannelListener(this);
   this.server_obj = server_obj;
 }
  public void start() {
    if (corr == null)
      corr =
          createRequestCorrelator(prot_adapter, this, local_addr)
              .asyncDispatching(async_dispatching);
    correlatorStarted();
    corr.start();

    if (channel != null) {
      List<Address> tmp_mbrs = channel.getView() != null ? channel.getView().getMembers() : null;
      setMembers(tmp_mbrs);
      if (channel instanceof JChannel) {
        TP transport = channel.getProtocolStack().getTransport();
        corr.registerProbeHandler(transport);
      }
      TP transport = channel.getProtocolStack().getTransport();
      hardware_multicast_supported = transport.supportsMulticasting();
      transport.registerProbeHandler(probe_handler);
    }
  }
 @Deprecated
 public RpcDispatcher(
     Channel channel,
     MessageListener l,
     MembershipListener l2,
     Object server_obj,
     boolean deadlock_detection,
     boolean concurrent_processing) {
   super(channel, l, l2, false, concurrent_processing);
   channel.addChannelListener(this);
   this.server_obj = server_obj;
 }
 /**
  * Sets the given UpHandler as the UpHandler for the channel, or, if the channel already has a
  * Muxer installed as it's UpHandler, sets the given handler as the Muxer's {@link
  * Muxer#setDefaultHandler(Object) default handler}. If the relevant handler is already installed,
  * the <code>canReplace</code> controls whether this method replaces it (after logging a WARN) or
  * simply leaves <code>handler</code> uninstalled.
  *
  * <p>Passing <code>false</code> as the <code>canReplace</code> value allows callers to use this
  * method to install defaults without concern about inadvertently overriding
  *
  * @param handler the UpHandler to install
  * @param canReplace <code>true</code> if an existing Channel upHandler or Muxer default upHandler
  *     can be replaced; <code>false</code> if this method shouldn't install
  */
 protected void installUpHandler(UpHandler handler, boolean canReplace) {
   UpHandler existing = channel.getUpHandler();
   if (existing == null) {
     channel.setUpHandler(handler);
   } else if (existing instanceof Muxer<?>) {
     @SuppressWarnings("unchecked")
     Muxer<UpHandler> mux = (Muxer<UpHandler>) existing;
     if (mux.getDefaultHandler() == null) {
       mux.setDefaultHandler(handler);
     } else if (canReplace) {
       log.warn(
           "Channel Muxer already has a default up handler installed ("
               + mux.getDefaultHandler()
               + ") but now it is being overridden");
       mux.setDefaultHandler(handler);
     }
   } else if (canReplace) {
     log.warn(
         "Channel already has an up handler installed ("
             + existing
             + ") but now it is being overridden");
     channel.setUpHandler(handler);
   }
 }
  @Deprecated
  public RpcDispatcher(
      PullPushAdapter adapter,
      Serializable id,
      MessageListener l,
      MembershipListener l2,
      Object server_obj) {
    super(adapter, id, l, l2);

    // Fixes bug #804956
    // channel.setChannelListener(this);
    if (this.adapter != null) {
      Transport t = this.adapter.getTransport();
      if (t != null && t instanceof Channel) {
        ((Channel) t).addChannelListener(this);
      }
    }

    this.server_obj = server_obj;
  }
 public RpcDispatcher(
     Channel channel, MessageListener l, MembershipListener l2, Object server_obj) {
   super(channel, l, l2);
   channel.addChannelListener(this);
   this.server_obj = server_obj;
 }
  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;
  }