00001 /* 00002 * ServiceEvent.hpp 00003 * 00004 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_SERVICE_EVENT_HPP 00017 #define COH_SERVICE_EVENT_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/util/Event.hpp" 00022 #include "coherence/util/Listeners.hpp" 00023 00024 COH_OPEN_NAMESPACE2(coherence,util) 00025 00026 class Service; 00027 00028 00029 /** 00030 * An event which indicates that a Service state has changed: 00031 * <ul> 00032 * <li>a service is starting</li> 00033 * <li>a service has started</li> 00034 * <li>a service is stopping</li> 00035 * <li>a service has stopped</li> 00036 * </ul> 00037 * A ServiceEvent object is sent as an argument to the ServiceListener 00038 * interface methods. 00039 * 00040 * @see Service 00041 * @see ServiceListener 00042 * 00043 * @author jh 2007.12.13 00044 */ 00045 class COH_EXPORT ServiceEvent 00046 : public class_spec<ServiceEvent, 00047 extends<Event> > 00048 { 00049 friend class factory<ServiceEvent>; 00050 00051 // ----- handle definitions --------------------------------------------- 00052 00053 public: 00054 /** 00055 * Service Handle definition. 00056 */ 00057 typedef TypedHandle<Service> ServiceHandle; 00058 00059 /** 00060 * Service View definition. 00061 */ 00062 typedef TypedHandle<const Service> ServiceView; 00063 00064 00065 // ----- Id definition -------------------------------------------------- 00066 00067 public: 00068 typedef enum 00069 { 00070 SERVICE_STARTING = 1, // the service is starting 00071 SERVICE_STARTED = 2, // the service has started 00072 SERVICE_STOPPING = 3, // the service is stopping 00073 SERVICE_STOPPED = 4 // the service has stopped 00074 } Id; 00075 00076 00077 // ----- constructors --------------------------------------------------- 00078 00079 protected: 00080 /** 00081 * Create a new ServiceEvent instance. 00082 * 00083 * @param vService the Service that fired the event 00084 * @param identity the event's ID, one of the Id enum values 00085 */ 00086 ServiceEvent(ServiceView vService, Id identity); 00087 00088 00089 // ----- ServiceEvent interface ----------------------------------------- 00090 00091 public: 00092 /** 00093 * Dispatch this event to the specified listeners collection. 00094 * 00095 * @param vListeners the listeners collection 00096 * 00097 * @throws ClassCastException if any of the targets is not an instance of 00098 * the ServiceListener interface 00099 */ 00100 virtual void dispatch(Listeners::View vListeners) const; 00101 00102 00103 // ----- Object interface ----------------------------------------------- 00104 00105 public: 00106 /** 00107 * {@inheritDoc} 00108 */ 00109 virtual void toStream(std::ostream& out) const; 00110 00111 00112 // ----- accessors ------------------------------------------------------ 00113 00114 public: 00115 /** 00116 * Return this event's ID. 00117 * 00118 * @return the event ID, one of the Id enum values 00119 */ 00120 virtual Id getId() const; 00121 00122 /** 00123 * Return the Service that fired the event. 00124 * 00125 * @return the Service 00126 */ 00127 virtual ServiceView getService() const; 00128 00129 00130 // ----- data members --------------------------------------------------- 00131 00132 protected: 00133 /** 00134 * The event's ID. 00135 */ 00136 Id m_id; 00137 }; 00138 00139 COH_CLOSE_NAMESPACE2 00140 00141 #endif // COH_SERVICE_EVENT_HPP