Package flex.messaging.messages

Examples of flex.messaging.messages.Message


     */
    public FlushResult flush(MessageClient client, List outboundQueue)
    {
        FlushResult flushResult = new FlushResult();
        List messagesForClient = new ArrayList();
        Message message = null;
        for (Iterator iter = outboundQueue.iterator(); iter.hasNext();)
        {
            message = (Message)iter.next();
            if (message.getClientId().equals(client.getClientId()))
            {
                iter.remove();
                if (!isMessageExpired(message))
                    messagesForClient.add(message);
            }
View Full Code Here


                        if (!messageClient.isAttemptingInvalidationClientNotification())
                        {
                            Object messageClientId = messageClient.getClientId();
                            for (Iterator iter = queue.messages.iterator(); iter.hasNext(); )
                            {
                                Message message = (Message)iter.next();
                                if (message.getClientId().equals(messageClientId))
                                    iter.remove();
                            }
                        }
                       
                        // If no active subscriptions require the queue, clean it up if possible.
View Full Code Here

                // We need a unique instance of the message for each client; both to prevent
                // outbound queue processing for various clients from interfering with each other
                // as well as needing to target the copy of the message to a specific MessageAgent
                // instance on the client.
                Message messageForClient = (Message)message.clone();

              // the MPIUTil call will be a no-op if MPI is not enabled.  Otherwise it will add
              // a server pre-push processing timestamp to the MPI object
            MessagePerformanceUtils.markServerPrePushTime(message);
            MessagePerformanceUtils.markServerPostAdapterTime(message);
            MessagePerformanceUtils.markServerPostAdapterExternalTime(message);

                // Target the message to a specific MessageAgent on the client.
                messageForClient.setClientId(client.getClientId());

                if (Log.isDebug())
                    Log.getLogger(MessageService.LOG_CATEGORY).debug("Routing message to FlexClient id:" + client.getFlexClient().getId() + "', MessageClient id: " + client.getClientId());

                getMessageBroker().routeMessageToMessageClient(messageForClient, client);
View Full Code Here

     *
     * @param command The <code>CommandMessage</code> to process.
     */
    protected Message manageSubscriptions(CommandMessage command)
    {
        Message replyMessage = null;

        MessageDestination destination = (MessageDestination)getDestination(command);
        SubscriptionManager subscriptionManager = destination.getSubscriptionManager();

        Object clientId = command.getClientId();
        String endpointId = (String)command.getHeader(Message.ENDPOINT_HEADER);

        String subtopicString = (String) command.getHeader(AsyncMessage.SUBTOPIC_HEADER_NAME);

        ServiceAdapter adapter = destination.getAdapter();

        if (command.getOperation() == CommandMessage.SUBSCRIBE_OPERATION)
        {
            String selectorExpr = (String) command.getHeader(CommandMessage.SELECTOR_HEADER);

            getMessageBroker().inspectChannel(command, destination);

            // Give MessagingAdapter a chance to block the subscribe.
            if ((adapter instanceof MessagingAdapter))
                ((MessagingAdapter)adapter).getSecurityConstraintManager().assertSubscribeAuthorization();

            try
            {
                /*
                 * This allows parallel add/remove subscribe calls (protected by the
                 * concurrent hash table) but prevents us from doing any table mods
                 * when the getSubscriptionState method is active
                 */
                subscribeLock.readLock().lock();

                if (adapter.handlesSubscriptions())
                {
                    replyMessage = (Message) adapter.manage(command);
                }
                else
                {
                    testSelector(selectorExpr, command);
                }
                /*
                 * Even if the adapter is managing the subscription, we still need to
                 * register this with the subscription manager so that we can match the
                 * endpoint with the clientId.  I am not sure I like this though because
                 * now the subscription is registered both with the adapter and with our
                 * system so keeping them in sync is potentially problematic.   Also, it
                 * seems like the adapter should have the option to manage endpoints themselves?
                 */
                subscriptionManager.addSubscriber(clientId, selectorExpr, subtopicString, endpointId);
            }
            finally
            {
                subscribeLock.readLock().unlock();
            }

            if (replyMessage == null)
                replyMessage = new AcknowledgeMessage();
        }
        else if (command.getOperation() == CommandMessage.UNSUBSCRIBE_OPERATION)
        {
            // Give MessagingAdapter a chance to block the unsubscribe.
            if ((adapter instanceof MessagingAdapter))
                ((MessagingAdapter)adapter).getSecurityConstraintManager().assertSubscribeAuthorization();

            String selectorExpr = (String) command.getHeader(CommandMessage.SELECTOR_HEADER);

            try
            {
                subscribeLock.readLock().lock();

                if (adapter.handlesSubscriptions())
                {
                    replyMessage = (Message) adapter.manage(command);
                }
                subscriptionManager.removeSubscriber(clientId, selectorExpr, subtopicString, endpointId);
            }
            finally
            {
                subscribeLock.readLock().unlock();
            }

            if (replyMessage == null)
                replyMessage = new AcknowledgeMessage();
        }
        else if (command.getOperation() == CommandMessage.MULTI_SUBSCRIBE_OPERATION)
        {
            getMessageBroker().inspectChannel(command, destination);

            // Give MessagingAdapter a chance to block the multi subscribe.
            if ((adapter instanceof MessagingAdapter))
                ((MessagingAdapter)adapter).getSecurityConstraintManager().assertSubscribeAuthorization();

            try
            {
                /*
                 * This allows parallel add/remove subscribe calls (protected by the
                 * concurrent hash table) but prevents us from doing any table mods
                 * when the getSubscriptionState method is active
                 */
                subscribeLock.readLock().lock();

                if (adapter.handlesSubscriptions())
                {
                    replyMessage = (Message) adapter.manage(command);
                }

                // Deals with legacy collection setting
                Object[] adds = getObjectArrayFromHeader(command.getHeader(CommandMessage.ADD_SUBSCRIPTIONS));
                Object[] rems = getObjectArrayFromHeader(command.getHeader(CommandMessage.REMOVE_SUBSCRIPTIONS));

                if (adds != null)
                {
                    for (int i = 0; i < adds.length; i++)
                    {
                        String ss = (String) adds[i];
                        int ix = ss.indexOf(CommandMessage.SUBTOPIC_SEPARATOR);
                        if (ix != -1)
                        {
                            String subtopic = (ix == 0 ? null : ss.substring(0, ix));
                            String selector = ss.substring(ix+CommandMessage.SUBTOPIC_SEPARATOR.length());
                            if (selector.length() == 0)
                                selector = null;

                            subscriptionManager.addSubscriber(clientId, selector, subtopic, endpointId);
                        }
                        // invalid message
                    }
                }

                if (rems != null)
                {
                    for (int i = 0; i < rems.length; i++)
                    {
                        String ss = (String) rems[i];
                        int ix = ss.indexOf(CommandMessage.SUBTOPIC_SEPARATOR);
                        if (ix != -1)
                        {
                            String subtopic = (ix == 0 ? null : ss.substring(0, ix));
                            String selector = ss.substring(ix+CommandMessage.SUBTOPIC_SEPARATOR.length());
                            if (selector.length() == 0)
                                selector = null;

                            subscriptionManager.removeSubscriber(clientId, selector, subtopic, endpointId);
                        }
                    }
                }
            }
            finally
            {
                subscribeLock.readLock().unlock();
            }

            if (replyMessage == null)
                replyMessage = new AcknowledgeMessage();
        }
        else if (command.getOperation() == CommandMessage.POLL_OPERATION)
        {
            // This code path handles poll messages sent by Consumer.receive().
            // This API should not trigger server side waits, so we invoke poll
            // and if there are no queued messages for this Consumer instance we
            // return an empty acknowledgement immediately.
            MessageClient client = null;
            try
            {
                client = subscriptionManager.getMessageClient(clientId, endpointId);

                if (client != null)
                {
                    if (adapter.handlesSubscriptions())
                    {
                        List missedMessages = (List)adapter.manage(command);
                        if (missedMessages != null && !missedMessages.isEmpty())
                        {
                            MessageBroker broker = getMessageBroker();
                            for (Iterator iter = missedMessages.iterator(); iter.hasNext();)
                                broker.routeMessageToMessageClient((Message)iter.next(), client);
                        }
                    }
                    FlushResult flushResult = client.getFlexClient().poll(client);
                    List messagesToReturn = (flushResult != null) ? flushResult.getMessages() : null;
                    if (messagesToReturn != null && !messagesToReturn.isEmpty())
                    {
                        replyMessage = new CommandMessage(CommandMessage.CLIENT_SYNC_OPERATION);
                        replyMessage.setBody(messagesToReturn.toArray());
                    }
                    else
                    {
                        replyMessage = new AcknowledgeMessage();
                    }
View Full Code Here

    public Set getSubscriberIds(String subtopicPattern, Map messageHeaders)
    {
        // This could be more efficient but we'd have to change the SQLParser
        // to accept a map.
        Message msg = new AsyncMessage();
        msg.setHeader(AsyncMessage.SUBTOPIC_HEADER_NAME, subtopicPattern);
        if (messageHeaders != null)
            msg.setHeaders(messageHeaders);
        return getSubscriberIds(msg, true);
    }
View Full Code Here

        else if (data.getClass().isArray())
        {
            data = Array.get(data, 0);
        }

        Message inMessage;
        if (data instanceof Message)
        {
            inMessage = (Message)data;
        }
        else
        {
            throw new MessageException("Request was not of type flex.messaging.messages.Message");
        }
       
        Object outMessage = null;

        String replyMethodName = MessageIOConstants.STATUS_METHOD;

        try
        {
            // Lookup or create the correct FlexClient.
            endpoint.setupFlexClient(inMessage);

            // Assign a clientId if necessary.
            // We don't need to assign clientIds to general poll requests.
            if (inMessage.getClientId() == null &&
                (!(inMessage instanceof CommandMessage) || ((CommandMessage)inMessage).getOperation() != CommandMessage.POLL_OPERATION))
            {
                Object clientId = UUIDUtils.createUUID();
                inMessage.setClientId(clientId);
            }
           
            // Messages received via the AMF channel can be batched (by NetConnection on the client) and
            // we must not put the handler thread into a poll-wait state if a poll command message is followed by
            // or preceeded by other messages in the batch; the request-response loop must complete without waiting.
            // If the poll command is the only message in the batch it's ok to wait.
            // If it isn't ok to wait, tag the poll message with a header that short-circuits any potential poll-wait.
            if (inMessage instanceof CommandMessage)
            {
                CommandMessage command = (CommandMessage)inMessage;
                if ((command.getOperation() == CommandMessage.POLL_OPERATION) && (context.getRequestMessage().getBodyCount() != 1))
                    command.setHeader(CommandMessage.SUPPRESS_POLL_WAIT_HEADER, Boolean.TRUE);
            }           
           
            // If MPI is enabled update the MPI metrics on the object referred to by the context
            // and the messages
            if (context.isMPIenabled())           
              MessagePerformanceUtils.setupMPII(context, inMessage);

            // Service the message.
            outMessage = endpoint.serviceMessage(inMessage);                      

            // if processing of the message resulted in an error, set up context and reply method accordingly
            if (outMessage instanceof ErrorMessage)
            {
                context.setStatus(MessageIOConstants.STATUS_ERR);
                replyMethodName = MessageIOConstants.STATUS_METHOD;               
            }
            else
            {
                replyMethodName = MessageIOConstants.RESULT_METHOD;
            }
        }
        catch (MessageException e)
        {
            context.setStatus(MessageIOConstants.STATUS_ERR);
            replyMethodName = MessageIOConstants.STATUS_METHOD;

            outMessage = e.createErrorMessage();
            ((ErrorMessage)outMessage).setCorrelationId(inMessage.getMessageId());
            ((ErrorMessage)outMessage).setDestination(inMessage.getDestination());
            ((ErrorMessage)outMessage).setClientId(inMessage.getClientId());

            if (e instanceof flex.messaging.security.SecurityException)
            {
                if (Log.isDebug())
                    Log.getLogger(LOG_CATEGORY).debug("Security error for message: " +
                         e.toString() + StringUtils.NEWLINE +
                         "  incomingMessage: " + inMessage + StringUtils.NEWLINE +
                         "  errorReply: " + outMessage);
            }
            else if (e.getCode() != null && e.getCode().equals(MessageService.NOT_SUBSCRIBED_CODE))
            {
                if (Log.isDebug())
                    Log.getLogger(LOG_CATEGORY).debug("Client not subscribed: " +
                         e.toString() + StringUtils.NEWLINE +
                         "  incomingMessage: " + inMessage + StringUtils.NEWLINE +
                         "  errorReply: " + outMessage);
            }
            else if (Log.isError())
                Log.getLogger(LOG_CATEGORY).error("Error handling message: " +
                     e.toString() + StringUtils.NEWLINE +
                     "  incomingMessage: " + inMessage + StringUtils.NEWLINE +
                     "  errorReply: " + outMessage);
        }
        catch (Throwable t)
        {
            // Handle any uncaught failures. The normal exception path on the server
            // is to throw MessageExceptions which are handled in the catch block above,
            // so if that was skipped we have an overlooked or serious problem.
            context.setStatus(MessageIOConstants.STATUS_ERR);
            replyMethodName = MessageIOConstants.STATUS_METHOD;
           
            String lmeMessage = t.getMessage();
            if (lmeMessage == null)
              lmeMessage = t.getClass().getName();
           
            MessageException lme = new MessageException();
            lme.setMessage(UNHANDLED_ERROR, new Object[] {lmeMessage});
                       
            outMessage = lme.createErrorMessage();
            ((ErrorMessage)outMessage).setCorrelationId(inMessage.getMessageId());
            ((ErrorMessage)outMessage).setDestination(inMessage.getDestination());
            ((ErrorMessage)outMessage).setClientId(inMessage.getClientId());           
           
            if (Log.isError())
            {
                StringBuffer sb = new StringBuffer();
                StackTraceElement [] el = t.getStackTrace();
View Full Code Here

    private List legacyRequest(ActionContext context, List oldParams)
    {
        List newParams = new ArrayList(1);
        Map headerMap = new HashMap();
        Object body = oldParams;
        Message message = null;
        MessageBody requestBody = context.getRequestMessageBody();

        // Legacy Packet Security
        List packetHeaders = context.getRequestMessage().getHeaders();
        packetCredentials(packetHeaders, headerMap);
View Full Code Here

                else if (data.getClass().isArray())
                {
                    data = Array.get(data, 0);
                }

                Message inMessage;
                if (data instanceof Message)
                {
                    inMessage = (Message)data;
                    if (inMessage.getClientId() != null)
                    {
                        ((ErrorMessage)methodResult).setClientId(inMessage.getClientId().toString());
                    }
                    if (inMessage.getMessageId() != null)
                    {
                        ((ErrorMessage)methodResult).setCorrelationId(inMessage.getMessageId());
                        ((ErrorMessage)methodResult).setDestination(inMessage.getDestination());
                    }
                }
            }

            responseBody.setData(methodResult);
View Full Code Here

            Amf3Output amfOut = new Amf3Output(serializationContext);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            DataOutputStream dataOutStream = new DataOutputStream(outStream);
            amfOut.setOutputStream(dataOutStream);
           
            Message message = (Message)iter.next();
           
            // Add performance information if MPI is enabled.
            if (isRecordMessageSizes() || isRecordMessageTimes())
                addPerformanceInfo(message);
           
View Full Code Here

            AmfxOutput amfxOut = new AmfxOutput(serializationContext);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            DataOutputStream dataOutStream = new DataOutputStream(outStream);
            amfxOut.setOutputStream(dataOutStream);
           
            Message message = (Message)iter.next();

            // Add performance information if MPI is enabled.
            if (isRecordMessageSizes() || isRecordMessageTimes())
                addPerformanceInfo(message);           
           
View Full Code Here

TOP

Related Classes of flex.messaging.messages.Message

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.