KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > invalidation > InvalidationManager


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.cache.invalidation;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.HashSet JavaDoc;
26
27 import javax.management.MBeanParameterInfo JavaDoc;
28 import javax.management.MBeanOperationInfo JavaDoc;
29
30 import org.jboss.cache.invalidation.InvalidationManager.BridgeInvalidationSubscriptionImpl;
31
32 /**
33  * Implementation of InvalidationManagerMBean
34  *
35  * @see org.jboss.cache.invalidation.InvalidationManagerMBean
36  *
37  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
38  * @version $Revision: 37459 $
39  */

40 public class InvalidationManager
41    extends org.jboss.system.ServiceMBeanSupport
42    implements InvalidationManagerMBean
43 {
44    
45    // Constants -----------------------------------------------------
46

47    public static final String JavaDoc DEFAULT_JMX_SERVICE_NAME = "jboss.cache:service=InvalidationManager";
48    public static final String JavaDoc DEFAULT_INVALIDERS_JMX_NAME = "jboss.cache:service=InvalidationGroup";
49    
50    // Attributes ----------------------------------------------------
51

52    protected java.util.Hashtable JavaDoc groups = new java.util.Hashtable JavaDoc ();
53    protected java.util.Vector JavaDoc bridgeSubscribers = new java.util.Vector JavaDoc ();
54    protected int hashcode = 0;
55    
56    protected boolean DEFAULT_TO_ASYNCHRONOUS_MODE = false;
57    
58    // Static --------------------------------------------------------
59

60    // Constructors --------------------------------------------------
61

62    public InvalidationManager () { super(); }
63    
64    public void startService () throws Exception JavaDoc
65    {
66       // bind us in system registry
67
//
68
log.debug ("Starting Invalidation Manager " + this.getServiceName ().toString ());
69       org.jboss.system.Registry.bind (this.getServiceName ().toString (), this);
70       this.hashcode = this.getServiceName ().hashCode ();
71    }
72    
73    public void stopService ()
74    {
75       log.debug ("Stoping Invalidation Manager " + this.getServiceName ().toString ());
76       org.jboss.system.Registry.unbind (this.getServiceName ().toString ());
77    }
78    
79    public boolean getIsAsynchByDefault()
80    {
81       return DEFAULT_TO_ASYNCHRONOUS_MODE;
82    }
83    public void setIsAsynchByDefault(boolean flag)
84    {
85       this.DEFAULT_TO_ASYNCHRONOUS_MODE = flag;
86    }
87    
88    public java.util.Collection JavaDoc getInvalidationGroups ()
89    {
90       return this.groups.values ();
91    }
92    
93    public InvalidationGroup getInvalidationGroup (String JavaDoc groupName)
94    {
95       synchronized (this.groups)
96       {
97          InvalidationGroup group = (InvalidationGroup)this.groups.get (groupName);
98          if (group == null)
99          {
100             group = createGroup (groupName);
101          }
102
103          group.addReference ();
104
105          return group;
106       }
107    }
108
109    public synchronized BridgeInvalidationSubscription registerBridgeListener (InvalidationBridgeListener listener)
110    {
111       log.debug ("Subscribing a new cache-invalidation bridge");
112       BridgeInvalidationSubscription subs = new BridgeInvalidationSubscriptionImpl(listener);
113
114       java.util.Vector JavaDoc newVector = new java.util.Vector JavaDoc (this.bridgeSubscribers);
115       newVector.add (subs);
116       this.bridgeSubscribers = newVector;
117       
118       return subs;
119    }
120    
121    public void batchInvalidate (BatchInvalidation[] invalidations)
122    {
123       this.batchInvalidate (invalidations, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
124    }
125    
126    public void batchInvalidate (BatchInvalidation[] invalidations, boolean asynchronous)
127    {
128       if (log.isTraceEnabled ())
129          log.trace ("Batch cache invalidation. Caches concerned: " + invalidations.length);
130       
131       this.crossDomainBatchInvalidate (null, invalidations, asynchronous);
132    }
133
134    public void invalidateAll(String JavaDoc groupName)
135    {
136       invalidateAll(groupName, DEFAULT_TO_ASYNCHRONOUS_MODE);
137    }
138
139    public void invalidateAll(String JavaDoc groupName, boolean async)
140    {
141       if (log.isTraceEnabled ())
142          log.trace ("Invalidate all for group: " + groupName);
143
144       crossDomainInvalidateAll(null, groupName, async);
145    }
146
147    // Public --------------------------------------------------------
148

149    // Z implementation ----------------------------------------------
150

151    // Object overrides ---------------------------------------------------
152

153    public int hashCode ()
154    {
155       return hashcode;
156    }
157    // Package protected ---------------------------------------------
158

159    // Protected -----------------------------------------------------
160

161    protected InvalidationGroup createGroup (String JavaDoc groupName)
162    {
163       InvalidationGroup group = new org.jboss.cache.invalidation.InvalidationManager.InvalidationGroupImpl (groupName);
164       this.groups.put (groupName, group);
165
166       // register the group with JMX so it can be easyly remotly
167
// reached (and thus cache can be invalidated)
168
//
169
try
170       {
171          log.debug ("Creating and registering a new InvalidationGroup: " + groupName);
172          javax.management.ObjectName JavaDoc groupObjectName = new javax.management.ObjectName JavaDoc (DEFAULT_INVALIDERS_JMX_NAME + ",GroupName="+groupName);
173          this.getServer ().registerMBean (group, groupObjectName);
174       }
175       catch (Exception JavaDoc e)
176       {
177          log.debug ("Problem while trying to register a new invalidation group in JMX", e);
178       }
179
180       // warn bridges
181
//
182
log.debug ("Informing bridges about new group creation ...");
183       for (int i=0; i<bridgeSubscribers.size (); i++)
184          ((BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i))).groupCreated (groupName);
185       
186       return group;
187    }
188    
189    protected void removeGroup (String JavaDoc groupName)
190    {
191       synchronized (this.groups)
192       {
193          this.groups.remove (groupName);
194
195          // Remove group from JMX
196
//
197
try
198          {
199             log.debug ("Removing and JMX-unregistering an InvalidationGroup: " + groupName);
200             javax.management.ObjectName JavaDoc groupObjectName = new javax.management.ObjectName JavaDoc (DEFAULT_INVALIDERS_JMX_NAME + ",GroupName="+groupName);
201             this.getServer ().unregisterMBean (groupObjectName);
202          }
203          catch (Exception JavaDoc e)
204          {
205             log.debug ("Problem while trying to un-register a new invalidation group in JMX", e);
206          }
207
208          // warn bridges
209
//
210
for (int i=0; i<bridgeSubscribers.size (); i++)
211             ((BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i))).groupDropped (groupName);
212       }
213                
214    }
215    
216    protected synchronized void unregisterBridgeListener (BridgeInvalidationSubscription bridgeSubscriber)
217    {
218       // safe remove to avoid problems with iterators
219
//
220
log.debug ("Unsubscription of a cache-invalidation bridge");
221       
222       java.util.Vector JavaDoc newVector = new java.util.Vector JavaDoc (this.bridgeSubscribers);
223       newVector.remove (bridgeSubscriber);
224       this.bridgeSubscribers = newVector;
225    }
226    
227    protected void doLocalOnlyInvalidation (String JavaDoc groupName, Serializable JavaDoc key, boolean asynchronous)
228    {
229       InvalidationGroupImpl group = (InvalidationGroupImpl)this.groups.get (groupName);
230       if (group != null)
231          group.localOnlyInvalidate (key, asynchronous);
232    }
233    
234    protected void doLocalOnlyInvalidations (String JavaDoc groupName, Serializable JavaDoc[] keys, boolean asynchronous)
235    {
236       InvalidationGroupImpl group = (InvalidationGroupImpl)this.groups.get (groupName);
237       if (group != null)
238          group.localOnlyInvalidate (keys, asynchronous);
239    }
240
241    protected void doLocalOnlyInvalidateAll (String JavaDoc groupName, boolean asynchronous)
242    {
243       InvalidationGroupImpl group = (InvalidationGroupImpl)this.groups.get (groupName);
244       if (group != null)
245          group.localOnlyInvalidateAll();
246    }
247
248    protected void doBridgedOnlyInvalidation (BridgeInvalidationSubscriptionImpl exceptSource, String JavaDoc groupName, Serializable JavaDoc key)
249    {
250       for (int i=0; i<bridgeSubscribers.size (); i++)
251       {
252          BridgeInvalidationSubscriptionImpl bridge = (BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i));
253          if (bridge != exceptSource)
254             bridge.bridgedInvalidate (groupName, key, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
255       }
256    }
257    
258    protected void doBridgedOnlyInvalidation (BridgeInvalidationSubscriptionImpl exceptSource, String JavaDoc groupName, Serializable JavaDoc[] keys)
259    {
260       for (int i=0; i<bridgeSubscribers.size (); i++)
261       {
262          BridgeInvalidationSubscriptionImpl bridge = (BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i));
263          if (bridge != exceptSource)
264             bridge.bridgedInvalidate (groupName, keys, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
265       }
266    }
267
268    protected void doBridgedOnlyInvalidateAll (BridgeInvalidationSubscriptionImpl exceptSource, String JavaDoc groupName)
269    {
270       for (int i=0; i<bridgeSubscribers.size (); i++)
271       {
272          BridgeInvalidationSubscriptionImpl bridge = (BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i));
273          if (bridge != exceptSource)
274             bridge.bridgedInvalidateAll (groupName, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
275       }
276    }
277
278    // this is called when an invalidation occurs in one of the group. Common behaviour
279
// can be groupped here. By default, we simply forward the invalidations to the
280
// available bridges.
281
//
282
protected void localGroupInvalidationEvent (String JavaDoc groupName, Serializable JavaDoc key, boolean asynchronous)
283    {
284       for (int i=0; i<bridgeSubscribers.size (); i++)
285          ((BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i))).bridgedInvalidate (groupName, key, asynchronous);
286    }
287    
288    protected void localGroupInvalidationsEvent (String JavaDoc groupName, Serializable JavaDoc[] keys, boolean asynchronous)
289    {
290       for (int i=0; i<bridgeSubscribers.size (); i++)
291          ((BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i))).bridgedInvalidate (groupName, keys, asynchronous);
292    }
293
294    protected void localGroupInvalidateAllEvent (String JavaDoc groupName, boolean asynchronous)
295    {
296       for (int i=0; i<bridgeSubscribers.size (); i++)
297          ((BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i))).bridgedInvalidateAll (groupName, asynchronous);
298    }
299
300    // We warn other groups and the local group (if available)
301
//
302
protected void bridgeGroupInvalidationEvent (BridgeInvalidationSubscriptionImpl source, String JavaDoc groupName, Serializable JavaDoc key)
303    {
304       doBridgedOnlyInvalidation (source, groupName, key);
305       doLocalOnlyInvalidation (groupName, key, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
306    }
307    
308    protected void bridgeGroupInvalidationEvent (BridgeInvalidationSubscriptionImpl source, String JavaDoc groupName, Serializable JavaDoc[] keys)
309    {
310       doBridgedOnlyInvalidation (source, groupName, keys);
311       doLocalOnlyInvalidation (groupName, keys, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
312    }
313
314    protected void bridgeGroupInvalidateAllEvent (BridgeInvalidationSubscriptionImpl source, String JavaDoc groupName)
315    {
316       doBridgedOnlyInvalidateAll (source, groupName);
317       doLocalOnlyInvalidateAll (groupName, this.DEFAULT_TO_ASYNCHRONOUS_MODE);
318    }
319
320    protected void crossDomainBatchInvalidate (BridgeInvalidationSubscriptionImpl source, BatchInvalidation[] invalidations, boolean asynchronous)
321    {
322       if (invalidations == null)
323          return;
324       
325       // local invalidation first
326
//
327
for (int i=0; i<invalidations.length; i++)
328       {
329          BatchInvalidation currInvalid = invalidations[i];
330          
331          doLocalOnlyInvalidations (currInvalid.getInvalidationGroupName (),
332                                   currInvalid.getIds (),
333                                   asynchronous);
334       }
335       
336       // bridged invalidation next
337
//
338
for (int i=0; i<bridgeSubscribers.size (); i++)
339       {
340          BridgeInvalidationSubscriptionImpl bridge = (BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i));
341          if (bridge != source)
342             bridge.bridgedBatchInvalidations (invalidations, asynchronous);
343       }
344    }
345
346    protected void crossDomainInvalidateAll(BridgeInvalidationSubscriptionImpl source, String JavaDoc groupName, boolean asynchronous)
347    {
348       // local invalidation first
349
//
350
doLocalOnlyInvalidateAll(groupName, asynchronous);
351
352       // bridged invalidation next
353
//
354
for (int i=0; i<bridgeSubscribers.size (); i++)
355       {
356          BridgeInvalidationSubscriptionImpl bridge = (BridgeInvalidationSubscriptionImpl)(bridgeSubscribers.elementAt (i));
357          if (bridge != source)
358             bridge.bridgedInvalidateAll(groupName, asynchronous);
359       }
360    }
361
362    // Private -------------------------------------------------------
363

364    // Inner classes -------------------------------------------------
365

366    /**
367     * This class implements the InvalidationGroup interface. It represent the
368     * meeting point of caches and invaliders for a same group.
369     */

370    class InvalidationGroupImpl implements InvalidationGroup, javax.management.DynamicMBean JavaDoc
371    {
372       protected org.jboss.logging.Logger igLog = null;
373       protected String JavaDoc groupName = null;
374       protected boolean asynchronous = DEFAULT_TO_ASYNCHRONOUS_MODE;
375       protected HashSet JavaDoc registered = new HashSet JavaDoc();
376       protected int counter = 0;
377       
378       public int hashCode ()
379       {
380          return groupName.hashCode ();
381       }
382       
383       public String JavaDoc getGroupName ()
384       {
385          return this.groupName;
386       }
387       
388       public InvalidationGroupImpl (String JavaDoc groupName)
389       {
390          this.groupName = groupName;
391          this.igLog = org.jboss.logging.Logger.getLogger(getClass() + "." + groupName);
392       }
393       
394       public InvalidationManagerMBean getInvalidationManager ()
395       {
396          return InvalidationManager.this;
397       }
398
399       public void invalidate (Serializable JavaDoc key)
400       {
401          this.invalidate (key, this.asynchronous);
402       }
403       
404       public void invalidate (Serializable JavaDoc key, boolean asynchronous)
405       {
406          localOnlyInvalidate (key, asynchronous);
407          
408          localGroupInvalidationEvent (this.groupName, key, asynchronous);
409       }
410
411       public void invalidate (Serializable JavaDoc[] keys)
412       {
413          this.invalidate (keys, this.asynchronous);
414       }
415       
416       public void invalidate (Serializable JavaDoc[] keys, boolean asynchronous)
417       {
418          localOnlyInvalidate (keys, asynchronous);
419          
420          localGroupInvalidationsEvent (this.groupName, keys, asynchronous);
421       }
422
423       public void invalidateAll()
424       {
425          invalidateAll(asynchronous);
426       }
427
428       public void invalidateAll(boolean asynchronous)
429       {
430          localOnlyInvalidateAll();
431          localGroupInvalidateAllEvent(groupName, asynchronous);
432       }
433
434       public synchronized void register (Invalidatable newRegistered)
435       {
436          // we make a temp copy to avoid concurrency issues with the invalidate method
437
//
438
HashSet JavaDoc newlyRegistered = new HashSet JavaDoc (this.registered);
439          newlyRegistered.add (newRegistered);
440          
441          this.registered = newlyRegistered;
442       }
443       
444       public synchronized void unregister (Invalidatable oldRegistered)
445       {
446          // we make a temp copy to avoid concurrency issues with the invalidate method
447
//
448
HashSet JavaDoc newlyRegistered = new HashSet JavaDoc(this.registered);
449          newlyRegistered.remove (oldRegistered);
450          
451          this.registered = newlyRegistered;
452          
453          this.removeReference ();
454       }
455
456       public void setAsynchronousInvalidation (boolean async)
457       {
458          this.asynchronous = async;
459       }
460       
461       public boolean getAsynchronousInvalidation ()
462       {
463          return this.asynchronous;
464       }
465    
466       public void addReference ()
467       {
468          counter++;
469          igLog.debug ("Counter reference value (++): " + counter);
470       }
471       
472       public int getReferenceCount ()
473       {
474          return this.counter;
475       }
476       
477       public void removeReference ()
478       {
479          counter--;
480          igLog.debug ("Counter reference value (--): " + counter);
481          
482          if (counter<=0)
483          {
484             removeGroup (this.groupName);
485                                  
486             //Iterator iter = this.registered.iterator ();
487
//while (iter.hasNext ())
488
// ((Invalidatable)iter.next ()).groupIsDropped () ;
489
}
490       }
491       
492       // DynamicMBean implementation ----------------------------------------------
493

494       public Object JavaDoc getAttribute (String JavaDoc attribute) throws javax.management.AttributeNotFoundException JavaDoc, javax.management.MBeanException JavaDoc, javax.management.ReflectionException JavaDoc
495       {
496          if (attribute == null || attribute.equals (""))
497             throw new IllegalArgumentException JavaDoc ("null or empty attribute name");
498          
499          if (attribute.equals ("AsynchronousInvalidation"))
500             return new Boolean JavaDoc(this.asynchronous);
501          else
502             throw new javax.management.AttributeNotFoundException JavaDoc(attribute + " is not a known attribute");
503       }
504       
505       public javax.management.AttributeList JavaDoc getAttributes (java.lang.String JavaDoc[] attributes)
506       {
507          return null;
508       }
509       
510       public javax.management.MBeanInfo JavaDoc getMBeanInfo ()
511       {
512          
513          MBeanParameterInfo JavaDoc serSimpleParam = new MBeanParameterInfo JavaDoc (
514                   "key",
515                   Serializable JavaDoc.class.getName (),
516                   "Primary key to be invalidated"
517          );
518       
519          MBeanParameterInfo JavaDoc serArrayParam = new MBeanParameterInfo JavaDoc (
520                   "keys",
521                   Serializable JavaDoc[].class .getName (),
522                   "Primary keys to be invalidated"
523          );
524       
525          MBeanParameterInfo JavaDoc asynchParam = new MBeanParameterInfo JavaDoc (
526                   "asynchronous",
527                   Boolean JavaDoc.class.getName (),
528                   "Indicates if the invalidation should be asynchronous or must be synchronous"
529          );
530       
531       javax.management.MBeanAttributeInfo JavaDoc[] attrInfo = new javax.management.MBeanAttributeInfo JavaDoc[] {
532        new javax.management.MBeanAttributeInfo JavaDoc("AsynchronousInvalidation",
533                Boolean JavaDoc.class.getName(),
534                "Indicates if invalidation, by default, should be done asynchronously",
535                true,
536                true,
537                false)};
538
539          MBeanOperationInfo JavaDoc[] opInfo = {
540             new MBeanOperationInfo JavaDoc("invalidate",
541                                    "invalidate a single key using default (a)synchronous behaviour",
542                                    new MBeanParameterInfo JavaDoc[] {serSimpleParam},
543                                    void.class.getName(),
544                                    MBeanOperationInfo.ACTION),
545
546             new MBeanOperationInfo JavaDoc("invalidate",
547                                    "invalidate a single key indicating the (a)synchronous behaviour",
548                                    new MBeanParameterInfo JavaDoc[] {serSimpleParam, asynchParam},
549                                    void.class.getName(),
550                                    MBeanOperationInfo.ACTION),
551
552             new MBeanOperationInfo JavaDoc("invalidate",
553                                    "invalidate multiple keys using default (a)synchronous behaviour",
554                                    new MBeanParameterInfo JavaDoc[] {serArrayParam},
555                                    void.class.getName(),
556                                    MBeanOperationInfo.ACTION),
557
558             new MBeanOperationInfo JavaDoc("invalidate",
559                                    "invalidate multiple keys indicating the (a)synchronous behaviour",
560                                    new MBeanParameterInfo JavaDoc[] {serArrayParam, asynchParam},
561                                    void.class.getName(),
562                                    MBeanOperationInfo.ACTION),
563
564             new MBeanOperationInfo JavaDoc("invalidateAll",
565                                    "invalidate all keys using default (a)synchronous behaviour",
566                                    new MBeanParameterInfo JavaDoc[] {},
567                                    void.class.getName(),
568                                    MBeanOperationInfo.ACTION),
569
570             new MBeanOperationInfo JavaDoc("invalidateAll",
571                                    "invalidate all keys with specified (a)synchronous behaviour",
572                                    new MBeanParameterInfo JavaDoc[] {asynchParam},
573                                    void.class.getName(),
574                                    MBeanOperationInfo.ACTION)
575          };
576
577          javax.management.MBeanNotificationInfo JavaDoc[] notifyInfo = null;
578          javax.management.MBeanConstructorInfo JavaDoc[] ctorInfo = new javax.management.MBeanConstructorInfo JavaDoc[] {};
579
580          return new javax.management.MBeanInfo JavaDoc(getClass().getName(),
581                               "Cache invalidation for group named " + this.groupName,
582                               attrInfo,
583                               ctorInfo,
584                               opInfo,
585                               notifyInfo);
586       }
587       
588       public java.lang.Object JavaDoc invoke (java.lang.String JavaDoc actionName, java.lang.Object JavaDoc[] params, java.lang.String JavaDoc[] signature) throws javax.management.MBeanException JavaDoc, javax.management.ReflectionException JavaDoc
589       {
590          if ("invalidate".equals (actionName))
591          {
592             if (params.length == 1)
593             {
594                if (params[0] instanceof Serializable JavaDoc[])
595                   this.invalidate ((Serializable JavaDoc[])params[0]);
596                else if (params[0] instanceof Serializable JavaDoc)
597                   this.invalidate ((Serializable JavaDoc)params[0]);
598                else
599                   throw new IllegalArgumentException JavaDoc ("First argument must be Serializable (or array of)");
600             }
601             else if (params.length == 2)
602             {
603                if (params[0] instanceof Serializable JavaDoc[])
604                   this.invalidate ((Serializable JavaDoc[])params[0], ((Boolean JavaDoc)params[1]).booleanValue ());
605                else if (params[0] instanceof Serializable JavaDoc)
606                   this.invalidate ((Serializable JavaDoc)params[0], ((Boolean JavaDoc)params[1]).booleanValue ());
607                else
608                   throw new IllegalArgumentException JavaDoc ("First argument must be Serializable (or array of)");
609             }
610             else
611             {
612                throw new IllegalArgumentException JavaDoc ("Unknown operation with these parameters: " + actionName);
613             }
614          }
615          else if("invalidateAll".equals(actionName))
616          {
617             if(params == null || params.length == 0)
618             {
619                this.invalidateAll();
620             }
621             else if (params.length == 1)
622             {
623                this.invalidateAll (((Boolean JavaDoc)params[1]).booleanValue ());
624             }
625             else
626             {
627                throw new IllegalArgumentException JavaDoc ("invalidateAll can take zero or one parameter but got " + params.length);
628             }
629          }
630          else
631          {
632             throw new IllegalArgumentException JavaDoc ("Unknown operation: " + actionName);
633          }
634          return null;
635       }
636       
637       public void setAttribute (javax.management.Attribute JavaDoc attribute) throws javax.management.AttributeNotFoundException JavaDoc, javax.management.InvalidAttributeValueException JavaDoc, javax.management.MBeanException JavaDoc, javax.management.ReflectionException JavaDoc
638       {
639          String JavaDoc attrName = attribute.getName();
640         if (attrName == null || attrName.equals (""))
641             throw new IllegalArgumentException JavaDoc ("null or empty attribute name");
642          
643          if (attrName.equals ("AsynchronousInvalidation"))
644          {
645             Object JavaDoc value = attribute.getValue ();
646             if (value instanceof Boolean JavaDoc)
647                this.asynchronous = ((Boolean JavaDoc)value).booleanValue ();
648             else
649                throw new javax.management.InvalidAttributeValueException JavaDoc("Attribute is of boolean type");
650          }
651          else
652             throw new javax.management.AttributeNotFoundException JavaDoc(attrName + " is not a known attribute");
653       }
654       
655       public javax.management.AttributeList JavaDoc setAttributes (javax.management.AttributeList JavaDoc attributes)
656       {
657          return null;
658       }
659       
660       // Protected ------------------------------------------------------------------------
661

662       protected void localOnlyInvalidate (Serializable JavaDoc[] keys, boolean asynchronous)
663       {
664          java.util.Iterator JavaDoc iter = this.registered.iterator ();
665          while (iter.hasNext ())
666          {
667             Invalidatable inv = (Invalidatable)iter.next ();
668             inv.areInvalid (keys);
669          }
670       }
671       
672       protected void localOnlyInvalidate (Serializable JavaDoc key, boolean asynchronous)
673       {
674          java.util.Iterator JavaDoc iter = this.registered.iterator ();
675          while (iter.hasNext ())
676          {
677             Invalidatable inv = (Invalidatable)iter.next ();
678             inv.isInvalid (key);
679          }
680
681       }
682
683       protected void localOnlyInvalidateAll()
684       {
685          java.util.Iterator JavaDoc iter = this.registered.iterator ();
686          while (iter.hasNext ())
687          {
688             Invalidatable inv = (Invalidatable)iter.next ();
689             inv.invalidateAll();
690          }
691       }
692    }
693    
694    // *******************************************************************************************33
695
// *******************************************************************************************33
696
// *******************************************************************************************33
697

698    class BridgeInvalidationSubscriptionImpl
699       implements BridgeInvalidationSubscription
700    {
701       
702       protected InvalidationBridgeListener listener = null;
703       
704       public BridgeInvalidationSubscriptionImpl (InvalidationBridgeListener listener)
705       {
706          this.listener = listener;
707       }
708       
709       public void invalidate (String JavaDoc invalidationGroupName, Serializable JavaDoc key)
710       {
711          bridgeGroupInvalidationEvent (this, invalidationGroupName, key);
712       }
713       
714       public void invalidate (String JavaDoc invalidationGroupName, Serializable JavaDoc[] keys)
715       {
716          bridgeGroupInvalidationEvent (this, invalidationGroupName, keys);
717       }
718
719       public void invalidateAll(String JavaDoc groupName)
720       {
721          bridgeGroupInvalidateAllEvent(this, groupName);
722       }
723
724       public void batchInvalidate (BatchInvalidation[] invalidations)
725       {
726          crossDomainBatchInvalidate (this, invalidations, DEFAULT_TO_ASYNCHRONOUS_MODE);
727          
728       }
729       
730       public void unregister ()
731       {
732          unregisterBridgeListener (this);
733       }
734       
735       // Internal callbacks
736
//
737

738       protected void bridgedInvalidate (String JavaDoc invalidationGroupName, Serializable JavaDoc key, boolean asynchronous)
739       {
740          this.listener.invalidate (invalidationGroupName, key, asynchronous);
741       }
742       
743       protected void bridgedInvalidate (String JavaDoc invalidationGroupName, Serializable JavaDoc[] keys, boolean asynchronous)
744       {
745          this.listener.invalidate (invalidationGroupName, keys, asynchronous);
746       }
747
748       protected void bridgedInvalidateAll (String JavaDoc invalidationGroupName, boolean asynchronous)
749       {
750          this.listener.invalidateAll (invalidationGroupName, asynchronous);
751       }
752       
753       protected void bridgedBatchInvalidations (BatchInvalidation[] invalidations, boolean asynchronous)
754       {
755          this.listener.batchInvalidate (invalidations, asynchronous);
756       }
757       
758       protected void groupCreated (String JavaDoc invalidationGroupName)
759       {
760          this.listener.newGroupCreated (invalidationGroupName);
761       }
762
763       protected void groupDropped (String JavaDoc invalidationGroupName)
764       {
765          this.listener.groupIsDropped (invalidationGroupName);
766       }
767       
768    }
769 }
770
Popular Tags