* method may return different objects.
*
* If the object is expired from the cache it is recomputed using the
- * callback. In case the callback throws an exception the
- * last known value is used. In case an exception is thrown, the problem is
- * also logged. In case a recomputation is already being done by another
- * thread, the last known value is immediately returned.
+ * callback. In case the callback throws an exception the last known value
+ * is used. In case an exception is thrown, the problem is also logged. In
+ * case a recomputation is already being done by another thread, the last
+ * known value is immediately returned.
*
* @return Object.
*/
synchronized (this) {
value = object;
- }
+ }
} catch (Exception e) {
LOGGER.log(Level.INFO,
"Recomputation of cached item failed for key '" + objectKey +
computing = false;
}
}
- synchronized(this) {
- return value;
+ synchronized (this) {
+ return value;
}
}
*/
public static interface Computation<Key extends Serializable, Value extends Serializable> {
/**
- * Gets the object. Called when the object is not in the cache.
- * In case computation fails, an exception should be thrown to ensure that the last
- * known value will be used.
+ * Gets the object. Called when the object is not in the cache. In case
+ * computation fails, an exception should be thrown to ensure that the
+ * last known value will be used.
*
* @param aObjectKey
* Id of the object in the cache.
private Computation<T> computedValue;
private Boolean busy;
- private T value;
+ private T value;
/**
* Constructs the compute guard
lock = aLock;
computedValue = aComputation;
busy = false;
- value = null;
+ value = null;
}
/**
return value;
}
}
-
+
/**
- * Gets the currently cached value. No recomputation is performed.
- * @return Cached value.
+ * Gets the currently cached value. No recomputation is performed.
+ *
+ * @return Cached value.
*/
- public T getCached() {
- synchronized(lock) {
- return value;
+ public T getCached() {
+ synchronized (lock) {
+ return value;
}
-
+
}
-
+
/**
- * Sets the value explicitly.
- * @param aValue value to set.
+ * Sets the value explicitly.
+ *
+ * @param aValue
+ * value to set.
*/
- public void set(T aValue) {
- synchronized(lock) {
+ public void set(T aValue) {
+ synchronized (lock) {
value = aValue;
}
}
* 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.wamblee.cache;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
-
import org.wamblee.io.InputResource;
import java.io.IOException;
*/
public class EhCache<KeyType extends Serializable, ValueType extends Serializable>
implements org.wamblee.cache.Cache<KeyType, ValueType> {
- private static final Logger LOGGER = Logger.getLogger(EhCache.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(EhCache.class
+ .getName());
/**
* EH Cache manager.
* 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.wamblee.cache;
import java.io.Serializable;
* 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.wamblee.cache;
import java.io.Serializable;
* 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.
- */
+ */
/**
* This package provides an interface for a cache together with several implementations.
* The main interfaces and classes are: