KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > CacheObjectContainer


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: CacheObjectContainer.java,v 1.8 2003/04/06 13:57:32 mediumnet Exp $
8

9 package org.ozoneDB;
10
11 import org.ozoneDB.DxLib.DxCollection;
12 import org.ozoneDB.core.*;
13 import org.ozoneDB.io.stream.ResolvingObjectInputStream;
14
15 import java.io.*;
16 import java.lang.reflect.Constructor JavaDoc;
17
18
19 /**
20  * An implementation of {@link ObjectContainer} that works together with {@link
21  * ClientCacheDatabase} to provide an client site cache. A client program never
22  * needs to directly deal with it.
23  *
24  *
25  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
26  * @version $Revision: 1.8 $Date: 2003/04/06 13:57:32 $
27  */

28 public final class CacheObjectContainer implements ObjectContainer, Serializable {
29
30     private static long touchCount;
31
32     private transient ClientCacheDatabase db;
33
34     protected transient AbstractTransaction tx;
35
36     private transient long lastTouched;
37
38     /**
39      * True if the container has to be synched with the server.
40      */

41     private transient boolean dirty;
42
43     private int state;
44
45     /**
46      * The time when this container was fetched from the server. This is
47      * initialized and used by the server only.
48      */

49     private long modTime;
50
51     private OzoneCompatible target;
52
53     private ObjectID id;
54
55     private String JavaDoc name;
56
57     private int access;
58
59
60     public CacheObjectContainer( ObjectContainer rhs ) {
61         this( rhs.target(), rhs.id(), rhs.name(), OzoneInterface.Public );
62         modTime = rhs.modTime();
63     }
64
65
66     public CacheObjectContainer( OzoneCompatible _target, ObjectID _id, String JavaDoc _name, int _access ) {
67         target = _target;
68         target.setContainer( this );
69         id = _id;
70         name = _name;
71         access = _access;
72         state = STATE_CLEAN;
73
74         touch();
75     }
76
77
78     public int access() {
79         return access;
80     }
81
82
83     public int state() {
84         return state;
85     }
86
87
88     public boolean dirty() {
89         return dirty;
90     }
91
92
93     public void setDirty( boolean _dirty ) {
94         dirty = _dirty;
95     }
96
97
98     public void raiseState( int newState ) {
99         int oldState = state;
100         state = newState > state ? newState : state;
101
102         if (state >= STATE_MODIFIED) {
103             dirty = true;
104         }
105
106         // don't write containers back to the server that has been created and
107
// deleted in one transaction
108
if (state == STATE_DELETED && oldState == STATE_CREATED) {
109             dirty = false;
110         }
111     }
112
113
114     public void clearState() {
115         state = STATE_CLEAN;
116         dirty = false;
117     }
118
119
120     public void touch() {
121         touchCount++;
122     }
123
124
125     public long lastTouched() {
126         return lastTouched;
127     }
128
129
130     public long modTime() {
131         return modTime;
132     }
133
134
135     protected void setModTime( long _modTime ) {
136         modTime = _modTime;
137     }
138
139
140     public Lock lock() {
141         throw new RuntimeException JavaDoc( "Method not implemented." );
142     }
143
144
145     public DxCollection allLockers() {
146         throw new RuntimeException JavaDoc( "Method not implemented." );
147     }
148
149
150     public void setTarget( OzoneCompatible _target ) {
151         if (target != null) {
152             target.setContainer( null );
153         }
154
155         target = _target;
156         target.setContainer( this );
157     }
158
159
160     public OzoneCompatible target() {
161         return target;
162     }
163
164
165     public Class JavaDoc targetClass() {
166         return target.getClass();
167     }
168
169
170     public void setDatabase( ClientCacheDatabase _db ) {
171         db = _db;
172     }
173
174
175     public OzoneInterface database() {
176         return db;
177     }
178
179
180     public ObjectID id() {
181         return id;
182     }
183
184
185     public Permissions permissions() {
186         throw new RuntimeException JavaDoc( "Method not implemented." );
187     }
188
189
190     public String JavaDoc name() {
191         return name;
192     }
193
194
195     public void setName( String JavaDoc _name ) {
196         name = _name;
197     }
198
199
200     public OzoneProxy ozoneProxy() {
201         try {
202             String JavaDoc implName = targetClass().getName();
203             String JavaDoc proxyName;
204             if (implName.endsWith( ObjectContainer.IMPLNAME_POSTFIX )) {
205                 proxyName = implName.substring( 0, implName.length() - 5 );
206             } else {
207                 proxyName = implName + PROXYNAME_POSTFIX;
208             }
209
210             // todo: uncommented until verified that it works
211
//Class cl = Class.forName( proxyName );
212
Class JavaDoc cl = Env.currentEnv().classManager.classForName(proxyName);
213
214             Class JavaDoc[] argTypes = {ObjectID.class, OzoneInterface.class};
215             Constructor JavaDoc ctor = cl.getConstructor( argTypes );
216
217             // System.out.println ("creating proxy: " + cl.getName());
218
Object JavaDoc[] args = {id(), database()};
219             return (OzoneProxy)ctor.newInstance( args );
220         } catch (Exception JavaDoc e) {
221             throw new RuntimeException JavaDoc( e.toString() );
222         }
223     }
224
225
226     public OzoneCompatible targetClone() throws Exception JavaDoc {
227         ByteArrayOutputStream bout = new ByteArrayOutputStream( 2048 );
228         ObjectOutputStream out = new ObjectOutputStream( bout );
229         out.writeObject( target() );
230         out.close();
231         ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) );
232         Object JavaDoc targetClone = in.readObject();
233         in.close();
234         return (OzoneCompatible)targetClone;
235     }
236
237
238     public Object JavaDoc invokeTarget( Env env, String JavaDoc methodName, String JavaDoc sig, Object JavaDoc[] args ) throws Exception JavaDoc {
239         throw new RuntimeException JavaDoc( "Method not implemented." );
240     }
241
242
243     public Object JavaDoc invokeTarget( Env env, int methodIndex, Object JavaDoc[] args ) throws Exception JavaDoc {
244         throw new RuntimeException JavaDoc( "Method not implemented." );
245     }
246
247
248     public void createTarget( Env env, Class JavaDoc cl, String JavaDoc sig, Object JavaDoc[] args ) throws Exception JavaDoc {
249         throw new RuntimeException JavaDoc( "Method not implemented." );
250     }
251
252
253     public void deleteTarget() {
254         throw new RuntimeException JavaDoc( "Method not implemented." );
255     }
256
257
258     public void nameTarget( String JavaDoc _name ) {
259         throw new RuntimeException JavaDoc( "Method not implemented." );
260     }
261
262
263     public void finalizeTarget() throws Exception JavaDoc {
264         throw new RuntimeException JavaDoc( "Method not implemented." );
265     }
266
267
268     /**
269         Pins this ObjectContainer.
270         Every caller of this method must pair this call with a call to {@link #unpin}.
271         An ObjectContainer remains in main memory at least as long as it is pinned.
272     */

273     public void pin() {
274         throw new RuntimeException JavaDoc("Method not implemented.");
275     }
276
277     /**
278         Unpins this ObjectContainer.
279         This method must be called exactly once for every call to {@link #pin}.
280     */

281     public void unpin() {
282         throw new RuntimeException JavaDoc("Method not implemented.");
283     }
284
285     /**
286         Returns wether this ObjectContainer is pinned.
287     */

288     public boolean isPinned() {
289         throw new RuntimeException JavaDoc("Method not implemented.");
290     }
291
292     /**
293         Ensures that the garbageCollectionLevel is at least the given currentGarbageCollectionLevel.
294         The return value is meaningful if the supplied newGarbageCollectionLevel is the currentGarbageCollectionLevel
295
296         @return
297             <=0 if this object still has to be processed.
298                 This is the case if it belongs to the surelyReachable set but not to the processedReachable set
299             > otherwise
300
301             <0 if this object has been updated
302             =0 if this object has not been updated, it is surelyReachable
303             >0 if this object has not been updated, it is processedReachable
304     */

305     public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) {
306         throw new RuntimeException JavaDoc("Method not implemented.");
307     }
308
309     /**
310         Returns the garbageCollectionLevel this ObjectContainer has reached due to (not) calling {@link #ensureGarbageCollectionLevel}.
311     */

312     public int getGarbageCollectionLevel() {
313         throw new RuntimeException JavaDoc("Method not implemented.");
314     }
315         
316     public void invokeOnActivate() {
317         throw new RuntimeException JavaDoc("Method not implemented.");
318     }
319
320     public boolean shouldOnActivateBeCalled() {
321         throw new RuntimeException JavaDoc("Method not implemented.");
322     }
323
324     public void invokeOnPassivate() {
325         throw new RuntimeException JavaDoc("Method not implemented.");
326     }
327
328     public boolean shouldOnPassivateBeCalled() {
329         throw new RuntimeException JavaDoc("Method not implemented.");
330     }
331
332     public void setShouldCallOnPassivate(boolean shouldOnPassivateBeCalled) {
333         throw new RuntimeException JavaDoc("Method not implemented.");
334     }
335
336     public void setShouldCallOnActivate(boolean shouldOnActivateBeCalled) {
337         throw new RuntimeException JavaDoc("Method not implemented.");
338     }
339
340     public void requireWriteLocking() {
341         throw new RuntimeException JavaDoc("Method not implemented.");
342     }
343 }
344
345 // :indentSize=4:tabSize=4:noTabs=true:
346
Popular Tags