⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cachemanager.java

📁 iiitAccessServer是一个用Java编写的基于规则的企业鉴别系统。它作为一个服务器工作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. *  * This program 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 General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * version $Id: CacheManager.java,v 1.26 2003/04/14 20:39:56 joerg Exp $ ******************************************************************************/package de.iiit.access.server.plugins.cachemanager;import de.iiit.access.server.*;import de.iiit.access.server.api.*;import de.iiit.access.server.util.*;import de.iiit.xmlconfig.*;import de.iiit.ldap.*;import de.iiit.jdbc.*;import java.io.*;import java.nio.channels.*;import java.util.*;import java.util.regex.*;import javax.naming.*;import org.apache.log4j.Logger;/** The CacheManager manages the 2<sup>nd</sup>-level cache stored in databases. * To do this, it reads and parses the OpenLDAP server's replication log file. * If a fatal error occurs, the whole AccessServer will be aborted by a call to * System.exit(). */public class CacheManager implements ThreadPluginIf{    /** CVS Version Tag */    private static final String vcid = "$Id: CacheManager.java,v 1.26 2003/04/14 20:39:56 joerg Exp $";        private static final String REPLICATION_FILE   = "ReplicationFile";    private static final String REFRESH_INTERVAL   = "RefreshInterval";        private static final String MD5PATTERN_LENGTH  = "Md5PatternLength";    private static final String SMTP_SERVER        = "SMTPServer";    private static final String SMTP_PORT          = "SMTPPort";    private static final String SMTP_USER          = "SMTPUser";    private static final String SMTP_PASSWORD      = "SMTPPassword";    private static final String SMTP_MAIL_TO       = "SMTPMailTo";        private static final String JDBC_DRIVER        = "ClassName";    private static final String JDBC_URL           = "Url";    private static final String JDBC_USERNAME      = "UserName";    private static final String JDBC_PASSWORD      = "Password";    private static final String JDBC_CONNECTIONS   = "Connections";        private static final String JDBC_DRIVER_CONFIG = "JdbcDriver";        private static final String ADMIN_DATABASE_CONFIG = "AdminDatabase";    private static final String CACHE_DATABASE_CONFIG = "CacheDatabase";    private String replicationFile  = null;    private int    refreshIntervall = 10000;        private String smtpServer       = null;    private int    smtpPort         = -1;    private String smtpUser         = null;    private String smtpPassword     = null;    private String smtpMailTo       = null;    private CacheToDoHandler         toDoHandler  = null;    private CacheManagerErrorHandler errorHandler = null;        private Configuration config                = null;    private Configuration adminDbConfig         = null;    private Vector        cacheDbConfigVector   = null;    private Vector        jdbcConfigVector      = null;    private JdbcConnectionPool adminPool = null;    private Vector cachePools = new Vector();    private Hashtable md5PatternIndex = new Hashtable();    private int md5PatternLength = 0;    private Set userList = null;        private Logger logger = Logger.getLogger(this.getClass());    private LdapUtil ldapUtil = null;        private static final char[] hexadecimal =             {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',              'a', 'b', 'c', 'd', 'e', 'f'};                 /** Creates a new instance of CacheDatabaseManager */    public CacheManager()    {    }        /** Initializes the CacheManagerPlugin     * @param config the configuration of the cache manager     */        public void initialize(Configuration config)    {        boolean cfgError = false;        Configuration ldapConfig = null;                this.config = config;                if (config == null)        {            logger.fatal("No CacheManagerPlugin configuration found");            cfgError = true;        }        else            ldapConfig = config.getSubConfiguration("LdapConfig");                if (ldapConfig == null)            ldapConfig = AccessServer.getSubConfiguration("LdapConfig");                if (ldapConfig == null)        {            logger.fatal("The CacheManagerPlugin can not work without a LDAP configuration");            cfgError = true;        }        else        {            ldapUtil = new LdapUtil();            ldapUtil.initialize(ldapConfig);        }                        Vector v = config.getSubConfigurations(ADMIN_DATABASE_CONFIG);         if (v != null)            adminDbConfig = (Configuration) v.get(0);        else        {            logger.fatal("No configuration for admin db found");            cfgError = true;        }                cacheDbConfigVector = config.getSubConfigurations(CACHE_DATABASE_CONFIG);                if (cacheDbConfigVector == null)        {            logger.fatal("No configuration for cache db found");            cfgError = true;        }                replicationFile  = config.getAttribute(REPLICATION_FILE);            refreshIntervall = Integer.parseInt(config.getAttribute(REFRESH_INTERVAL, "10")) * 1000;        md5PatternLength = Integer.parseInt(config.getAttribute(MD5PATTERN_LENGTH, "0"));                smtpServer       = config.getAttribute(SMTP_SERVER);        smtpPort         = Integer.parseInt(config.getAttribute(SMTP_PORT, "-1"));        smtpUser         = config.getAttribute(SMTP_USER);        smtpPassword     = config.getAttribute(SMTP_PASSWORD);        smtpMailTo       = config.getAttribute(SMTP_MAIL_TO);        if (smtpServer == null || smtpMailTo == null)        {            logger.warn("No SMTP configuration found");        }                if ((replicationFile == null) || (replicationFile.equals("")))        {            logger.fatal("No LDAP replication file configured");            cfgError = true;        }                jdbcConfigVector = config.getSubConfigurations(JDBC_DRIVER_CONFIG);        if (jdbcConfigVector == null)        {            logger.fatal("No JDBC configuration found");              cfgError = true;        }                if (cfgError)            System.exit(1);        try        {            JdbcUtil.registerJdbcDriver(jdbcConfigVector);        }        catch(Exception e)        {            logger.fatal("Error while registering JDBC driver", e);              System.exit(1);        }            initializeAdminDb();        initializeCacheDb();    }    /** Starts the CacheManager's background threads.     * This method is called by the AccessServer after the initialization of all sub-moduls.     */        public void start()    {                       errorHandler = new CacheManagerErrorHandler(this);        toDoHandler = new CacheToDoHandler(this);        toDoHandler.start();    }    /** This method is called by the AccessServer when the background threads should     * stop because of a shutdown of the AccessServer itself.     */    public void shutdown()    {        if (toDoHandler != null)            toDoHandler.shutdown();    }        private void initializeAdminDb()    {        String jdbcUrl         = adminDbConfig.getAttribute(JDBC_URL);        String jdbcUsername    = adminDbConfig.getAttribute(JDBC_USERNAME);        String jdbcPassword    = adminDbConfig.getAttribute(JDBC_PASSWORD);        int    jdbcConnections = adminDbConfig.getIntAttribute(JDBC_CONNECTIONS);                    adminPool = new JdbcConnectionPool(jdbcUrl, jdbcUsername, jdbcPassword, jdbcConnections);    }        private void initializeCacheDb()    {        JdbcConnectionPool pool = null;                int pattern = 1 << md5PatternLength;                int iMax = cacheDbConfigVector.size();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -