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

📄 jembeanhelper.java

📁 这是个爬虫和lucece相结合最好了
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * environment is not open.     * @param attribute name/value pair     */    public void setAttribute(Environment targetEnv,                             Attribute attribute)         throws AttributeNotFoundException,               InvalidAttributeValueException {        if (attribute == null) {            throw new AttributeNotFoundException("Attribute cannot be null");        }        /* Sanity check parameters. */        String name = attribute.getName();        Object value = attribute.getValue();	if (name == null) {	    throw new AttributeNotFoundException(                                     "Attribute name cannot be null");	}	if (value == null) {	    throw new InvalidAttributeValueException(                                      "Attribute value for attribute " +                                      name + " cannot be null");	}        try {            if (name.equals(ATT_SET_READ_ONLY)) {                openConfig.setReadOnly(((Boolean) value).booleanValue());            } else if (name.equals(ATT_SET_TRANSACTIONAL)) {                openConfig.setTransactional(((Boolean) value).booleanValue());            } else if (name.equals(ATT_SET_SERIALIZABLE)) {                openConfig.setTxnSerializableIsolation(                                             ((Boolean) value).booleanValue());            } else {                /* Set the specified attribute if the environment is open. */                if (targetEnv != null) {                    EnvironmentMutableConfig config =                        targetEnv.getMutableConfig();                    if (name.equals(ATT_CACHE_SIZE)) {                        config.setCacheSize(((Long) value).longValue());                        targetEnv.setMutableConfig(config);                    } else if (name.equals(ATT_CACHE_PERCENT)) {                        config.setCachePercent(((Integer) value).intValue());                        targetEnv.setMutableConfig(config);                    } else {                        throw new AttributeNotFoundException("attribute " +                                                             name +                                                             " is not valid.");                    }                } else {                    throw new AttributeNotFoundException("attribute " +                                                         name +                                                         " is not valid.");                }            }        } catch (NumberFormatException e) {            throw new InvalidAttributeValueException("attribute name=" + name);        } catch (DatabaseException e) {            throw new InvalidAttributeValueException("attribute name=" + name +                                                     e.getMessage());        }    }    /********************************************************************/    /* JE Operations                                                    */    /********************************************************************/    /**     * Get mbean operation metadata for this environment.     *     * @param targetEnv The target JE environment. May be null if the     * environment is not open.     * @return List of MBeanOperationInfo describing available operations.     */    public List<MBeanOperationInfo> getOperationList(Environment targetEnv) {        setNeedReset(false);        List<MBeanOperationInfo> operationList = new ArrayList<MBeanOperationInfo>();        if (targetEnv != null) {            /*              * These operations are only available if the environment is             * open.             */            operationList.add(OP_CLEAN_INFO);            operationList.add(OP_EVICT_INFO);            operationList.add(OP_ENV_STAT_INFO);            operationList.add(OP_ENV_STAT_STR_INFO);            operationList.add(OP_LOCK_STAT_INFO);            operationList.add(OP_LOCK_STAT_STR_INFO);            operationList.add(OP_DB_NAMES_INFO);            operationList.add(OP_DB_STAT_INFO);            /* Add checkpoint only for transactional environments. */            boolean isTransactional = false;            try {                EnvironmentConfig config = targetEnv.getConfig();                isTransactional = config.getTransactional();            } catch (DatabaseException e) {                /* Don't make any operations available. */                return new ArrayList<MBeanOperationInfo>();            }                        if (isTransactional) {                operationList.add(OP_CHECKPOINT_INFO);                operationList.add(OP_TXN_STAT_INFO);            } else {                operationList.add(OP_SYNC_INFO);            }        }        return operationList;    }    /**     * Invoke an operation for the given environment.     *      * @param targetEnv The target JE environment. May be null if the     * environment is not open.     * @param actionName operation name.     * @param params operation parameters. May be null.     * @param signature operation signature. May be null.     * @return the operation result     */    public Object invoke(Environment targetEnv,                         String actionName,                         Object [] params,                         String [] signature)         throws MBeanException {        /* Sanity checking. */        if (actionName == null) {            throw new IllegalArgumentException("actionName cannot be null");        }        try {            if (targetEnv != null) {                if (actionName.equals(OP_CLEAN)) {                    int numFiles = targetEnv.cleanLog();                    return new Integer(numFiles);                } else if (actionName.equals(OP_EVICT)) {                    targetEnv.evictMemory();                    return null;                } else if (actionName.equals(OP_CHECKPOINT)) {                    CheckpointConfig config = new CheckpointConfig();                    if ((params != null) && (params.length > 0)) {                        Boolean force = (Boolean) params[0];                        config.setForce(force.booleanValue());                    }                    targetEnv.checkpoint(config);                    return null;                } else if (actionName.equals(OP_SYNC)) {                    targetEnv.sync();                    return null;                } else if (actionName.equals(OP_ENV_STAT)) {                    return targetEnv.getStats(getStatsConfig(params));                } else if (actionName.equals(OP_ENV_STAT_STR)) {                    return targetEnv.getStats(getStatsConfig(params)).toString();                } else if (actionName.equals(OP_LOCK_STAT)) {                    return targetEnv.getLockStats(getStatsConfig(params));                } else if (actionName.equals(OP_LOCK_STAT_STR)) {                    return targetEnv.getLockStats(getStatsConfig(params)).toString();                } else if (actionName.equals(OP_TXN_STAT)) {                    return targetEnv.getTransactionStats(                                                       getStatsConfig(params));                } else if (actionName.equals(OP_DB_NAMES)) {                    return targetEnv.getDatabaseNames();                } else if (actionName.equals(OP_DB_STAT)) {                    return getDatabaseStats(targetEnv, params);                }            }             return new IllegalArgumentException("actionName: " +                                                actionName +                                                " is not valid");        } catch (DatabaseException e) {            /*              * Add both the message and the exception for easiest             * deciphering of the problem. Sometimes the original exception             * stacktrace gets hidden in server logs.             */            throw new MBeanException(e, e.getMessage());        }    }    /**     * Helper for creating a StatsConfig object to use as an operation      * parameter.     */    private StatsConfig getStatsConfig(Object [] params) {        StatsConfig statsConfig = new StatsConfig();        if ((params != null) && (params.length > 0) && (params[0] != null)) {            Boolean clear = (Boolean) params[0];            statsConfig.setClear(clear.booleanValue());        }        if ((params != null) && (params.length > 1) && (params[1] != null)) {            Boolean fast = (Boolean) params[1];            statsConfig.setFast(fast.booleanValue());        }        return statsConfig;    }    /**     * Helper to get statistics for a given database.     * @param params operation parameters     * @return DatabaseStats object     */    private DatabaseStats getDatabaseStats(Environment targetEnv,                                           Object [] params)        throws IllegalArgumentException,	       DatabaseException {        if ((params == null) || (params.length < 3)) {            return null;        }        String dbName = (String)params[2];        Database db = null;        try {            DatabaseConfig dbConfig = new DatabaseConfig();            dbConfig.setReadOnly(true);            DbInternal.setUseExistingConfig(dbConfig, true);            db = targetEnv.openDatabase(null, dbName, dbConfig);            return db.getStats(getStatsConfig(params));        } finally {            if (db != null) {                db.close();            }        }    }    /********************************************************************/    /* JE Notifications.    /********************************************************************/    /**     * No notifications are supported.     * @return List of MBeanNotificationInfo for available notifications.     */    public MBeanNotificationInfo []        getNotificationInfo(Environment targetEnv) {        return null;    }    /********************************************************************/    /* private helpers.    /********************************************************************/    private synchronized void setNeedReset(boolean reset) {        needReset = reset;    }    private synchronized void resetIfOpenStateChanged(boolean isOpen) {        if (isOpen != envWasOpen) {            setNeedReset(true);            envWasOpen = isOpen;        }    }}

⌨️ 快捷键说明

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