KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > bean > TransactionBeanCache


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * TransactionBeanCache.java
20  */

21
22 // java package
23
package com.rift.coad.lib.bean;
24
25 // java imports
26
import java.util.ArrayList JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.LinkedHashMap JavaDoc;
33 import java.util.LinkedHashSet JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.concurrent.ConcurrentHashMap JavaDoc;
36 import javax.rmi.PortableRemoteObject JavaDoc;
37 import javax.transaction.xa.XAException JavaDoc;
38 import javax.transaction.xa.XAResource JavaDoc;
39 import javax.transaction.xa.Xid JavaDoc;
40
41 // logging import
42
import org.apache.log4j.Logger;
43
44 // coadunation imports
45
import com.rift.coad.lib.cache.Cache;
46 import com.rift.coad.lib.cache.CacheEntry;
47 import com.rift.coad.lib.configuration.ConfigurationFactory;
48 import com.rift.coad.lib.configuration.Configuration;
49 import com.rift.coad.lib.thread.ThreadStateMonitor;
50 import com.rift.coad.util.lock.LockRef;
51 import com.rift.coad.util.lock.ObjectLockFactory;
52 import com.rift.coad.util.transaction.TransactionManager;
53
54 /**
55  * This object is responsible for managing the transaction bean cache.
56  *
57  * @author Brett Chaldecott
58  */

59 public class TransactionBeanCache implements Cache,XAResource JavaDoc {
60     
61     /**
62      * This object represents a change in the change list
63      */

64     public class ChangeEntry {
65         // member variables
66
private Object JavaDoc key = null;
67         private Object JavaDoc value = null;
68         private byte changeType = 0;
69         
70         
71         /**
72          * The constructor of the change entry object.
73          *
74          * @param key The key to identify this change.
75          * @param value The new value for this change.
76          * @param changeType The type of change that has occurred.
77          */

78         public ChangeEntry(Object JavaDoc key, Object JavaDoc value, byte changeType) {
79             this.key = key;
80             this.value = value;
81             this.changeType = changeType;
82         }
83         
84         
85         /**
86          * This method returns the key identifying this object.
87          *
88          * @return The key identifying this object.
89          */

90         public Object JavaDoc getKey() {
91             return key;
92         }
93         
94         
95         /**
96          * This method returns the value identifying this object.
97          *
98          * @return The value identifying this object.
99          */

100         public Object JavaDoc getValue() {
101             return value;
102         }
103         
104         
105         /**
106          * This method returns the change type for this object.
107          *
108          * @return The change type for this object.
109          */

110         public byte getChangeType() {
111             return changeType;
112         }
113     }
114     
115     /**
116      * The object that represents a change on this cache object.
117      */

118     public class Changes {
119         // the class private member variables
120
private Xid JavaDoc transactionId = null;
121         private List JavaDoc locks = new ArrayList JavaDoc();
122         private List JavaDoc changesEntries = new ArrayList JavaDoc();
123         
124         
125         /**
126          * The constructor of the changes object.
127          *
128          * @param transactionId The id of the current transaction
129          */

130         public Changes(Xid JavaDoc transactionId) {
131             this.transactionId = transactionId;
132         }
133         
134         
135         /**
136          * This method will add a lock to the list of locks.
137          *
138          * @exception MessageServiceException
139          */

140         public void addLock(LockRef lock) throws BeanException {
141             locks.add(lock);
142         }
143         
144         
145         /**
146          * This method adds a new entry to the entries list.
147          *
148          * @param key The key to add to the list.
149          * @param value The value to add to the list
150          * @exception BeanException
151          */

152         public void addEntry(Object JavaDoc key, Object JavaDoc value) throws
153                 BeanException {
154             changesEntries.add(new ChangeEntry(key,value,ADD));
155         }
156         
157         
158         /**
159          * This method adds a new remove entry to the list.
160          *
161          * @param key The key to add to the list.
162          * @param value The object that is getting removed.
163          * @exception BeanException
164          */

165         public void addRemoveEntry(Object JavaDoc key, Object JavaDoc value) throws
166                 BeanException {
167             changesEntries.add(new ChangeEntry(key,value,REMOVE));
168         }
169         
170         
171         /**
172          * This method returns the list of added entries
173          *
174          * @return The list of queues.
175          */

176         public List JavaDoc getChangeEntries() {
177             return changesEntries;
178         }
179         
180         
181         /**
182          * This method returns the list of locks.
183          *
184          * @return The list of locks.
185          */

186         public List JavaDoc getLocks() {
187             return locks;
188         }
189     }
190     
191     // class constants
192
private final static String JavaDoc CACHE_EXPIRY_TIME = "bean_cache_expiry";
193     private final static long CACHE_EXPIRY_TIME_DEFAULT = 30 * 60 * 1000;
194     private final static byte ADD = 1;
195     private final static byte UPDATE = 2;
196     private final static byte REMOVE = 3;
197     
198     // the logger reference
199
protected Logger log =
200             Logger.getLogger(TransactionBeanCache.class.getName());
201     
202     // the cache entries
203
private long defaultCacheExpiryTime = 0;
204     private ThreadStateMonitor status = new ThreadStateMonitor();
205     private ThreadLocal JavaDoc currentTransaction = new ThreadLocal JavaDoc();
206     private Map JavaDoc keyLockMap = new HashMap JavaDoc();
207     private Map JavaDoc baseCacheEntries = new ConcurrentHashMap JavaDoc();
208     private Map JavaDoc transactionChanges = new ConcurrentHashMap JavaDoc();
209     
210     /**
211      * Creates a new instance of TransactionBeanCache
212      *
213      * @exception BeanException
214      */

215     public TransactionBeanCache() throws BeanException {
216         try {
217             Configuration config = ConfigurationFactory.getInstance().
218                     getConfig(BeanCache.class);
219             defaultCacheExpiryTime = config.getLong(CACHE_EXPIRY_TIME,
220                     CACHE_EXPIRY_TIME_DEFAULT);
221         } catch (Exception JavaDoc ex) {
222             log.error("Failed to start the TransactionBeanCache object " +
223                     "because : " + ex.getMessage(),ex);
224             throw new BeanException(
225                     "Failed to start the TransactionBeanCache object " +
226                     "because : " + ex.getMessage(),ex);
227         }
228     }
229     
230     
231     /**
232      * This method is called to perform garbage collection on the cache entries.
233      */

234     public void garbageCollect() {
235         // copy the entries map
236
Map JavaDoc entries = new HashMap JavaDoc();
237         entries.putAll(this.baseCacheEntries);
238         
239         // loop through the entires and remove the expired ones
240
Date JavaDoc expiryDate = new Date JavaDoc();
241         for (Iterator JavaDoc iter = entries.keySet().iterator();iter.hasNext();) {
242             Object JavaDoc cacheKey = iter.next();
243             LockRef lockRef = null;
244             try {
245                 lockRef = getLockRef(cacheKey);
246             } catch (Exception JavaDoc ex) {
247                 log.error("Failed to aquire lock on [" + cacheKey
248                         + "] because :" + ex.getMessage(),ex);
249                 continue;
250             }
251             try {
252                 BeanCacheEntry beanCacheEntry =
253                         (BeanCacheEntry)entries.get(cacheKey);
254                 if (beanCacheEntry.isExpired(expiryDate)) {
255                     if (beanCacheEntry.getCacheEntry() != null) {
256                         try {
257                             PortableRemoteObject.unexportObject(
258                                     (java.rmi.Remote JavaDoc)
259                                     beanCacheEntry.getCacheEntry());
260                             this.baseCacheEntries.remove(cacheKey);
261                             beanCacheEntry.cacheRelease();
262                         } catch (java.rmi.NoSuchObjectException JavaDoc ex) {
263                             log.warn("The object was never exported : " +
264                                     ex.getMessage(),ex);
265                             // remove from cache
266
synchronized(entries) {
267                                 this.baseCacheEntries.remove(cacheKey);
268                             }
269                             beanCacheEntry.cacheRelease();
270                         } catch (Exception JavaDoc ex) {
271                             log.error("Failed to un-export this object : " +
272                                     ex.getMessage(),ex);
273                         }
274                     } else {
275                         // if this object has not cache entry as in no rmi tie
276
// class than just remove it.
277
this.baseCacheEntries.remove(cacheKey);
278                         beanCacheEntry.cacheRelease();
279                     }
280                 }
281             } finally {
282                 try {
283                     lockRef.release();
284                 } catch (Exception JavaDoc ex) {
285                     log.error("Failed to release the lock on [" + cacheKey
286                             + "] because :" + ex.getMessage(),ex);
287                 }
288             }
289         }
290     }
291     
292     
293     /**
294      * This method is called to forcibly remove everything from the cache.
295      */

296     public void clear() {
297         LockRef lockRef = null;
298         try {
299             lockRef = ObjectLockFactory.getInstance().acquireReadLock(this);
300             // copy the entries map
301
status.terminate(false);
302             Map JavaDoc entries = new HashMap JavaDoc();
303             entries.putAll(this.baseCacheEntries);
304             this.baseCacheEntries.clear();
305
306             // loop through the entires and remove the expired ones
307
for (Iterator JavaDoc iter = entries.keySet().iterator();iter.hasNext();) {
308                 Object JavaDoc cacheKey = iter.next();
309                 BeanCacheEntry beanCacheEntry =
310                         (BeanCacheEntry)entries.get(cacheKey);
311                 if (beanCacheEntry.getCacheEntry() != null)
312                 {
313                     try {
314                         PortableRemoteObject.unexportObject(
315                                 (java.rmi.Remote JavaDoc)
316                                 beanCacheEntry.getCacheEntry());
317                     } catch (java.rmi.NoSuchObjectException JavaDoc ex) {
318                         log.warn("The cache object was not bound : " +
319                                 ex.getMessage(),ex);
320                     } catch (Exception JavaDoc ex) {
321                         log.error("Failed to un-export the cached object : " +
322                                 ex.getMessage(),ex);
323                     }
324                 }
325                 beanCacheEntry.cacheRelease();
326             }
327             
328         } catch (Exception JavaDoc ex) {
329             log.error("Failed to clear the bean cache : " + ex.getMessage(),ex);
330         } finally {
331             try {
332                 lockRef.release();
333             } catch (Exception JavaDoc ex) {
334                 log.error("Failed to release the write lock : " +
335                         ex.getMessage(),ex);
336             }
337         }
338     }
339     
340     
341     /**
342      * This mehtod returns true if the cache contains the checked entry.
343      *
344      * @return TRUE if the cache contains the checked entry.
345      * @param cacheEntry The entry to perform the check for.
346      */

347     public boolean contains(Object JavaDoc cacheKey) {
348         try {
349             TransactionManager.getInstance().bindResource(this,false);
350             getLock(cacheKey);
351             return baseCacheEntries.containsKey(cacheKey);
352         } catch (Exception JavaDoc ex) {
353             log.error(
354                     "Failed to retrieve the cache entries : " + ex.getMessage(),
355                     ex);
356             return false;
357         }
358     }
359     
360     
361     /**
362      * This method returns the bean cache entry.
363      *
364      * @return The reference to the bean cache object.
365      * @param key The key to retrieve.
366      * @exception BeanException
367      */

368     public BeanCacheEntry getCacheEntry(Object JavaDoc cacheKey) throws BeanException {
369         try {
370             TransactionManager.getInstance().bindResource(this,false);
371             getLock(cacheKey);
372             BeanCacheEntry beanCacheEntry =
373                     (BeanCacheEntry)baseCacheEntries.get(cacheKey);
374             if (beanCacheEntry != null) {
375                 beanCacheEntry.touch();
376             }
377             return beanCacheEntry;
378         } catch (Exception JavaDoc ex) {
379             throw new BeanException("Failed to retrieve the cache entries : "
380                     + ex.getMessage(),ex);
381         }
382     }
383     
384     
385     /**
386      * This method adds the entry to the cache.
387      *
388      * @param cacheKey The key to identify this entry by.
389      * @param wrappedObject The object wrapped by the cache entry.
390      * @param entry An entry in the cache
391      */

392     public void addCacheEntry(long timeout,Object JavaDoc cacheKey, Object JavaDoc wrappedObject,
393             CacheEntry entry) throws BeanException {
394         try {
395             TransactionManager.getInstance().bindResource(this,false);
396             getLock(cacheKey);
397             if (baseCacheEntries.containsKey(cacheKey)) {
398                 throw new BeanException("Entry is already in the cache.");
399             }
400             long cacheTimeout = timeout;
401             if (timeout == -1) {
402                 cacheTimeout = defaultCacheExpiryTime;
403             }
404             BeanCacheEntry beanCacheEntry = new BeanCacheEntry(cacheTimeout,
405                     cacheKey, wrappedObject, entry);
406             baseCacheEntries.put(cacheKey, beanCacheEntry);
407             Changes changes = (Changes)transactionChanges.get(
408                     currentTransaction.get());
409             changes.addEntry(cacheKey,beanCacheEntry);
410         } catch (BeanException ex) {
411             throw ex;
412         } catch (Exception JavaDoc ex) {
413             throw new BeanException("Failed to add a cache entrie : "
414                     + ex.getMessage(),ex);
415         }
416     }
417     
418     
419     /**
420      * This method adds a new entry to the cache.
421      *
422      * @param cacheKey The key to identify this entry by.
423      * @param wrappedObject The object wrapped by the proxy.
424      * @param proxy The proxy to add.
425      * @param handle The handler for the bean proxy object.
426      */

427     public void addCacheEntry(long timeout, Object JavaDoc cacheKey, Object JavaDoc wrappedObject,
428             Object JavaDoc proxy, CacheEntry handle) throws BeanException {
429         try {
430             TransactionManager.getInstance().bindResource(this,false);
431             getLock(cacheKey);
432             if (baseCacheEntries.containsKey(cacheKey)) {
433                 throw new BeanException("Entry is already in the cache.");
434             }
435             long cacheTimeout = timeout;
436             if (timeout == -1) {
437                 cacheTimeout = defaultCacheExpiryTime;
438             }
439             BeanCacheEntry beanCacheEntry = new BeanCacheEntry(cacheTimeout,
440                     cacheKey, wrappedObject, proxy, handle);
441             
442             baseCacheEntries.put(cacheKey, beanCacheEntry);
443             Changes changes = (Changes)transactionChanges.get(
444                     currentTransaction.get());
445             changes.addEntry(cacheKey,beanCacheEntry);
446         } catch (BeanException ex) {
447             throw ex;
448         } catch (Exception JavaDoc ex) {
449             throw new BeanException("Failed to add a cache entrie : "
450                     + ex.getMessage(),ex);
451         }
452     }
453     
454     
455     /**
456      * This method removes the entry from the cache based on the key passed in.
457      *
458      * @param cacheKey The key in the cache to remove.
459      */

460     public void removeCacheEntry(Object JavaDoc cacheKey) throws BeanException {
461         try {
462             TransactionManager.getInstance().bindResource(this,false);
463             getLock(cacheKey);
464             Object JavaDoc entry = baseCacheEntries.get(cacheKey);
465             baseCacheEntries.remove(cacheKey);
466             Changes changes = (Changes)transactionChanges.get(
467                     currentTransaction.get());
468             changes.addRemoveEntry(cacheKey,entry);
469         } catch (Exception JavaDoc ex) {
470             throw new BeanException("Failed to remove a cache entrie : "
471                     + ex.getMessage(),ex);
472         }
473     }
474     
475     
476     /**
477      * This method is called to commit the specified transaction.
478      *
479      * @param xid The id of the transaction to commit.
480      * @param onePhase If true a one phase commit should be used.
481      * @exception XAException
482      */

483     public synchronized void commit(Xid JavaDoc xid, boolean b) throws XAException JavaDoc {
484         try {
485             if (this.status.isTerminated()) {
486                 log.error("Commit called on terminated cache, ignoring.");
487                 return;
488             }
489             Changes changes = (Changes)transactionChanges.get(xid);
490             for (Iterator JavaDoc iter = changes.getLocks().iterator();
491             iter.hasNext();) {
492                 LockRef lockRef = (LockRef)iter.next();
493                 lockRef.release();
494             }
495             transactionChanges.remove(xid);
496         } catch (Exception JavaDoc ex) {
497             log.error("Failed to commit the changes : " +
498                     ex.getMessage(),ex);
499             throw new XAException JavaDoc("Failed to commit the changes : " +
500                     ex.getMessage());
501         }
502     }
503     
504     
505     /**
506      * The resource manager has dissociated this object from the transaction.
507      *
508      * @param xid The id of the transaction that is getting ended.
509      * @param flags The flags associated with this operation.
510      * @exception XAException
511      */

512     public void end(Xid JavaDoc xid, int i) throws XAException JavaDoc {
513     }
514     
515     
516     /**
517      * The transaction has been completed and must be forgotten.
518      *
519      * @param xid The id of the transaction to forget.
520      * @exception XAException
521      */

522     public void forget(Xid JavaDoc xid) throws XAException JavaDoc {
523         try {
524             if (this.status.isTerminated()) {
525                 log.error("Commit called on terminated cache, ignoring.");
526                 return;
527             }
528             Changes changes = (Changes)transactionChanges.get(xid);
529             for (Iterator JavaDoc iter = changes.getLocks().iterator();
530             iter.hasNext();) {
531                 LockRef lockRef = (LockRef)iter.next();
532                 lockRef.release();
533             }
534             transactionChanges.remove(xid);
535         } catch (Exception JavaDoc ex) {
536             log.error("Failed to forget the changes : " +
537                     ex.getMessage(),ex);
538             throw new XAException JavaDoc("Failed to forget the changes : " +
539                     ex.getMessage());
540         }
541     }
542     
543     
544     /**
545      * This method returns the transaction timeout for this object.
546      *
547      * @return The int containing the transaction timeout.
548      * @exception XAException
549      */

550     public int getTransactionTimeout() throws XAException JavaDoc {
551         return -1;
552     }
553     
554     
555     /**
556      * This method returns true if this object is the resource manager getting
557      * queried.
558      *
559      * @return TRUE if this is the resource manager, FALSE if not.
560      * @param xaResource The resource to perform the check against.
561      * @exception XAException
562      */

563     public boolean isSameRM(XAResource JavaDoc xAResource) throws XAException JavaDoc {
564         return this == xAResource;
565     }
566     
567     
568     /**
569      * This is called before a transaction is committed.
570      *
571      * @return The results of the transaction.
572      * @param xid The id of the transaction to check against.
573      * @exception XAException
574      */

575     public int prepare(Xid JavaDoc xid) throws XAException JavaDoc {
576         return XAResource.XA_OK;
577     }
578     
579     
580     /**
581      * This method returns the list of transaction branches for this resource
582      * manager.
583      *
584      * @return The list of resource branches.
585      * @param flags The flags
586      * @exception XAException
587      */

588     public Xid JavaDoc[] recover(int i) throws XAException JavaDoc {
589         return null;
590     }
591     
592     
593     /**
594      * This method is called to roll back the specified transaction.
595      *
596      * @param xid The id of the transaction to roll back.
597      * @exception XAException
598      */

599     public void rollback(Xid JavaDoc xid) throws XAException JavaDoc {
600         try {
601             if (this.status.isTerminated()) {
602                 log.error("Commit called on terminated cache, ignoring.");
603             return;
604             }
605             Changes changes = (Changes)transactionChanges.get(xid);
606             List JavaDoc changeEntries = changes.getChangeEntries();
607             for (int index = 0; index < changeEntries.size(); index++) {
608                 ChangeEntry changeEntry = (ChangeEntry)changeEntries.get(
609                         changeEntries.size() - (index + 1));
610                 if (changeEntry.getChangeType() == ADD) {
611                     BeanCacheEntry beanCacheEntry =
612                             (BeanCacheEntry)changeEntry.getValue();
613                     if (beanCacheEntry.getCacheEntry() != null) {
614                         try {
615                             PortableRemoteObject.unexportObject(
616                                     (java.rmi.Remote JavaDoc)
617                                     beanCacheEntry.getCacheEntry());
618                             beanCacheEntry.cacheRelease();
619                         } catch (java.rmi.NoSuchObjectException JavaDoc ex) {
620                             log.warn("The object was never exported : " +
621                                     ex.getMessage(),ex);
622                             beanCacheEntry.cacheRelease();
623                         } catch (Exception JavaDoc ex) {
624                             log.error("Failed to un-export this object : " +
625                                     ex.getMessage(),ex);
626                             beanCacheEntry.cacheRelease();
627                         }
628                     } else {
629                         // if this object has not cache entry as in no rmi tie
630
// class than just remove it.
631
beanCacheEntry.cacheRelease();
632                     }
633                     baseCacheEntries.remove(changeEntry.getKey());
634                     
635                 } else if (changeEntry.getChangeType() == REMOVE) {
636                     baseCacheEntries.put(changeEntry.getKey(),
637                             changeEntry.getValue());
638                 }
639             }
640             
641             for (Iterator JavaDoc iter = changes.getLocks().iterator();
642             iter.hasNext();) {
643                 LockRef lockRef = (LockRef)iter.next();
644                 lockRef.release();
645             }
646             transactionChanges.remove(xid);
647         } catch (Exception JavaDoc ex) {
648             log.error("Failed to rollback the changes : " +
649                     ex.getMessage(),ex);
650             throw new XAException JavaDoc("Failed to rollback the changes : " +
651                     ex.getMessage());
652         }
653     }
654     
655     
656     /**
657      * This method sets the transaction timeout for this resource manager.
658      *
659      * @return TRUE if the transaction timeout can be set successfully.
660      * @param transactionTimeout The new transaction timeout value.
661      * @exception XAException
662      */

663     public boolean setTransactionTimeout(int i) throws XAException JavaDoc {
664         return true;
665     }
666     
667     
668     /**
669      * This method is called to start a transaction on a resource manager.
670      *
671      * @param xid The id of the new transaction.
672      * @param flags The flags associated with the transaction.
673      * @exception XAException
674      */

675     public void start(Xid JavaDoc xid, int i) throws XAException JavaDoc {
676         try {
677             checkStatus();
678             if (!transactionChanges.containsKey(xid)) {
679                 transactionChanges.put(xid,new Changes(xid));
680             }
681             currentTransaction.set(xid);
682         } catch (Exception JavaDoc ex) {
683             log.error("Cannot start a transaction because : " +
684                     ex.getMessage(),ex);
685             throw new XAException JavaDoc("Cannot start a transaction because : " +
686                     ex.getMessage());
687         }
688     }
689     
690     
691     /**
692      * This method checks the bean cache status.
693      */

694     private void checkStatus() throws BeanException {
695         if (status.isTerminated()) {
696             throw new BeanException("Bean cache has been terminated.");
697         }
698     }
699     
700     
701     /**
702      * This method returns the named lock
703      *
704      * @return The reference to the lock.
705      * @param The name of the queue that must be locked.
706      * @exception MessageServiceException
707      */

708     private void getLock(Object JavaDoc name) throws BeanException {
709         try {
710             Object JavaDoc key = null;
711             synchronized(keyLockMap) {
712                 if (keyLockMap.containsKey(name)) {
713                     key = keyLockMap.get(name);
714                 } else {
715                     key = name.toString();
716                     keyLockMap.put(name,key);
717                 }
718             }
719             LockRef lockRef =
720                     ObjectLockFactory.getInstance().acquireWriteLock(key,
721                     currentTransaction.get());
722             Changes changes = (Changes)transactionChanges.get(
723                     currentTransaction.get());
724             changes.addLock(lockRef);
725         } catch (Exception JavaDoc ex) {
726             log.error("Failed to retrieve a lock on the bean cache entry : " +
727                     ex.getMessage(),ex);
728             throw new BeanException
729                     ("Failed to retrieve a lock on the bean cache entry : " +
730                     ex.getMessage(),ex);
731         }
732     }
733     
734     
735     /**
736      * This method returns the named lock
737      *
738      * @return The reference to the lock.
739      * @param The name of the queue that must be locked.
740      * @exception MessageServiceException
741      */

742     private LockRef getLockRef(Object JavaDoc name) throws BeanException {
743         try {
744             Object JavaDoc key = null;
745             synchronized(keyLockMap) {
746                 if (keyLockMap.containsKey(name)) {
747                     key = keyLockMap.get(name);
748                 } else {
749                     key = name.toString();
750                     keyLockMap.put(name,key);
751                 }
752             }
753             return ObjectLockFactory.getInstance().acquireWriteLock(key);
754         } catch (Exception JavaDoc ex) {
755             log.error("Failed to retrieve a lock on the bean cache entry : " +
756                     ex.getMessage(),ex);
757             throw new BeanException
758                     ("Failed to retrieve a lock on the bean cache entry : " +
759                     ex.getMessage(),ex);
760         }
761     }
762 }
763
Popular Tags