📄 env.java
字号:
} } /** * Save the setup (state and config) of the current server environment. */ protected void storeSetup() throws Exception { OutputStream stateOut = new BufferedOutputStream( new FileOutputStream( new File( dir, STATE_FILE ) ), 4 * 1024 ); OutputStream configOut = new BufferedOutputStream( new FileOutputStream( new File( dir, CONFIG_FILE ) ), 4096 ); try { // save state state.save( stateOut, "Ozone Server State File.\n#Do not edit!" ); // save config StringBuffer head = new StringBuffer( 1024 ); head.append( "Ozone Server Config File.\n" ); head.append( "#\n" ); head.append( "# Do not use comments. This file will be overwritten,\n" ); head.append( "# if the config changes. See the ozone documentation\n" ); head.append( "# for details about the properties and their values.\n" ); config.save( configOut, head.toString() ); } finally { stateOut.close(); configOut.close(); } } /** * Env is an Observer that observes its Setup object to write changes to * disk. */ public void update( Observable observable, Object obj ) { logWriter.newEntry( this, "update()", LogWriter.DEBUG ); try { if (obj == state) { logWriter.newEntry( this, " state has changed...", LogWriter.DEBUG ); storeSetup(); } else if (obj == config) { logWriter.newEntry( this, " config has changed...", LogWriter.DEBUG ); storeSetup(); } else { throw new RuntimeException( "Don't know specified Observable object." ); } } catch (Exception e) { logWriter.newEntry( this, "update(): ", e, LogWriter.WARN ); throw new RuntimeException( e.toString() ); } } /** * Initialize server logging. If the server runs standalone, there are two * LogTarget: stdout and file. Which log messages are written to which target * is specified in the config file. If the server runs in debug mode, debug * messages are written to each target. */ protected void initLogs( boolean _local, int _debugLevel ) throws Exception { DxCollection stdoutList = config.stringsProperty( Setup.STDOUT_LOG, "" ); DxCollection fileList = config.stringsProperty( Setup.FILE_LOG, "" ); int stdoutFlags = 0; for (DxIterator it = stdoutList.iterator(); it.next() != null;) { String entry = (String)it.object(); if (entry.equals( "WARN" )) { stdoutFlags |= LogWriter.WARN; } if (entry.equals( "ERROR" )) { stdoutFlags |= LogWriter.ERROR; } if (entry.equals( "INFO" )) { stdoutFlags |= LogWriter.INFO; } if (entry.equals( "DEBUG" )) { stdoutFlags |= LogWriter.DEBUG; } if (entry.equals( "DEBUG2" )) { stdoutFlags |= LogWriter.DEBUG2; } if (entry.equals( "DEBUG3" )) { stdoutFlags |= LogWriter.DEBUG3; } // stdoutFlags = stdoutFlags | LogWriter.DEBUG | LogWriter.DEBUG2 | LogWriter.DEBUG3; } int fileFlags = 0; for (DxIterator it = fileList.iterator(); it.next() != null;) { String entry = (String)it.object(); if (entry.equals( "WARN" )) { fileFlags |= LogWriter.WARN; } if (entry.equals( "ERROR" )) { fileFlags |= LogWriter.ERROR; } if (entry.equals( "INFO" )) { fileFlags |= LogWriter.INFO; } if (entry.equals( "DEBUG" )) { fileFlags |= LogWriter.DEBUG; } if (entry.equals( "DEBUG2" )) { fileFlags |= LogWriter.DEBUG2; } if (entry.equals( "DEBUG3" )) { fileFlags |= LogWriter.DEBUG3; } } if (_local) { logWriter.addLogTarget( new FileOutputStream( dir + LOG_FILE ), fileFlags | _debugLevel ); } else { logWriter.addLogTarget( new FileOutputStream( dir + LOG_FILE ), fileFlags | _debugLevel ); logWriter.addLogTarget( System.out, stdoutFlags | _debugLevel ); } } 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 (adminPort != null) { adminPort.shutdown(); adminPort = null; } if (deadlockThread != null) { deadlockThread.stop(); deadlockThread = null; logWriter.newEntry( this, "Deadlock recognition stopped.", LogWriter.INFO ); } transactionManager.shutdown(); transactionManager = null; store.shutdown(); store = null; userManager.shutdown(); userManager = null; classManager.shutdown(); classManager = null; storeSetup(); logWriter.newEntry( this, "Bye.", LogWriter.INFO ); theEnv = null; } catch (Exception e) { fatalError( null, "Env.shutdown(): " + e.toString(), e ); } } /** * gibt fehlermeldung aus und beendet die VM */ public void fatalError( Object sender, String msg, Exception e ) { logWriter.newEntry( sender, msg, e, LogWriter.ERROR ); // FIXME: shutdown??? System.exit( 1 ); } public int dbID() { return config.intProperty( Setup.DB_ID, -1 ); } public int portNum() { return config.intProperty( Setup.PORT, -1 ); } public int adminPortNum() { return config.intProperty( Setup.ADMIN_PORT, -1 ); } /** * Factory method to create or re-use a DR object. */ public DeadlockRecognition deadlockRecognition() { if (dr == null) { dr = new EdgeChasing( this ); } return dr; } public long nextID() { return nextID( 1 ); } public synchronized long nextID( long range ) { if (idCount + range >= idBorder) { try { idCount = state.longProperty( Setup.XOID, -1 ); if (idCount == -1) { throw new Exception( "Unable to create new ID number." ); } idBorder = idCount + range + idRange; state.setLongProperty( Setup.XOID, idBorder ); state.notifyObservers(); } catch (Exception e) { fatalError( null, "nextID(): " + e.toString(), e ); } } long result = ++idCount; idCount += range; return result; } /** * Initialize the internal memory counter so that freeMemory() returns * correct results. */ protected void calcMemory() { logWriter.newEntry( this, "checking memory... ", LogWriter.INFO ); Runtime rt = Runtime.getRuntime(); try { DxBag bag = new DxArrayBag(); for (;;) { bag.add( new byte[100000] ); } } catch (OutOfMemoryError e) { totalMemory = rt.totalMemory(); rt.gc(); } logWriter.newEntry( this, " total: " + totalMemory, LogWriter.INFO ); logWriter.newEntry( this, " free : " + rt.freeMemory(), LogWriter.INFO ); } /** * Return the amount of *total* free memory in the system. The results * returned by Runtime.freeMemory() may change overtime and so its * useless for ozone. */ public long freeMemory() { Runtime rt = Runtime.getRuntime(); long hiddenMemory = totalMemory - rt.totalMemory(); // keep xMB free at least return Math.max( rt.freeMemory() + hiddenMemory - 4000000L, 0 ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -