Examples of EventSubscriber


Examples of de.danet.an.workflow.api.EventSubscriber

  assertTrue(data.equals("Sent to: account@bank.com"));
    }

    public void waitForCompletion () throws Exception {
  // Obtain subscriber
  EventSubscriber subs = workflowService().createEventSubscriber ();

  // create the required  process
        WfRequester req = new DefaultRequester (workflowService());
  process = createProcess("ut-procdef-audit", "auditTest2", req);
  String procKey = process.key();
  assertTrue(process!=null);
  process.start ();

  WfAuditEvent e = null;
  while (true) {
            e = subs.receive(5000);
            assertTrue ("Timeout receiving event", e != null);
      if (e.eventType().equals (WfAuditEvent.PROCESS_STATE_CHANGED)
    && e.processKey().equals (procKey)
    && ((WfStateAuditEvent)e).newState().startsWith ("closed")) {
    break;
      }
  }
        assertTrue (e instanceof ProcessClosedAuditEvent);
        ProcessData res = ((ProcessClosedAuditEvent)e).result();
        assertTrue (res.keySet().size() == 2);
        assertTrue (res.keySet().contains("outVal1"));
        assertTrue (res.keySet().contains("inOutVal1"));
  assertTrue (subs.receive(2500) == null);
  workflowService().release (subs);
    }
View Full Code Here

Examples of de.danet.an.workflow.api.EventSubscriber

  workflowService().release (subs);
    }

    public void testFilters () throws Exception {
  // Obtain subscribers
  EventSubscriber subs = workflowService().createEventSubscriber ();

  // create the required  process
        WfRequester req = new DefaultRequester (workflowService());
  process = createProcess("ut-procdef-audit", "auditTest2", req);
  String procKey = process.key();
  assertTrue(process != null);

  // additional subscribers
  final int[] counters = new int[5];
  EventSubscriber subsAll = workflowService().createEventSubscriber ();
  subsAll.setEventHandler(new WfAuditHandler () {
    public void receiveEvent (WfAuditEvent e) {
        counters[0] += 1;
    }
      });
  EventSubscriber subsProc = workflowService()
      .createEventSubscriber (procKey, null);
  subsProc.setEventHandler(new WfAuditHandler () {
    public void receiveEvent (WfAuditEvent e) {
        counters[1] += 1;
    }
      });
  EventSubscriber subsPSC = workflowService().createEventSubscriber
      (procKey, WfAuditEvent.PROCESS_STATE_CHANGED);
  subsPSC.setEventHandler(new WfAuditHandler () {
    public void receiveEvent (WfAuditEvent e) {
        assertTrue (e.eventType().equals
        (WfAuditEvent.PROCESS_STATE_CHANGED));
        counters[2] += 1;
    }
      });
  EventSubscriber subsASC = workflowService().createEventSubscriber
      (procKey, WfAuditEvent.ACTIVITY_STATE_CHANGED);
  subsASC.setEventHandler(new WfAuditHandler () {
    public void receiveEvent (WfAuditEvent e) {
        assertTrue (e.eventType().equals
        (WfAuditEvent.ACTIVITY_STATE_CHANGED));
        counters[3] += 1;
    }
      });
  EventSubscriber subsPASC = workflowService().createEventSubscriber
      (procKey, WfAuditEvent.PROCESS_STATE_CHANGED
       + ", " + WfAuditEvent.ACTIVITY_STATE_CHANGED);
  subsPASC.setEventHandler(new WfAuditHandler () {
    public void receiveEvent (WfAuditEvent e) {
        assertTrue (e.eventType().equals
        (WfAuditEvent.PROCESS_STATE_CHANGED)
        || e.eventType().equals
        (WfAuditEvent.ACTIVITY_STATE_CHANGED));
View Full Code Here

Examples of de.danet.an.workflow.api.EventSubscriber

    /* Comment copied from interface. */
    public WfObject eventReceiver (WfAuditHandler handler)
  throws RemoteException {
  try {
      EventSubscriber es = new EventSubscriberImpl (null, null);
      es.setEventHandler (handler);
      return es;
  } catch (IOException e) {
      // This mapping is wrong but backward compatible, and the
      // method now deprecated anyway.
      throw (RemoteException)
View Full Code Here

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

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

            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

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

                    // 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

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

    }

    @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

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

        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

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

    }

    @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

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

        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
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.