Package org.xmlBlaster.util.dispatch

Examples of org.xmlBlaster.util.dispatch.DispatchManager


                  log.severe("Can't create session " + sessionName.getAbsoluteName());
                  return null;
               }
            }
           
            DispatchManager mgr = myRemotePartnerLogin.getDispatchManager();
            if (mgr != null) {
               boolean fireInitial = true;
                mgr.addConnectionStatusListener(new I_ConnectionStatusListener() {
                   // The !remote! node has logged in (not our client connection)
                   public void toAlive(DispatchManager dispatchManager, ConnectionStateEnum oldState) {
                      SessionInfo myRemotePartnerLogin = fatherGlob.getRequestBroker().getAuthenticate(secretSessionId).getSessionInfo(sessionName);
                      if (myRemotePartnerLogin != null && myRemotePartnerLogin.getAddressServer() != null) {
                         Object obj = myRemotePartnerLogin.getAddressServer().getCallbackDriver();
View Full Code Here


    * All entries from our holdback queue are flushed to the official queues
    * of the DispatchManager
    */
   private void flushHoldbackQueue(DispatchManagerEntry managerEntry) {
      synchronized (this)  {
         DispatchManager dispatchManager = managerEntry.getDispatchManager();
         I_Queue holdbackQueue = managerEntry.getHoldbackQueue();
         if (holdbackQueue != null && holdbackQueue.getNumOfEntries() > 0) {
            log.info("Flushing " + holdbackQueue.getNumOfEntries() + " entries from holdback queue " + holdbackQueue.getStorageId());
            List<I_Entry> list = null;
            int lastSize = -99;
            while (holdbackQueue.getNumOfEntries() > 0) {

               try {
                  list = holdbackQueue.peek(-1, -1);
                  if (holdbackQueue.getNumOfEntries() == lastSize) {
                     log.severe("PANIC: " + holdbackQueue.getNumOfEntries() + " entries from holdback queue " + holdbackQueue.getStorageId() + " can't be flushed, giving up!");
                     break;
                  }
                  lastSize = (int)holdbackQueue.getNumOfEntries();
               }
               catch (XmlBlasterException e) {
                  log.severe("PANIC: Can't flush holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.getNumOfEntries() + " entries: " + e.getMessage());
                  e.printStackTrace();
                  continue;
               }

               MsgQueueEntry[] queueEntries = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
               // On error we send them as dead letters, as we don't know what to do with them in our holdback queue
               try {
                  dispatchManager.getQueue().put(queueEntries, false);
               }
               catch (XmlBlasterException e) {
                  log.warning("flushHoldbackQueue() failed: " + e.getMessage());
                  // errorCode == "ONOVERFLOW"
                  dispatchManager.getMsgErrorHandler().handleError(new MsgErrorInfo(glob, queueEntries, dispatchManager, e));
               }

               try {
                  long num = holdbackQueue.removeNum(list.size());
                  if (num != list.size()) {
                     log.severe("PANIC: Expected to remove from holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.getNumOfEntries() + " entries " + list.size() + " entries, but only " + num + " where removed");
                  }
               }
               catch (XmlBlasterException e) {
                  log.severe("PANIC: Expected to remove from holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.getNumOfEntries() + " entries " + list.size() + " entries: " + e.getMessage());
               }
            }

            holdbackQueue.clear();
            dispatchManager.notifyAboutNewEntry();
         }
         else {
            if (log.isLoggable(Level.FINE)) log.fine("No holdback queue for " + dispatchManager.getId() + ", nothing to flush");
         }
      }
   }
View Full Code Here

      if (sessionInfo == null) {
         log.severe("getDispatchManager the sessionInfo object is null");
         Thread.dumpStack();
         return null;
      }
      DispatchManager dispatchManager = sessionInfo.getDispatchManager();
      if (dispatchManager == null) {
         log.severe("getDispatchManager the dispatcherManager object is null");
         Thread.dumpStack();
         return null;
      }
View Full Code Here

    */
   public void subscriptionAdd(SubscriptionEvent e)
      throws XmlBlasterException {
      SubscriptionInfo subscriptionInfo = e.getSubscriptionInfo();
      if (log.isLoggable(Level.FINER)) log.finer("onAddSubscriber");
      DispatchManager dispatchManager = getDispatchManager(subscriptionInfo);
      if (dispatchManager != null) dispatchManager.addConnectionStatusListener(this);
      this.isReady = true;
      toRunning();
   }
View Full Code Here

    * @param subscriptionInfo
    */
   public void subscriptionRemove(SubscriptionEvent e) throws XmlBlasterException {
      SubscriptionInfo subscriptionInfo = e.getSubscriptionInfo();
      if (log.isLoggable(Level.FINER)) log.finer("onRemoveSubscriber");
      DispatchManager dispatchManager = getDispatchManager(subscriptionInfo);
      if (dispatchManager != null) dispatchManager.removeConnectionStatusListener(this);
   }
View Full Code Here

   public boolean match(SessionInfo receiver, MsgUnit msgUnit, Query query) throws XmlBlasterException {
      if (msgUnit == null) {
         Thread.dumpStack();
         throw new XmlBlasterException(glob, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Illegal argument in match() call");
      }
      DispatchManager dm = receiver.getDispatchManager();
      dm.addConnectionStatusListener(this); // register for toAlive() and toPolling() events (multiple calls don't harm)
      try {
         if (dm.isPolling() || dm.isShutdown()) {
            String[] subIds = receiver.getSubscriptions();
            if (log.isLoggable(Level.FINE))
               log.fine(dm.getSessionName().getAbsoluteName() + " is not reachable, cleaning "
                     + subIds.length + " subscriptions and "
                     + dm.getQueue().getNumOfEntries() + " callbackQueue entries");
            for (int i=0; i<subIds.length; i++) {
               receiver.unSubscribe(Constants.SUBSCRIPTIONID_URL_PREFIX+subIds[i], null);
            }
            //Can cause deadlock between CacheQueueInterceptor.clear sync and TopicHandler sync (see from toPolling or toAlive below)
            //dm.getQueue().clear();
View Full Code Here

      try {
         XmlBlasterException xmlBlasterException = msgErrorInfo.getXmlBlasterException();
         ErrorCode errorCode = xmlBlasterException.getErrorCode();
         message = xmlBlasterException.getMessage();
         MsgQueueEntry[] msgQueueEntries = msgErrorInfo.getMsgQueueEntries();
         DispatchManager dispatchManager = (this.sessionInfo == null) ? null : this.sessionInfo.getDispatchManager();
         I_Queue msgQueue = msgErrorInfo.getQueue()// is null if entry is not yet in queue
  
         if (log.isLoggable(Level.FINER)) log.finer("Error handling started: " + msgErrorInfo.toString());
  
         if (msgQueueEntries != null && msgQueueEntries.length > 0) {
            // 1. Generate dead letters from passed messages
            glob.getRequestBroker().deadMessage(msgQueueEntries, msgQueue, message);
  
            if (msgQueue != null) {
               // Remove the above published dead message from the queue
               try {
                  if (log.isLoggable(Level.FINE)) log.fine("Removing " + msgQueueEntries.length + " dead messages from queue");
                  long removed = 0L;
                  boolean tmp[] = msgQueue.removeRandom(msgQueueEntries);
                  for (int i=0; i < tmp.length; i++) if (tmp[i]) removed++;
                  if (removed != msgQueueEntries.length) {
                     log.warning("Expected to remove " + msgQueueEntries.length + " messages from queue but where only " + removed + ": " + message);
                  }
               }
               catch (XmlBlasterException e) {
                  log.warning("Can't remove " + msgQueueEntries.length + " messages from queue: " + e.getMessage() + ". Original cause was: " + message);
               }
            }
         }
  
         if (xmlBlasterException.isUser()) {
            // The update() method from the client has thrown a ErrorCode.USER* error
            if (log.isLoggable(Level.FINE)) log.fine("Error handlig for exception " + errorCode.toString() + " done");
            return;
         }
  
         // 2a. Generate dead letters if there are some entries in the queue
         size = (msgQueue == null) ? 0 : msgQueue.getNumOfEntries();
         if (log.isLoggable(Level.FINE)) log.fine("Flushing " + size + " remaining message from queue");
         if (size > 0) {
            try {
               QueuePropertyBase queueProperty = (QueuePropertyBase)msgQueue.getProperties();
               if (queueProperty == null || queueProperty.onFailureDeadMessage()) {
                  while (msgQueue.getNumOfEntries() > 0L) {
                     List<I_Entry> list = msgQueue.peek(-1, MAX_BYTES);
                     MsgQueueEntry[] msgArr = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
                     if (msgArr.length > 0) {
                        glob.getRequestBroker().deadMessage(msgArr, (I_Queue)null, message);
                     }
                     if (msgArr.length > 0) {
                        msgQueue.removeRandom(msgArr);
                     }
                  }
               }
               else {
                  log.severe("PANIC: Only onFailure='" + Constants.ONOVERFLOW_DEADMESSAGE +
                        "' is implemented, " + msgQueue.getNumOfEntries() + " messages are lost: " + message);
               }
            }
            catch(Throwable e) {
               e.printStackTrace();
               log.severe("PANIC: givingUpDelivery failed, " + size +
                              " messages are lost: " + message + ": " + e.toString());
            }
         }

         // 2b. Generate dead letters if there is a raw message which we could not parse
         if (msgErrorInfo.getMsgUnitRaw() != null) {
             MsgUnitRaw msgUnitRaw = msgErrorInfo.getMsgUnitRaw();
             glob.getRequestBroker().publishDeadMessageRaw(msgErrorInfo.getSessionName(), msgUnitRaw, message, null);
         }

         // We do a auto logout if the callback is down
         if (dispatchManager == null || dispatchManager.isDead()) {
            if (log.isLoggable(Level.FINE)) log.fine("Doing error handling for dead connection state ...");
  
            if (dispatchManager!=null) dispatchManager.shutdown();
  
            // 3. Kill login session
            if (this.sessionInfo != null && // if callback has been configured (async)
                sessionInfo.getConnectQos().getSessionCbQueueProperty().getCallbackAddresses().length > 0) {
              
View Full Code Here

                        continue;
                      SessionInfo[] ses = subjectInfo.getSessions();
                      for (int se=0; se<ses.length; se++) {
                        if (!wildcardMatch(sessionName.getPublicSessionId(), ses[se].getPublicSessionId()))
                          continue;
                        DispatchManager mgr = ses[se].getDispatchManager();
                            if (mgr != null) {
                                mgr.addConnectionStatusListener(this);
                             }
                      }
                    }
                  }
               }
               else {
                  log.fine("Register callback session state event = " + event);
                  SessionInfo sessionInfo = this.requestBroker.getAuthenticate().getSessionInfo(sessionName);
                  DispatchManager mgr = null;
                  if (sessionInfo != null)
                     mgr = sessionInfo.getDispatchManager();
                  if (mgr != null) {
                     mgr.addConnectionStatusListener(this);
                  }
                  else {
                     if (this.pendingCallbackSessionInfoSet == null) this.pendingCallbackSessionInfoSet = new TreeSet();
                     this.pendingCallbackSessionInfoSet.add(sessionName.getAbsoluteName());
                  }
View Full Code Here

                  }
               }
               if (found) {
                  SessionName sessionName = new SessionName(this.engineGlob, name);
                  SessionInfo sessionInfo = this.requestBroker.getAuthenticate().getSessionInfo(sessionName);
                  DispatchManager mgr = null;
                  if (sessionInfo != null)
                     mgr = sessionInfo.getDispatchManager();
                  if (mgr != null) {
                     mgr.addConnectionStatusListener(this, true); // true: fire initial event
                     // done already:
                     //if (this.callbackSessionStateSet == null) this.callbackSessionStateSet = new TreeSet();
                     //this.callbackSessionStateSet.add(sessionName.getRelativeName());
                  }
                  else
View Full Code Here

                  System.err.println("EventPlugin.sessionPreRemoved: Unexpected occurrence of " + name);

               // Remove the listener for now
               SessionName sessionName = new SessionName(this.engineGlob, name);
               SessionInfo sessionInfo = this.requestBroker.getAuthenticate().getSessionInfo(sessionName);
               DispatchManager mgr = null;
               if (sessionInfo != null)
                  mgr = sessionInfo.getDispatchManager();
               if (mgr != null) {
                  mgr.removeConnectionStatusListener(this);
                  // this.callbackSessionStateSet does not change as the client could login again
               }
            } catch (Throwable e) {
               e.printStackTrace();
            }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.dispatch.DispatchManager

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.