Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/net/MemberEvent.hpp

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