Package org.xmlBlaster.engine.qos

Examples of org.xmlBlaster.engine.qos.GetReturnQosServer


    * @param contentMimeExtended Informative only, "XmlBlasterException" or "QueryResults"
    */
   private MsgUnit[] getResponseMessage(byte[] content, String contentMimeExtended)
   {
      PublishKey key = new PublishKey(glob, "__sys_jdbc."+ME, "text/xml", contentMimeExtended);
      GetReturnQosServer retQos = new GetReturnQosServer(glob, null, Constants.STATE_OK);

      MsgUnit mu = new MsgUnit(key.getData(), content, retQos.getData());

      if (log.isLoggable(Level.FINEST)) log.finest("SQL Results...\n" + new String(content));
      MsgUnit[] msgArr = new MsgUnit[1];
      msgArr[0] = mu;
      return msgArr;
View Full Code Here


            //if (sessionName != null) getQos.getData().getClientProperties().remove("__sessionName");
            String prefix = getQos.getData().getClientProperty("__prefix", (String)null);
            //if (prefix != null) publishQos.getData().getClientProperties().remove("__prefix");
            if (log.isLoggable(Level.FINE)) log.fine("Get " + xmlKey.getOid() + " prefix=" + prefix + " on session=" + otherSessionInfo.getSessionName().getRelativeName());
            ClientProperty[] props = otherSessionInfo.getRemotePropertyArr();
            GetReturnQosServer retQos = new GetReturnQosServer(glob, null, null);
            for (int i=0; i<props.length; i++)
               retQos.getData().getClientProperties().put(props[i].getName(), props[i]);
            MsgUnit[] msgUnitArr = new MsgUnit[1];
            GetKey gk = new GetKey(glob, xmlKey.getOid());
            msgUnitArr[0] = new MsgUnit(gk.getData(), new byte[0], retQos.getData());
            return msgUnitArr;
          }

         if (xmlKey.isAdministrative()) {
            if (!glob.supportAdministrative())
               throw new XmlBlasterException(glob, ErrorCode.RESOURCE_ADMIN_UNAVAILABLE, ME, "Sorry administrative get() is not available, try to configure xmlBlaster.");
            MsgUnit[] raw = glob.getMomClientGateway().getCommand(sessionInfo, xmlKey, getQos.getData());
            if (getQos.getWantContent())  return raw;

            MsgUnit[] msgUnitArr = new MsgUnit[raw.length];
            for(int i=0; i<raw.length; i++) {
               // byte[] cont = (getQos.getWantContent()) ? raw[i].getContent() : new byte[0];
               // msgUnitArr[i] = new MsgUnit(key, cont, raw[i].getQos());
               msgUnitArr[i] = new MsgUnit(raw[i], null, new byte[0], null);
            }
            return msgUnitArr;
         }

         if (Constants.JDBC_OID.equals(xmlKey.getOid()/*"__sys__jdbc"*/)) { // Query RDBMS !!! hack, we need a general service interface
            org.xmlBlaster.protocol.jdbc.XmlDBAdapter adap = new org.xmlBlaster.protocol.jdbc.XmlDBAdapter(glob,
                        xmlKey.getQueryString().getBytes(), (org.xmlBlaster.protocol.jdbc.NamedConnectionPool)this.glob.getObjectEntry("NamedConnectionPool-"+glob.getId()));
            return adap.query();
         }

         KeyData[] keyDataArr = queryMatchingKeys(sessionInfo, xmlKey, getQos.getData());
         ArrayList msgUnitList = new ArrayList(keyDataArr.length);

         if (log.isLoggable(Level.FINE)) log.fine("get(): " + ((keyDataArr!=null&&keyDataArr.length>0&&keyDataArr[0]!=null)?"Found local match "+keyDataArr[0].toXml():"No local match"));

         // Always forward the get request to the master
         // even if there are no matching keys
         // In the cluster environment all messages are accessed from the master cluster node,
         // tuning with XmlBlasterAccess.synchronousCache is not yet implemented.
         if (this.glob.isClusterManagerReady()) { // cluster support - forward erase to master
           try {
               MsgUnit tmp[] = glob.getClusterManager().forwardGet(sessionInfo, xmlKey, getQos);
               if (tmp != null && tmp.length > 0) {
                   log.info("get() access of " + tmp.length + " messages from cluster master");
                   for (int jj=0; jj<tmp.length; jj++) {
                       msgUnitList.add(tmp[jj]);
                       // We currently don' cache the message here in the slave !!!
                       // We could do it with the xmlBlasterConnection.initCache(int size)
                   }
               }
           }
           catch (XmlBlasterException e) {
               if (e.getErrorCode() == ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED) {
                   this.glob.setUseCluster(false);
               }
               else {
                   e.printStackTrace();
                   throw e;
               }
           }
           if (log.isLoggable(Level.FINE)) log.fine("get(): Found " + msgUnitList.size() + " remote matches for " + xmlKey.toXml());
         }

         NEXT_MSG: for (int ii=0; ii<keyDataArr.length; ii++) {
            KeyData xmlKeyExact = keyDataArr[ii];
            if (xmlKeyExact == null && xmlKey.isExact()) // subscription on a yet unknown message ...
               xmlKeyExact = xmlKey;

            TopicHandler topicHandler = this.glob.getTopicAccessor().access(xmlKeyExact.getOid());

            if( topicHandler == null ) {
               /*
               if (this.glob.useCluster()) { // cluster support - forward erase to master
                  try {
                     MsgUnit tmp[] = glob.getClusterManager().forwardGet(sessionInfo, xmlKey, getQos);
                     if (tmp != null && tmp.length > 0) {
                        log.info(ME, "get() access of " + tmp.length + " messages from cluster master");
                        for (int jj=0; jj<tmp.length; jj++) {
                           msgUnitList.add(tmp[jj]);
                           // We currently don' cache the message here in the slave !!!
                           // We could do it with the xmlBlasterConnection.initCache(int size)
                        }
                        continue NEXT_MSG;
                     }
                  }
                  catch (XmlBlasterException e) {
                     if (e.getErrorCode() == ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED) {
                        this.glob.setUseCluster(false);
                     }
                     else {
                        e.printStackTrace();
                        throw e;
                     }
                  }
               }
               */
               if (log.isLoggable(Level.FINE)) log.fine("get(): The key '"+xmlKeyExact.getOid()+"' is not available.");
               continue NEXT_MSG;

            } // topicHandler==null

            try {
               if (topicHandler.isAlive()) {

                  int numEntries = getQos.getHistoryQos().getNumEntries();
                  MsgUnitWrapper[] msgUnitWrapperArr = topicHandler.getMsgUnitWrapperArr(numEntries, getQos.getHistoryQos().getNewestFirst());

                  NEXT_HISTORY:
                  for(int kk=0; kk<msgUnitWrapperArr.length; kk++) {

                     MsgUnitWrapper msgUnitWrapper = msgUnitWrapperArr[kk];
                     if (msgUnitWrapper == null) {
                        continue NEXT_HISTORY;
                     }

                     if (this.glob.useCluster() && !msgUnitWrapper.getMsgQosData().isAtMaster()) {
                        if (log.isLoggable(Level.FINE)) log.fine("get(): Ignore message as we are not the master: " + msgUnitWrapper.toXml());
                        continue NEXT_HISTORY;
                     }

                     //topicHandler.checkFilter(SessionInfo publisherSessionInfo, SubscriptionInfo sub, MsgUnitWrapper msgUnitWrapper, boolean handleException)
                     AccessFilterQos[] filterQos = getQos.getAccessFilterArr();
                     if (filterQos != null) {
                        if (log.isLoggable(Level.FINE)) log.fine("Checking " + filterQos.length + " filters");
                        for (int jj=0; jj<filterQos.length; jj++) {
                           I_AccessFilter filter = getAccessPluginManager().getAccessFilter(
                                                        filterQos[jj].getType(),
                                                        filterQos[jj].getVersion(),
                                                        msgUnitWrapper.getContentMime(),
                                                        msgUnitWrapper.getContentMimeExtended());
                           if (log.isLoggable(Level.FINE)) log.fine("get("+xmlKeyExact.getOid()+") filter=" + filter + " qos=" + getQos.toXml());
                           if (filter != null && filter.match(sessionInfo,
                                                        msgUnitWrapper.getMsgUnit(),
                                                        filterQos[jj].getQuery()) == false)
                              continue NEXT_HISTORY; // filtered message is not send to client
                        }
                     }

                     if (msgUnitWrapper.isExpired()) {
                        continue NEXT_HISTORY;
                     }

                     MsgUnit mm = msgUnitWrapper.getMsgUnit();
                     if (mm == null) {
                        continue NEXT_HISTORY; // WeakReference to cache lost and lookup failed
                     }

                     GetReturnQosServer retQos = new GetReturnQosServer(glob, msgUnitWrapper.getMsgQosData(), Constants.STATE_OK);
                     byte[] cont = (getQos.getWantContent()) ? mm.getContent() : new byte[0];
                     mm = new MsgUnit(mm, null, cont, retQos.getData());
                     msgUnitList.add(mm);

                  } // for each history entry

               } // topicHandler.isAlive()
View Full Code Here

TOP

Related Classes of org.xmlBlaster.engine.qos.GetReturnQosServer

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.