KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > classicStore > DeathObject


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core 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$
8

9 package org.ozoneDB.core.storage.classicStore;
10
11 import org.ozoneDB.core.*;
12 import org.ozoneDB.core.storage.classicStore.ClassicObjectContainer;
13 import org.ozoneDB.core.storage.classicStore.ClassicStore;
14 import org.ozoneDB.core.storage.classicStore.ClusterID;
15 import org.ozoneDB.util.*;
16 import org.ozoneDB.DxLib.*;
17 import org.ozoneDB.OzoneCompatible;
18 import org.ozoneDB.io.stream.ResolvingObjectInputStream;
19
20 import java.io.*;
21
22
23 /**
24  * Stellt einen eintrag in die objektliste des clusterspaces dar.
25  * Obj is the object id of the ref. object.
26  * Data der datenteil des objektes in byte form
27  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
28  */

29 public class DeathObject extends DxObject {
30     public final static byte FREE = 0;
31     public final static byte DELETED = 1;
32     public final static byte FROZEN = 2;
33     public final static byte CHANGED = 3;
34
35     protected ObjectID oid;
36     protected byte[] data;
37     protected long size;
38     /**
39      * will be set while read the object state chunk (see
40      * Cluster.readObjects() and Cluster.appendObject())
41      */

42     protected long stateSize;
43     protected byte state = FREE;
44
45     /** References for the double linked list */
46     public DeathObject previous;
47     public DeathObject next;
48
49
50     public DeathObject() {
51     }
52
53
54     public DeathObject( ObjectID _oid ) {
55         oid = _oid;
56     }
57
58
59     public final ObjectID objID() {
60         return oid;
61     }
62
63
64     public final byte[] data() {
65         return data;
66     }
67
68
69     public final void setData( byte[] _data ) {
70         data = _data;
71         setSize( data.length );
72     }
73
74
75     public final long size() {
76         return size;
77     }
78
79
80     public final void setSize( long s ) {
81         size = s;
82     }
83
84
85     public final byte state() {
86         return state;
87     }
88
89
90     public final ClusterID clusterID() {
91         return container().clusterID();
92     }
93
94
95     public final void setCluID( ClusterID _cid ) {
96         container().setClusterID( _cid );
97     }
98
99
100     public final ClassicObjectContainer container() {
101         return (ClassicObjectContainer)((ClassicStore)Env.currentEnv().getStoreManager()).objectSpace.objectForID( oid );
102     }
103
104
105     public final void setState( byte s ) {
106         state = s;
107         // Speicher freigeben, da DeathObject selbst nicht sofort aus dem
108
// ClusterSpace geloescht wird, sondern in priorityQueue referenziert
109
// wird.
110
if (state == DELETED) {
111             data = null;
112             oid = null;
113         }
114     }
115
116
117     public OzoneCompatible enlive() throws IOException {
118         if (data != null) {
119             try {
120                 //env.logWriter.newEntry ("enlive data size: " + data.length, LogWriter.DEBUG3);
121
ByteArrayInputStream bs = new ByteArrayInputStream( data );
122                 ObjectInput in = new ResolvingObjectInputStream( bs );
123                 OzoneCompatible obj = (OzoneCompatible)in.readObject();
124                 in.close();
125                 bs.close();
126
127                 // NEW: if an object is activated, we don't need the data any longer
128
data = null;
129
130                 return obj;
131             } catch (Exception JavaDoc e) {
132                 Env.currentEnv().logWriter.newEntry( this, e.toString(), LogWriter.WARN );
133                 throw new IOException( e.toString() );
134             }
135         }
136         return null;
137     }
138 }
139
Popular Tags