Package org.xmlBlaster.client

Examples of org.xmlBlaster.client.I_XmlBlasterAccess


            }
           
            if (ret == 'q')
               break;

            I_XmlBlasterAccess con = new XmlBlasterAccess(glob.getClone(null));

            con.registerConnectionListener(new I_ConnectionStateListener() {

               public void reachedAlive(ConnectionStateEnum oldState,
                     I_XmlBlasterAccess connection) {
                  log.info("I_ConnectionStateListener: Connected");
               }

               public void reachedPolling(ConnectionStateEnum oldState,
                     I_XmlBlasterAccess connection) {
                  log
                        .warning("I_ConnectionStateListener: No connection to xmlBlaster server, we are polling ...");
               }

               public void reachedDead(ConnectionStateEnum oldState,
                     I_XmlBlasterAccess connection) {
                  log.warning("I_ConnectionStateListener: Connection from "
                        + connection.getGlobal().getId()
                        + " to xmlBlaster is DEAD, doing exit.");
               }
               public void reachedAliveSync(ConnectionStateEnum oldState, I_XmlBlasterAccess connection) {
               }

            });

            ConnectQos qos = new ConnectQos(glob);
            if (connectPersistent) {
               qos.setPersistent(connectPersistent);
            }
            if (connectQosClientPropertyMap != null) {
               Iterator it = connectQosClientPropertyMap.keySet().iterator();
               while (it.hasNext()) {
                  String key = (String) it.next();
                  qos.addClientProperty(key, connectQosClientPropertyMap.get(
                        key).toString());
               }
            }
            //log.info("ConnectQos is " + qos.toXml());
            /* ConnectReturnQos crq = */con.connect(qos, new I_Callback() {
               public String update(String cbSessionId, UpdateKey updateKey,
                     byte[] content, UpdateQos updateQos)
                     throws XmlBlasterException {
                  try {
                     log.info("Received '" + updateKey.getOid() + "':"
                           + new String(content, "UTF-8"));
                  } catch (UnsupportedEncodingException e) {
                     log.severe("Update failed: " + e.toString());
                  }
                  return "";
               }
            }); // Login to xmlBlaster, register for updates
            log.info("Connect success");

            if (ret == 'd') {
               DisconnectQos dq = new DisconnectQos(glob);
               con.disconnect(dq);
               log.info("Disconnected from server, all resources released");
            } else {
               con.leaveServer(null);
               ret = 0;
               log.info("Left server, our server side session remains, bye");
            }
            con = null;

View Full Code Here


      this.glob = glob;


      try {
         ConnectQos loginQos = new ConnectQos(null); // creates "<qos></qos>" string
         I_XmlBlasterAccess blasterConnection = glob.getXmlBlasterAccess();
         blasterConnection.connect(loginQos, this)// Now we are connected to xmlBlaster MOM server.

         // Subscribe to messages with XPATH using some helper classes
         log.info("Subscribing #1 for anonymous callback class using XPath syntax ...");
         SubscribeKey key = new SubscribeKey(glob, "//DispatchTest", "XPATH");
         SubscribeQos qos = new SubscribeQos(glob);
         blasterConnection.subscribe(key, qos, new I_Callback() {
               public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
                  log.info("Receiving message with specialized update() #1 ...");
                  numReceived1++;
                  System.out.println(updateKey.toXml());
                  System.out.println((new String(content)).toString());
                  System.out.println(updateQos.toXml());
                  return "";
               }
            });


         log.info("Subscribing #2 for anonymous callback class using XPath syntax ...");
         key = new SubscribeKey(glob, "A message id");
         blasterConnection.subscribe(key, qos, new I_Callback() {
               public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
                  log.info("Receiving message with specialized update() #2 ...");
                  numReceived2++;
                  System.out.println(updateKey.toXml());
                  System.out.println((new String(content)).toString());
                  System.out.println(updateQos.toXml());
                  return "";
               }
            });


         // Construct a message and publish it ...
         String publishOid1 = "";
         // This time, as an example, we don't use the wrapper helper classes,
         // and create the string 'by hand':
         String xmlKey =   "<key oid='' contentMime='text/xml'>\n" +
                           "   <DispatchTest>" +
                           "   </DispatchTest>" +
                           "</key>";
         String content = "Some content #1";
         MsgUnit msgUnit = new MsgUnit(xmlKey, content.getBytes(), "<qos></qos>");
         publishOid1 = blasterConnection.publish(msgUnit).getKeyOid();
         log.info("Publishing done, returned oid=" + publishOid1);

         try { Thread.sleep(1000); } catch( InterruptedException i) {} // Wait a second

         String publishOid2 = "";
         xmlKey = "<key oid='A message id' contentMime='text/xml'>\n" +
                  "</key>";
         content = "Some content #2";
         msgUnit = new MsgUnit(xmlKey, content.getBytes(), "<qos></qos>");
         publishOid2 = blasterConnection.publish(msgUnit).getKeyOid();
         log.info("Publishing done, returned oid=" + publishOid2);


         try { Thread.sleep(1000); } catch( InterruptedException i) {} // Wait a second

         if (numReceived1 == 1)
            log.info("Success, got Callback #1 after publishing");
         else
            log.severe(numReceived1 + " callbacks arrived, did expect one after a simple subscribe with a publish");

         if (numReceived2 == 1)
            log.info("Success, got Callback #2 after publishing");
         else
            log.severe(numReceived2 + " callbacks arrived, did expect one after a simple subscribe with a publish");


         // cleaning up .... erase() the previous published message
         xmlKey = "<key oid='" + publishOid1 + "' queryType='EXACT'>\n" +
                  "</key>";
         EraseReturnQos[] strArr = blasterConnection.erase(xmlKey, "<qos></qos>");
         if (strArr.length != 1) log.severe("Erased " + strArr.length + " message.");

         xmlKey = "<key oid='" + publishOid2 + "' queryType='EXACT'>\n" +
                  "</key>";
         strArr = blasterConnection.erase(xmlKey, "<qos></qos>");
         if (strArr.length != 1) log.severe("Erased " + strArr.length + " message.");

         blasterConnection.disconnect(null);
      }
      catch(XmlBlasterException e) {
         log.severe("XmlBlasterException: " + e.getMessage());
      }
      catch (Exception e) {
View Full Code Here

         {
            Global global = new Global(args);
            ConnectQos qos = new ConnectQos(global, userName + "/" + sessionId, "secret");
            qos.getSessionCbQueueProperty().setMaxEntries(10L);
            qos.getSessionCbQueueProperty().setMaxEntriesCache(10L);
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            SubscribeKey subKey = new SubscribeKey(global, topicName);
            SubscribeQos subQos = new SubscribeQos(global);
            conn.subscribe(subKey, subQos);
            // conn.leaveServer(null);
            DisconnectQos disconnectQos = new DisconnectQos(global);
            disconnectQos.setLeaveServer(true);
            conn.disconnect(disconnectQos);
         }

         Global secondGlobal = new Global(args);
         MsgInterceptor msgInterceptor = new MsgInterceptor(secondGlobal, log, null);
         ConnectQos qos = new ConnectQos(secondGlobal, "tester/1", "secret");
         I_XmlBlasterAccess conn2 = secondGlobal.getXmlBlasterAccess();
         conn2.connect(qos, msgInterceptor);
         SubscribeKey subKey = new SubscribeKey(secondGlobal, "__sys__Event");
         SubscribeQos subQos = new SubscribeQos(secondGlobal);
         conn2.subscribe(subKey, subQos);
         msgInterceptor.clear();

         {
            // publish now
            Global global = new Global(args);
            qos = new ConnectQos(global, "testPublisher/1", "secret");
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            PublishKey pubKey = new PublishKey(global, topicName);
            PublishQos pubQos = new PublishQos(global);
            for (int i=0; i < 5; i++) {
               String content = "This is test " + i;
               conn.publish(new MsgUnit(pubKey, content.getBytes(), pubQos));
            }
           
            int ret = msgInterceptor.waitOnUpdate(3000L, 1);
            assertEquals("We expected one message for the excess of the history queue", 1, ret);
            msgInterceptor.clear();
            for (int i=5; i < 8; i++) {
               String content = "This is test " + i;
               conn.publish(new MsgUnit(pubKey, content.getBytes(), pubQos));
            }
            ret = msgInterceptor.waitOnUpdate(3000L, 1);
            assertEquals("We expected one message", 1, ret);
            msgInterceptor.clear();
            conn.disconnect(new DisconnectQos(global));
         }

         {
            Global global = new Global(args);
            qos = new ConnectQos(global, userName + "/" + sessionId, "secret");
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            Thread.sleep(1000L);
            conn.disconnect(new DisconnectQos(global));
         }
         conn2.disconnect(new DisconnectQos(secondGlobal));
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

         {
            Global global = new Global(args);
            ConnectQos qos = new ConnectQos(global, userName + "/" + sessionId, "secret");
            qos.getSessionCbQueueProperty().setMaxEntries(10L);
            qos.getSessionCbQueueProperty().setMaxEntriesCache(10L);
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            SubscribeKey subKey = new SubscribeKey(global, topicName);
            SubscribeQos subQos = new SubscribeQos(global);
            conn.subscribe(subKey, subQos);
            // conn.leaveServer(null);
            DisconnectQos disconnectQos = new DisconnectQos(global);
            disconnectQos.setLeaveServer(true);
            conn.disconnect(disconnectQos);
         }

         Global secondGlobal = new Global(args);
         MsgInterceptor msgInterceptor = new MsgInterceptor(secondGlobal, log, null);
         ConnectQos qos = new ConnectQos(secondGlobal, "tester/2", "secret");
         I_XmlBlasterAccess conn2 = secondGlobal.getXmlBlasterAccess();
         conn2.connect(qos, msgInterceptor);
         SubscribeKey subKey = new SubscribeKey(secondGlobal, "__sys__Event");
         SubscribeQos subQos = new SubscribeQos(secondGlobal);
         conn2.subscribe(subKey, subQos);
         msgInterceptor.clear();

         {
            // publish now
            Global global = new Global(args);
            qos = new ConnectQos(global, "testPublisher/1", "secret");
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            PublishKey pubKey = new PublishKey(global, topicName);
            PublishQos pubQos = new PublishQos(global);
            for (int i=0; i < 5; i++) {
               String content = "This is test " + i;
               conn.publish(new MsgUnit(pubKey, content.getBytes(), pubQos));
            }
           
            int ret = msgInterceptor.waitOnUpdate(3000L, 1);
            assertEquals("We expected one message for the excess of the history queue", 1, ret);
            msgInterceptor.clear();
            for (int i=5; i < 8; i++) {
               String content = "This is test " + i;
               conn.publish(new MsgUnit(pubKey, content.getBytes(), pubQos));
            }
            ret = msgInterceptor.waitOnUpdate(3000L, 2);
            assertEquals("We expected two messages: one for the excess of the callback queue and the other for the excess of the history queue of the __sys__Event topic", 2, ret);
            msgInterceptor.clear();
            conn.disconnect(new DisconnectQos(global));
         }

         {
            Global global = new Global(args);
            qos = new ConnectQos(global, userName + "/" + sessionId, "secret");
            I_XmlBlasterAccess conn = global.getXmlBlasterAccess();
            conn.connect(qos, this);
            Thread.sleep(1000L);
            conn.disconnect(new DisconnectQos(global));
         }
         conn2.disconnect(new DisconnectQos(secondGlobal));
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

      }
   }

   public void testSendAdministrativeCommand() {
      log.fine("sendAdministrativeCommand() ...");
      I_XmlBlasterAccess con = this.connGlobal.getXmlBlasterAccess();
      String sessionName = con.getSessionName().getAbsoluteName();
      {
         String command = sessionName+"/?dispatcherActive";
         log.info("Trying command '" + command + "'");
         try {
            String ret = con.sendAdministrativeCommand(command);
            log.info("Success: " + command + " returned '" + ret + "'");
            assertEquals("true", ret);
         }
         catch(XmlBlasterException e) {
            fail(e.getMessage());
         }
      }
      {
         String command = sessionName+"/?dispatcherActive=false";
         log.info("Trying command '" + command + "'");
         try {
            String ret = con.sendAdministrativeCommand(command);
            log.info("Success: " + command + " returned '" + ret + "'");
            assertEquals("OK", ret);
         }
         catch(XmlBlasterException e) {
            fail(e.getMessage());
         }
      }
      {
         String command = sessionName+"/?dispatcherActive";
         log.info("Trying command '" + command + "'");
         try {
            String ret = con.sendAdministrativeCommand(command);
            log.info("Success: " + command + " returned '" + ret + "'");
            assertEquals("false", ret);
         }
         catch(XmlBlasterException e) {
            fail(e.getMessage());
         }
      }
      {
         String command = "set " + sessionName+"/?dispatcherActive=true";
         log.info("Trying command '" + command + "'");
         try {
            String ret = con.sendAdministrativeCommand(command);
            log.info("Success: " + command + " returned '" + ret + "'");
            assertEquals("OK", ret);
         }
         catch(XmlBlasterException e) {
            fail(e.getMessage());
         }
      }
      {
         String command = "get " + sessionName+"/?dispatcherActive";
         log.info("Trying command '" + command + "'");
         try {
            String ret = con.sendAdministrativeCommand(command);
            log.info("Success: " + command + " returned '" + ret + "'");
            assertEquals("true", ret);
         }
         catch(XmlBlasterException e) {
            fail(e.getMessage());
View Full Code Here

    * @param passwd     The loginpassword.
    * @return The sender connection.
    */
   protected I_XmlBlasterAccess connectClient(String name, String passwd) {
      log.info("connect to client: name='" + name + "' passwd='" + passwd + "'");
         I_XmlBlasterAccess sc = null;
      try {
         sc = glob.getXmlBlasterAccess();
         ConnectQos qos = new ConnectQos(glob, name, passwd); // == "<qos></qos>";
         sc.connect(qos, this);
         log.info(name + " connected" );
      } catch (Exception e) {
          log.severe(e.toString());
          e.printStackTrace();
      }
View Full Code Here

         if (!args[0].equals("-key")) {
            printUsage();
            System.exit(0);
         }

         I_XmlBlasterAccess xmlBlaster = new XmlBlasterAccess(args);
         new SimpleReader(xmlBlaster, args[1]);

         while (true) {
            try {
               Thread.sleep(10);
View Full Code Here

      this.glob = (this.glob == null) ? Global.instance() : this.glob;

      this.updateInterceptor = new MsgInterceptor(this.glob, log, null);
     
      try {
         I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess(); // Find orb

         String passwd = "secret";
         ConnectQos connectQos = new ConnectQos(this.glob, senderName, passwd); // == "<qos>...</qos>";
         connectQos.setSessionName(new SessionName(this.glob, this.sessionName));
         con.connect(connectQos, this)// 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

      String xmlKey = "<key oid='' queryType='XPATH'>\n" +
                      "   //TestAdminGet-AGENT" +
                      "</key>";

      String qos = "<qos><forceDestroy>true</forceDestroy></qos>";
      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
      try {
         EraseReturnQos[] arr = con.erase(xmlKey, qos);

         PropString defaultPlugin = new PropString("CACHE,1.0");
         String propName = defaultPlugin.setFromEnv(this.glob, glob.getStrippedId(), null, "persistence", Constants.RELATING_TOPICSTORE, "defaultPlugin");
         log.info("Lookup of propName=" + propName + " defaultValue=" + defaultPlugin.getValue());
      }
      catch(XmlBlasterException e) {
         log.severe("XmlBlasterException: " + e.getMessage());
      }
      finally {
         con.disconnect(null);
         // reset to default server bootstrapPort (necessary if other tests follow in the same JVM).
         this.glob = null;
         con = null;
         Global.instance().shutdown();
      }
View Full Code Here

            System.err.println("Example:\n");
            System.err.println("java javaclients.simplereader.SimpleReaderGui -xpath '//key' -session.name simpleReader -passwd secret -protocol SOCKET -dispatch/connection/plugin/socket/hostname localhost -dumpToFile true -directoryName ${user.home}/FileDumper\n");
            System.exit(1);
         }

         I_XmlBlasterAccess xmlBlaster = glob.getXmlBlasterAccess();
         srGui = new SimpleReaderGui(xmlBlaster);
         srGui.loadImage();
         String loginName = glob.getProperty().get("session.name", "");
         ConnectQos qos = (loginName.length() < 1) ? new ConnectQos(glob, USR_LOGIN, null) : new ConnectQos(glob);
         xmlBlaster.connect(qos, srGui);
         srGui.setTitle(ME + "  " + xmlBlaster.getSessionName().getNodeIdStr() + "  <no subscription>");
      }
      catch(Exception ex) {
         log_error( ME, ex.toString(), "");
         ex.printStackTrace();
      }
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.