📄 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-2000 by SMB GmbH. All rights reserved.//// $Id: ClassicObjectContainer.java,v 1.9 2000/10/28 16:55:17 daniela Exp $package org.ozoneDB.core.classicStore;import java.io.*;import java.util.*;import java.lang.reflect.*;import org.ozoneDB.*;import org.ozoneDB.tools.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.core.*;import org.ozoneDB.util.*;/** */public final class ClassicObjectContainer extends DxObject implements ObjectContainer, 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.store).objectSpace.clusterSpace; target = _target; objID = _objID; permissions = _permissions; lock = new DefaultLock(); created = true; deleted = false; target.setContainer( this ); } // #### methods from ObjectContainer ###################################### /** * True, wenn beide auf ein OzoneCompatible mit gleicher ID verweisen. */ 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(); } /** */ 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 MethodNotFoundExc( 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 ObjectInputStream( 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() ); } } /** */ public int lockLevel( Transaction ta ) { return lock.level( ta ); } /** * Gibt collection mit entweder dem writeLocker oder allen * readLockern, d.h. alle potentiell behindernden transaktionen */ 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; } /** */ public synchronized void notifyAllTAs( Transaction ta ) { env.logWriter.newEntry( this, ta.toString() + " notify all TAs...", LogWriter.DEBUG3 ); lock.notifyAll(); } // #### methods from ClassicObjectContainer ############################### /** */ public OzoneCompatible targetShadow() { return targetShadow; } /** * Liefert referenz auf das eigentliche objekt. darf nicht * targetShadow beruecksichtigen, da ClusterSPace darauf aufbaut. */ public OzoneCompatible target() { return target; } /** * Setzen oder loeschen des objektes. commit() ist unteilbar, deshalb * kein snchronized. * Achtung: object ist evtl. gerade geclustert und muss vorher * eingelagert werden; das darf nicht hier gemacht werden, da * diese methode auch vom store benutzt wird. */ protected OzoneCompatible setObject( OzoneCompatible obj ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -