Dispatches the message represented by the given token.

@param token
the token representing the message
@param context
the context associated with the message
431550
void dispatch(final SibRaMessageToken token, final Map context) {

        final String methodName = "dispatch";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName,
                    new Object[] { token, context });
        }

        SibRaMessagingEngineConnection connection = null;
        BifurcatedConsumerSession session = null;
        SibRaDispatcher dispatcher = null;
        try {

            /*
             * Obtain connection to messaging engine
             */

            connection = getConnection(token.getBusName(), token.getMeUuid());

            /*
             * Obtain bifurcated consumer session
             */

            synchronized (_sessionsByMeUuid) {

                Map sessionsById = (Map) _sessionsByMeUuid.get(token
                        .getMeUuid());

                if (sessionsById == null) {

                    sessionsById = new HashMap();
                    _sessionsByMeUuid.put(token.getMeUuid(), sessionsById);

                }

                session = (BifurcatedConsumerSession) sessionsById
                        .get(Long.valueOf(token.getSessionId()));

                if (session == null) {

                    /*
                     * Create a new bifurcated consumer session
                     */

                    session = connection.getConnection()
                            .createBifurcatedConsumerSession(
                                    token.getSessionId());
                    sessionsById.put(Long.valueOf(token.getSessionId()), session);

                }

            }

            /**
             * Create the first dispatcher
             */
            if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled()) SibTr.debug(TRACE, "creating dispatcher for: " + _j2eeName);
            dispatcher = connection.createDispatcher(session, Reliability.getReliability(token.getUnrecoveredReliability()), token.getMaxFailedDeliveries(), token.getSequentialMessageThreshold());

            /*
             * Get the array of message ids
             */
            SIMessageHandle [] msgHandles = token.getMessageHandleArray();
            SIBusMessage [] messages = null;

            /**
             * If we are a non transactional MDB then
             * - If we can delete the messages when they are read then perform a readAndDeleteSet
             * - If the messages should be kept (the message has a higher reliability than unrecovered reliability
             * defined on the session) then just perform a read set.
             * For transactional MDBs do not read the messages yet. This will be done in the dispatcher's
             * dispatch code after a transaction has been started so that the readAndDelete can be performed
             * under this transaction.
             */
            if ((dispatcher instanceof SibRaNonTransactionalDispatcher) && (messages == null)) {
              if (token.isDeleteMessagesWhenRead()) {

                  if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled ()) {
                    SibTr.debug(this, TRACE,
                        "These messages will be deleted when read " + Arrays.toString(token.getMessageHandleArray ()));
                  }

                  messages = session.readAndDeleteSet(token.getMessageHandleArray (), null); // For messages that are being deleted

              } else {

                  if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled ()) {
                    SibTr.debug(this, TRACE,
                        "These messages will be read but not deleted yet " + Arrays.toString(token.getMessageHandleArray ()));
                  }

                  messages = session.readSet (token.getMessageHandleArray ()); // For messages that are not being deleted

              }

            }

            if ((msgHandles != null) && (msgHandles.length > 0)) {

                for (int i = 0; i < msgHandles.length; i++) {

                  /**
                   * Create a new dispatcher if we need one.
                   */
                  if (dispatcher == null) {
                        dispatcher = connection.createDispatcher(session, Reliability.getReliability(token.getUnrecoveredReliability()), token.getMaxFailedDeliveries(), token.getSequentialMessageThreshold());
                  }

                    dispatcher.dispatch(msgHandles[i], messages == null ? null : messages [i], context);

                    // Close the dispatcher and create a new one.
                    connection.closeDispatcher(dispatcher);
                    dispatcher = null;

                }
            } else {

                SibTr.error(TRACE, "READ_SET_CWSIV1051", new Object[] {
                        Long.valueOf(token.getSessionId()), token.getMeUuid(),
                        Arrays.deepToString (msgHandles), token.getJ2EEName() });

            }

        } catch (final SISessionUnavailableException exception) {

            // No FFDC code needed

            /*
             * Session has been closed by listener and message will have been
             * unlocked
             */

            if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled()) {
                SibTr.exception(this, TRACE, exception);
            }

        }
        catch (final SIMessageNotLockedException exception) {

            // No FFDC code needed

            /*
             * Message lock has expired and message will be reassigned
             */

            if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled()) {
                SibTr.exception(this, TRACE, exception);
            }

        }
    catch (SIRollbackException exception) {

            FFDCFilter.processException(exception, CLASS_NAME + "."
                    + methodName, "1:348:1.19", this);
            SibTr.warning(TRACE, "EXCEPTION_CWSIV1052", new Object[] {
                    Long.valueOf(token.getSessionId()), token.getMeUuid(),
                    Arrays.deepToString(token.getMessageHandleArray()), exception });

        } catch (final Exception exception) {

            FFDCFilter.processException(exception, CLASS_NAME + "."
                    + methodName, "1:356:1.19", this);
            SibTr.warning(TRACE, "EXCEPTION_CWSIV1052", new Object[] {
                    Long.valueOf(token.getSessionId()), token.getMeUuid(),
                    Arrays.deepToString(token.getMessageHandleArray()), exception });

            /*
             * Close the dispatcher before closing the connection (if the connection is 
             * closed while a dispatcher is open the closeConnection will just hang waiting
             * for the last dispatcher to be closed).
             */
            if (dispatcher != null) {
                connection.closeDispatcher(dispatcher);
            }

            // 255651: Close the connection to the ME if an unknown error occurs
            // to flush the connection and force a new one to be created
            closeConnection(token.getMeUuid(), false);

            // null out the disptacher so we don't try and close it again.
            dispatcher = null;

        } finally {

            /*
             * Close the dispatcher if its not already been closed
             */

            if (dispatcher != null) {
                connection.closeDispatcher(dispatcher);
            }

        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
104932
void start(final Context context) {
		checkConversationQueue();

		ApptentiveLog.i(TROUBLESHOOT, "Overriding log level: " + VERBOSE);
		oldLogLevel = ApptentiveLog.getLogLevel();
		ApptentiveLog.overrideLogLevel(VERBOSE);

		// show debug notification
		showDebugNotification(context);
	}
907212
public void setContext(DisplayContext context) {
        if (context.type() == DisplayContext.Type.CAPITALIZATION) {
            capitalizationSetting = context;
        }
    }
1283461
protected final void closeContext(GenerationContext context) {
		boolean runPostElements = false;
		GenerationContext selectedContext = null;
		synchronized (this) {
			final Iterator<GenerationContext> iterator = this.bufferedContexes.iterator();
			while (selectedContext == null && iterator.hasNext()) {
				final GenerationContext candidate = iterator.next();
				if (Objects.equal(candidate.getTypeIdentifier(), context.getTypeIdentifier())) {
					runPostElements = candidate.getParentContext() == null;
					selectedContext = candidate;
				}
			}
		}
		if (selectedContext == null) {
			throw new IllegalStateException("Not same contexts when closing"); //$NON-NLS-1$
		}
		if (runPostElements) {
			for (final Runnable handler : selectedContext.getPostFinalizationElements()) {
				handler.run();
			}
		}
		synchronized (this) {
			final Iterator<GenerationContext> iterator = this.bufferedContexes.iterator();
			while (iterator.hasNext()) {
				final GenerationContext candidate = iterator.next();
				if (selectedContext == candidate) {
					candidate.setParentContext(null);
					iterator.remove();
					return;
				}
			}
		}
	}
89206
public void push(T token) {
        if (token == lastPushed) return;
        lastPushed = token;
        if (token.getChannel() == TokenChannel.Default) {
            main.add(token);
        }
        all.add(token);
    }
770543
private void handleToken(String token) throws OptionParserException {
        currentToken = token;
        if (!"--".equals(token)) {
            if (currentOption != null && currentOption.acceptsValue() &&
                    !currentOption.isWithEqualSign() && isArgument(token)) {
                String t = OptionUtils.stripLeadingAndTrailingQuotes(token);
                currentOption.addValue(t);
            } else if (token.startsWith("--")) {
                String t = OptionUtils.stripLeadingHyphens(token);
                handleLongOption(t);
            } else if (token.startsWith("-") && token.length() > 1) {
                String t = OptionUtils.stripLeadingHyphens(token);
                handleShortAndLongOption(t);
            } else {
                handleUnknownToken(token);
            }
        }
        if (currentOption != null && !currentOption.acceptsValue()) {
            currentOption = null;
        }
    }
147442
public void addToken(Token token)
    {
        // Add verification of no token overlap
        if (!token.getSentence().equals(this))
            throw new IllegalArgumentException();
        tokens.add(token);
    }
177167
@Override
    public void parse(ParseContext context)
            throws MonetaryParseException {
        if (!context.consume(token)) {
            throw new MonetaryParseException(context.getOriginalInput(),
                    context.getErrorIndex());
        }
    }
142999
protected static function rawblock(&$token, &$context) {
        $inner = $token[Token::POS_INNERTAG];
        trim($inner);

        // skip parse when inside raw block
        if ($context['rawblock'] && !(($token[Token::POS_BEGINRAW] === '{{') && ($token[Token::POS_OP] === '/') && ($context['rawblock'] === $inner))) {
            return true;
        }

        $token[Token::POS_INNERTAG] = $inner;

        // Handle raw block
        if ($token[Token::POS_BEGINRAW] === '{{') {
            if ($token[Token::POS_ENDRAW] !== '}}') {
                $context['error'][] = 'Bad token ' . Token::toString($token) . ' ! Do you mean ' . Token::toString($token, array(Token::POS_ENDRAW => '}}')) . ' ?';
            }
            if ($context['rawblock']) {
                Parser::setDelimiter($context);
                $context['rawblock'] = false;
            } else {
                if ($token[Token::POS_OP]) {
                    $context['error'][] = "Wrong raw block begin with " . Token::toString($token) . ' ! Remove "' . $token[Token::POS_OP] . '" to fix this issue.';
                }
                $context['rawblock'] = $token[Token::POS_INNERTAG];
                Parser::setDelimiter($context);
                $token[Token::POS_OP] = '#';
            }
            $token[Token::POS_ENDRAW] = '}}';
        }
    }
840697
public static void initialize(Context context, int components) {
        NotificationDelegater delegater = getInstance();
        if (delegater.center() != null)
            throw new IllegalStateException("NotificationDelegater already init.");

        delegater.setContext(context);
        delegater.initComponents(components);
        Log.i(TAG, "Notification delegater initialize");
    }
331065
@Override
  public void onToken(Context context, String token, Bundle bundle) {
    updateAVInstallation(token);
  }
60616
public void registerPushServicesWithToken(final String token) {
        String httpURI;
        String httpMethod;

        JSONObject data = new JSONObject();
        try {
            data.put("token", token);
            data.put("service", "google");

            SharedPreferences prefs = appContext.getSharedPreferences(appContext.getPackageName(), Context.MODE_PRIVATE);

            if (null != prefs) {
                String lastKnownPushToken = prefs.getString(PROPERTY_LAST_VALID_PUSH_TOKEN, "notAvailable");
                String lastKnownPushTokenID = prefs.getString(PROPERTY_LAST_VALID_PUSH_TOKEN_ID, "notAvailable");

                if ((null == lastKnownPushTokenID) || (lastKnownPushTokenID.equals("notAvailable"))) {
                    httpURI = String.format("/v1/connections/%s/push-token", localConnectionID);
                    httpMethod = "post";
                    createOrUpdatePushServiceToken(token, httpURI, httpMethod, data, prefs);
                } else if (!lastKnownPushToken.equals("notAvailable") && !lastKnownPushToken.equals(token)) {
                    httpURI = String.format("/v1/connections/%s/push-token/%s", localConnectionID, lastKnownPushTokenID);
                    httpMethod = "put";
                    createOrUpdatePushServiceToken(token, httpURI, httpMethod, data, prefs);
                }
            }
        } catch(JSONException e) {
            Log.d("", "Invalid JSON format for token");
        }
    }
705061
public void push( Token token ) {
        size++;
        if( first == null ) {
            first = token;
            last = token;
            token.previous = null;
            token.next = null;
        } else {
            last.next = token;
            token.previous = last;
            token.next = null;
            last = token;
        }
    }
996771
public final void handleMessageSent(HttpRequestContext context, long bytes) {
    checkNotNull(context, "context");
    context.sentMessageSize.addAndGet(bytes);
    if (context.span.getOptions().contains(Options.RECORD_EVENTS)) {
      // record compressed size
      recordMessageEvent(context.span, context.sentSeqId.addAndGet(1L), Type.SENT, bytes, 0L);
    }
  }
881125
public static void beginContext(ControlContainerContext context)
    {
        Stack<ControlContainerContext> contextStack = _threadContexts.get();
        if (contextStack == null)
        {
            contextStack = new Stack<ControlContainerContext>();
            _threadContexts.set(contextStack);
        }
        contextStack.push(context);
    }
375888
private boolean tryToDispatchTokens(MessageHolderWithTokens msg) {
        try {
            dispatchTokensEvent.fire(msg);
            return true;
        } catch (MessageDeliveryException e) {
            Throwable cause = e.getCause();
            if (isQueueFullException(cause)) {
                return false;
            }
            throw e;
        }
    }
338052
public void init(HttpInboundServiceContext context) {
        this.message = context.getRequest();
        if (this.useEE7Streams) {
            this.body = new HttpInputStreamEE7(context);
        } else {
            this.body = new HttpInputStreamImpl(context);
        }
    }