001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.ecm.core.management.statuses;
021
022import java.io.Serializable;
023import java.util.HashMap;
024import java.util.Map;
025
026import org.nuxeo.ecm.core.api.SimplePrincipal;
027import org.nuxeo.ecm.core.api.security.SecurityConstants;
028import org.nuxeo.ecm.core.event.Event;
029import org.nuxeo.ecm.core.event.EventContext;
030import org.nuxeo.ecm.core.event.EventProducer;
031import org.nuxeo.ecm.core.event.impl.InlineEventContext;
032import org.nuxeo.ecm.core.management.api.AdministrativeStatusManager;
033import org.nuxeo.runtime.api.Framework;
034
035public class CoreEventNotifier implements Notifier {
036
037    @Override
038    public void notifyEvent(String eventName, String instanceIdentifier, String serviceIdentifier) {
039
040        Map<String, Serializable> eventProperties = new HashMap<String, Serializable>();
041
042        eventProperties.put("category", AdministrativeStatusManager.ADMINISTRATIVE_EVENT_CATEGORY);
043        eventProperties.put(AdministrativeStatusManager.ADMINISTRATIVE_EVENT_INSTANCE, instanceIdentifier);
044        eventProperties.put(AdministrativeStatusManager.ADMINISTRATIVE_EVENT_SERVICE, serviceIdentifier);
045
046        EventContext ctx = new InlineEventContext(new SimplePrincipal(SecurityConstants.SYSTEM_USERNAME),
047                eventProperties);
048
049        Event event = ctx.newEvent(eventName);
050        Framework.getService(EventProducer.class).fireEvent(event);
051    }
052
053}