01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project;
16:
17: import net.refractions.udig.catalog.IGeoResource;
18:
19: /**
20: * Controls the caching of resources returned by:
21: * {@link ILayer#getResource(Class, org.eclipse.core.runtime.IProgressMonitor)}.
22: * <p>
23: * Example:
24: * If a new feature store was returned each time then every plugin that is interested in
25: * events would need to create a resource interceptor and every request for a FeatureStore
26: * would result in both a new FeatureStore and a new listener for every interested plugin.
27: * Since the Datastore's Listener manager often keeps the listeners indefinately then we
28: * would very quickly have 10s to 100s of listeners that can't be garbage collected and
29: * possibly featurestores as well.
30: * </p>
31: * <p>
32: * The "active" caching strategy is stored in the
33: * ProjectPlugin.getPlugin().getPreferenceStore().getString( "P_LAYER_RESOURCE_CACHING_STRATEGY" ).
34: * </p><p>
35: * Set the preference to activate a custom Caching strategy.
36: * </p>
37: * @author Jesse
38: * @since 1.1.0
39: */
40: public interface IResourceCachingInterceptor {
41: /**
42: * Called to see if the resource should be obtained from cache
43: *
44: * @param <T> the type of the resource. Can be most any type of Object
45: * @param layer the layer that the resource is being obtained from
46: * @param geoResource the resource obtained from the GeoResource. <b>NO</b> interceptors have ran on the resource.
47: * @param requestedType the type of object that the caller requested
48: * @return true if the resource should be obtained from the cache.
49: */
50: <T> boolean isCached(ILayer layer, IGeoResource geoResource,
51: Class<T> requestedType);
52:
53: /**
54: * Obtains the resource from the cache.
55: *
56: * @param <T> the type of the resource. Can be most any type of Object
57: * @param layer the layer that the resource is being obtained from
58: * @param requestedType the type of object that the caller requested
59: * @return the cached instance of the resource.
60: */
61: <T> T get(ILayer layer, Class<T> requestedType);
62:
63: /**
64: * Caches the resource.
65: *
66: * @param <T> the type of the resource. Can be most any type of Object
67: * @param layer the layer that the resource is being obtained from
68: * @param resource the resource obtained from the GeoResource. All the PRE interceptors have ran on the resource.
69: * @param requestedType the type of object that the caller requested
70: */
71: <T> void put(ILayer layer, T resource, Class<T> requestedType);
72:
73: }
|