Exemple #1
0
  public static void main(String[] args) throws LBMException {
    LBMContext ctx = null; /* Context object: container for UM "instance". */
    LBMSource src = null; /* Source object: for sending messages. */

    SrcCB srccb = new SrcCB();

    /** * Initialization: create necessary UM objects. ** */
    try {
      LBMTopic topic = null;
      LBMSourceAttributes srcAttr = null;

      ctx = new LBMContext();
      srcAttr = new LBMSourceAttributes();
      srcAttr.setValue("ume_store", "127.0.0.1:29999");
      srcAttr.setValue("ume_store_behavior", "qc");
      topic = ctx.allocTopic("test.topic", srcAttr);
      src = ctx.createSource(topic, srccb, null, null);
    } catch (LBMException ex) {
      System.err.println("Error initializing LBM objects: " + ex.toString());
      System.exit(1);
    }

    while (true) {
      if (srcReady == 1) {
        /** * Send a message. ** */
        try {
          src.send("test".getBytes(), "test".getBytes().length, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
        } catch (LBMException ex) {
          /* Error trying to send, wait 1 second and try again */
          try {
            Thread.sleep(1000);
          } catch (InterruptedException tex) {
            System.err.println("Error Thread.sleep interrupted: " + tex.toString());
            System.exit(1);
          }
        }
      } else {
        /* No quorum, wait 1 second and check again */
        System.out.println("Source is not ready to send (no quorum)");
        try {
          Thread.sleep(1000);
        } catch (InterruptedException tex) {
          System.err.println("Error Thread.sleep interrupted: " + tex.toString());
          System.exit(1);
        }
      }
    }
  } /* main */
  public static void main(String[] args) throws LBMException {
    LBMContext ctx = null; /* Context object: container for UM "instance". */

    /** * Initialization: create necessary UM objects. ** */
    try {
      ctx = new LBMContext();
    } catch (LBMException ex) {
      System.err.println("Error initializing LBM objects: " + ex.toString());
      System.exit(1);
    }

    callback cb = new callback();
    LBMTimer timer = new LBMTimer(ctx, 1000, cb, null);

    while (wait == 1) {
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
      }
    }

    ctx.close();
  } /* main */