Package org.xmlBlaster.client

Examples of org.xmlBlaster.client.I_XmlBlasterAccess


      log.info("Sending Broadcast request for repl='" + replicationPrefix + "' and statement='" + sql + "' and requestId='" + requestId + "'");
      String dbWatcherSessionId = individualInfo.get(SENDER_SESSION, null);
      registerSqlStatement(replicationPrefix, requestId, sql);
     
      log.info("Broadcasting sql statement '" + sql + "' for master '" + replicationPrefix + "'");
      I_XmlBlasterAccess conn = this.global.getXmlBlasterAccess();
      // no oid for this ptp message
      PublishKey pubKey = new PublishKey(this.global, REQUEST_BROADCAST_SQL_TOPIC);
      Destination destination = new Destination(new SessionName(this.global, dbWatcherSessionId));
      destination.forceQueuing(true);
      PublishQos pubQos = new PublishQos(this.global, destination);
      pubQos.setPersistent(true);
      if (isHighPrio)
         pubQos.setPriority(PriorityEnum.HIGH8_PRIORITY);
      // pubQos.addClientProperty(ACTION_ATTR, STATEMENT_ACTION);
      pubQos.addClientProperty(STATEMENT_ATTR, sql);
      pubQos.addClientProperty(STATEMENT_PRIO_ATTR, isHighPrio);
      pubQos.addClientProperty(STATEMENT_ID_ATTR, requestId);
      pubQos.addClientProperty(SQL_TOPIC_ATTR, this.sqlTopic);
      if (this.maxResponseEntries > -1L) {
         pubQos.addClientProperty(MAX_ENTRIES_ATTR, this.maxResponseEntries);
         log.info("Be aware that the number of entries in the result set will be limited to '" + this.maxResponseEntries + "'. To change this use 'replication.sqlMaxEntries'");
      }
      MsgUnit msg = new MsgUnit(pubKey, STATEMENT_ACTION.getBytes(), pubQos);
      conn.publish(msg);
     
   }
View Full Code Here


      if (individualInfo != null) {
         String dbWatcherSessionId = individualInfo.get(SENDER_SESSION, null);
         if (dbWatcherSessionId == null)
            throw new Exception("The replication source with replication.prefix='" +  replPrefix + "' had no '_senderSession' attribute set in its configuration");

         I_XmlBlasterAccess conn = this.global.getXmlBlasterAccess();
         PublishKey pubKey = new PublishKey(this.global, REQUEST_RECREATE_TRIGGERS);
         Destination destination = new Destination(new SessionName(this.global, dbWatcherSessionId));
         destination.forceQueuing(true);
         PublishQos pubQos = new PublishQos(this.global, destination);
         pubQos.setPersistent(false);
         MsgUnit msg = new MsgUnit(pubKey, REPL_REQUEST_RECREATE_TRIGGERS.getBytes(), pubQos);
         conn.publish(msg);
         return "Recreate Triggers for '" + replPrefix + "' is ongoing now";
      }
      else
         throw new Exception("Could not find a replication source with replication.prefix='" + replPrefix + "'");
   }
View Full Code Here

   }
  
   public static void main(String[] args) {
      try {
         Global global = new Global(args);
         I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
         ConnectQos connectQos = new ConnectQos(global);
         conn.connect(connectQos, new ReplManagerPlugin()); // just a fake
        
         String cmd = global.getProperty().get("cmd", (String)null);
         if (cmd == null)
            mainUsage();
        
         String requestId = global.getProperty().get("requestId", (String)null);
         if (requestId == null)
            mainUsage();
        
         int count = Integer.parseInt(requestId.trim());
        
         String repl = global.getProperty().get(REPL_PREFIX_KEY, REPL_PREFIX_DEFAULT);
         if (repl == null)
            mainUsage();
        
         PublishKey pubKey = new PublishKey(global, "broadcastChecker");

         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String line = null;
         while ( (line=br.readLine()) != null) {
            PublishQos pubQos = new PublishQos(global,new Destination(new SessionName(global, SESSION_ID)));
            requestId = "" + count++;
            MsgUnit msg = null;
            if (cmd.equals("insert")) {
               pubQos.addClientProperty("_command", "broadcastSql");
               pubQos.addClientProperty("requestId", requestId);
               pubQos.addClientProperty("replication.prefix", repl);
               msg = new MsgUnit(pubKey, line.trim().getBytes(), pubQos);
            }
            else {
               pubQos.addClientProperty("_command", "removeBroadcast");
               msg = new MsgUnit(pubKey, requestId.getBytes(), pubQos);
            }
            if (line != null && line.trim().length() > 0) {
               conn.publish(msg);
            }
         }
         conn.erase(new EraseKey(global, "broadcastChecker"), new EraseQos(global));
         conn.disconnect(new DisconnectQos(global));
         br.close();
      }
      catch (Throwable ex) {
         ex.printStackTrace();
      }
View Full Code Here

      if (individualInfo == null)
         return "the replication with Id='" + replicationPrefix + "' was not found (has not been registered). Allowed ones are : " + getReplications();

      try {
         String dbWatcherSessionId = individualInfo.get(SENDER_SESSION, null);
         I_XmlBlasterAccess conn = this.global.getXmlBlasterAccess();
         // no oid for this ptp message
         PublishKey pubKey = new PublishKey(this.global, SIMPLE_MESSAGE);
         Destination destination = new Destination(new SessionName(this.global, dbWatcherSessionId));
         destination.forceQueuing(true);
         PublishQos pubQos = new PublishQos(this.global, destination);
         // pubQos.addClientProperty(ACTION_ATTR, STATEMENT_ACTION);
         MsgUnit msg = new MsgUnit(pubKey, msgTxt.getBytes(), pubQos);
         conn.publish(msg);
      }
      catch (Exception ex) {
         ex.printStackTrace();
         return "Could not publish the message";
      }
View Full Code Here

   private boolean consuming = true;
   private String queueOid;

   public HelloWorld9(Global glob) {
      this.glob = glob;
      final I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
      this.timeout = this.glob.getProperty().get("timeout", timeout);
      this.consuming = this.glob.getProperty().get("consuming", consuming);
      this.queueOid = this.glob.getProperty().get("queueOid", "topic/Hello");
     
      try {
         ConnectQos qos = new ConnectQos(glob);
         con.connect(qos, null)// Login to xmlBlaster
        
         Thread thread = new Thread(new Runnable() {
            public void run() {
               while (true) {
                  try {
                     int ret = Global.waitOnKeyboardHit("Hit a key to call receive() or 'q' to quit> ");
                     if (ret == 'q') {
                        stopThis = true;
                        break;
                     }
                     int count = 1;
                     if (ret > '0' && ret <= '9') count = ret - '0';
                     System.out.println("Waiting on '" + queueOid + "' maxEntries=" + count + " timeout=" + timeout + " consumable=" + consuming + " ...");
                     MsgUnit[] msgs = con.receive(queueOid, count, timeout, consuming);
                     System.out.println("Received " + msgs.length + " messages");
                     for (int i=0; i<msgs.length; i++)
                        System.out.println("#" + i + ": " + msgs[i].getContentStr());
                  }
                  catch (XmlBlasterException e) {
                     log.severe(e.getMessage());
                  }
               }
            }
         });
         thread.start();

         while (!stopThis)
            try { Thread.sleep(100); } catch (InterruptedException e) {}

         con.disconnect(new DisconnectQos(glob));
         glob.shutdown(); // free resources
      }
      catch (XmlBlasterException e) {
         log.severe(e.getMessage());
      }
View Full Code Here

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

     
      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
     
      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 = glob.getProperty().get("session.name", "HelloWorld3");
         String passwd = glob.getProperty().get("passwd", "secret");

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


         PublishKey pk = new PublishKey(glob, "HelloWorld3", "text/xml", "1.0");
         pk.setClientTags("<org.xmlBlaster><demo/></org.xmlBlaster>");
         PublishQos pq = new PublishQos(glob);
         pq.addClientProperty("myAge", 84);
         MsgUnit msgUnit = new MsgUnit(pk, "Hi", pq);
         con.publish(msgUnit);


         GetKey gk = new GetKey(glob, "HelloWorld3");
         GetQos gq = new GetQos(glob);
         MsgUnit[] msgs = con.get(gk, gq);
         if (msgs.length > 0) {
            GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
            log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
                      "' and status=" + grq.getState());
         }


         SubscribeKey sk = new SubscribeKey(glob, "HelloWorld3");
         SubscribeQos sq = new SubscribeQos(glob);
         SubscribeReturnQos subRet = con.subscribe(sk, sq);


         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 i) {} // wait a second to receive update()


         UnSubscribeKey uk = new UnSubscribeKey(glob, subRet.getSubscriptionId());
         UnSubscribeQos uq = new UnSubscribeQos(glob);
         UnSubscribeReturnQos[] urq = con.unSubscribe(uk, uq);
         if (urq.length > 0) log.info("Unsubscribed from topic");

         EraseKey ek = new EraseKey(glob, "HelloWorld3");
         EraseQos eq = new EraseQos(glob);
         EraseReturnQos[] eraseArr = con.erase(ek, eq);
         if (eraseArr.length > 0) log.info("Erased topic");

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

*/
public class HelloWorld2 implements I_Callback
{
   public HelloWorld2(final Global glob) {
      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();

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

         con.subscribe("<key oid='HelloWorld2'/>", "<qos/>");
        
         // A similar subscription with XPATH:
         //con.subscribe("<key oid='' queryType='XPATH'>//key[@oid='HelloWorld2']</key>", "<qos/>");

         con.publish(new MsgUnit(glob, "<key oid='HelloWorld2'/>", "Hi".getBytes(),
                                     "<qos/>"));

         // wait a second
         try { Thread.sleep(1000); } catch(Exception e) { }
         Global.waitOnKeyboardHit("\nHit a key to logout and terminate ...");

         con.erase("<key oid='HelloWorld2'/>", null);
         try { Thread.sleep(100); } catch(Exception e) { }  // To process erase event
         con.disconnect(null);
      }
      catch (Exception e) {
         System.err.println(e.getMessage());
      }
   }
View Full Code Here

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

     
      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
     
      try {
         ConnectQos qos = new ConnectQos(glob);

         // '-dispatch/connection/doSendConnect false' on command line would do the same
         qos.doSendConnect(false);
        
         // Initializes everything but does NOT send connect message
         con.connect(qos, this);

         log.info("Waiting now for updates ...");
         char ret = 0;
         while (ret != 'q')
            ret = (char)Global.waitOnKeyboardHit("Enter 'q' to quit");
        
         con.disconnect(null); // Cleanup client library
      }
      catch (XmlBlasterException e) {
         log.severe(e.getMessage());
      }
      catch (Throwable e) {
View Full Code Here

         log.info("   -oid            " + oid);
         log.info("   -xpath          " + xpath);
         log.info("   -forceDestroy   " + forceDestroy);
         log.info("   -persistent     " + persistent);

         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();
         log.info("============= CreatingConnectQos");
         ConnectQos qos = new ConnectQos(glob);
         log.info("ConnectQos is " + qos.toXml());
         ConnectReturnQos crq = con.connect(qos, null)// Login to xmlBlaster, register for updates
         log.info("Connect success as " + crq.toXml());

         if (interactive) {
            log.info("Hit a key to erase");
            try { System.in.read(); } catch(java.io.IOException e) {}
         }

         EraseKey ek;
         if (xpath != null)
            ek = new EraseKey(glob, xpath, Constants.XPATH);
         else
            ek = new EraseKey(glob, oid);
         EraseQos eq = new EraseQos(glob);
         eq.setForceDestroy(forceDestroy);
         eq.setPersistent(persistent);
         if (historyNumErase != -99) {
            eq.getData().setHistoryQos(new HistoryQos(glob, historyNumErase));
         }
         EraseReturnQos[] eraseArr = con.erase(ek, eq);
         for (int i=0; i < eraseArr.length; i++) {
            log.info(eraseArr[i].toXml());
         }
         log.info("Erased " + eraseArr.length + " topics");

         log.info("Hit a key to exit");
         try { System.in.read(); } catch(java.io.IOException e) {}

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

*/
public class HelloWorld
{
   public HelloWorld(String[] args) {
      try {
         I_XmlBlasterAccess con = new XmlBlasterAccess(args);

         con.connect(null, null);    // Login to xmlBlaster as "guest"

         MsgUnit[] msgs = con.get("<key oid='__cmd:?freeMem'/>", null);

         System.out.println("\nHelloWorld: xmlBlaster has currently " +
                new String(msgs[0].getContent()) + " bytes of free memory\n");

         con.disconnect(null);
      }
      catch (Exception e) {
         System.err.println("HelloWorld: We have a problem: " + e.toString());
      }
   }
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.