001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo - initial API and implementation
011 *
012 * $Id$
013 */
014
015package org.nuxeo.runtime;
016
017/**
018 * An event in the Nuxeo Runtime life cycle.
019 * <p>
020 * The following event types are defined:
021 * <ul>
022 * <li> <code>RUNTIME_ABOUT_TO_START</code> Sent before starting the runtime
023 * <li> <code>RUNTIME_STARTED</code> Sent after the runtime was started
024 * <li> <code>RUNTIME_ABOUT_TO_STOP</code> Sent before stopping the runtime
025 * <li> <code>RUNTIME_STOPPED</code> Sent after the runtime stopped
026 * </ul>
027 * Note: these events are not supposed to leave the runtime, hence are not declared serializable.
028 *
029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
030 */
031public class RuntimeServiceEvent {
032
033    // the event IDs
034    public static final int RUNTIME_ABOUT_TO_START = 0;
035
036    public static final int RUNTIME_STARTED = 1;
037
038    public static final int RUNTIME_ABOUT_TO_STOP = 2;
039
040    public static final int RUNTIME_STOPPED = 3;
041
042    /** The event id. */
043    public final int id;
044
045    public final RuntimeService runtime;
046
047    public RuntimeServiceEvent(int id, RuntimeService runtime) {
048        this.id = id;
049        this.runtime = runtime;
050    }
051
052    /**
053     * Gets the event name as a string.
054     *
055     * @return the event name
056     */
057    public final String getEventName() {
058        switch (id) {
059        case RUNTIME_STARTED:
060            return "RUNTIME_STARTED";
061        case RUNTIME_STOPPED:
062            return "RUNTIME_STOPPED";
063        case RUNTIME_ABOUT_TO_STOP:
064            return "RUNTIME_ABOUT_TO_STOP";
065        case RUNTIME_ABOUT_TO_START:
066            return "RUNTIME_ABOUT_TO_START";
067        }
068        return "UNKNOWN";
069    }
070
071    @Override
072    public String toString() {
073        return getEventName();
074    }
075
076    // FIXME: review this, this looks suspicious (doesn't check on this.id).
077    @Override
078    public boolean equals(Object obj) {
079        if (obj == this) {
080            return true;
081        }
082        if (obj == null) {
083            return false;
084        }
085        return obj.getClass().equals(this.getClass());
086    }
087
088}