Examples of SubscriptionManager


Examples of org.wso2.eventing.SubscriptionManager

    }

    @SuppressWarnings("unchecked")
    private EventBrokerService buildEventSource(OMElement configElement)
            throws ClassNotFoundException {
        SubscriptionManager subscriptionManager;
        NotificationManager notificationManager;
        EventDispatcher eventDispatcher;

        String eventSourceName = null;
        OMAttribute eventSourceNameAttribute = configElement.getAttribute(
                new QName(ATTR_NAME)) ;
        if (eventSourceNameAttribute != null) {
            eventSourceName = eventSourceNameAttribute.getAttributeValue();
        }

        OMElement subscriptionManagerElement = configElement.getFirstChildWithName(new QName(
                BROKER_CONFIG_NAMESPACE, LOCAL_NAME_SUBSCRIPTION_MANAGER_CONFIG));

        String subscriptionManagerClass = subscriptionManagerElement.getAttribute(
                new QName(ATTR_CLASS)).getAttributeValue();

        try {
            subscriptionManager =
                    (SubscriptionManager) Class.forName(subscriptionManagerClass).newInstance();
        } catch(Exception e) {
            String message = "Error while creating Subscription Manager";
            log.error(message, e);
            if (e instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)e;
            }
            throw new ActivationException(message, e);
        }

        Map<String, String> subscriptionManagerParameters = getParameters(
                subscriptionManagerElement.getChildrenWithName(new QName(
                        BROKER_CONFIG_NAMESPACE, LOCAL_NAME_PARAMETER)));
        Set<Map.Entry<String, String>> parameters = subscriptionManagerParameters.entrySet();
        for(Map.Entry<String, String> e : parameters) {
            subscriptionManager.addProperty(e.getKey(), e.getValue());
        }

        OMElement notificationManagerElement = configElement.getFirstChildWithName(new QName(
                BROKER_CONFIG_NAMESPACE, LOCAL_NAME_NOTIFICATION_MANAGER_CONFIG));

        String notificationManagerClass = notificationManagerElement.getAttribute(
                new QName(ATTR_CLASS)).getAttributeValue();

        try {
            notificationManager =
                    (NotificationManager) Class.forName(notificationManagerClass).newInstance();
            if (notificationManager instanceof CarbonNotificationManager) {
                Map<String, String> notificationManagerParameters = getParameters(
                        notificationManagerElement.getChildrenWithName(new QName(
                                BROKER_CONFIG_NAMESPACE, LOCAL_NAME_PARAMETER)));
                ((CarbonNotificationManager) notificationManager).init(
                        notificationManagerParameters);
            }
        } catch(Exception e) {
            String message = "Error while creating Notification Manager";
            log.error(message, e);
            if (e instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)e;
            }
            throw new ActivationException(message, e);
        }

        String eventDispatcherName = configElement.getFirstChildWithName(new QName(
                BROKER_CONFIG_NAMESPACE, LOCAL_NAME_EVENT_DISPATCHER_CONFIG)).getText().trim();

        try {
            eventDispatcher = (EventDispatcher) Class.forName(eventDispatcherName).newInstance();
            if (eventDispatcher instanceof CarbonEventDispatcher) {
                ((CarbonEventDispatcher)eventDispatcher).init(serverConfigurationContext);
            }
        } catch(Exception e) {
            String message = "Error while creating Event Dispatcher";
            log.error(message, e);
            if (e instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)e;
            }
            throw new ActivationException(message, e);
        }

        try {
            notificationManager.registerEventDispatcher(eventDispatcher);
            CarbonEventBroker broker;
            if (eventSourceName != null) {
                broker = (CarbonEventBroker)CarbonEventBroker.getInstance(eventSourceName);
            } else {
                broker = (CarbonEventBroker)CarbonEventBroker.getInstance();
            }
            broker.registerSubscriptionManager(subscriptionManager);
            broker.registerNotificationManager(notificationManager);
            subscriptionManager.init();
            if (eventSourceName != null) {
                dictionary.put(ATTR_NAME, eventSourceName);
            } else {
                dictionary.put(ATTR_NAME, DEFAULT_EVENT_SOURCE_NAME);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.