Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/Listeners.hpp

00001 /*
00002 * Listeners.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_LISTENERS_HPP
00017 #define COH_LISTENERS_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/EventListener.hpp"
00022 
00023 COH_OPEN_NAMESPACE2(coherence,util)
00024 
00025 
00026 /**
00027 * Provides a simple, efficient, and thread-safe implementation of a list
00028 * of event listeners.
00029 *
00030 * The implementation is optimized based on the assumption that listeners are
00031 * added and removed relatively rarely, and that the list of listeners is
00032 * requested relatively often.
00033 *
00034 * Thread safety is implemented by synchronizing on all methods that modify
00035 * any data member of the class.  Read-only methods are not synchronized.
00036 *
00037 * @author jh  2007.12.13
00038 */
00039 class COH_EXPORT Listeners
00040     : public class_spec<Listeners>
00041     {
00042     friend class factory<Listeners>;
00043 
00044     // ----- constructors ---------------------------------------------------
00045 
00046     protected:
00047         /**
00048         * Create a new Listeners instance.
00049         */
00050         Listeners();
00051 
00052 
00053     // ----- Listeners interface --------------------------------------------
00054 
00055     public:
00056         /**
00057         * Add a listener.
00058         *
00059         * @param hListener the EventListener to add
00060         */
00061         virtual void add(EventListener::Handle hListener);
00062 
00063         /**
00064         * Remove a listener.
00065         *
00066         * @param vListener the EventListener to remove
00067         */
00068         virtual void remove(EventListener::View vListener);
00069 
00070         /**
00071         * Add all listeners from another Listeners object.
00072         *
00073         * @param vListeners  the Listeners to add
00074         */
00075         virtual void addAll(Listeners::View vListeners);
00076 
00077         /**
00078         * Remove all listeners.
00079         */
00080         virtual void removeAll();
00081 
00082         /**
00083         * Check if there are no listeners.
00084         *
00085         * @return true if there are no listeners
00086         */
00087         virtual bool isEmpty() const;
00088 
00089         /**
00090         * Check if a listener is in the list of listeners.
00091         *
00092         * @param hListener the EventListener to search for
00093         *
00094         * @return true if the listener is in the list of listeners
00095         */
00096         virtual bool contains(EventListener::Handle hListener) const;
00097 
00098         /**
00099         * Get the list of listeners.
00100         *
00101         * @return a the list of listeners
00102         */
00103         virtual ObjectArray::View listeners() const;
00104 
00105 
00106     // ----- Object interface -----------------------------------------------
00107 
00108     public:
00109         /**
00110         * {@inheritDoc}
00111         */
00112         virtual void toStream(std::ostream& out) const;
00113 
00114 
00115     // ----- data members ---------------------------------------------------
00116 
00117     private:
00118         /**
00119         * The registered listeners.
00120         */
00121         MemberHandle<ObjectArray> m_haListener;
00122     };
00123 
00124 COH_CLOSE_NAMESPACE2
00125 
00126 #endif // COH_LISTENERS_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.