📄 env.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: Env.java,v 1.13.2.2 2003/12/21 16:01:23 per_nyfelt Exp $package org.ozoneDB.core;import java.io.*;import java.lang.reflect.Constructor;import java.util.StringTokenizer;import org.ozoneDB.Database;import org.ozoneDB.DxLib.*;import org.ozoneDB.Setup;import org.ozoneDB.core.admin.AdminManager;import org.ozoneDB.core.dr.DeadlockRecognition;import org.ozoneDB.core.dr.EdgeChasing;import org.ozoneDB.OzoneInterface;import org.ozoneDB.util.*;/** * Env is the environment of a ozone database server. Currently there * is only one environment allowed per JVM. A server environment can be * initialized by the a Server or by a LocalDatabase. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @author <a href="http://www.medium.net/">Medium.net</a> * @author Per Nyfelt * @version $Revision: 1.13.2.2 $Date: 2003/12/21 16:01:23 $ */public final class Env { /** Wether ozone should do selfChecks at different code locations. If set to true, diagnostic messages are printed out in case something unusual or bad has been detected. If set to false, ozone will run at full speed. This is a kind of "poor man"s assertion facility as long as ozone should be compileable by javac older than from JDK1.4 TODO now that we require 1.4 this can be upgraded to use asserts instead */ public final static boolean selfCheck = true; // constant members *********************************** public final static String VERSION = "@version@"; public final static String OS_DIR = "ostab"; public final static String STATE_FILE = "state.properties"; public final static String CONFIG_FILE = "config.properties"; public final static String DATA_DIR = "data" + File.separator; public final static String STATS_DIR = "stats"; /** * AdminPort and InvokeServer accepts and admin requests */ public final static int ACCEPT_THREAD_PRIORITY = Thread.NORM_PRIORITY + 2; /** * Thread priority of normal transaction. */ public final static int TRANSACTION_THREAD_PRIORITY = Thread.NORM_PRIORITY; public final static int TRANSACTION_MUTEX_PRIORITY = TRANSACTION_THREAD_PRIORITY + 1; /** * Thread priority deadlock recognition. */ public final static int DEADLOCK_THREAD_PRIORITY = Thread.NORM_PRIORITY; /** * Priority of the server thread (Server.main()) */ public final static int SERVER_THREAD_PRIORITY = Thread.NORM_PRIORITY + 2; // class members ************************************** /** * The one and only ozone environment of this VM. */ public static Env theEnv; protected static OzoneSecurityManager securityManager; // instance members *********************************** protected File databaseDir; /** * Holds the content of the 'state.properties' file. After * changing the content the state must be written to disk to make * changes persistent. */ public Setup state; /** * Holds the content of the 'config.properties' config file. */ public Setup config; public LogWriter logWriter; /** * This indicates that we are about to shutdown. */ public boolean shuttingdown = false; /* * The total memory of this VM. */ protected long totalMemory; /* * The amount of memory that should be kept free. */ protected long keepMemory; /** * Interface for the database objects inside the server. */ public Database database; private DxBag components; public KeyGenerator keyGenerator; public AdminManager adminManager; public ClassManager classManager; public TransactionManager transactionManager; public StoreManager storeManager; public UserManager userManager; protected LocalClientTracker localClientTracker; protected GarbageCollector garbageCollector; protected InvokeServer invokeServer; protected DeadlockThread deadlockThread; protected DeadlockRecognition dr; // class methods ************************************** /** * Returns the environment of the current thread. Useful for objects that * do not store the enviroment itself like ObjectContainer. * * * @return The environment of the current thread or null if called outside * the server. */ public static Env currentEnv() { return theEnv; } // instance methods *********************************** /** * Construct a new ozone server environment. * * * @param dirName Directory of the database. * @param debugLevel the debug level that should be used, * overriding the entry in config.properties. If null then the * config.properties entry will be used. */ public Env(String dirName, String debugLevel) throws Exception { if (theEnv != null) { throw new Exception("ozone environment (Env) already initialized for this VM"); } try { // give the engine its environment first but don't forget to // reset it if we catch an exception theEnv = this; //dir = new String( dirName ) + File.separator; databaseDir = new File(dirName + File.separator); if (!databaseDir.isDirectory()) { throw new Exception("No database found at '" + databaseDir + "'."); } checkJavaVersion(); initSetup(); initLogs(debugLevel); getLogWriter().newEntry(this, "Ozone version @version@", LogWriter.INFO); getLogWriter().newEntry(this, "Copyright (C) 1997-@year@ The Ozone Database Project", LogWriter.INFO); getLogWriter().newEntry(this, "contains libraries from the Apache Software Foundation", LogWriter.INFO); getLogWriter().newEntry(this, "contains libraries from SUN microsystems", LogWriter.INFO); getLogWriter().newEntry(this, "contains libraries from the W3C", LogWriter.INFO); getLogWriter().newEntry(this, "contains libraries from Exoffice, Inc.", LogWriter.INFO); getLogWriter().newEntry(this, "contains libraries (JavaClass) from Markus Dahm ", LogWriter.INFO); getLogWriter().newEntry(this, "Copyright (C) under owner's respective terms.", LogWriter.INFO); if (System.getSecurityManager() == null) { securityManager = new OzoneSecurityManager(); System.setSecurityManager(securityManager); } calcMemory(); components = new DxArrayBag(16); localClientTracker = new LocalClientTracker(); garbageCollector = new GarbageCollector(this); components.add(garbageCollector); garbageCollector.startup(); keyGenerator = new KeyGenerator(this); components.add(keyGenerator); keyGenerator.startup(); database = new Database(this); classManager = new ClassManager(this); components.add(classManager); classManager.startup(); // UserManager has to be initialized before the recovery userManager = new UserManager(this); components.add(userManager); userManager.startup(); transactionManager = new TransactionManager(this); components.add(transactionManager); transactionManager.startup(); // initialize the storeManager String storeClassName = config.stringProperty(Setup.STORE, "org.ozoneDB.core.storage.wizardStore.WizardStore"); // todo: uncommented until verified when this should be removed // We should not use Class.forName since it breaks hot deployment of classes //Class storeClass = Class.forName(storeClassName); Class storeClass = classManager.classForName(storeClassName); if (storeClass == null) { getLogWriter().newEntry(this, "Store not found: " + storeClassName, LogWriter.ERROR); System.exit(1); } Constructor ctor = storeClass.getConstructor(new Class[]{Env.class}); storeManager = (StoreManager) ctor.newInstance(new Object[]{this}); storeManager.init(this); components.add(storeManager); storeManager.startup(); // initialize adminManager adminManager = new AdminManager(this); components.add(adminManager); adminManager.startup(); } catch (Exception e) { theEnv = null; if (logWriter != null) { logWriter.newEntry(this, "Unable to initialize server.", e, LogWriter.ERROR); } else { System.out.println("Unable to initialize server."); e.printStackTrace(); } throw e; } } /** Makes sure the server is running at the required minimum version level */ private void checkJavaVersion() throws Exception { String javaVersion = System.getProperty("java.version"); StringTokenizer tokenizer = new StringTokenizer(javaVersion, "."); int majorVersion = 0; if (tokenizer.hasMoreTokens()) { majorVersion = Integer.parseInt(tokenizer.nextToken()); } int minorVersion = 0; if (tokenizer.hasMoreTokens()) { minorVersion = Integer.parseInt(tokenizer.nextToken()); } if (majorVersion == 1 && minorVersion < 4) { throw new Exception("Java version 1.4 or higher is required to run the server"); } } public void shutdown() { shuttingdown = true; try { logWriter.newEntry(this, "shutdown...", LogWriter.INFO); // if (storageFrame != null) { // storageFrame.dispose(); // storageFrame = null; // logWriter.newEntry (this, "ozonometer closed.", LogWriter.INFO); // } if (invokeServer != null) { invokeServer.shutdown(); invokeServer = null; } if (deadlockThread != null) { //TODO: find another way to do this, stop() is deprecated deadlockThread.stopRunning(); deadlockThread = null; logWriter.newEntry(this, "Deadlock recognition stopped.", LogWriter.INFO); } transactionManager.shutdown();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -