Skip to content

Package: ImageModelCache

ImageModelCache

nameinstructionbranchcomplexitylinemethod
ImageModelCache()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getInstance()
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setDefault(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image;
28:
29: import java.io.Serializable;
30:
31: /***********************************************************************************************************************
32: *
33: * A cache of ImageModels used for distributed computing. The purpose of the
34: * cache is - quite obviously - to reduce the need for moving image through the
35: * network among different computing nodes.
36: *
37: * @author Fabrizio Giudici
38: *
39: **********************************************************************************************************************/
40: public abstract class ImageModelCache
41: {
42: /**
43: * The default class.
44: */
45: private static Class<? extends ImageModelCache> defaultClass = DefaultImageModelCache.class;
46:
47: /**
48: * The singleton instance.
49: */
50: private static ImageModelCache instance;
51:
52: /*******************************************************************************************************************
53: *
54: *
55: ******************************************************************************************************************/
56: protected ImageModelCache()
57: {
58: }
59:
60: /*******************************************************************************************************************
61: *
62: * Sets the default implementation of the cache for the local VM.
63: *
64: * @param defaultClass the implementation class
65: * @throws IllegalStateException if a cache has been already instantiated
66: *
67: ******************************************************************************************************************/
68: public static void setDefault (final Class<? extends ImageModelCache> defaultClass)
69: {
70: // if (instance != null)
71: // {
72: // throw new IllegalStateException("A local cache has been already instantiated");
73: // }
74:
75: ImageModelCache.defaultClass = defaultClass;
76: instance = null;
77: }
78:
79: /*******************************************************************************************************************
80: *
81: * Returns the default instance of the cache on the local VM.
82: *
83: * @return the local cache
84: *
85: ******************************************************************************************************************/
86: public static synchronized ImageModelCache getInstance() // FIXME: rename to getDefault(), it's no more a singleton
87: {
88: try
89: {
90:• if (instance == null)
91: {
92: instance = defaultClass.newInstance();
93: }
94:
95: return instance;
96: }
97: catch (Exception e)
98: {
99: throw new RuntimeException(e);
100: }
101: }
102:
103: /*******************************************************************************************************************
104: *
105: * Adds an ImageModel to the cache. The image is always added only in the
106: * local cache. Remote caches will pull the images they lack on demand.
107: *
108: * @param imageModel the ImageModel to add
109: *
110: ******************************************************************************************************************/
111: public abstract void store (ImageModel imageModel);
112:
113: /*******************************************************************************************************************
114: *
115: * Updates an ImageModel in the cache. This means that all remote copies of
116: * this image will be invalidated.
117: *
118: * TODO: should investigate more complex cases. Maybe the remote workers
119: * still want to work with a remote snapshot. Include versioning instead of
120: * invalidating?
121: *
122: * @param imageModel the ImageModel to update
123: *
124: ******************************************************************************************************************/
125: public abstract void update (ImageModel imageModel);
126:
127: /*******************************************************************************************************************
128: *
129: * Removes an ImageModel from the cache. According to the value of the
130: * <code>remote</code> parameter, the operation is performed only locally
131: * or also to remote caches.
132: *
133: * @param id the id of the ImageModel to remove
134: * @param remove true if the operation must be performed also remotely
135: *
136: ******************************************************************************************************************/
137: public abstract void remove (Serializable id, boolean remote);
138:
139: /*******************************************************************************************************************
140: *
141: * Finds an ImageModel in the cache. According to the value of the
142: * <code>remote</code> parameter, the search is performed only locally
143: * or also to remote caches.
144: *
145: * @param id the id of the ImageModel to remove
146: * @param remove true if the operation must be performed also remotely
147: *
148: ******************************************************************************************************************/
149: public abstract ImageModel retrieve (Serializable id, boolean remote);
150:
151: /*******************************************************************************************************************
152: *
153: * Returns true if there's a local copy with the given id.
154: *
155: * @param id the id of the ImageModel to remove
156: * @return true if there's a local copy
157: *
158: ******************************************************************************************************************/
159: public abstract boolean contains (Serializable id);
160: }