Exemplo n.º 1
0
  /** Tests https://jira.jboss.org/jira/browse/JGRP-1079 */
  public void testOOBMessageLoss() throws Exception {
    Util.close(b); // we only need 1 channel
    MyReceiver receiver = new MySleepingReceiver("C1", 1000);
    a.setReceiver(receiver);

    TP transport = a.getProtocolStack().getTransport();
    transport.setOOBRejectionPolicy("discard");

    final int NUM = 10;

    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(null, null, i);
      msg.setFlag(Message.OOB);
      a.send(msg);
    }
    STABLE stable = (STABLE) a.getProtocolStack().findProtocol(STABLE.class);
    if (stable != null) stable.runMessageGarbageCollection();
    Collection<Integer> msgs = receiver.getMsgs();

    for (int i = 0; i < 20; i++) {
      if (msgs.size() == NUM) break;
      Util.sleep(1000);
      sendStableMessages(a, b);
    }

    System.out.println("msgs = " + Util.print(msgs));

    assert msgs.size() == NUM
        : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs);
    for (int i = 1; i <= NUM; i++) {
      assert msgs.contains(i);
    }
  }
Exemplo n.º 2
0
 private static void setOOBPoolSize(JChannel... channels) {
   for (Channel channel : channels) {
     TP transport = channel.getProtocolStack().getTransport();
     transport.setOOBThreadPoolMinThreads(1);
     transport.setOOBThreadPoolMaxThreads(2);
   }
 }
 private static void disableBundling(JChannel ch) {
   ProtocolStack stack = ch.getProtocolStack();
   TP transport = stack.getTransport();
   if (transport != null) {
     transport.setEnableBundling(false);
   }
 }
Exemplo n.º 4
0
 protected TimeScheduler getTimer() {
   if (prot_stack != null) {
     TP transport = prot_stack.getTransport();
     if (transport != null) return transport.getTimer();
   }
   return null;
 }
Exemplo n.º 5
0
  public void stop() {
    if (corr != null) corr.stop();

    if (channel instanceof JChannel) {
      TP transport = channel.getProtocolStack().getTransport();
      transport.unregisterProbeHandler(probe_handler);
      corr.unregisterProbeHandler(transport);
    }
  }
Exemplo n.º 6
0
 public void init() throws Exception {
   if (view_ack_collection_timeout <= 0)
     throw new IllegalArgumentException("view_ack_collection_timeout has to be greater than 0");
   if (merge_timeout <= 0)
     throw new IllegalArgumentException("merge_timeout has to be greater than 0");
   prev_members = new BoundedList<Address>(num_prev_mbrs);
   prev_views = new BoundedList<Tuple<View, Long>>(num_prev_views);
   TP transport = getTransport();
   timer = transport.getTimer();
   if (timer == null) throw new Exception("timer is null");
   if (impl != null) impl.init();
   transport.registerProbeHandler(this);
 }
Exemplo n.º 7
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);
    }
  }
Exemplo n.º 8
0
  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);
    }
  }
Exemplo n.º 9
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);
  }
Exemplo n.º 10
0
  @Override
  public Channel createChannel(String id) throws Exception {
    JChannel channel = new MuxChannel(this);

    // We need to synchronize on shared transport,
    // so we don't attempt to init a shared transport multiple times
    TP transport = channel.getProtocolStack().getTransport();
    if (transport.isSingleton()) {
      synchronized (transport) {
        this.init(transport);
      }
    } else {
      this.init(transport);
    }

    channel.setName(configuration.getEnvironment().getNodeName() + "/" + id);

    TransportConfiguration transportConfiguration = this.configuration.getTransport();
    if (transportConfiguration.hasTopology()) {
      channel.setAddressGenerator(
          new TopologyAddressGenerator(
              channel,
              transportConfiguration.getSiteId(),
              transportConfiguration.getRackId(),
              transportConfiguration.getMachineId()));
    }

    MBeanServer server = this.configuration.getMBeanServer();
    if (server != null) {
      try {
        this.channels.put(channel, id);
        JmxConfigurator.registerChannel(channel, server, id);
      } catch (Exception e) {
        ROOT_LOGGER.warn(e.getMessage(), e);
      }
      channel.addChannelListener(this);
    }

    return channel;
  }
Exemplo n.º 11
0
 void runServer() throws Exception {
   System.setProperty("jgroups.bind_addr", host);
   if (port > 0) {
     Protocol transport = ch.getProtocolStack().getTransport();
     if (transport instanceof TP) {
       ((TP) transport).setBindPort(port);
     }
   }
   ch.connect(null); // this makes it a unicast channel
   System.out.println(
       "server started at " + new java.util.Date() + ", listening on " + ch.getAddress());
   while (ch.isOpen()) {
     Util.sleep(10000);
   }
 }
Exemplo n.º 12
0
 private void init(TP transport) {
   TransportConfiguration transportConfig = this.configuration.getTransport();
   SocketBinding binding = transportConfig.getSocketBinding();
   if (binding != null) {
     SocketFactory factory = transport.getSocketFactory();
     if (!(factory instanceof ManagedSocketFactory)) {
       transport.setSocketFactory(new ManagedSocketFactory(factory, binding.getSocketBindings()));
     }
   }
   ThreadFactory threadFactory = transportConfig.getThreadFactory();
   if (threadFactory != null) {
     if (!(transport.getThreadFactory() instanceof ThreadFactoryAdapter)) {
       transport.setThreadFactory(new ThreadFactoryAdapter(threadFactory));
     }
   }
   ExecutorService defaultExecutor = transportConfig.getDefaultExecutor();
   if (defaultExecutor != null) {
     if (!(transport.getDefaultThreadPool() instanceof ManagedExecutorService)) {
       transport.setDefaultThreadPool(new ManagedExecutorService(defaultExecutor));
     }
   }
   ExecutorService oobExecutor = transportConfig.getOOBExecutor();
   if (oobExecutor != null) {
     if (!(transport.getOOBThreadPool() instanceof ManagedExecutorService)) {
       transport.setOOBThreadPool(new ManagedExecutorService(oobExecutor));
     }
   }
   ScheduledExecutorService timerExecutor = transportConfig.getTimerExecutor();
   if (timerExecutor != null) {
     if (!(transport.getTimer() instanceof TimerSchedulerAdapter)) {
       this.setValue(
           transport,
           "timer",
           new TimerSchedulerAdapter(new ManagedScheduledExecutorService(timerExecutor)));
     }
   }
 }
Exemplo n.º 13
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");
      }
    }