📄 objectspace.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: ObjectSpace.java,v 1.10 2000/10/28 16:55:17 daniela Exp $package org.ozoneDB.core.classicStore;import java.io.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.*;import org.ozoneDB.core.*;import org.ozoneDB.util.*;/** */public final class ObjectSpace extends Object { /** */ final static long serialVersionUID = 2; final static byte subSerialVersionUID = 1; /** The environment of this object. */ protected transient Env env; protected transient ClusterSpace clusterSpace; /** */ protected DxMap objectTable; protected DxMap nameTable; /** */ public ObjectSpace( Env _env ) { env = _env; clusterSpace = new ClusterSpace( _env ); } /** */ public void startup() throws Exception { env.logWriter.newEntry( this, "startup...", LogWriter.INFO ); int tableBuffSize = env.config.intProperty( Setup.CS_TABLE_BUFF_SIZE, -1 ); if (tableBuffSize == -1) { env.logWriter.newEntry( this, "Property " + Setup.CS_TABLE_BUFF_SIZE + " is not set.", LogWriter.WARN ); tableBuffSize = 20; } //objectTable = new DxDiskHashMap (env.dir + Env.OS_DIR + File.separator + "idtable", tableBuffSize / 256, 12); objectTable = new DxHashMap( 1000 ); nameTable = new DxHashMap( 10 ); clusterSpace.startup(); } /** */ public void shutdown() throws Exception { env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO ); clusterSpace.shutdown(); //objectTable.printCacheStatistics(); if (objectTable instanceof DxDiskHashMap) { ((DxDiskHashMap)objectTable).cleanFiles(); } } /** */ public synchronized void addObject( ObjectContainer container ) throws Exception { //use a copy of the objID because objectTable is a diskHash objectTable.addForKey( container, container.id().clone() ); if (container.name() != null) { nameTable.addForKey( container, new String( container.name() ) ); } } /** * Creates a new object container for the given target with the given oid * and an optional name. */ public synchronized ObjectContainer newContainer( Transaction ta, OzoneCompatible target, ObjectID objID, Permissions permissions ) throws ClassicStoreExc { ClassicObjectContainer container = new ClassicObjectContainer( target, objID, permissions ); if (!objectTable.addForKey( container, objID.clone() )) { throw new ClassicStoreExc( "ObjectID " + objID + " already exists !" ); } return container; } /** * @param id The object id to search for. * @return The object container with the given id or null. */ public ObjectContainer objectForID( ObjectID id ) { return (ObjectContainer)objectTable.elementForKey( id ); } /** * Applies a name to an object. * @param container The container to name. * @param name The new name of the container. */ public void nameObject( ObjectContainer container, String name ) throws ClassicStoreExc { if (container.name() != null) { nameTable.removeForKey( container.name() ); } if (name != null) { if (!nameTable.addForKey( container, new String( name ) )) { throw new ClassicStoreExc( "Name '" + name + "' already exists !" ); } container.nameTarget( name ); } } /** * @param name * @return The object container with the given name. */ public ObjectContainer objectForName( String name ) { return (ObjectContainer)nameTable.elementForKey( name ); } /** * entfernt ObjectContainer fuer entsprechende ObjectID; */ public synchronized void deleteObject( ObjectContainer toRemove ) { synchronized (toRemove) { objectTable.removeForKey( toRemove.id() ); if (toRemove.name() != null) { nameTable.removeForKey( toRemove.name() ); } } } /** */ public synchronized void prepareCommitObjects( Transaction ta ) throws Exception { env.logWriter.newEntry( this, "prepareCommitObjects: transaction " + ta.taID(), LogWriter.DEBUG3 ); //at first we have to insert new objects + containers into the object //space, so that we have access to them while further commiting DxListBag created = new DxListBag(); DxListBag modified = new DxListBag(); DxIterator it = ta.idTable.iterator(); ClassicObjectContainer container; while ((container = (ClassicObjectContainer)it.next()) != null) { if (container.isCreated()) { addObject( container ); created.add( container ); } else { if (container.lockLevel( ta ) > Lock.LEVEL_READ) { modified.add( container.id() ); } } } //make all changes persistent clusterSpace.prepareCommit( ta.taID(), created, modified ); // remove all deleted objects from the object space _after_ commiting // them; otherwise we wouldn't have access to them while commiting // commit all written objects _after_ we know everthing worked fine; // if not, the transaction has to abort it = ta.idTable.iterator(); while ((container = (ClassicObjectContainer)it.next()) != null) { if (container.isDeleted()) { deleteObject( container ); } else { container.commitTarget( ta ); } } } /** */ public synchronized void commitObjects( Transaction ta ) { clusterSpace.commitTransaction( ta.taID() ); } /** */ public synchronized void abortObjects( Transaction ta ) throws Exception { DxIterator it = ta.idTable.iterator(); ClassicObjectContainer container; while ((container = (ClassicObjectContainer)it.next()) != null) { container.abortTarget( ta ); } clusterSpace.abortTransaction( ta.taID() ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -