Package org.xmlBlaster.client

Examples of org.xmlBlaster.client.I_XmlBlasterAccess


   public ClientSub(Global glob) {
      this.glob = glob;

      try {
         I_XmlBlasterAccess blasterConnection = glob.getXmlBlasterAccess();
         blasterConnection.connect(null, this);
         // Now we are connected to xmlBlaster MOM server.

         int numTests = glob.getProperty().get("numTests", 1);
         for (int i=0; i<numTests; i++)
            sendSomeMessages(blasterConnection);

         /* // Run forever
         while (true) {
            try { Thread.currentThread().sleep(100000000L);
            } catch(InterruptedException e) { log.warning("Caught exception: " + e.toString()); }
         }
         */

         blasterConnection.disconnect(null);
      }
      catch (Exception e) {
         log.severe("Client failed: " + e.toString());
         // e.printStackTrace();
      }
View Full Code Here


   private Global glob;

   public DelegateDemo(Global glob) {
      this.glob = glob;
      try {
         I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(this.glob);

         String receiver = this.glob.getProperty().get("emailDestination",
               (String) null);
         if (receiver == null) {
            System.out.println("Usage:");
            System.out
                  .println("  java javaclients.email.DelegateDemo -protocol email -emailDestination blue@localhost");
            System.exit(1);
         }

         CallbackAddress cbAddr = new CallbackAddress(this.glob, "email");
         cbAddr.setRawAddress(receiver);
         cbAddr.setOneway(true);
         qos.addCallbackAddress(cbAddr);

         // null: Login to xmlBlaster without callback instantiation!
         con.connect(qos, null);

         con.subscribe("<key oid='EmailDemo'/>", "<qos/>");
         System.out
               .println("Subscribed topic 'EmailDemo' for to email destination '"
                     + receiver + "'");

         while (true) {
            int ch = Global
                  .waitOnKeyboardHit("["
                        + receiver
                        + "] Hit a key 'p' to publish, 'u' to unSubscribe or 'q' to quit >");
            if (ch == 'q')
               break;
            if (ch == 'p') {
               con.publish(new MsgUnit("<key oid='EmailDemo'/>", "Hi"
                     .getBytes(), "<qos/>"));
            }
            if (ch == 'u') {
               con.unSubscribe("<key oid='EmailDemo'/>", "<qos/>");
               break;
            }
         }

         con.disconnect(null);
      } catch (Exception e) {
         System.out.println(e.toString());
      }
   }
View Full Code Here

   public HelloWorldVolatile(Global glob) {
      this.glob = glob;

      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(glob);
         con.connect(qos, this)// Login to xmlBlaster, register for updates

         // Subscribe for the volatile message
         SubscribeKey sk = new SubscribeKey(glob, "HelloWorldVolatile");
         SubscribeQos sq = new SubscribeQos(glob);
         SubscribeReturnQos subRet = con.subscribe(sk, sq);

         // Publish a volatile message
         PublishKey pk = new PublishKey(glob, "HelloWorldVolatile", "text/xml", "1.0");
         PublishQos pq = new PublishQos(glob);
         pq.setVolatile(true);
         MsgUnit msgUnit = new MsgUnit(pk, "Hi", pq);
         con.publish(msgUnit);

         // This should not be possible as the message was volatile
         try {
            GetKey gk = new GetKey(glob, "HelloWorldVolatile");
            GetQos gq = new GetQos(glob);
            MsgUnit[] msgs = con.get(gk, gq);
            if (msgs.length > 0) {
               GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
               log.severe("Did not expect any message as it was volatile");
            }
         }
         catch (XmlBlasterException e) {
            log.severe("Didn't expect an exception in get(): " + e.getMessage());
         }

         DisconnectQos dq = new DisconnectQos(glob);
         con.disconnect(dq);
      }
      catch (XmlBlasterException e) {
         log.severe(e.getMessage());
      }
   }
View Full Code Here

   private Global glob;

   public DemoCb(Global glob) {
      this.glob = glob;
      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(glob);

         //CallbackAddress cbAddr = new CallbackAddress(glob, "EMAIL");
         //cbAddr.setRawAddress("demo@localhost");
         //qos.addCallbackAddress(cbAddr);
        
         con.connect(qos, this);

         con.subscribe("<key oid='EmailDemo'/>", "<qos/>");

         while (true) {
            int ch = Global.waitOnKeyboardHit("Hit a key to publish a message (type 'q' to quit)>");
            if (ch == 'q')
               break;
            con.publish(new MsgUnit("<key oid='EmailDemo'/>", "Hi".getBytes(),
                  "<qos/>"));
            Thread.sleep(1000);
         }
         con.disconnect(null);
      } catch (Exception e) {
         System.out.println(e.toString());
      }
   }
View Full Code Here

      this.destinations = new PtPDestination[this.numDestinations];
      for (int i=0; i < this.numDestinations; i++)
         this.destinations[i] = new PtPDestination(this.glob, this.subjectName + "/" + (i+1));
      log.info("XmlBlaster is ready for testing");
      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess(); // Find orb
         String passwd = "secret";
         ConnectQos connectQos = new ConnectQos(glob, "src_" + this.subjectName, passwd); // == "<qos>...</qos>";
         if (log.isLoggable(Level.FINE)) log.fine("setUp: connectQos '" + connectQos.toXml() + "'");
         con.connect(connectQos, null)// Login to xmlBlaster, register for updates

      }
      catch (XmlBlasterException e) {
          log.warning("setUp() - login failed: " + e.getMessage());
          fail("setUp() - login fail: " + e.getMessage());
View Full Code Here

    * <p />
    * cleaning up .... erase() the previous message OID and logout
    */
   protected void tearDown() {
      log.info("Entering tearDown(), test is finished");
      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
      try {
         EraseKey key = new EraseKey(this.glob, "testPtPDispatch");
         EraseQos qos = new EraseQos(this.glob);
         con.erase(key, qos);
      }
      catch(XmlBlasterException ex) {
         ex.printStackTrace();
      }
      finally {
         con.disconnect(null);
         // Global.instance().shutdown();
         // the unknown destinations must be handled inside the specific tests
         this.glob.shutdown();
         this.glob = null;
      }
View Full Code Here

   private static Logger log = Logger.getLogger(Latency.class.getName());

   public Latency(Global glob) {

      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(glob);
         con.connect(qos, this)// Login to xmlBlaster, register for updates

         PublishKey pk = new PublishKey(glob, "Latency", "text/xml", "1.0");
         PublishQos pq = new PublishQos(glob);
         MsgUnit msgUnit = new MsgUnit(pk.toXml(), "Hi".getBytes(), pq.toXml());

         SubscribeKey sk = new SubscribeKey(glob, "Latency");
         SubscribeQos sq = new SubscribeQos(glob);
         con.subscribe(sk.toXml(), sq.toXml()).getSubscriptionId();

         int numSend = glob.getProperty().get("numSend", 10);

         for (int ii=0; ii<numSend; ii++) {
            startTime = System.currentTimeMillis();
            con.publish(msgUnit);
            while (true) {
               try { Thread.sleep(50); } catch( InterruptedException i) {}
               if (messageArrived) {
                  messageArrived = false;
                  break;
               }
            }
         }

         try { Thread.sleep(1000); } catch( InterruptedException i) {} // wait a second to receive update()

         DisconnectQos dq = new DisconnectQos(glob);
         con.disconnect(dq);
      }
      catch (Exception e) {
         log.severe(e.toString());
      }
   }
View Full Code Here

      try {
         // force XMLRPC protocol:
         glob.getProperty().set("client.protocol", "XMLRPC");
        
         I_XmlBlasterAccess client = glob.getXmlBlasterAccess();
        
         log.info("Going to invoke xmlBlaster using XmlRpc-I_XmlBlasterAccess");
         ConnectQos connectQos = new ConnectQos(glob, "LunaMia", "silence");
         client.connect(connectQos, null);
         log.info("Connection successful");

         String contentString = "This is a simple Test Message for the xml-rpc Protocol";
         byte[] content = contentString.getBytes();

         PublishKey xmlKey = new PublishKey(glob, "", "text/plain", null);

         MsgUnit msgUnit = new MsgUnit(xmlKey.toXml(), content, "<qos><forceUpdate /></qos>");
         client.publish(msgUnit);
         log.info("Published a message");

         client.disconnect(null);
      }
      catch (XmlBlasterException ex) {
         log.severe("exception: " + ex.toString());
      }
      catch (Throwable ex1) {
View Full Code Here

   private void doPublish(byte[] content, int maxChunkSize, boolean doInterrupt, String name) throws XmlBlasterException {
      log.info("Publishing for '" + name + "'");
      // Global glob = this.global.getClone(null);
      Global glob = this.connGlobal;
      I_XmlBlasterAccess conn = glob.getXmlBlasterAccess();
      PublishKey key = new PublishKey(glob, this.oid);
      PublishQos qos = new PublishQos(glob);
      qos.setPersistent(true);
      if (doInterrupt)
         qos.addClientProperty("interrupted", true);
      qos.addClientProperty("nameOfTest", name);
      qos.addClientProperty(Constants.addJmsPrefix(XBConnectionMetaData.JMSX_MAX_CHUNK_SIZE, log), maxChunkSize);
      ByteArrayInputStream bais = new ByteArrayInputStream(content);
      conn.publishStream(bais, key.getData(), qos.getData(), maxChunkSize, null);
   }
View Full Code Here

      this.glob = glob;

      for(int i=0; i<conList.length; i++) {
         ME = conList[i].helpText;
         conList[i].con = conList[i].glob.getXmlBlasterAccess();
         I_XmlBlasterAccess con = conList[i].con;
         try {

            // Check if other login name or password was given on command line:
            // (This is redundant as it is done by ConnectQos already)
            String name = con.getGlobal().getProperty().get("session.name", "AllProtocols");
            String passwd = con.getGlobal().getProperty().get("passwd", "secret");

            ConnectQos qos = new ConnectQos(con.getGlobal(), name, passwd);
            con.connect(qos, this)// Login to xmlBlaster, register for updates


            PublishKey pk = new PublishKey(con.getGlobal(), "AllProtocols", "text/xml", "1.0");
            pk.setClientTags("<org.xmlBlaster><demo/></org.xmlBlaster>");
            PublishQos pq = new PublishQos(con.getGlobal());
            MsgUnit msgUnit = new MsgUnit(pk, "Hi", pq);
            con.publish(msgUnit);


            GetKey gk = new GetKey(con.getGlobal(), "AllProtocols");
            GetQos gq = new GetQos(con.getGlobal());
            MsgUnit[] msgs = con.get(gk.toXml(), gq.toXml());
            GetReturnQos grq = new GetReturnQos(con.getGlobal(), msgs[0].getQos());

            log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
                         "' and status=" + grq.getState());


            SubscribeKey sk = new SubscribeKey(con.getGlobal(), "AllProtocols");
            SubscribeQos sq = new SubscribeQos(con.getGlobal());
            SubscribeReturnQos subRet = con.subscribe(sk.toXml(), sq.toXml());


            msgUnit = new MsgUnit(pk, "Ho".getBytes(), pq);
            PublishReturnQos prq = con.publish(msgUnit);

            log.info("Got status='" + prq.getState() + "' for published message '" + prq.getKeyOid());

            try { Thread.sleep(1000); }
            catch( InterruptedException ie) {} // wait a second to receive update()


            UnSubscribeKey uk = new UnSubscribeKey(con.getGlobal(), subRet.getSubscriptionId());
            UnSubscribeQos uq = new UnSubscribeQos(con.getGlobal());
            UnSubscribeReturnQos[] urq = con.unSubscribe(uk.toXml(), uq.toXml());

            EraseKey ek = new EraseKey(con.getGlobal(), "AllProtocols");
            EraseQos eq = new EraseQos(con.getGlobal());
            EraseReturnQos[] eraseArr = con.erase(ek.toXml(), eq.toXml());

            DisconnectQos dq = new DisconnectQos(con.getGlobal());
            con.disconnect(dq);
         }
         catch (XmlBlasterException e) {
            log.severe(e.getMessage());
         }
         catch (Throwable e) {
View Full Code Here

TOP

Related Classes of org.xmlBlaster.client.I_XmlBlasterAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.