00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_SERVICE_EVENT_HPP 00008 #define COH_SERVICE_EVENT_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/util/Event.hpp" 00013 #include "coherence/util/Listeners.hpp" 00014 00015 COH_OPEN_NAMESPACE2(coherence,util) 00016 00017 class Service; 00018 00019 00020 /** 00021 * An event which indicates that a Service state has changed: 00022 * <ul> 00023 * <li>a service is starting</li> 00024 * <li>a service has started</li> 00025 * <li>a service is stopping</li> 00026 * <li>a service has stopped</li> 00027 * </ul> 00028 * A ServiceEvent object is sent as an argument to the ServiceListener 00029 * interface methods. 00030 * 00031 * @see Service 00032 * @see ServiceListener 00033 * 00034 * @author jh 2007.12.13 00035 */ 00036 class COH_EXPORT ServiceEvent 00037 : public class_spec<ServiceEvent, 00038 extends<Event> > 00039 { 00040 friend class factory<ServiceEvent>; 00041 00042 // ----- handle definitions --------------------------------------------- 00043 00044 public: 00045 /** 00046 * Service Handle definition. 00047 */ 00048 typedef TypedHandle<Service> ServiceHandle; 00049 00050 /** 00051 * Service View definition. 00052 */ 00053 typedef TypedHandle<const Service> ServiceView; 00054 00055 00056 // ----- Id definition -------------------------------------------------- 00057 00058 public: 00059 typedef enum 00060 { 00061 service_starting = 1, // the service is starting 00062 service_started = 2, // the service has started 00063 service_stopping = 3, // the service is stopping 00064 service_stopped = 4 // the service has stopped 00065 } Id; 00066 00067 00068 // ----- constructors --------------------------------------------------- 00069 00070 protected: 00071 /** 00072 * Create a new ServiceEvent instance. 00073 * 00074 * @param vService the Service that fired the event 00075 * @param identity the event's ID, one of the Id enum values 00076 */ 00077 ServiceEvent(ServiceView vService, Id identity); 00078 00079 private: 00080 /** 00081 * Blocked copy constructor. 00082 */ 00083 ServiceEvent(const ServiceEvent&); 00084 00085 00086 // ----- ServiceEvent interface ----------------------------------------- 00087 00088 public: 00089 /** 00090 * Dispatch this event to the specified listeners collection. 00091 * 00092 * @param vListeners the listeners collection 00093 * 00094 * @throws ClassCastException if any of the targets is not an instance of 00095 * the ServiceListener interface 00096 */ 00097 virtual void dispatch(Listeners::View vListeners) const; 00098 00099 00100 // ----- Object interface ----------------------------------------------- 00101 00102 public: 00103 /** 00104 * {@inheritDoc} 00105 */ 00106 virtual TypedHandle<const String> toString() const; 00107 00108 00109 // ----- accessors ------------------------------------------------------ 00110 00111 public: 00112 /** 00113 * Return this event's ID. 00114 * 00115 * @return the event ID, one of the Id enum values 00116 */ 00117 virtual Id getId() const; 00118 00119 /** 00120 * Return the Service that fired the event. 00121 * 00122 * @return the Service 00123 */ 00124 virtual ServiceView getService() const; 00125 00126 00127 // ----- data members --------------------------------------------------- 00128 00129 protected: 00130 /** 00131 * The event's ID. 00132 */ 00133 Id m_id; 00134 }; 00135 00136 COH_CLOSE_NAMESPACE2 00137 00138 #endif // COH_SERVICE_EVENT_HPP