Revision 2571 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/util/CachedValue.java
CachedValue.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* gvSIG. Desktop Geographic Information System. |
3 | 3 |
* |
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
|
4 |
* Copyright (C) 2007-2021 gvSIG Association.
|
|
5 | 5 |
* |
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
... | ... | |
30 | 30 |
|
31 | 31 |
/** |
32 | 32 |
* |
33 |
* @author jjdelcerro |
|
33 |
* @author gvSIG Team |
|
34 |
* @param <T> |
|
34 | 35 |
*/ |
35 |
public abstract class CachedValue<T> {
|
|
36 |
public class CachedValue<T> { |
|
36 | 37 |
|
37 | 38 |
private T value = null; |
38 | 39 |
private long lastAccess = 0; |
39 | 40 |
private long expireTimeInMillis; |
41 |
private java.util.concurrent.Callable<T> reload; |
|
40 | 42 |
|
41 | 43 |
public CachedValue() { |
42 |
this(3000); |
|
44 |
this(3000, null);
|
|
43 | 45 |
} |
44 | 46 |
|
45 | 47 |
public CachedValue(long expireTimeInMillis) { |
48 |
this(expireTimeInMillis, null); |
|
49 |
} |
|
50 |
|
|
51 |
public CachedValue(java.util.concurrent.Callable<T> reload) { |
|
52 |
this(3000, reload); |
|
53 |
} |
|
54 |
|
|
55 |
public CachedValue(long expireTimeInMillis, java.util.concurrent.Callable<T> reload) { |
|
46 | 56 |
this.expireTimeInMillis = expireTimeInMillis; |
57 |
this.reload = reload; |
|
47 | 58 |
} |
48 | 59 |
|
49 | 60 |
protected void reload() { |
50 |
// Overwrite this method. |
|
61 |
if( this.reload!=null ) { |
|
62 |
try { |
|
63 |
this.value = this.reload.call(); |
|
64 |
} catch (Exception ex) { |
|
65 |
// FIXME: calling Callable.call exception ?? |
|
66 |
} |
|
67 |
} |
|
51 | 68 |
} |
52 | 69 |
|
53 | 70 |
protected final T getValue() { |
Also available in: Unified diff