Пример #1
0
 private static void setStableGossip(JChannel... channels) {
   for (Channel channel : channels) {
     ProtocolStack stack = channel.getProtocolStack();
     STABLE stable = (STABLE) stack.findProtocol(STABLE.class);
     stable.setDesiredAverageGossip(2000);
   }
 }
Пример #2
0
  /**
   * Tests sending 1, 2 (OOB) and 3, where they are received in the order 1, 3, 2. Message 3 should
   * not get delivered until message 4 is received (http://jira.jboss.com/jira/browse/JGRP-780)
   */
  public void testRegularAndOOBUnicasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class);

    Address dest = b.getAddress();
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownUnicasts(1);
    a.send(m2);
    a.send(m3);

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 3 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(a, b);
    }

    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
 private static void disableBundling(JChannel ch) {
   ProtocolStack stack = ch.getProtocolStack();
   TP transport = stack.getTransport();
   if (transport != null) {
     transport.setEnableBundling(false);
   }
 }
Пример #4
0
  public void testRegularAndOOBUnicasts2() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(
        discard, ProtocolStack.BELOW, (Class<? extends Protocol>[]) Util.getUnicastProtocols());

    Address dest = b.getAddress();
    Message m1 = new Message(dest, 1);
    Message m2 = new Message(dest, 2).setFlag(Message.Flag.OOB);
    Message m3 = new Message(dest, 3).setFlag(Message.Flag.OOB);
    Message m4 = new Message(dest, 4);

    MyReceiver receiver = new MyReceiver("B");
    b.setReceiver(receiver);
    a.send(m1);

    discard.setDropDownUnicasts(2);
    a.send(m2); // dropped
    a.send(m3); // dropped
    a.send(m4);

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 4 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(a, b);
    }
    System.out.println("list = " + list);
    assert list.size() == 4 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4);
  }
Пример #5
0
  public void testRegularAndOOBMulticasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class);
    a.setDiscardOwnMessages(true);

    Address dest = null; // send to all
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownMulticasts(1);
    a.send(m2);
    a.send(m3);

    Util.sleep(500);
    Collection<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 10; i++) {
      System.out.println("list = " + list);
      if (list.size() == 3) break;
      Util.sleep(1000); // give the asynchronous msgs some time to be received
      sendStableMessages(a, b);
    }
    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
 public static DISCARD getDiscardForCache(Cache<?, ?> c) throws Exception {
   JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractComponent(c, Transport.class);
   Channel ch = jgt.getChannel();
   ProtocolStack ps = ch.getProtocolStack();
   DISCARD discard = new DISCARD();
   ps.insertProtocol(discard, ProtocolStack.ABOVE, TP.class);
   return discard;
 }
 private static void modifyConfigs(JChannel... channels) throws Exception {
   for (JChannel ch : channels) {
     ProtocolStack stack = ch.getProtocolStack();
     stack.removeProtocol("MERGE2");
     stack.removeProtocol("VERIFY_SUSPECT");
     stack.removeProtocol("FC");
   }
 }
Пример #8
0
 protected void discard(boolean flag, JChannel... channels) throws Exception {
   for (JChannel ch : channels) {
     ProtocolStack stack = ch.getProtocolStack();
     DISCARD discard = (DISCARD) stack.findProtocol(DISCARD.class);
     if (discard == null)
       stack.insertProtocol(
           discard = new DISCARD(), ProtocolStack.ABOVE, stack.getTransport().getClass());
     discard.setDiscardAll(flag);
   }
 }
 /**
  * Inserts a DELAY protocol in the JGroups stack used by the cache, and returns it. The DELAY
  * protocol can then be used to inject delays in milliseconds both at receiver and sending side.
  *
  * @param cache
  * @param in_delay_millis
  * @param out_delay_millis
  * @return a reference to the DELAY instance being used by the JGroups stack
  * @throws Exception
  */
 public static DELAY setDelayForCache(Cache<?, ?> cache, int in_delay_millis, int out_delay_millis)
     throws Exception {
   JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractComponent(cache, Transport.class);
   Channel ch = jgt.getChannel();
   ProtocolStack ps = ch.getProtocolStack();
   DELAY delay = new DELAY();
   delay.setInDelay(in_delay_millis);
   delay.setOutDelay(out_delay_millis);
   ps.insertProtocol(delay, ProtocolStack.ABOVE, TP.class);
   return delay;
 }
Пример #10
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);
    }
  }
Пример #11
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);
  }
  @BeforeMethod
  protected void setup() throws Exception {
    receiver = new MockProtocol();
    nak = (NAKACK2) new NAKACK2().setValue("use_mcast_xmit", false);
    transport = new MockTransport();
    ProtocolStack stack = new ProtocolStack();
    stack.addProtocols(transport, nak, receiver);
    stack.init();

    nak.down(new Event(Event.BECOME_SERVER));
    nak.down(new Event(Event.SET_LOCAL_ADDRESS, A));
    Digest digest = new Digest(view.getMembersRaw(), new long[] {0, 0, 0, 0});
    nak.down(new Event(Event.SET_DIGEST, digest));
  }
Пример #13
0
 protected TimeScheduler getTimer() {
   if (prot_stack != null) {
     TP transport = prot_stack.getTransport();
     if (transport != null) return transport.getTimer();
   }
   return null;
 }
Пример #14
0
  @Test(invocationCount = 5)
  @SuppressWarnings("unchecked")
  public void testRandomRegularAndOOBMulticasts() throws Exception {
    DISCARD discard = new DISCARD();
    discard.setLocalAddress(a.getAddress());
    discard.setDownDiscardRate(0.5);
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class);
    MyReceiver r1 = new MyReceiver("C1"), r2 = new MyReceiver("C2");
    a.setReceiver(r1);
    b.setReceiver(r2);
    final int NUM_MSGS = 20;
    final int NUM_THREADS = 10;

    send(null, NUM_MSGS, NUM_THREADS, 0.5); // send on random channel (c1 or c2)

    Collection<Integer> one = r1.getMsgs(), two = r2.getMsgs();
    for (int i = 0; i < 10; i++) {
      if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break;
      System.out.println("one size " + one.size() + ", two size " + two.size());
      Util.sleep(1000);
      sendStableMessages(a, b);
    }
    System.out.println("one size " + one.size() + ", two size " + two.size());

    stack.removeProtocol("DISCARD");

    for (int i = 0; i < 5; i++) {
      if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break;
      sendStableMessages(a, b);
      Util.sleep(500);
    }
    System.out.println(
        "C1 received "
            + one.size()
            + " messages ("
            + NUM_MSGS
            + " expected)"
            + "\nC2 received "
            + two.size()
            + " messages ("
            + NUM_MSGS
            + " expected)");

    check(NUM_MSGS, one, two);
  }
Пример #15
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)
  }
Пример #16
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);
 }
Пример #17
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;
 }
Пример #18
0
 private static void changeProperties(JChannel ch) {
   ch.setOpt(Channel.AUTO_RECONNECT, true);
   ProtocolStack stack = ch.getProtocolStack();
   GMS gms = (GMS) stack.findProtocol("GMS");
   if (gms != null) {
     gms.setViewBundling(true);
     gms.setMaxBundlingTime(300);
     gms.setPrintLocalAddr(false);
   }
   MERGE2 merge = (MERGE2) stack.findProtocol("MERGE2");
   if (merge != null) {
     merge.setMinInterval(2000);
     merge.setMaxInterval(5000);
   }
   VIEW_SYNC sync = (VIEW_SYNC) stack.findProtocol(VIEW_SYNC.class);
   if (sync != null) sync.setAverageSendInterval(5000);
   NAKACK nakack = (NAKACK) stack.findProtocol(NAKACK.class);
   if (nakack != null) nakack.setLogDiscardMsgs(false);
 }
Пример #19
0
  private void createChannels(
      boolean copy_multicasts,
      boolean copy_unicasts,
      int num_outgoing_copies,
      int num_incoming_copies)
      throws Exception {
    c1 = createChannel(true, 3);
    DUPL dupl = new DUPL(copy_multicasts, copy_unicasts, num_incoming_copies, num_outgoing_copies);
    ProtocolStack stack = c1.getProtocolStack();
    stack.insertProtocol(dupl, ProtocolStack.BELOW, NAKACK.class);

    c2 = createChannel(c1);
    c3 = createChannel(c1);

    c1.connect("DuplicateTest");
    c2.connect("DuplicateTest");
    c3.connect("DuplicateTest");

    Util.waitUntilAllChannelsHaveSameSize(20000, 1000, c1, c2, c3);
  }
Пример #20
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);
  }
Пример #21
0
  public ProtocolTester(String prot_spec, Protocol harness) throws Exception {
    if (prot_spec == null || harness == null)
      throw new Exception("ProtocolTester(): prot_spec or harness is null");

    props = prot_spec;
    this.harness = harness;
    props = "LOOPBACK:" + props; // add a loopback layer at the bottom of the stack

    config = new Configurator();
    JChannel mock_channel = new JChannel() {};
    ProtocolStack stack = new ProtocolStack(mock_channel);
    stack.setup(Configurator.parseConfigurations(props));
    stack.insertProtocol(harness, ProtocolStack.ABOVE, stack.getTopProtocol().getClass());

    bottom = stack.getBottomProtocol();

    // has to be set after StartProtocolStack, otherwise the up and down handler threads in the
    // harness
    // will be started as well (we don't want that) !
    // top.setUpProtocol(harness);
  }
Пример #22
0
 public StackPanel(JChannel channel) {
   super();
   setBorder(BorderFactory.createTitledBorder("ProtocolStack"));
   this.setLayout(new GridLayout(0, 2));
   this.stack = channel.getProtocolStack();
   Iterator iter = stack.getProtocols().iterator();
   String debugLevels[] = new String[] {"DEBUG", "INFO", "ERROR"};
   while (iter.hasNext()) {
     Protocol p = (Protocol) iter.next();
     JLabel field = new JLabel(p.getName());
     JComboBox pane = new JComboBox(debugLevels);
     this.add(field);
     this.add(pane);
   }
 }
Пример #23
0
    protected void makeUnique(Channel channel, int num, String mcast_address) throws Exception {
      ProtocolStack stack = channel.getProtocolStack();
      Protocol transport = stack.getTransport();

      if (transport instanceof UDP) {
        short mcast_port = ResourceManager.getNextMulticastPort(InetAddress.getByName(bind_addr));
        ((UDP) transport).setMulticastPort(mcast_port);
        if (mcast_address != null) {
          ((UDP) transport).setMulticastAddress(InetAddress.getByName(mcast_address));
        } else {
          String mcast_addr = ResourceManager.getNextMulticastAddress();
          ((UDP) transport).setMulticastAddress(InetAddress.getByName(mcast_addr));
        }
      } else if (transport instanceof BasicTCP) {
        List<Integer> ports =
            ResourceManager.getNextTcpPorts(InetAddress.getByName(bind_addr), num);
        ((TP) transport).setBindPort(ports.get(0));
        // ((TP) transport).setPortRange(num);

        Protocol ping = stack.findProtocol(TCPPING.class);
        if (ping == null)
          throw new IllegalStateException(
              "TCP stack must consist of TCP:TCPPING - other config are not supported");

        List<String> initial_hosts =
            ports
                .stream()
                .map(port -> String.format("%s[%d]", bind_addr, port))
                .collect(Collectors.toList());
        String tmp = Util.printListWithDelimiter(initial_hosts, ",", 2000, false);
        List<PhysicalAddress> init_hosts = Util.parseCommaDelimitedHosts(tmp, 0);
        ((TCPPING) ping).setInitialHosts(init_hosts);
      } else {
        throw new IllegalStateException("Only UDP and TCP are supported as transport protocols");
      }
    }
Пример #24
0
  public void testRegularAndOOBUnicasts2() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = c1.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class);

    Address dest = c2.getAddress();
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);
    m3.setFlag(Message.OOB);
    Message m4 = new Message(dest, null, 4);

    MyReceiver receiver = new MyReceiver("C2");
    c2.setReceiver(receiver);
    c1.send(m1);

    discard.setDropDownUnicasts(1);
    c1.send(m3);

    discard.setDropDownUnicasts(1);
    c1.send(m2);

    c1.send(m4);
    Util.sleep(1000); // sleep some time to receive all messages

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 4 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(c1, c2);
    }
    log.info("list = " + list);
    assert list.size() == 4 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4);
  }
Пример #25
0
 public void setProtocolStack(ProtocolStack stack) {
   this.prot_stack = stack;
   if (prot_stack != null) prot_stack.setChannel(this);
 }
Пример #26
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;
 }
Пример #27
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;
 }
Пример #28
0
 public Map<String, Object> dumpStats(String protocol_name, List<String> attrs) {
   return prot_stack.dumpStats(protocol_name, attrs);
 }
Пример #29
0
 @ManagedOperation
 public Map<String, Object> dumpStats(String protocol_name) {
   return prot_stack.dumpStats(protocol_name, null);
 }
Пример #30
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)
 }