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_MEMBER_EVENT_HPP 00008 #define COH_MEMBER_EVENT_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/net/Member.hpp" 00013 #include "coherence/util/Event.hpp" 00014 #include "coherence/util/Listeners.hpp" 00015 00016 COH_OPEN_NAMESPACE2(coherence,net) 00017 00018 using coherence::util::Event; 00019 using coherence::util::Listeners; 00020 00021 class Service; 00022 00023 00024 /** 00025 * An event which indicates that membership has changed: 00026 * <ul> 00027 * <li>a Member has joined 00028 * <li>a Member is leaving 00029 * <li>a Member has left 00030 * </ul> 00031 * A MemberEvent object is sent as an argument to the MemberListener 00032 * interface methods. 00033 * 00034 * @see MemberListener 00035 * 00036 * @author jh 2007.12.20 00037 */ 00038 class COH_EXPORT MemberEvent 00039 : public class_spec<MemberEvent, 00040 extends<Event> > 00041 { 00042 friend class factory<MemberEvent>; 00043 00044 // ----- handle definitions --------------------------------------------- 00045 00046 public: 00047 /** 00048 * Service Handle definition. 00049 */ 00050 typedef TypedHandle<Service> ServiceHandle; 00051 00052 /** 00053 * Service View definition. 00054 */ 00055 typedef TypedHandle<const Service> ServiceView; 00056 00057 00058 // ----- Id definition -------------------------------------------------- 00059 00060 public: 00061 typedef enum 00062 { 00063 member_joined = 1, // the Member has joined 00064 member_leaving = 2, // the Member is leaving 00065 member_left = 3 // the Member has left 00066 } Id; 00067 00068 00069 // ----- constructors --------------------------------------------------- 00070 00071 protected: 00072 /** 00073 * Create a new MemberEvent instance. 00074 * 00075 * @param vService the Service that fired the event 00076 * @param identity the event's ID, one of the Id enum values 00077 * @param vMember the Member associated with the new MemberEvent 00078 */ 00079 MemberEvent(ServiceView vService, Id identity, Member::View vMember); 00080 00081 00082 // ----- MemberEvent interface ------------------------------------------ 00083 00084 public: 00085 /** 00086 * Dispatch this event to the specified listeners collection. 00087 * 00088 * @param vListeners the listeners collection 00089 * 00090 * @throws ClassCastException if any of the targets is not an instance of 00091 * the MemberListener interface 00092 */ 00093 virtual void dispatch(Listeners::View vListeners) const; 00094 00095 /** 00096 * Check whether a Member object for this event represents the local 00097 * member of the cluster. 00098 * 00099 * @return true iff the event's Member object represents the local 00100 * cluster member 00101 */ 00102 virtual bool isLocal() const; 00103 00104 00105 // ----- Object interface ----------------------------------------------- 00106 00107 public: 00108 /** 00109 * {@inheritDoc} 00110 */ 00111 virtual TypedHandle<const String> toString() const; 00112 00113 00114 // ----- accessors ------------------------------------------------------ 00115 00116 public: 00117 /** 00118 * Return this event's ID. 00119 * 00120 * @return the event ID, one of the Id enum values 00121 */ 00122 virtual Id getId() const; 00123 00124 /** 00125 * Return the Service that fired the event. 00126 * 00127 * @return the Service 00128 */ 00129 virtual ServiceView getService() const; 00130 00131 /** 00132 * Return the Member associated with this event. 00133 * 00134 * @return the Member 00135 */ 00136 virtual Member::View getMember() const; 00137 00138 00139 // ----- data members --------------------------------------------------- 00140 00141 protected: 00142 /** 00143 * The event's ID. 00144 */ 00145 Id m_id; 00146 00147 /** 00148 * The Member associated with this event. 00149 */ 00150 FinalView<Member> f_vMember; 00151 }; 00152 00153 COH_CLOSE_NAMESPACE2 00154 00155 #endif // COH_MEMBER_EVENT_HPP