Package org.apache.cloudstack.framework.events

Examples of org.apache.cloudstack.framework.events.EventSubscriber


        for (UUID subscriberId : subscribers.keySet()) {
            Pair<EventTopic, EventSubscriber>  subscriberDetails =  subscribers.get(subscriberId);
            // if the event matches subscribers interested event topic then call back the subscriber with the event
            if (isEventMatchesTopic(event, subscriberDetails.first())) {
                EventSubscriber subscriber =  subscriberDetails.second();
                subscriber.onEvent(event);
            }
        }
    }
View Full Code Here


            channel.basicConsume(queueName, s_autoAck, queueName, new DefaultConsumer(channel) {
                @Override
                public void handleDelivery(String queueName, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    Ternary<String, Channel, EventSubscriber> queueDetails = s_subscribers.get(queueName);
                    if (queueDetails != null) {
                        EventSubscriber subscriber = queueDetails.third();
                        String routingKey = envelope.getRoutingKey();
                        String eventSource = getEventSourceFromRoutingKey(routingKey);
                        String eventCategory = getEventCategoryFromRoutingKey(routingKey);
                        String eventType = getEventTypeFromRoutingKey(routingKey);
                        String resourceType = getResourceTypeFromRoutingKey(routingKey);
                        String resourceUUID = getResourceUUIDFromRoutingKey(routingKey);
                        Event event = new Event(eventSource, eventCategory, eventType, resourceType, resourceUUID);
                        event.setDescription(new String(body));

                        // deliver the event to call back object provided by subscriber
                        subscriber.onEvent(event);
                    }
                }
            });

            // update the channel details for the subscription
View Full Code Here

                    // prepare consumer on AMQP server for each of subscriber
                    for (String subscriberId : s_subscribers.keySet()) {
                        Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(subscriberId);
                        String bindingKey = subscriberDetails.first();
                        EventSubscriber subscriber = subscriberDetails.third();

                        /** create a queue with subscriber ID as queue name and bind it to the exchange
                         *  with binding key formed from event topic
                         */
                        Channel channel = createChannel(connection);
                        createExchange(channel, amqpExchangeName);
                        channel.queueDeclare(subscriberId, false, false, false, null);
                        channel.queueBind(subscriberId, amqpExchangeName, bindingKey);

                        // register a callback handler to receive the events that a subscriber subscribed to
                        channel.basicConsume(subscriberId, s_autoAck, subscriberId, new DefaultConsumer(channel) {
                            @Override
                            public void handleDelivery(String queueName, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                                Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(queueName); // queue name == subscriber ID

                                if (subscriberDetails != null) {
                                    EventSubscriber subscriber = subscriberDetails.third();
                                    String routingKey = envelope.getRoutingKey();
                                    String eventSource = getEventSourceFromRoutingKey(routingKey);
                                    String eventCategory = getEventCategoryFromRoutingKey(routingKey);
                                    String eventType = getEventTypeFromRoutingKey(routingKey);
                                    String resourceType = getResourceTypeFromRoutingKey(routingKey);
                                    String resourceUUID = getResourceUUIDFromRoutingKey(routingKey);

                                    // create event object from the message details obtained from AMQP server
                                    Event event = new Event(eventSource, eventCategory, eventType, resourceType, resourceUUID);
                                    event.setDescription(new String(body));

                                    // deliver the event to call back object provided by subscriber
                                    subscriber.onEvent(event);
                                }
                            }
                        });

                        // update the channel details for the subscription
View Full Code Here

    }

    @Test
    public void testSubscribe() throws Exception {
        EventTopic topic = mock(EventTopic.class);
        EventSubscriber subscriber = mock(EventSubscriber.class);

        InMemoryEventBus bus = new InMemoryEventBus();

        UUID uuid = bus.subscribe(topic, subscriber);
        assertNotNull(uuid);
View Full Code Here

        assertTrue(bus.totalSubscribers() == 0);
    }

    @Test(expected = EventBusException.class)
    public void testSubscribeFailTopic() throws Exception {
        EventSubscriber subscriber = mock(EventSubscriber.class);

        InMemoryEventBus bus = new InMemoryEventBus();

        bus.subscribe(null, subscriber);
    }
View Full Code Here

    }

    @Test
    public void testUnsubscribe() throws Exception {
        EventTopic topic = mock(EventTopic.class);
        EventSubscriber subscriber = mock(EventSubscriber.class);

        InMemoryEventBus bus = new InMemoryEventBus();

        UUID uuid = bus.subscribe(topic, subscriber);
        assertNotNull(uuid);
View Full Code Here

        bus.unsubscribe(null, null);
    }

    @Test(expected = EventBusException.class)
    public void testUnsubscribeFailWrongUUID() throws Exception {
        EventSubscriber subscriber = mock(EventSubscriber.class);
        InMemoryEventBus bus = new InMemoryEventBus();
        UUID uuid = UUID.randomUUID();

        bus.unsubscribe(uuid, subscriber);
    }
View Full Code Here

    }

    @Test
    public void testPublish() throws Exception {
        EventTopic topic = mock(EventTopic.class);
        EventSubscriber subscriber = mock(EventSubscriber.class);
        Event event = mock(Event.class);

        InMemoryEventBus bus = new InMemoryEventBus();

        UUID uuid = bus.subscribe(topic, subscriber);
View Full Code Here

        assertTrue(bus.totalSubscribers() == 0);
    }

    @Test
    public void testPublishEmpty() throws Exception {
        EventSubscriber subscriber = mock(EventSubscriber.class);
        Event event = mock(Event.class);

        InMemoryEventBus bus = new InMemoryEventBus();
        bus.publish(event);
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.framework.events.EventSubscriber

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.