Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/iapi/services/cache/Cacheable.java


1   /*
2   
3      Derby - Class org.apache.derby.iapi.services.cache.Cacheable
4   
5      Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.iapi.services.cache;
22  
23  import org.apache.derby.iapi.error.StandardException;
24  
25  /**
26    Any object that implements this interface can be cached using the services of
27    the CacheManager/CacheFactory. In addition to implementing this interface the
28    class must be public and it must have a public no-arg constructor. This is because
29    the cache manager will construct objects itself and then set their identity
30    by calling the setIdentity method.
31    <P>
32    A Cacheable object has five states:
33    <OL>
34    <OL>
35    <LI> No identity - The object is only accessable by the cache manager
36    <LI> Identity, clean, unkept - The object has an identity, is clean but is only accessable by the cache manager
37    <LI> Identity, clean, kept - The object has an identity, is clean, and is in use by one or more threads 
38    <LI> Identity, kept, dirty - The object has an identity, is dirty, and is in use by one or more threads 
39    <LI> Identity, unkept, dirty - The object has an identity, is dirty but is only accessable by the cache manager
40    </OL>
41    </OL>
42    <BR>
43    While the object is kept it is guaranteed
44    not to change identity. While it is unkept no-one outside of the
45    cache manager can have a reference to the object.
46    The cache manager returns kept objects and they return to the unkept state
47    when all the current users of the object have released it.
48    <BR>
49    It is required that the object can only move into a dirty state while it is kept.
50  
51    <BR> MT - Mutable : thread aware - Calls to Cacheable method must only be made by the
52    cache manager or the object itself.
53  
54    @see CacheManager
55    @see CacheFactory
56    @see Class#newInstance
57  */
58  public interface Cacheable  {
59  
60    /**
61          Set the identity of the object.
62          <p>
63      Set the identity of the object to represent an item that already exists,
64      e.g. an existing container.
65      The object will be in the No Identity state,
66      ie. it will have just been created or clearIdentity() was just called. 
67      <BR>
68      The object must copy the information out of key, not just store a reference to key.
69      After this call the expression getIdentity().equals(key) must return true.
70      <BR>
71      If the class of the object needs to change (e.g. to support a different format)
72      then the object should create a new object, call its initParameter() with the parameters
73      the original object was called with, set its identity and return a reference to it. The cache
74      manager will discard the reference to the old object. 
75      <BR>
76      If an exception is thrown the object must be left in the no-identity state.
77  
78      <BR> MT - single thread required - Method must only be called be cache manager
79      and the cache manager will guarantee only one thread can be calling it.
80  
81      @return an object reference if the object can take on the identity, null otherwise.
82  
83      @exception StandardException Standard Cloudscape Policy
84  
85      @see CacheManager#find
86  
87    */
88    public Cacheable setIdentity(Object key) throws StandardException;
89  
90    /**
91          Create a new item.
92          <p>
93      Create a new item and set the identity of the object to represent it.
94      The object will be in the No Identity state,
95      ie. it will have just been created or clearIdentity() was just called. 
96      <BR>
97      The object must copy the information out of key, not just store a reference to key
98      if the key is not immutable.
99      After this call the expression getIdentity().equals(key) must return true.
100     <BR>
101     <BR>
102     If the class of the object needs to change (e.g. to support a different format)
103     then the object should create a new object, call its initParameter() with the parameters
104     the original object was called with, set its identity and return a reference to it. The cache
105     manager will discard the reference to the old object. 
106     <BR>
107     If an exception is thrown the object must be left in the no-identity state.
108 
109     <BR> MT - single thread required - Method must only be called be cache manager
110     and the cache manager will guarantee only one thread can be calling it.
111 
112     @return an object reference if the object can take on the identity, null otherwise.
113 
114     @exception StandardException If forCreate is true and the object cannot be created.
115 
116     @see CacheManager#create
117 
118   */
119   public Cacheable createIdentity(Object key, Object createParameter) throws StandardException;
120 
121 
122   /**
123     Put the object into the No Identity state. 
124 
125     <BR> MT - single thread required - Method must only be called be cache manager
126     and the cache manager will guarantee only one thread can be calling it.
127 
128   */
129   public void clearIdentity();
130 
131   /**
132     Get the identity of this object.
133 
134     <BR> MT - thread safe.
135 
136   */
137   public Object getIdentity();
138 
139 
140   /**
141     Returns true of the object is dirty. 
142     May be called when the object is kept or unkept.
143 
144     <BR> MT - thread safe 
145 
146   */
147   public boolean isDirty();
148 
149   /**
150     Clean the object.
151     It is up to the object to ensure synchronization of the isDirty()
152     and clean() method calls.
153     <BR>
154     If forRemove is true then the 
155     object is being removed due to an explict remove request, in this case
156     the cache manager will have called this method regardless of the
157     state of the isDirty() 
158 
159     <BR>
160     If an exception is thrown the object must be left in the clean state.
161 
162     <BR> MT - thread safe - Can be called at any time by the cache manager, it is the
163     responsibility of the object implementing Cacheable to ensure any users of the
164     object do not conflict with the clean call.
165 
166     @exception StandardException Standard Cloudscape error policy.
167 
168   */
169   public void clean(boolean forRemove) throws StandardException;
170 }
171