cacheConfig.xml中读取配置文件信息二2010-07-07

    /** 获取本实例.
     * @return CacheConfigReader cache配置文件读取实例
     */
    public static CacheConfigReader getInstance()
    {
        // 从classpath中读取配置文件
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        URL url = loader.getResource("cacheConfig.xml");
        File configFile = new File(url.getFile());
        // 实例为null或者配置文件被修改则重新读取配置文件
        if ((null == sInstance) || (sLastModified != configFile.lastModified()))
        {
            sInstance = new CacheConfigReader(url.getFile());

            // 设置最终修改时间
            sLastModified = configFile.lastModified();
        }
        return sInstance;
    }

    /** 取得Cassandra集群服务器.
     */
    public String[] getCassandraClient()
    {
        if (null != sServerList)
        {
            return sServerList.clone();
        }
        return null;
    }

    /** 取得默认Keyspace.
     */
    public String getDefaultKeyspace()
    {
        return sDefaultKeyspace;
    }

    /** 取得默认ColumnFamily.
     */
    public String getDefaultColumnFamily()
    {
        return sDefaultColumnFamily;
    }

    /** 根据属性名从绑定中取得属性值.
     */
    public String getPropertyFromBinding(String aPropertyName)
    {
        return (String) sDataBindingMap.get(aPropertyName);
    }

    /** 解析缓存服务器列表.
     */
    private String[] readServerList(XPath aXpath, Document aDoc)
        throws XPathExpressionException
    {
        XPathExpression pathExpression = aXpath.compile("//servers/list/value");

        NodeList servers = (NodeList) pathExpression.evaluate(aDoc,
                XPathConstants.NODESET);

        String[] serverList = new String[servers.getLength()];

        for (int i = 0; i < servers.getLength(); i++)
        {
            serverList[i] = servers.item(i).getTextContent();
        }
        return serverList;
    }

你可能感兴趣的:(thread,xml,cache,cassandra)