001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Core License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: DeathObject.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
008:
009: package org.ozoneDB.core.classicStore;
010:
011: import org.ozoneDB.core.*;
012: import org.ozoneDB.util.*;
013: import org.ozoneDB.DxLib.*;
014: import org.ozoneDB.OzoneCompatible;
015: import java.io.*;
016:
017: /**
018: * stellt einen eintrag in die objektliste des clusterspaces dar;
019: * obj ist die objekt id des ref. objektes;
020: * data der datenteil des objektes in byte form
021: */
022: public class DeathObject extends DxObject {
023: public final static byte FREE = 0;
024: public final static byte DELETED = 1;
025: public final static byte FROZEN = 2;
026: public final static byte CHANGED = 3;
027:
028: protected ObjectID oid;
029: protected byte[] data;
030: protected long size;
031: /**
032: * will be set while read the object state chunk (see
033: * Cluster.readObjects() and Cluster.appendObject())
034: */
035: protected long stateSize;
036: protected byte state = FREE;
037:
038: /** References for the double linked list */
039: public DeathObject previous;
040: public DeathObject next;
041:
042: public DeathObject() {
043: }
044:
045: public DeathObject(ObjectID _oid) {
046: oid = _oid;
047: }
048:
049: public final ObjectID objID() {
050: return oid;
051: }
052:
053: public final byte[] data() {
054: return data;
055: }
056:
057: public final void setData(byte[] _data) {
058: data = _data;
059: setSize(data.length);
060: }
061:
062: public final long size() {
063: return size;
064: }
065:
066: public final void setSize(long s) {
067: size = s;
068: }
069:
070: public final byte state() {
071: return state;
072: }
073:
074: public final ClusterID clusterID() {
075: return container().clusterID();
076: }
077:
078: public final void setCluID(ClusterID _cid) {
079: container().setClusterID(_cid);
080: }
081:
082: public final ClassicObjectContainer container() {
083: return (ClassicObjectContainer) ((ClassicStore) Env
084: .currentEnv().store).objectSpace.objectForID(oid);
085: }
086:
087: public final void setState(byte s) {
088: state = s;
089: // Speicher freigeben, da DeathObject selbst nicht sofort aus dem
090: // ClusterSpace geloescht wird, sondern in priorityQueue referenziert
091: // wird.
092: if (state == DELETED) {
093: data = null;
094: oid = null;
095: }
096: }
097:
098: public OzoneCompatible enlive() throws IOException {
099: if (data != null) {
100: try {
101: //env.logWriter.newEntry ("enlive data size: " + data.length, LogWriter.DEBUG3);
102: ByteArrayInputStream bs = new ByteArrayInputStream(data);
103: ObjectInput in = new ObjectInputStream(bs);
104: OzoneCompatible obj = (OzoneCompatible) in.readObject();
105: in.close();
106: bs.close();
107:
108: // NEW: if an object is activated, we don't need the data any longer
109: data = null;
110:
111: return obj;
112: } catch (Exception e) {
113: Env.currentEnv().logWriter.newEntry(this , e.toString(),
114: LogWriter.WARN);
115: throw new IOException(e.toString());
116: }
117: }
118: return null;
119: }
120: }
|