// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: DeathObject.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
package org.ozoneDB.core.classicStore;
import org.ozoneDB.core.*;
import org.ozoneDB.util.*;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.OzoneCompatible;
import java.io.*;
/**
* stellt einen eintrag in die objektliste des clusterspaces dar;
* obj ist die objekt id des ref. objektes;
* data der datenteil des objektes in byte form
*/
public class DeathObject extends DxObject {
public final static byte FREE = 0;
public final static byte DELETED = 1;
public final static byte FROZEN = 2;
public final static byte CHANGED = 3;
protected ObjectID oid;
protected byte[] data;
protected long size;
/**
* will be set while read the object state chunk (see
* Cluster.readObjects() and Cluster.appendObject())
*/
protected long stateSize;
protected byte state = FREE;
/** References for the double linked list */
public DeathObject previous;
public DeathObject next;
public DeathObject() {
}
public DeathObject( ObjectID _oid ) {
oid = _oid;
}
public final ObjectID objID() {
return oid;
}
public final byte[] data() {
return data;
}
public final void setData( byte[] _data ) {
data = _data;
setSize( data.length );
}
public final long size() {
return size;
}
public final void setSize( long s ) {
size = s;
}
public final byte state() {
return state;
}
public final ClusterID clusterID() {
return container().clusterID();
}
public final void setCluID( ClusterID _cid ) {
container().setClusterID( _cid );
}
public final ClassicObjectContainer container() {
return (ClassicObjectContainer)((ClassicStore)Env.currentEnv().store).objectSpace.objectForID( oid );
}
public final void setState( byte s ) {
state = s;
// Speicher freigeben, da DeathObject selbst nicht sofort aus dem
// ClusterSpace geloescht wird, sondern in priorityQueue referenziert
// wird.
if (state == DELETED) {
data = null;
oid = null;
}
}
public OzoneCompatible enlive() throws IOException {
if (data != null) {
try {
//env.logWriter.newEntry ("enlive data size: " + data.length, LogWriter.DEBUG3);
ByteArrayInputStream bs = new ByteArrayInputStream( data );
ObjectInput in = new ObjectInputStream( bs );
OzoneCompatible obj = (OzoneCompatible)in.readObject();
in.close();
bs.close();
// NEW: if an object is activated, we don't need the data any longer
data = null;
return obj;
} catch (Exception e) {
Env.currentEnv().logWriter.newEntry( this, e.toString(), LogWriter.WARN );
throw new IOException( e.toString() );
}
}
return null;
}
}