📄 sesameserver.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.server;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Properties;import org.openrdf.util.io.IOUtil;import org.openrdf.util.log.ThreadLog;import org.openrdf.sesame.config.SystemConfig;import org.openrdf.sesame.config.SystemConfigCenterListener;import org.openrdf.sesame.repository.RepositoryList;import org.openrdf.sesame.repository.local.LocalService;/** * Static object that represents a locally running Sesame server. * * @author Jeen Broekstra * @version $Revision: 1.20 $ */public class SesameServer {/*-------------+| Variables |+-------------*/ private static LocalService _localService; // Default: no users, no repositories private static SystemConfig _sysConfig = new SystemConfig(); /** The base dir to resolve any relative paths against. **/ private static File _baseDir = null; /** The version of this code base. **/ private static String _version = null; /** * Sails that have already been instantiated and initialized, * mapped using the repository ID. **/ private static Map _sharedSails = new HashMap(); private static List _listeners = new ArrayList();/*-------------+| Methods |+-------------*/ /** * Creates a LocalService object with the supplied SystemConfig. This * LocalService can subsequently be shared across the JVM, to allow * different services and protocol handlers to access the local * repositories. */ public static void createLocalService() { _localService = new LocalService(_sysConfig); } /** * Retrieves a LocalService object that can be used to access local * repositories automatically */ public static LocalService getLocalService() { return _localService; } /** * Gets the current system configuration of the system. **/ public static SystemConfig getSystemConfig() { return _sysConfig; } /** * Sets a new system configuration for the system. * Loads a new configuration and refreshes Sesame. * @param newConfig the new SystemConfig */ public static void setSystemConfig(SystemConfig newConfig) { // Check if something changed in the RMI-related parameters boolean oldEnabled = false; String oldFac = null; int oldPort = -1; if (_sysConfig != null) { oldEnabled = _sysConfig.isRMIEnabled(); oldFac = _sysConfig.getRMIFactoryClass(); oldPort = _sysConfig.getRMIPort(); } boolean newEnabled = newConfig.isRMIEnabled(); String newFac = newConfig.getRMIFactoryClass(); int newPort = newConfig.getRMIPort(); if (oldEnabled != newEnabled || (oldFac == null) != (newFac == null) || // one is null, the other isn't oldFac != null && !oldFac.equals(newFac) || oldPort != newPort) { // something changed in the RMI settings // unbind any old RMI server if (oldEnabled) { _unbindRMIServer(oldFac, oldPort); } // bind the new RMI server if (newEnabled) { _bindRMIServer(newFac, newPort); } } // Unset all old system properties Properties oldSystemProps = _sysConfig.getSystemProps(); Iterator keys = oldSystemProps.keySet().iterator(); while (keys.hasNext()) { String key = (String)keys.next(); System.setProperty(key, ""); } // Set all new system properties Properties newSystemProps = newConfig.getSystemProps(); keys = newSystemProps.keySet().iterator(); while (keys.hasNext()) { String key = (String)keys.next(); String value = newSystemProps.getProperty(key); System.setProperty(key, value); } _sysConfig = newConfig; if (_localService == null) { createLocalService(); } else { _localService.setSystemConfig(newConfig); } _notifyListeners(); } /** * Sets the base dir against which to resolve relative paths. **/ public static void setBaseDir(File baseDir) { _baseDir = baseDir; } /** * Gets the base dir against which to resolve relative paths (null if not set). **/ public static File getBaseDir() { return _baseDir; } /** * Sets the default log file for all threads that have not registered * themselves with ThreadLog. **/ public static void setDefaultLogFile(String fileName) { if (_sysConfig.getLogDir() == null || fileName == null) { // logDir not yet initialized or no filename, log to System.err ThreadLog.setDefaultLog(null, ThreadLog.WARNING); } else { File logDir = new File(_baseDir, _sysConfig.getLogDir()); String logFile = new File(logDir, fileName).getPath(); int logLevel = _sysConfig.getLogLevel(); ThreadLog.setDefaultLog(logFile, logLevel); } } /** * Unsets the default log file. **/ public static void unsetDefaultLogFile() { ThreadLog.unsetDefaultLog(); } /** * Sets the log file for the thread calling this method. All * logging calls to ThreadLog will be logged in this file. **/ public static void setThreadLogFile(String fileName) { if (_sysConfig.getLogDir() == null || fileName == null) { // logDir not yet initialized or no filename, log to System.err ThreadLog.registerThread(null, ThreadLog.ALL); } else { File logDir = new File(_baseDir, _sysConfig.getLogDir()); String logFile = new File(logDir, fileName).getPath(); int logLevel = _sysConfig.getLogLevel(); ThreadLog.registerThread(logFile, logLevel); } } /** * Sets the log file for the thread calling this method. All * logging calls to ThreadLog will be logged in this file. The * calling thread is supposed to do stuff with the indicated * <tt>repositoryID</tt>. **/ public static void setThreadLogFileForRepository(String repositoryID) { RepositoryList list = _localService.getRepositoryList(); if (list.getRepository(repositoryID) != null) { // only set if the specified repository is known. if not, the thread will still log // in the default log file. setThreadLogFile("repositories/" + repositoryID + ".log"); } } /** * Unsets the log file for the thread calling this method. **/ public static void unsetThreadLogFile() { ThreadLog.deregisterThread(); } /** * Gets the version of this code base. * * @return A version String, e.g. "1.0". **/ public static String getVersion() { if (_version == null) { InputStream in = SesameServer.class.getClassLoader().getResourceAsStream("VERSION"); if (in == null) { _version = "[VERSION FILE MISSING]"; } else { try { _version = new String(IOUtil.readFully(in)).trim(); in.close(); } catch (IOException e) { ThreadLog.error("Unable to read version from file", e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -