KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > rendered > TileLRUMember


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.rendered;
19
20 import java.awt.image.Raster JavaDoc;
21 import java.lang.ref.Reference JavaDoc;
22 import java.lang.ref.SoftReference JavaDoc;
23
24 /**
25  * This is a useful class that wraps a Raster for patricipation in
26  * an LRU Cache. When this object drops out of the LRU cache it
27  * removes it's hard reference to the tile, but retains it's soft
28  * reference allowing for the recovery of the tile when the JVM is
29  * not under memory pressure
30  */

31 public class TileLRUMember implements LRUCache.LRUObj {
32     private static final boolean DEBUG = false;
33             
34     protected LRUCache.LRUNode myNode = null;
35     protected Reference JavaDoc wRaster = null;
36     protected Raster JavaDoc hRaster = null;
37
38     public TileLRUMember() { }
39
40     public TileLRUMember(Raster JavaDoc ras) {
41         setRaster(ras);
42     }
43
44     public void setRaster(Raster JavaDoc ras) {
45         hRaster = ras;
46         wRaster = new SoftReference JavaDoc(ras);
47     }
48
49     public boolean checkRaster() {
50         if (hRaster != null) return true;
51
52         if ((wRaster != null) &&
53             (wRaster.get() != null)) return true;
54             
55         return false;
56     }
57
58     public Raster JavaDoc retrieveRaster() {
59         if (hRaster != null) return hRaster;
60         if (wRaster == null) return null;
61
62         hRaster = (Raster JavaDoc)wRaster.get();
63
64         if (hRaster == null) // didn't manage to retrieve it...
65
wRaster = null;
66
67         return hRaster;
68     }
69
70     public LRUCache.LRUNode lruGet() { return myNode; }
71     public void lruSet(LRUCache.LRUNode nde) { myNode = nde; }
72     public void lruRemove() {
73         myNode = null;
74         hRaster = null;
75         if (DEBUG) System.out.println("Removing");
76     }
77 }
78
79
Popular Tags