コード例 #1
0
  public void start() throws Exception {
    int c;

    channel = new JChannel();
    channel.connect("PullPushTestMux");
    adapter = new PullPushAdapter(channel);
    adapter.setListener(this);

    listeners = new MyListener[10];
    for (int i = 0; i < listeners.length; i++) {
      listeners[i] = new MyListener(i, adapter);
    }

    while ((c = choice()) != 'q') {
      c -= 48;
      if (c < 0 || c > 9) {
        System.err.println("Choose between 0 and 9");
        continue;
      }
      if (c == 0) adapter.send(new Message(null, null, "Message from default message listener"));
      else listeners[c].sendMessage();
    }

    channel.close();
    System.exit(0);
  }
コード例 #2
0
  @Override
  public synchronized void start() throws Exception {
    String clusterName = clusteringConfiguration.getClusterName();
    if (clusterName == null) {
      throw new IllegalStateException(BusI18n.clusterNameRequired.text());
    }
    if (channel != null) {
      // Disconnect from any previous channel ...
      channel.removeChannelListener(listener);
      channel.setReceiver(null);
    }
    // Create the new channel by calling the delegate method ...
    channel = newChannel();
    // Add a listener through which we'll know what's going on within the cluster ...
    channel.addChannelListener(listener);

    // Set the receiver through which we'll receive all of the changes ...
    channel.setReceiver(receiver);

    // Now connect to the cluster ...
    channel.connect(clusterName);

    // start the delegate
    delegate.start();
  }
コード例 #3
0
  protected void startJGroupsChannelIfNeeded() {
    if (startChannel) {
      String clusterName = configuration.getClusterName();
      try {
        channel.connect(clusterName);
      } catch (Exception e) {
        throw new CacheException("Unable to start JGroups Channel", e);
      }

      try {
        // Normally this would be done by CacheManagerJmxRegistration but
        // the channel is not started when the cache manager starts but
        // when first cache starts, so it's safer to do it here.
        globalStatsEnabled = configuration.isExposeGlobalJmxStatistics();
        if (globalStatsEnabled) {
          String groupName =
              String.format("type=channel,cluster=%s", ObjectName.quote(clusterName));
          mbeanServer = JmxUtil.lookupMBeanServer(configuration);
          domain = JmxUtil.buildJmxDomain(configuration, mbeanServer, groupName);
          JmxConfigurator.registerChannel(
              (JChannel) channel, mbeanServer, domain, clusterName, true);
        }
      } catch (Exception e) {
        throw new CacheException("Channel connected, but unable to register MBeans", e);
      }
    }
    address = fromJGroupsAddress(channel.getAddress());
    if (!startChannel) {
      // the channel was already started externally, we need to initialize our member list
      viewAccepted(channel.getView());
    }
    if (log.isInfoEnabled()) log.localAndPhysicalAddress(getAddress(), getPhysicalAddresses());
  }
コード例 #4
0
ファイル: FlushTest.java プロジェクト: rvansa/JGroups
  public void testSequentialFlushInvocation() throws Exception {
    Channel a = null, b = null, c = null;
    try {
      a = createChannel(true, 3, "A");
      a.connect("testSequentialFlushInvocation");

      b = createChannel((JChannel) a, "B");
      b.connect("testSequentialFlushInvocation");

      c = createChannel((JChannel) a, "C");
      c.connect("testSequentialFlushInvocation");

      Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b, c);

      for (int i = 0; i < 100; i++) {
        System.out.print("flush #" + i + ": ");
        a.startFlush(false);
        a.stopFlush();
        System.out.println("OK");
      }
    } finally {
      Util.close(a, b, c);
    }
  }
コード例 #5
0
 @BeforeClass
 protected void setUp() throws Exception {
   channel = createChannel(true);
   disp = new RpcDispatcher(channel, this);
   channel.connect(getUniqueClusterName("RpcDispatcherUnicastMethodExceptionTest"));
 }