summaryrefslogtreecommitdiffstats
path: root/simple/simple-common/src/main/java/org/simpleframework/common/lease/LeaseMap.java
blob: 711a466b1c84e48243c30692db43fff463b7d55e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * LeaseMap.java May 2004
 *
 * Copyright (C) 2004, Niall Gallagher <niallg@users.sf.net>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.
 */

package org.simpleframework.common.lease;

import java.util.concurrent.ConcurrentHashMap;

/**
 * The <code>LeaseMap</code> object is used to map lease keys to the
 * lease objects managing those objects. This allows components that
 * are using the leasing framework to associate an object with its
 * lease and vice versa. Such a capability enables lease renewals to
 * be performed without the need for a direct handle on the lease.
 * 
 * @author Niall Gallagher
 */
public class LeaseMap<T> extends ConcurrentHashMap<T, Lease<T>> {
   
   /**
    * Constructor for the <code>LeaseMap</code> object. This will
    * create a map for mapping leased resource keys to the leases
    * that manage them. Having such a map allows leases to be 
    * maintained without having a direct handle on the lease.
    */
   public LeaseMap() {
      super();
   }
   
   /**
    * Constructor for the <code>LeaseMap</code> object. This will
    * create a map for mapping leased resource keys to the leases
    * that manage them. Having such a map allows leases to be 
    * maintained without having a direct handle on the lease.
    * 
    * @param capacity this is the initial capacity of the map
    */
   public LeaseMap(int capacity) {
      super(capacity);
   }
   
   /**
    * This is used to acquire the <code>Lease</code> object that is
    * mapped to the specified key. Overriding this method ensures
    * that even without generic parameters a type safe method for
    * acquiring the registered lease objects can be used.
    * 
    * @param key this is the key used to acquire the lease object
    * 
    * @return this is the lease that is associated with the key
    */
   public Lease<T> get(Object key) {
      return super.get(key);
   }
   
   /**
    * This is used to remove the <code>Lease</code> object that is
    * mapped to the specified key. Overriding this method ensures
    * that even without generic parameters a type safe method for
    * removing the registered lease objects can be used.
    * 
    * @param key this is the key used to remove the lease object
    * 
    * @return this is the lease that is associated with the key
    */
   public Lease<T> remove(Object key) {
      return super.remove(key);
   }
}