Пример #1
0
 /**
  * Simple test program
  *
  * @param args Command-line arguments
  * @throws Exception If an error occurs
  */
 public static void main(String args[]) throws Exception {
   McastService service = new McastService();
   java.util.Properties p = new java.util.Properties();
   p.setProperty("mcastPort", "5555");
   p.setProperty("mcastAddress", "224.10.10.10");
   p.setProperty("mcastClusterDomain", "catalina");
   p.setProperty("bindAddress", "localhost");
   p.setProperty("memberDropTime", "3000");
   p.setProperty("mcastFrequency", "500");
   p.setProperty("tcpListenPort", "4000");
   p.setProperty("tcpListenHost", "127.0.0.1");
   p.setProperty("tcpSecurePort", "4100");
   p.setProperty("udpListenPort", "4200");
   service.setProperties(p);
   service.start();
   Thread.sleep(60 * 1000 * 60);
 }
Пример #2
0
  /**
   * Starts up the channel. This can be called multiple times for individual services to start The
   * svc parameter can be the logical or value of any constants
   *
   * @param svc int value of <br>
   *     DEFAULT - will start all services <br>
   *     MBR_RX_SEQ - starts the membership receiver <br>
   *     MBR_TX_SEQ - starts the membership broadcaster <br>
   *     SND_TX_SEQ - starts the replication transmitter<br>
   *     SND_RX_SEQ - starts the replication receiver<br>
   * @throws ChannelException if a startup error occurs or the service is already started.
   */
  protected synchronized void internalStart(int svc) throws ChannelException {
    try {
      boolean valid = false;
      // make sure we don't pass down any flags that are unrelated to the bottom layer
      svc = svc & Channel.DEFAULT;

      if (startLevel == Channel.DEFAULT) return; // we have already started up all components
      if (svc == 0) return; // nothing to start

      if (svc == (svc & startLevel)) {
        throw new ChannelException(
            sm.getString("channelCoordinator.alreadyStarted", Integer.toString(svc)));
      }

      // must start the receiver first so that we can coordinate the port it
      // listens to with the local membership settings
      if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
        clusterReceiver.setMessageListener(this);
        clusterReceiver.start();
        // synchronize, big time FIXME
        membershipService.setLocalMemberProperties(
            getClusterReceiver().getHost(),
            getClusterReceiver().getPort(),
            getClusterReceiver().getSecurePort(),
            getClusterReceiver().getUdpPort());
        valid = true;
      }
      if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
        clusterSender.start();
        valid = true;
      }

      if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
        membershipService.setMembershipListener(this);
        if (membershipService instanceof McastService) {
          ((McastService) membershipService).setMessageListener(this);
        }
        membershipService.start(MembershipService.MBR_RX);
        valid = true;
      }
      if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
        membershipService.start(MembershipService.MBR_TX);
        valid = true;
      }

      if (!valid) {
        throw new IllegalArgumentException(sm.getString("channelCoordinator.invalid.startLevel"));
      }
      startLevel = (startLevel | svc);
    } catch (ChannelException cx) {
      throw cx;
    } catch (Exception x) {
      throw new ChannelException(x);
    }
  }