Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.3.0)

E80355-01

coherence/util/Listeners.hpp

00001 /*
00002 * Listeners.hpp
00003 *
00004 * Copyright (c) 2000, 2017, 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     // ----- helper methods -------------------------------------------------
00107 
00108     private:
00109         /**
00110         * Return an array containing the union of the the specified lists.
00111         *
00112         * @param haListener1 array of listeners
00113         * @param haListener2 array of listeners
00114         *
00115         * @return the union of the two arrays of listeners
00116         */
00117         ObjectArray::Handle unionArrays(ObjectArray::Handle haListener1, ObjectArray::Handle haListener2);
00118 
00119         /**
00120         * Returns the array of listeners (sync or async) that corresponds to
00121         * the specific listener.
00122         *
00123         * @param vListener the EventListener to find a array for
00124         *
00125         * @return the array of listeners corresponding to the specified listener
00126         */
00127         ObjectArray::Handle getListenerListFor(EventListener::View vListener);
00128 
00129         /**
00130         * Set the array of listeners (sync or async) that corresponds to the
00131         * specified listener.  For example, if the specified listener is a
00132         * SynchronousListener, set the synchronous listener array to the specified
00133         * listener list.
00134         *
00135         * @param vListener the listener to set the array for
00136         * @param hListenerArray the array of listeners
00137         */
00138         void setListenerListFor(EventListener::View vListener, ObjectArray::Handle hListenerArray);
00139 
00140     public:
00141         /**
00142         * Set the array of filters associated with this listener object.
00143         *
00144         * @since Coherence 3.7.1.8
00145         *
00146         * @param hFilters  the array of filters
00147         */
00148         void setFilters(ObjectArray::View vFilters);
00149 
00150         /**
00151         * Return the array of filters associated with this listener object.
00152         *
00153         * @since Coherence 3.7.1.8
00154         *
00155         * @return  the array of filters
00156         */
00157         ObjectArray::View getFilters() const;
00158 
00159 
00160     // ----- Object interface -----------------------------------------------
00161 
00162     public:
00163         /**
00164         * {@inheritDoc}
00165         */
00166         virtual TypedHandle<const String> toString() const;
00167 
00168 
00169     // ----- data members ---------------------------------------------------
00170 
00171     private:
00172         /**
00173         * The registered asynchronous listeners.
00174         */
00175         MemberHandle<ObjectArray> m_haAsyncListeners;
00176 
00177         /**
00178         * The registered synchronous listeners.
00179         */
00180         MemberHandle<ObjectArray> m_haSyncListeners;
00181 
00182         /**
00183         * An optional array of filters associated with this Listeners object.
00184         * @since Coherence 3.7.1.8
00185         */
00186         MemberView<ObjectArray> m_vaFilters;
00187     };
00188 
00189 COH_CLOSE_NAMESPACE2
00190 
00191 #endif // COH_LISTENERS_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.