From: Dave B. <bla...@us...> - 2013-03-26 17:25:46
|
Update of /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient/internal/wbem/indications In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv9122/src/org/sblim/cimclient/internal/wbem/indications Modified Files: Tag: Experimental CIMEventDispatcher.java Log Message: 2628 Limit size of LinkedList of CIMEvents to be dispatched Index: CIMEventDispatcher.java =================================================================== RCS file: /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java,v retrieving revision 1.7.2.6 retrieving revision 1.7.2.7 diff -u -d -r1.7.2.6 -r1.7.2.7 --- CIMEventDispatcher.java 6 Feb 2012 22:07:56 -0000 1.7.2.6 +++ CIMEventDispatcher.java 26 Mar 2013 17:25:44 -0000 1.7.2.7 @@ -1,7 +1,7 @@ /** * CIMEventDispatcher.java * - * (C) Copyright IBM Corp. 2005, 2012 + * (C) Copyright IBM Corp. 2005, 2013 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE @@ -24,6 +24,7 @@ * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address + * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched */ package org.sblim.cimclient.internal.wbem.indications; @@ -48,6 +49,8 @@ private boolean iAlive = true; + private int iMaxEvents = 0; + private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); /** @@ -61,10 +64,27 @@ * dispatched. */ public CIMEventDispatcher(EventListener pListener) { + this(pListener, 0); + } + + /** + * Construct a CIMEventDispatcher object which distributes CIMEvents to the + * appropriate CIMListener. The EventListener must be an instance of + * IndicationListener or IndicationListenerSBLIM. + * + * @param pListener + * The CIMListener (IndicationListener or + * IndicationListenerSBLIM) which receives the CIMEvents to be + * dispatched. + * @param pMaxEvents + * The maximum number of CIMEvents waiting to be dispatched. + */ + public CIMEventDispatcher(EventListener pListener, int pMaxEvents) { if (!(pListener instanceof IndicationListener) && !(pListener instanceof IndicationListenerSBLIM)) throw new IllegalArgumentException( "Listener must be instance of IndicationListener or IndicationListenerSBLIM"); this.iListener = pListener; + this.iMaxEvents = pMaxEvents; setDaemon(true); setName("CIMEventDispatcher"); start(); @@ -79,9 +99,20 @@ public synchronized void dispatchEvent(CIMEvent pEvent) { if (pEvent != null) { + if (this.iMaxEvents > 0) { + int size = this.iEventQueue.size(); + if (size >= this.iMaxEvents) { + for (int i = size - this.iMaxEvents + 1; i > 0; i--) { + CIMEvent event = this.iEventQueue.remove(0); + this.iLogger.trace(Level.FINE, "Deleted CIMEvent (id=" + event.getID() + + ") from the queue (maximum size of " + this.iMaxEvents + + " reached)"); + } + } + } this.iEventQueue.add(pEvent); this.iLogger.trace(Level.FINE, "Added CIMEvent (id=" + pEvent.getID() - + " to the queue (" + this.iEventQueue.size() + " elements total)"); + + ") to the queue (" + this.iEventQueue.size() + " elements total)"); notify(); } else { this.iLogger.trace(Level.WARNING, "CIMEvent to dispatch was null"); @@ -122,7 +153,7 @@ if (this.iEventQueue.size() > 0) { event = this.iEventQueue.remove(0); this.iLogger.trace(Level.FINER, "Removed CIMEvent (id=" + event.getID() - + "from the queue (" + this.iEventQueue.size() + " elements left)"); + + ") from the queue (" + this.iEventQueue.size() + " elements left)"); } } return event; |