< prev index next >

src/java.naming/share/classes/com/sun/jndi/ldap/EventSupport.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 233             System.err.println("EventSupport removing unsolicited: " + unsolicited);
 234         }
 235         if (unsolicited != null) {
 236             unsolicited.removeElement(l);
 237         }
 238     }
 239 
 240     synchronized boolean hasUnsolicited() {
 241         return (unsolicited != null && unsolicited.size() > 0);
 242     }
 243 
 244     /**
 245       * package private;
 246       * Called by NamingEventNotifier to remove itself when it encounters
 247       * a NamingException.
 248       */
 249     synchronized void removeDeadNotifier(NotifierArgs info) {
 250         if (debug) {
 251             System.err.println("EventSupport.removeDeadNotifier: " + info.name);
 252         }




 253         notifiers.remove(info);
 254     }

 255 
 256     /**
 257      * Fire an event to unsolicited listeners.
 258      * package private;
 259      * Called by LdapCtx when its clnt receives an unsolicited notification.
 260      */
 261     synchronized void fireUnsolicited(Object obj) {
 262         if (debug) {
 263             System.err.println("EventSupport.fireUnsolicited: " + obj + " "
 264                 + unsolicited);
 265         }
 266         if (unsolicited == null || unsolicited.size() == 0) {
 267             // This shouldn't really happen, but might in case
 268             // there is a timing problem that removes a listener
 269             // before a fired event reaches here.
 270             return;
 271         }
 272 
 273         if (obj instanceof UnsolicitedNotification) {
 274 


 312         if (eventQueue != null) {
 313             eventQueue.stop();
 314             eventQueue = null;
 315         }
 316         // %%% Should we fire NamingExceptionEvents to unsolicited listeners?
 317     }
 318 
 319     /*
 320      * The queue of events to be delivered.
 321      */
 322     private EventQueue eventQueue;
 323 
 324     /**
 325      * Add the event and vector of listeners to the queue to be delivered.
 326      * An event dispatcher thread dequeues events from the queue and dispatches
 327      * them to the registered listeners.
 328      * Package private; used by NamingEventNotifier to fire events
 329      */
 330     synchronized void queueEvent(EventObject event,
 331                                  Vector<? extends NamingListener> vector) {





 332         if (eventQueue == null)
 333             eventQueue = new EventQueue();
 334 
 335         /*
 336          * Copy the vector in order to freeze the state of the set
 337          * of EventListeners the event should be delivered to prior
 338          * to delivery.  This ensures that any changes made to the
 339          * Vector from a target listener's method during the delivery
 340          * of this event will not take effect until after the event is
 341          * delivered.
 342          */
 343         @SuppressWarnings("unchecked") // clone()
 344         Vector<NamingListener> v =
 345                 (Vector<NamingListener>)vector.clone();
 346         eventQueue.enqueue(event, v);
 347     }
 348 
 349     // No finalize() needed because EventSupport is always owned by
 350     // an LdapCtx. LdapCtx's finalize() and close() always call cleanup() so
 351     // there is no need for EventSupport to have a finalize().
   1 /*
   2  * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 233             System.err.println("EventSupport removing unsolicited: " + unsolicited);
 234         }
 235         if (unsolicited != null) {
 236             unsolicited.removeElement(l);
 237         }
 238     }
 239 
 240     synchronized boolean hasUnsolicited() {
 241         return (unsolicited != null && unsolicited.size() > 0);
 242     }
 243 
 244     /**
 245       * package private;
 246       * Called by NamingEventNotifier to remove itself when it encounters
 247       * a NamingException.
 248       */
 249     synchronized void removeDeadNotifier(NotifierArgs info) {
 250         if (debug) {
 251             System.err.println("EventSupport.removeDeadNotifier: " + info.name);
 252         }
 253         if (notifiers != null) {
 254             // Only do this if cleanup() not been triggered, otherwise here
 255             // will throw NullPointerException since notifiers will be set to
 256             // null in cleanup()
 257             notifiers.remove(info);
 258         }
 259     }
 260 
 261     /**
 262      * Fire an event to unsolicited listeners.
 263      * package private;
 264      * Called by LdapCtx when its clnt receives an unsolicited notification.
 265      */
 266     synchronized void fireUnsolicited(Object obj) {
 267         if (debug) {
 268             System.err.println("EventSupport.fireUnsolicited: " + obj + " "
 269                 + unsolicited);
 270         }
 271         if (unsolicited == null || unsolicited.size() == 0) {
 272             // This shouldn't really happen, but might in case
 273             // there is a timing problem that removes a listener
 274             // before a fired event reaches here.
 275             return;
 276         }
 277 
 278         if (obj instanceof UnsolicitedNotification) {
 279 


 317         if (eventQueue != null) {
 318             eventQueue.stop();
 319             eventQueue = null;
 320         }
 321         // %%% Should we fire NamingExceptionEvents to unsolicited listeners?
 322     }
 323 
 324     /*
 325      * The queue of events to be delivered.
 326      */
 327     private EventQueue eventQueue;
 328 
 329     /**
 330      * Add the event and vector of listeners to the queue to be delivered.
 331      * An event dispatcher thread dequeues events from the queue and dispatches
 332      * them to the registered listeners.
 333      * Package private; used by NamingEventNotifier to fire events
 334      */
 335     synchronized void queueEvent(EventObject event,
 336                                  Vector<? extends NamingListener> vector) {
 337         if (notifiers == null) {
 338             // That means cleanup() already done, not queue event anymore,
 339             // otherwise, new created EventQueue will not been cleanup.
 340             return;
 341         }
 342         if (eventQueue == null)
 343             eventQueue = new EventQueue();
 344 
 345         /*
 346          * Copy the vector in order to freeze the state of the set
 347          * of EventListeners the event should be delivered to prior
 348          * to delivery.  This ensures that any changes made to the
 349          * Vector from a target listener's method during the delivery
 350          * of this event will not take effect until after the event is
 351          * delivered.
 352          */
 353         @SuppressWarnings("unchecked") // clone()
 354         Vector<NamingListener> v =
 355                 (Vector<NamingListener>)vector.clone();
 356         eventQueue.enqueue(event, v);
 357     }
 358 
 359     // No finalize() needed because EventSupport is always owned by
 360     // an LdapCtx. LdapCtx's finalize() and close() always call cleanup() so
 361     // there is no need for EventSupport to have a finalize().
< prev index next >