Package flex.messaging.services

Examples of flex.messaging.services.Service


     */
    private void startServices()
    {
        for (Iterator iter=services.values().iterator(); iter.hasNext(); )
        {
            Service svc = (Service) iter.next();

            long timeBeforeStartup = 0;
            if (Log.isDebug())
            {
                timeBeforeStartup = System.currentTimeMillis();
                Log.getLogger(LOG_CATEGORY_STARTUP_SERVICE).debug("Service with id '{0}' is starting.",
                        new Object[]{svc.getId()});
            }

            svc.start();

            if (Log.isDebug())
            {
                long timeAfterStartup = System.currentTimeMillis();
                Long diffMillis = new Long(timeAfterStartup - timeBeforeStartup);
                Log.getLogger(LOG_CATEGORY_STARTUP_SERVICE).debug("Service with id '{0}' is ready (startup time: '{1}' ms)",
                        new Object[]{svc.getId(), diffMillis});
            }
        }
    }
View Full Code Here


     */
    private void stopServices()
    {
        for (Iterator iter=services.values().iterator(); iter.hasNext(); )
        {
            Service svc = (Service) iter.next();
            svc.stop();
        }
    }
View Full Code Here

        // Make sure message has a messageId
        checkMessageId(message);

        Object serviceResult = null;
        boolean serviced = false;
        Service service = null;
        String destId = message.getDestination();
        try
        {
            String serviceId = (String)destinationToService.get(destId);

            if ((serviceId == null) && (destId != null) && (!serviceValidationListeners.isEmpty()))
            {
                for (Enumeration iter = serviceValidationListeners.elements(); iter.hasMoreElements();)
                {
                    ((ServiceValidationListener)iter.nextElement()).validateDestination(destId);
                }
                serviceId = (String)destinationToService.get(destId);
            }

            if (serviceId != null)
            {
                service = (Service)services.get(serviceId);
                serviced = true;
                Destination destination = service.getDestination(destId);
                inspectOperation(message, destination);
                // Remove the validate endopint header if it was set.
                if (message.headerExists(Message.VALIDATE_ENDPOINT_HEADER))
                    message.getHeaders().remove(Message.VALIDATE_ENDPOINT_HEADER);

                if (Log.isDebug())
                    Log.getLogger(getLogCategory(message)).debug(
                            "Before invoke service: " + service.getId() + StringUtils.NEWLINE +
                            "  incomingMessage: " + message + StringUtils.NEWLINE);

                extractRemoteCredentials(service, message);
                serviceResult = service.serviceMessage(message);
            }

            if (!serviced)
            {
                MessageException lme = new MessageException();
                // No destination with id ''{0}'' is registered with any service.
                lme.setMessage(NO_SERVICE_FOR_DEST, new Object[] {destId});
                throw lme;
            }

            if (Log.isDebug())
            {
                String debugServiceResult = Log.getPrettyPrinter().prettify(serviceResult);
                Log.getLogger(getLogCategory(message)).debug(
                     "After invoke service: " + service.getId() + StringUtils.NEWLINE +
                     "  reply: " + debugServiceResult + StringUtils.NEWLINE);
            }

            AcknowledgeMessage ack = null;
            if (serviceResult instanceof AcknowledgeMessage)
            {
                // service will return an ack if they need to transform it in some
                // service-specific way (paging is an example)
                ack = (AcknowledgeMessage)serviceResult;
            }
            else
            {
                // most services will return a result of some sort, possibly null,
                // and expect the broker to compose a message to deliver it
                ack = new AcknowledgeMessage();
                ack.setBody(serviceResult);
            }
            ack.setCorrelationId(message.getMessageId());
            ack.setClientId(message.getClientId());
            return ack;
        }
        catch (MessageException exc)
        {
            exc.logAtHingePoint(message,
                                null, /* No outbound error message at this point. */
                                "Exception when invoking service '" + (service == null ? "(none)" : service.getId()) + "': ");

            throw exc;
        }
        catch (RuntimeException exc)
        {
            Log.getLogger(LogCategories.MESSAGE_GENERAL).error(
                 "Exception when invoking service: " +
                 (service == null ? "(none)" : service.getId()) +
                 StringUtils.NEWLINE +
                 "  with message: " + message + StringUtils.NEWLINE +
                 ExceptionUtil.exceptionFollowedByRootCausesToString(exc) + StringUtils.NEWLINE);

            throw exc;
        }
        catch (Error exc)
        {
            Log.getLogger(LogCategories.MESSAGE_GENERAL).error(
                 "Error when invoking service: " +
                 (service == null ? "(none)" : service.getId()) +
                 StringUtils.NEWLINE +
                 "  with message: " + message + StringUtils.NEWLINE +
                 ExceptionUtil.exceptionFollowedByRootCausesToString(exc) + StringUtils.NEWLINE);

            throw exc;
View Full Code Here

        checkMessageId(command);

        String destId = command.getDestination();

        AsyncMessage replyMessage = null;
        Service service = null;
        String serviceId = null;
        Object commandResult = null;
        boolean serviced = false;

        // Forward login and logout commands to AuthenticationService
        if (command.getOperation() == CommandMessage.LOGIN_OPERATION
                || command.getOperation() == CommandMessage.LOGOUT_OPERATION)
            serviceId = "authentication-service";
        else
            serviceId = (String)destinationToService.get(destId);

        service = (Service)services.get(serviceId);
        if (service != null)
        {
            // Before passing the message to the service, need to check
            // the security constraints.
            Destination destination = service.getDestination(destId);
            if (destination != null)
                inspectOperation(command, destination);

            try
            {
                extractRemoteCredentials(service, command);
                commandResult = service.serviceCommand(command);
                serviced = true;
            }
            catch (UnsupportedOperationException e)
            {
                ServiceException se = new ServiceException();
                se.setMessage(SERVICE_CMD_NOT_SUPPORTED, new Object[] {service.getClass().getName()});
                throw se;
            }
            catch (SecurityException se)
            {
                // when a LOGIN message causes a security exception, we want to continue processing here
                // to allow metadata to be sent to clients communicating with runtime destinations.
                // The result will be an error message with a login fault message as well as the metadata
                if (serviceId.equals("authentication-service"))
                {
                    commandResult = se.createErrorMessage();
                    if (Log.isDebug())
                        Log.getLogger(LOG_CATEGORY).debug("Security error for message: " +
                                se.toString() + StringUtils.NEWLINE +
                             "  incomingMessage: " + command + StringUtils.NEWLINE +
                             "  errorReply: " + commandResult);
                    serviced = true;
                }
                else
                {
                    throw se;
                }
            }
        }

        if (commandResult == null)
        {
            replyMessage = new AcknowledgeMessage();
        }
        else if (commandResult instanceof AsyncMessage)
        {
            replyMessage = (AsyncMessage)commandResult;
        }
        else
        {
            replyMessage = new AcknowledgeMessage();
            replyMessage.setBody(commandResult);
        }

        // Update the replyMessage body with server configuration if the
        // operation is ping or login and make sure to return the FlexClient Id value.
        if (command.getOperation() == CommandMessage.CLIENT_PING_OPERATION
                || command.getOperation() == CommandMessage.LOGIN_OPERATION)
        {
            boolean needsConfig = false;
            if (command.getHeader(CommandMessage.NEEDS_CONFIG_HEADER) != null)
                needsConfig = ((Boolean)(command.getHeader(CommandMessage.NEEDS_CONFIG_HEADER))).booleanValue();

            // Send configuration information only if the client requested.
            if (needsConfig)
            {
                ConfigMap serverConfig = describeServices(endpoint);
                if (serverConfig.size() > 0)
                    replyMessage.setBody(serverConfig);
            }

            // Record the features available over this endpoint
            double msgVersion = endpoint.getMessagingVersion();
            if (msgVersion > 0)
                replyMessage.setHeader(CommandMessage.MESSAGING_VERSION, new Double(msgVersion));

            // Record the flex client ID
            FlexClient flexClient = FlexContext.getFlexClient();
            if (flexClient != null)
                replyMessage.setHeader(Message.FLEX_CLIENT_ID_HEADER, flexClient.getId());
        }
        else if (!serviced)
        {
            MessageException lme = new MessageException();
            // No destination with id ''{0}'' is registered with any service.
            lme.setMessage(NO_SERVICE_FOR_DEST, new Object[] {destId});
            throw lme;
        }

        replyMessage.setCorrelationId(command.getMessageId());
        replyMessage.setClientId(command.getClientId());
        if (replyMessage.getBody() instanceof java.util.List)
        {
            replyMessage.setBody(((List) replyMessage.getBody()).toArray());
        }

        if (Log.isDebug())
            Log.getLogger(getLogCategory(command)).debug(
                 "Executed command: " +
                 (service == null ? "(default service)" : "service=" +
                                                          service.getId()) + StringUtils.NEWLINE +
                                                                           "  commandMessage: " + command + StringUtils.NEWLINE +
                                                                           "  replyMessage: " + replyMessage + StringUtils.NEWLINE);

        return replyMessage;
    }
View Full Code Here

    destSecurityConstraint = properties.getProperty("dest-security-constraint");
    destChannel = properties.getPropertyAsString("dest-channel","my-amf");
   
    includeEndsWithBeans = properties.getPropertyAsString("includeEndsWithBeans",DEFAULT_INCLUDE_END_WITH_BEANS);
   
    Service remotingService = broker.getService(serviceId);
    if(remotingService == null) {
      throw createServiceException("not found Service with serviceId:"+serviceId);
    }
     
        createSpringDestinations(remotingService);
View Full Code Here

    packageToScan = properties.getProperty("package-to-scan");
    if(packageToScan == null || "".equals(packageToScan.trim())) {
      throw createServiceException("'package-to-scan' property must be specify");
    }
   
    Service remotingService = broker.getService(serviceId);
    if(remotingService == null) {
      throw createServiceException("not found Service with serviceId:"+serviceId);
    }

    createJavaBeanDestinations(remotingService);
View Full Code Here

    destSecurityConstraint = properties.getProperty("dest-security-constraint");
    destChannel = properties.getPropertyAsString("dest-channel","my-amf");
   
    includeEndsWithBeans = properties.getPropertyAsString("includeEndsWithBeans",DEFAULT_INCLUDE_END_WITH_BEANS);
   
    Service remotingService = broker.getService(serviceId);
    if(remotingService == null) {
      throw createServiceException("not found Service with serviceId:"+serviceId);
    }
     
        createSpringDestinations(remotingService);
View Full Code Here

                String serviceType = (String) params.get(1);
                // In this case, the destName is not used because the dest is in the
                // message.  It is here just to be consistent with the other methods and
                // in case we need to send something to a destination without a message.
                String destName = (String) params.get(2);
                Service svc = clusterManager.getMessageBroker().getServiceByType(serviceType);
                if (svc != null)
                {
                    String methodName = (String) params.get(0);
                    Object[] paramValues = params.subList(3, params.size()).toArray();
                    Method[] svcMethods = svc.getClass().getMethods();
                    // note: in order to avoid requiring services to have specific formal
                    // types on methods (superclasses aren't honored by reflection) we just
                    // grab the first method we see with the correct name
                    // -- intended for internal use only
                    for (int i=0; i<svcMethods.length; i++)
View Full Code Here

            getAdapter().start();
            return;
        }
                       
        // Check if the Service is started
        Service service = getService();
        if (!service.isStarted())
        {
            if (Log.isWarn())
            {
                Log.getLogger(getLogCategory()).warn("Destination with id '{0}' cannot be started" +
                        " when its Service with id '{1}' is not started.",
                        new Object[]{getId(), service.getId()});
            }  
            return;
        }
       
        // Set up management
        if (isManaged() && service.isManaged())
        {
            setupDestinationControl(service);
            ServiceControl controller = (ServiceControl)service.getControl();
            if (getControl() != null)
                controller.addDestination(getControl().getObjectName());       
        }
       
        super.start();
View Full Code Here

        String oldId = getId();
       
        super.setId(id);
       
        // Update the destination id in the service and MessageBroker
        Service service = getService();
        if (service != null)
        {
            service.getMessageBroker().unregisterDestination(oldId);
            service.getDestinations().remove(oldId);           
            service.getMessageBroker().registerDestination(id, service.getId());           
            service.getDestinations().put(id, this);                                   
        }       
    }
View Full Code Here

TOP

Related Classes of flex.messaging.services.Service

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.