예제 #1
0
 @BeforeMethod
 public void init() throws Exception {
   c1 = createChannel(true, 2);
   c1.setName("C1");
   c2 = createChannel(c1);
   c2.setName("C2");
   setOOBPoolSize(c1, c2);
   setStableGossip(c1, c2);
   c1.connect("OOBTest");
   c2.connect("OOBTest");
   View view = c2.getView();
   log.info("view = " + view);
   assert view.size() == 2 : "view is " + view;
 }
예제 #2
0
파일: OOBTest.java 프로젝트: jiwils/JGroups
 @BeforeMethod
 public void init() throws Exception {
   c1 = createChannel(true, 2);
   c1.setName("C1");
   c2 = createChannel(c1);
   c2.setName("C2");
   setOOBPoolSize(c1, c2);
   setStableGossip(c1, c2);
   c1.connect("OOBTest");
   c2.connect("OOBTest");
   View view = c2.getView();
   log.info("view = " + view);
   Util.waitUntilAllChannelsHaveSameSize(20000, 1000, c1, c2);
 }
예제 #3
0
 @BeforeMethod
 void init() throws Exception {
   a = createChannel(true, 2);
   a.setName("A");
   b = createChannel(a);
   b.setName("B");
   setOOBPoolSize(a, b);
   setStableGossip(a, b);
   a.connect("OOBTest");
   b.connect("OOBTest");
   View view = b.getView();
   System.out.println("view = " + view);
   Util.waitUntilAllChannelsHaveSameSize(20000, 1000, a, b);
 }
예제 #4
0
  /**
   * Constructor 1
   *
   * @param props
   * @param no_channel
   * @param jmx
   * @param use_state
   * @param state_timeout
   * @param use_unicasts
   * @param name
   * @param send_own_state_on_merge
   * @param gen
   * @throws Exception
   */
  public JWhiteBoard(
      String props,
      boolean no_channel,
      boolean jmx,
      boolean use_state,
      long state_timeout,
      boolean use_unicasts,
      String name,
      boolean send_own_state_on_merge,
      AddressGenerator gen)
      throws Exception {
    this.noChannel = no_channel;
    this.jmx = jmx;
    this.useState = use_state;
    this.stateTimeout = state_timeout;
    this.use_unicasts = use_unicasts;
    if (no_channel) return;

    channel = new JChannel(props);
    if (gen != null) channel.addAddressGenerator(gen);
    if (name != null) channel.setName(name);
    channel.setReceiver(this);
    channel.addChannelListener(this);
    this.send_own_state_on_merge = send_own_state_on_merge;
  }
  public void testNullMessageToAll() throws Exception {
    d1.setRequestHandler(new MyHandler(null));

    c2 = createChannel(c1);
    c2.setName("B");
    disableBundling(c2);
    long stop, start = System.currentTimeMillis();
    d2 = new MessageDispatcher(c2, null, null, new MyHandler(null));
    stop = System.currentTimeMillis();
    c2.connect("MessageDispatcherUnitTest");
    Assert.assertEquals(2, c2.getView().size());
    System.out.println("view: " + c2.getView());

    System.out.println("casting message");
    start = System.currentTimeMillis();
    RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0));
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assertNotNull(rsps);
    Assert.assertEquals(2, rsps.size());
    Rsp rsp = rsps.get(c1.getAddress());
    assertNotNull(rsp);
    Object ret = rsp.getValue();
    assert ret == null;

    rsp = rsps.get(c2.getAddress());
    assertNotNull(rsp);
    ret = rsp.getValue();
    assert ret == null;

    Util.close(c2);
  }
  private void sendMessageToBothChannels(int size) throws Exception {
    long start, stop;
    d1.setRequestHandler(new MyHandler(new byte[size]));

    c2 = createChannel(c1);
    c2.setName("B");
    disableBundling(c2);
    d2 = new MessageDispatcher(c2, null, null, new MyHandler(new byte[size]));
    c2.connect("MessageDispatcherUnitTest");
    Assert.assertEquals(2, c2.getView().size());

    System.out.println("casting message");
    start = System.currentTimeMillis();
    RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0));
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assertNotNull(rsps);
    Assert.assertEquals(2, rsps.size());
    Rsp rsp = rsps.get(c1.getAddress());
    assertNotNull(rsp);
    byte[] ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);

    rsp = rsps.get(c2.getAddress());
    assertNotNull(rsp);
    ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);

    Util.close(c2);
  }
예제 #7
0
  @BeforeMethod
  void init() throws Exception {
    createChannels(true, true, (short) 5, (short) 5);
    c1.setName("C1");
    c2.setName("C2");
    c3.setName("C3");
    a1 = c1.getAddress();
    a2 = c2.getAddress();
    a3 = c3.getAddress();

    r1 = new MyReceiver("C1");
    r2 = new MyReceiver("C2");
    r3 = new MyReceiver("C3");
    c1.setReceiver(r1);
    c2.setReceiver(r2);
    c3.setReceiver(r3);
  }
 @BeforeMethod
 void start() throws Exception {
   r1 = new MyReceiver("A");
   r2 = new MyReceiver("B");
   a = new JChannel(props);
   a.setName("A");
   a.connect(CLUSTER);
   a_addr = a.getAddress();
   a.setReceiver(r1);
   u1 = a.getProtocolStack().findProtocol(UNICAST.class);
   b = new JChannel(props);
   b.setName("B");
   b.connect(CLUSTER);
   b_addr = b.getAddress();
   b.setReceiver(r2);
   u2 = b.getProtocolStack().findProtocol(UNICAST.class);
   System.out.println("A=" + a_addr + ", B=" + b_addr);
 }
 @BeforeClass
 protected void setUp() throws Exception {
   c1 = createChannel(true);
   c1.setName("A");
   GMS gms = (GMS) c1.getProtocolStack().findProtocol(GMS.class);
   if (gms != null) gms.setPrintLocalAddress(false);
   disableBundling(c1);
   d1 = new MessageDispatcher(c1, null, null, null);
   c1.connect("MessageDispatcherUnitTest");
 }
예제 #10
0
 protected JChannel createChannel(String name) throws Exception {
   JChannel ch =
       Util.createChannel(
           new SHARED_LOOPBACK()
               .setValue("enable_bundling", false)
               .setValue("enable_unicast_bundling", false),
           new PING().setValue("timeout", 500).setValue("num_initial_members", 2),
           new NAKACK2().setValue("become_server_queue_size", 10),
           new UNICAST3(),
           new GMS().setValue("print_local_addr", false));
   ch.setName(name);
   return ch;
 }
예제 #11
0
 protected JChannel createNode(String site_name, String node_name) throws Exception {
   JChannel ch =
       new JChannel(
           new SHARED_LOOPBACK(),
           new PING().setValue("timeout", 300).setValue("num_initial_members", 2),
           new NAKACK2(),
           new UNICAST3(),
           new GMS().setValue("print_local_addr", false),
           new FORWARD_TO_COORD(),
           createRELAY2(site_name));
   ch.setName(node_name);
   return ch;
 }
예제 #12
0
  protected void _init(JChannel ch, long sleep_time, String name) throws Exception {
    this.sleep_time = sleep_time;
    channel = ch;
    if (name != null) channel.setName(name);
    channel.connect(getClass().getSimpleName());
    channel.setReceiver(receiver);

    try {
      MBeanServer server = Util.getMBeanServer();
      JmxConfigurator.registerChannel(
          channel, server, "jgroups-" + name, channel.getClusterName(), true);
    } catch (Throwable ex) {
      System.err.println("registering the channel with JMX failed: " + ex);
    }
  }
예제 #13
0
  private Clusterizer(ClusterBuilder cb) {
    this.clusterName = cb.clusterName;
    InetAddress my_addr;
    try {
      my_addr = InetAddress.getLocalHost();
      hostName = my_addr.getHostName();
      this.channelName = hostName + "." + (new java.util.Random()).nextInt(10000);
      this.channel = new JChannel("udp.xml");
      channel.setName(channelName);
      channel.setReceiver(this);
      channel.connect(clusterName);

    } catch (UnknownHostException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #14
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;
  }
예제 #15
0
  public void init(String props, String name) throws Throwable {
    channel = new JChannel(props);
    if (name != null) channel.setName(name);
    disp = new RpcDispatcher(channel, null, this, this);
    disp.setMethodLookup(
        new MethodLookup() {
          public Method findMethod(short id) {
            return METHODS[id];
          }
        });
    disp.setRequestMarshaller(new CustomMarshaller());
    channel.connect(groupname);
    local_addr = channel.getAddress();

    try {
      MBeanServer server = Util.getMBeanServer();
      JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
    } catch (Throwable ex) {
      System.err.println("registering the channel in JMX failed: " + ex);
    }

    if (members.size() < 2) return;
    Address coord = members.get(0);
    ConfigOptions config =
        (ConfigOptions)
            disp.callRemoteMethod(
                coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
    if (config != null) {
      this.oob = config.oob;
      this.sync = config.sync;
      this.num_threads = config.num_threads;
      this.num_msgs = config.num_msgs;
      this.msg_size = config.msg_size;
      this.anycast_count = config.anycast_count;
      this.read_percentage = config.read_percentage;
      System.out.println("Fetched config from " + coord + ": " + config);
    } else System.err.println("failed to fetch config from " + coord);
  }
예제 #16
0
 public JChannel name(String name) {
   setName(name);
   return this;
 }
예제 #17
0
  @Override
  public Channel createChannel(final String id) throws Exception {
    JGroupsLogger.ROOT_LOGGER.debugf(
        "Creating channel %s from stack %s", id, this.configuration.getName());

    PrivilegedExceptionAction<JChannel> action =
        new PrivilegedExceptionAction<JChannel>() {
          @Override
          public JChannel run() throws Exception {
            return new JChannel(JChannelFactory.this);
          }
        };
    final JChannel channel = WildFlySecurityManager.doChecked(action);
    ProtocolStack stack = channel.getProtocolStack();

    TransportConfiguration transportConfig = this.configuration.getTransport();
    SocketBinding binding = transportConfig.getSocketBinding();
    if (binding != null) {
      channel.setSocketFactory(new ManagedSocketFactory(binding.getSocketBindings()));
    }

    // Relay protocol is added to stack programmatically, not via ProtocolStackConfigurator
    RelayConfiguration relayConfig = this.configuration.getRelay();
    if (relayConfig != null) {
      String localSite = relayConfig.getSiteName();
      List<RemoteSiteConfiguration> remoteSites = this.configuration.getRelay().getRemoteSites();
      List<String> sites = new ArrayList<>(remoteSites.size() + 1);
      sites.add(localSite);
      // Collect bridges, eliminating duplicates
      Map<String, RelayConfig.BridgeConfig> bridges = new HashMap<>();
      for (final RemoteSiteConfiguration remoteSite : remoteSites) {
        String siteName = remoteSite.getName();
        sites.add(siteName);
        String clusterName = remoteSite.getClusterName();
        RelayConfig.BridgeConfig bridge =
            new RelayConfig.BridgeConfig(clusterName) {
              @Override
              public JChannel createChannel() throws Exception {
                JChannel channel = (JChannel) remoteSite.getChannel();
                // Don't use FORK in bridge stack
                channel.getProtocolStack().removeProtocol(FORK.class);
                return channel;
              }
            };
        bridges.put(clusterName, bridge);
      }
      RELAY2 relay = new RELAY2().site(localSite);
      for (String site : sites) {
        RelayConfig.SiteConfig siteConfig = new RelayConfig.SiteConfig(site);
        relay.addSite(site, siteConfig);
        if (site.equals(localSite)) {
          for (RelayConfig.BridgeConfig bridge : bridges.values()) {
            siteConfig.addBridge(bridge);
          }
        }
      }
      Map<String, String> relayProperties = new HashMap<>(relayConfig.getProperties());
      Configurator.resolveAndAssignFields(relay, relayProperties);
      Configurator.resolveAndInvokePropertyMethods(relay, relayProperties);
      stack.addProtocol(relay);
      relay.init();
    }

    UnknownForkHandler unknownForkHandler =
        new UnknownForkHandler() {
          private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);

          @Override
          public Object handleUnknownForkStack(Message message, String forkStackId) {
            return this.handle(message);
          }

          @Override
          public Object handleUnknownForkChannel(Message message, String forkChannelId) {
            return this.handle(message);
          }

          private Object handle(Message message) {
            Header header = (Header) message.getHeader(this.id);
            // If this is a request expecting a response, don't leave the requester hanging - send
            // an identifiable response on which it can filter
            if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) {
              Message response =
                  message
                      .makeReply()
                      .setFlag(message.getFlags())
                      .clearFlag(Message.Flag.RSVP, Message.Flag.SCOPED);

              response.putHeader(FORK.ID, message.getHeader(FORK.ID));
              response.putHeader(this.id, new Header(Header.RSP, 0, header.corrId));
              response.setBuffer(UNKNOWN_FORK_RESPONSE.array());

              channel.down(new Event(Event.MSG, response));
            }
            return null;
          }
        };

    // Add implicit FORK to the top of the stack
    FORK fork = new FORK();
    fork.setUnknownForkHandler(unknownForkHandler);
    stack.addProtocol(fork);
    fork.init();

    channel.setName(this.configuration.getNodeName());

    TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology();
    if (topology != null) {
      channel.addAddressGenerator(new TopologyAddressGenerator(topology));
    }

    return channel;
  }