📄 classicobjectcontainer.java
字号:
// 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$
package org.ozoneDB.core.storage.classicStore;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import org.ozoneDB.*;
import org.ozoneDB.io.stream.ResolvingObjectInputStream;
import org.ozoneDB.tools.OPP.OPP;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.core.*;
import org.ozoneDB.util.*;
/**
* @author <a href="http://www.softwarebuero.de/">SMB</a>
*/
public final class ClassicObjectContainer extends AbstractObjectContainer implements Externalizable {
/** magic number for streaming */
protected final static long serialVersionUID = 2;
protected final static byte subSerialVersionUID = 1;
/** global method cache */
private static DxHashMap methodTable = new DxHashMap( 64 );
/** objekte werden nach transaktion nicht geloescht */
protected static boolean keepObjectsAlive = true;
/** The environment of this object. */
protected transient Env env;
protected transient ClusterSpace clusterSpace;
/** permissions */
protected Permissions permissions;
/** null, if not activted */
protected OzoneCompatible target;
/** */
protected OzoneCompatible targetShadow;
/** */
protected byte[] targetBackup;
/** time of last invoke */
protected long touchTime = System.currentTimeMillis();
protected short touchCount = 1;
protected boolean touched = false;
/** a possible name for the object */
protected String name;
/** the id of the object */
protected ObjectID objID;
/** the cluster id where the object is stored */
protected ClusterID clusterID;
/** the lock of the object */
protected Lock lock = null;
/** */
protected boolean deleted = false;
/** */
protected boolean created = false;
/**
* constructor fuer streaming
*/
public ClassicObjectContainer() {
created = false;
deleted = false;
}
/**
* constructor; name ist optional
*/
public ClassicObjectContainer( OzoneCompatible _target, ObjectID _objID, Permissions _permissions ) {
env = Env.currentEnv();
clusterSpace = ((ClassicStore)env.getStoreManager()).objectSpace.clusterSpace;
target = _target;
objID = _objID;
permissions = _permissions;
//lock = new DefaultLock();
//todo assign lock to one of the new Lock implementation classes
created = true;
deleted = false;
target.setContainer( this );
}
// #### methods from ObjectContainer ######################################
/**
* Returns the time when the container was last commited with lock level
* greater than Lock.LEVEL_READ. The value returned by this method should
* only be compared against return values of this method.
*/
public long modTime() {
return 0;
}
public Lock lock() {
return null;
}
public void setTarget(OzoneCompatible _target) {
}
public Class targetClass() {
return null;
}
/**
Pins this ObjectContainer.
Every caller of this method must pair this call with a call to {@link #unpin}.
An ObjectContainer remains in main memory at least as long as it is pinned.
*/
public void pin() {
}
/**
Unpins this ObjectContainer.
This method must be called exactly once for every call to {@link #pin}.
*/
public void unpin() {
}
/**
Returns wether this ObjectContainer is pinned.
*/
public boolean isPinned() {
return false;
}
/**
Ensures that the garbageCollectionLevel is at least the given currentGarbageCollectionLevel.
The return value is meaningful if the supplied newGarbageCollectionLevel is the currentGarbageCollectionLevel
@return
<=0 if this object still has to be processed.
This is the case if it belongs to the surelyReachable set but not to the processedReachable set
> otherwise
<0 if this object has been updated
=0 if this object has not been updated, it is surelyReachable
>0 if this object has not been updated, it is processedReachable
*/
public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) {
return 0;
}
/**
Returns the garbageCollectionLevel this ObjectContainer has reached due to (not) calling {@link #ensureGarbageCollectionLevel}.
*/
public int getGarbageCollectionLevel() {
return 0;
}
/**
* True, when bouth OzoneCompatibles have the same ID.
*/
public boolean equals( Object obj ) {
if (obj instanceof ClassicObjectContainer) {
ClassicObjectContainer rhs = (ClassicObjectContainer)obj;
if (objID.equals( rhs.objID )) {
return true;
}
}
return false;
}
/** */
public void finalizeTarget() throws Exception {
//activatedObject().done();
// todo replace the done() uncommented above with whatever is appropriate now
}
/** */
public ObjectID id() {
return objID;
}
/** */
public boolean isCreated() {
return created;
}
/** */
public void deleteTarget() {
deleted = true;
}
/** */
public boolean isDeleted() {
return deleted;
}
/** */
public Object invokeTarget( Env env, String methodName, String sig, Object[] args ) throws Exception {
clusterSpace.touchObject( objID );
Method method = methodFor( methodName, sig, args );
if (method == null) {
throw new MethodNotFoundException( methodName );
}
return method.invoke( activatedObject(), args );
}
/** */
public void touch() {
touched = true;
++touchCount;
touchTime = System.currentTimeMillis();
}
/** */
public String name() {
return name;
}
/** */
public void setName( String _name ) {
nameTarget( _name );
}
/** */
public void nameTarget( String _name ) {
name = _name;
}
/** */
public Permissions permissions() {
return permissions;
}
/**
* Build a copy of the encap object. This is based on serialization,
* so no clone() method must be implemented by OzoneObjects.
*/
public OzoneCompatible targetClone() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream( bout );
out.writeObject( activatedObject() );
out.close();
ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) );
OzoneCompatible result = (OzoneCompatible)in.readObject();
in.close();
return result;
}
/**
*/
public OzoneProxy ozoneProxy() {
try {
String name = objectClass().getName() + PROXYNAME_POSTFIX;
OzoneProxy rObj = (OzoneProxy)env.classManager.classForName( name ).newInstance();
rObj.remoteID = id();
rObj.link = env.database;
return rObj;
} catch (Exception e) {
env.logWriter.newEntry( this, "ozoneProxy(): unable to create proper proxy object.", e, LogWriter.WARN );
return new OzoneProxy( id(), env.database );
}
}
/** */
public int lockLevel( Transaction ta ) {
return lock.level( ta );
}
/**
* @return a collection with holders of writeLocker or all
* readLocks, i.e. all potential hindering transactions
*/
public DxCollection allLockers() {
DxCollection lockerIDs = lock.lockerIDs();
DxArrayBag result = new DxArrayBag( lockerIDs.count() );
DxIterator it = lockerIDs.iterator();
while (it.next() != null) {
result.add( env.transactionManager.taForID( (TransactionID)it.object() ) );
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -