示例#1
0
  /**
   * Creates a channel from an array of protocols. Note that after a {@link
   * org.jgroups.JChannel#close()}, the protocol list <em>should not</em> be reused, ie. new
   * JChannel(protocols) would reuse the same protocol list, and this might lead to problems !
   *
   * @param protocols The list of protocols, from bottom to top, ie. the first protocol in the list
   *     is the transport, the last the top protocol
   * @throws Exception
   */
  public JChannel(Collection<Protocol> protocols) throws Exception {
    prot_stack = new ProtocolStack();
    setProtocolStack(prot_stack);
    for (Protocol prot : protocols) {
      prot_stack.addProtocol(prot);
      prot.setProtocolStack(prot_stack);
    }
    prot_stack.init();

    // Substitute vars with defined system props (if any)
    List<Protocol> prots = prot_stack.getProtocols();
    Map<String, String> map = new HashMap<>();
    for (Protocol prot : prots) Configurator.resolveAndAssignFields(prot, map);
  }
示例#2
0
  protected void stopStack(boolean stop, boolean destroy) {
    if (prot_stack != null) {
      try {
        if (stop) prot_stack.stopStack(cluster_name);

        if (destroy) prot_stack.destroy();
      } catch (Exception e) {
        log.error(Util.getMessage("StackDestroyFailure"), e);
      }

      TP transport = prot_stack.getTransport();
      if (transport != null) transport.unregisterProbeHandler(probe_handler);
    }
  }
示例#3
0
 protected TimeScheduler getTimer() {
   if (prot_stack != null) {
     TP transport = prot_stack.getTransport();
     if (transport != null) return transport.getTimer();
   }
   return null;
 }
示例#4
0
  protected final void init(ProtocolStackConfigurator configurator) throws Exception {
    List<ProtocolConfiguration> configs = configurator.getProtocolStack();
    // replace vars with system props
    configs.forEach(ProtocolConfiguration::substituteVariables);

    prot_stack = new ProtocolStack(this);
    prot_stack.setup(configs); // Setup protocol stack (creates protocol, calls init() on them)
  }
示例#5
0
 /**
  * Sends an event down the protocol stack. Note that - contrary to {@link #send(Message)}, if the
  * event is a message, no checks are performed whether the channel is closed or disconnected.
  *
  * @param evt the message to send down, encapsulated in an event
  */
 public Object down(Event evt) {
   if (evt == null) return null;
   if (stats && evt.getType() == Event.MSG) {
     sent_msgs++;
     sent_bytes += ((Message) evt.getArg()).getLength();
   }
   return prot_stack.down(evt);
 }
示例#6
0
 @ManagedOperation
 public Map<String, Object> dumpStats() {
   Map<String, Object> retval = prot_stack.dumpStats();
   if (retval != null) {
     Map<String, Long> tmp = dumpChannelStats();
     if (tmp != null) retval.put("channel", tmp);
   }
   return retval;
 }
示例#7
0
  protected void startStack(String cluster_name) throws Exception {
    /*make sure the channel is not closed*/
    checkClosed();

    /*make sure we have a valid channel name*/
    if (cluster_name == null) log.debug("cluster_name is null, assuming unicast channel");
    else this.cluster_name = cluster_name;

    if (socket_factory != null) prot_stack.getTopProtocol().setSocketFactory(socket_factory);

    prot_stack.startStack(
        cluster_name, local_addr); // calls start() in all protocols, from top to bottom

    /*create a temporary view, assume this channel is the only member and is the coordinator*/
    List<Address> t = new ArrayList<>(1);
    t.add(local_addr);
    my_view = new View(local_addr, 0, t); // create a dummy view

    TP transport = prot_stack.getTransport();
    transport.registerProbeHandler(probe_handler);
  }
示例#8
0
 protected final void init(JChannel ch) throws Exception {
   if (ch == null) throw new IllegalArgumentException("channel is null");
   prot_stack = new ProtocolStack(this);
   prot_stack.setup(
       ch.getProtocolStack()); // Setup protocol stack (creates protocol, calls init() on them)
 }
示例#9
0
 @ManagedOperation
 public Map<String, Object> dumpStats(String protocol_name) {
   return prot_stack.dumpStats(protocol_name, null);
 }
示例#10
0
 public Map<String, Object> dumpStats(String protocol_name, List<String> attrs) {
   return prot_stack.dumpStats(protocol_name, attrs);
 }
示例#11
0
 /**
  * Returns a pretty-printed form of all the protocols. If include_properties is set, the
  * properties for each protocol will also be printed.
  */
 @ManagedOperation
 public String printProtocolSpec(boolean include_properties) {
   ProtocolStack ps = getProtocolStack();
   return ps != null ? ps.printProtocolSpec(include_properties) : null;
 }
示例#12
0
 /**
  * Returns the protocol stack configuration in string format. An example of this property is<br>
  * "UDP:PING:FD:STABLE:NAKACK:UNICAST:FRAG:FLUSH:GMS:VIEW_ENFORCER:STATE_TRANSFER:QUEUE"
  */
 public String getProperties() {
   return prot_stack != null ? prot_stack.printProtocolSpec(true) : null;
 }
示例#13
0
 public void setProtocolStack(ProtocolStack stack) {
   this.prot_stack = stack;
   if (prot_stack != null) prot_stack.setChannel(this);
 }