~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to net/sf/ehcache/constructs/blocking/BlockingCache.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-07-14 02:08:53 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080714020853-37uz6uzh6mc5mcgx
Tags: 1.5.0-1
* New upstream release
* Add libjgroups-java to Build-Depends-Indep
* Bump Standards-Version to 3.8.0
* debian/copyright: remove the full text of Apache 2.0 license, as now
  is included in common licenses

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
 * Further improvements to hashing suggested by Joe Bowbeer.
92
92
 *
93
93
 * @author Greg Luck
94
 
 * @version $Id: BlockingCache.java 525 2007-07-31 22:41:54Z gregluck $
 
94
 * @version $Id: BlockingCache.java 704 2008-07-13 00:17:52Z gregluck $
95
95
 */
96
96
public class BlockingCache implements Ehcache {
97
97
 
503
503
     * Looks up an entry.  Blocks if the entry is null until a call to {@link #put} is done
504
504
     * to put an Element in.
505
505
     * <p/>
506
 
     * If a put is not done, the lock is never released
 
506
     * If a put is not done, the lock is never released.
507
507
     * <p/>
 
508
     * If this method throws an exception, it is the responsibility of the caller to catch that exception and call
 
509
     * <code>put(new Element(key, null));</code> to release the lock acquired. See {@link net.sf.ehcache.constructs.blocking.SelfPopulatingCache}
 
510
     * for an example.
 
511
     *
508
512
     * Note. If a LockTimeoutException is thrown while doing a {@link #get} it means the lock was never acquired,
509
513
     * therefore it is a threading error to call {@link #put}
510
514
     *
511
515
     * @throws LockTimeoutException if timeout millis is non zero and this method has been unable to
512
516
     *                              acquire a lock in that time
 
517
     * @throws RuntimeException if thrown the lock will not released. Catch and call<code>put(new Element(key, null));</code>
 
518
     * to release the lock acquired.
513
519
     */
514
 
    public Element get(final Object key) throws LockTimeoutException {
 
520
    public Element get(final Object key) throws RuntimeException, LockTimeoutException {
515
521
        Mutex lock = getLockForKey(key);
516
522
        try {
517
523
            if (timeoutMillis == 0) {
755
761
     *                                    further notification to doNotNotifyCacheReplicators cache peers
756
762
     * @return true if the element was removed, false if it was not found in the cache
757
763
     * @throws IllegalStateException if the cache is not {@link net.sf.ehcache.Status#STATUS_ALIVE}
758
 
     * @noinspection SameParameterValue
759
764
     */
760
765
    public boolean remove(Serializable key, boolean doNotNotifyCacheReplicators) throws IllegalStateException {
761
766
        return cache.remove(key, doNotNotifyCacheReplicators);
1038
1043
    public void loadAll(Collection keys, Object argument) throws CacheException {
1039
1044
        throw new CacheException("This method is not appropriate for a Blocking Cache");
1040
1045
    }
 
1046
 
 
1047
 
 
1048
    /**
 
1049
     * Whether this cache is disabled. "Disabled" means:
 
1050
     * <ol>
 
1051
     * <li>bootstrap is disabled
 
1052
     * <li>puts are discarded
 
1053
     * <li>putQuites are discarded
 
1054
     * </ol>
 
1055
     * In all other respects the cache continues as it is.
 
1056
     * <p/>
 
1057
     * You can disable and enable a cache programmatically through the {@link #setDisabled(boolean)} method.
 
1058
     * <p/>
 
1059
     * By default caches are enabled on creation, unless the <code>net.sf.ehcache.disabled</code> system
 
1060
     * property is set.
 
1061
     * @return true if the cache is disabled.
 
1062
     */
 
1063
    public boolean isDisabled() {
 
1064
        return cache.isDisabled();
 
1065
    }
 
1066
 
 
1067
    /**
 
1068
     * Disables or enables this cache. This call overrides the previous value of disabled, even if the
 
1069
     * <code>net.sf.ehcache.disabled</code> system property is set
 
1070
     * <p/>
 
1071
     * @param disabled true if you wish to disable, false to enable
 
1072
     * @see #isDisabled()
 
1073
     */
 
1074
    public void setDisabled(boolean disabled) {
 
1075
        cache.setDisabled(disabled);
 
1076
    }
 
1077
 
 
1078
 
1041
1079
}
1042
1080
 
1043
1081