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 * $Id$ 020 */ 021 022package org.nuxeo.runtime; 023 024/** 025 * An event in the Nuxeo Runtime life cycle. 026 * <p> 027 * The following event types are defined: 028 * <ul> 029 * <li> <code>RUNTIME_ABOUT_TO_START</code> Sent before starting the runtime 030 * <li> <code>RUNTIME_STARTED</code> Sent after the runtime was started 031 * <li> <code>RUNTIME_ABOUT_TO_STOP</code> Sent before stopping the runtime 032 * <li> <code>RUNTIME_STOPPED</code> Sent after the runtime stopped 033 * </ul> 034 * Note: these events are not supposed to leave the runtime, hence are not declared serializable. 035 * 036 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 037 */ 038public class RuntimeServiceEvent { 039 040 // the event IDs 041 public static final int RUNTIME_ABOUT_TO_START = 0; 042 043 public static final int RUNTIME_STARTED = 1; 044 045 public static final int RUNTIME_ABOUT_TO_STOP = 2; 046 047 public static final int RUNTIME_STOPPED = 3; 048 049 /** The event id. */ 050 public final int id; 051 052 public final RuntimeService runtime; 053 054 public RuntimeServiceEvent(int id, RuntimeService runtime) { 055 this.id = id; 056 this.runtime = runtime; 057 } 058 059 /** 060 * Gets the event name as a string. 061 * 062 * @return the event name 063 */ 064 public final String getEventName() { 065 switch (id) { 066 case RUNTIME_STARTED: 067 return "RUNTIME_STARTED"; 068 case RUNTIME_STOPPED: 069 return "RUNTIME_STOPPED"; 070 case RUNTIME_ABOUT_TO_STOP: 071 return "RUNTIME_ABOUT_TO_STOP"; 072 case RUNTIME_ABOUT_TO_START: 073 return "RUNTIME_ABOUT_TO_START"; 074 } 075 return "UNKNOWN"; 076 } 077 078 @Override 079 public String toString() { 080 return getEventName(); 081 } 082 083 // FIXME: review this, this looks suspicious (doesn't check on this.id). 084 @Override 085 public boolean equals(Object obj) { 086 if (obj == this) { 087 return true; 088 } 089 if (obj == null) { 090 return false; 091 } 092 return obj.getClass().equals(this.getClass()); 093 } 094 095}