Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cloud.eventsubscriber;
- import com.cloud.server.ManagementServer;
- import com.cloud.utils.component.Adapters;
- import com.cloud.utils.component.ComponentLocator;
- import com.cloud.utils.component.Manager;
- import org.apache.cloudstack.framework.events.Event;
- import org.apache.cloudstack.framework.events.EventBus;
- import org.apache.cloudstack.framework.events.EventSubscriber;
- import org.apache.cloudstack.framework.events.EventTopic;
- import org.apache.log4j.Logger;
- import javax.ejb.Local;
- import javax.naming.ConfigurationException;
- import java.util.Enumeration;
- import java.util.Map;
- import java.util.UUID;
- @Local(value = {EventNotificationsSubscriber.class})
- public class EventNotificationSubscriberImpl implements EventNotificationsSubscriber, Manager {
- protected static EventBus _eventBus = null;
- protected static boolean _eventBusLoaded = false;
- private static final Logger s_logger = Logger.getLogger(EventNotificationsSubscriber.class);
- UUID one;
- @Override
- public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
- _eventBus = getEventBusProvider();
- return true;
- }
- @Override
- public boolean start() {
- EventTopic topic = new EventTopic(null, null, null, null, null);
- try {
- if (_eventBus != null) {
- one = _eventBus.subscribe(topic, new EventNotificationHandler(1));
- }
- } catch (Exception e) {
- }
- return true;
- }
- @Override
- public boolean stop() {
- return true;
- }
- @Override
- public String getName() {
- return null;
- }
- private static EventBus getEventBusProvider() {
- ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
- Adapters<EventBus> eventBusImpls = locator.getAdapters(EventBus.class);
- if (eventBusImpls != null) {
- Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
- if (eventBusenum != null && eventBusenum.hasMoreElements()) {
- _eventBus = eventBusenum.nextElement();
- }
- }
- return _eventBus;
- }
- public class EventNotificationHandler implements EventSubscriber {
- int id;
- public EventNotificationHandler(int id) {
- this.id = id;
- }
- @Override
- public void onEvent(Event event) {
- s_logger.info("HANDLER" + id + " Category: " + event.getEventCategory() + " type: " + event.getEventType() +
- " resource type: " + event.getResourceType() + " resource UUID: " + event.getResourceUUID());
- s_logger.info("BODY : " + event.getDescription());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement