Search in sources :

Example 1 with ResourceListener

use of com.cloud.common.request.ResourceListener in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method processResourceEvent.

protected void processResourceEvent(final Integer event, final Object... params) {
    final List<ResourceListener> lst = this._lifeCycleListeners.get(event);
    if (lst == null || lst.size() == 0) {
        return;
    }
    String eventName;
    for (final ResourceListener l : lst) {
        if (event.equals(ResourceListener.EVENT_DISCOVER_BEFORE)) {
            l.processDiscoverEventBefore((Long) params[0], (Long) params[1], (Long) params[2], (URI) params[3], (String) params[4], (String) params[5], (List<String>) params[6]);
            eventName = "EVENT_DISCOVER_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_DISCOVER_AFTER)) {
            l.processDiscoverEventAfter((Map<? extends ServerResource, Map<String, String>>) params[0]);
            eventName = "EVENT_DISCOVER_AFTER";
        } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_BEFORE)) {
            l.processDeleteHostEventBefore((HostVO) params[0]);
            eventName = "EVENT_DELETE_HOST_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_AFTER)) {
            l.processDeletHostEventAfter((HostVO) params[0]);
            eventName = "EVENT_DELETE_HOST_AFTER";
        } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE)) {
            l.processCancelMaintenaceEventBefore((Long) params[0]);
            eventName = "EVENT_CANCEL_MAINTENANCE_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER)) {
            l.processCancelMaintenaceEventAfter((Long) params[0]);
            eventName = "EVENT_CANCEL_MAINTENANCE_AFTER";
        } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE)) {
            l.processPrepareMaintenaceEventBefore((Long) params[0]);
            eventName = "EVENT_PREPARE_MAINTENANCE_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER)) {
            l.processPrepareMaintenaceEventAfter((Long) params[0]);
            eventName = "EVENT_PREPARE_MAINTENANCE_AFTER";
        } else {
            throw new CloudRuntimeException("Unknown resource event:" + event);
        }
        s_logger.debug("Sent resource event " + eventName + " to listener " + l.getClass().getSimpleName());
    }
}
Also used : ResourceListener(com.cloud.common.request.ResourceListener) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ServerResource(com.cloud.common.resource.ServerResource) Map(java.util.Map) HashMap(java.util.HashMap) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 2 with ResourceListener

use of com.cloud.common.request.ResourceListener in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method unregisterResourceEvent.

@Override
public void unregisterResourceEvent(final ResourceListener listener) {
    synchronized (this._lifeCycleListeners) {
        final Iterator it = this._lifeCycleListeners.entrySet().iterator();
        while (it.hasNext()) {
            final Map.Entry<Integer, List<ResourceListener>> items = (Map.Entry<Integer, List<ResourceListener>>) it.next();
            final List<ResourceListener> lst = items.getValue();
            lst.remove(listener);
        }
    }
}
Also used : ResourceListener(com.cloud.common.request.ResourceListener) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ResourceListener (com.cloud.common.request.ResourceListener)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ServerResource (com.cloud.common.resource.ServerResource)1 HostVO (com.cloud.host.HostVO)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1