bundlefspersistencemanager.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 680 行 · 第 1/2 页

JAVA
680
字号
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.core.persistence.bundle;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.jackrabbit.core.fs.FileSystem;import org.apache.jackrabbit.core.fs.BasedFileSystem;import org.apache.jackrabbit.core.fs.local.LocalFileSystem;import org.apache.jackrabbit.core.persistence.PMContext;import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;import org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding;import org.apache.jackrabbit.core.persistence.bundle.util.TrackingInputStream;import org.apache.jackrabbit.core.persistence.util.Serializer;import org.apache.jackrabbit.core.persistence.util.BLOBStore;import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;import org.apache.jackrabbit.core.NodeId;import org.apache.jackrabbit.core.PropertyId;import org.apache.jackrabbit.core.state.ItemStateException;import org.apache.jackrabbit.core.state.NodeReferencesId;import org.apache.jackrabbit.core.state.NoSuchItemStateException;import org.apache.jackrabbit.core.state.NodeReferences;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.sql.SQLException;/** * This is a generic persistence manager that stores the {@link NodePropBundle}s * in a filesystem. * <p/> * Configuration:<br> * <ul> * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/> * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/> * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/> * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/> * <li>&lt;param name="{@link #setItemFSBlockSize(String) blobFSBlockSize}" value="0"/> * <li>&lt;param name="{@link #setItemFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/> * <li>&lt;param name="{@link #setItemFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/> * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="4096"/> * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/> * </ul> */public class BundleFsPersistenceManager extends AbstractBundlePersistenceManager {    /** the cvs/svn id */    static final String CVS_ID = "$URL: http://svn.apache.org/repos/asf/jackrabbit/tags/1.3.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java $ $Rev: 517150 $ $Date: 2007-03-12 11:42:12 +0200 (Mon, 12 Mar 2007) $";    /** the default logger */    private static Logger log = LoggerFactory.getLogger(BundleFsPersistenceManager.class);    /** flag indicating if this manager was initialized */    protected boolean initialized = false;    /** initial size of buffer used to serialize objects */    protected static final int INITIAL_BUFFER_SIZE = 1024;    /** file system where BLOB data is stored */    protected BundleFsPersistenceManager.CloseableBLOBStore blobStore;    /**     * Default blocksize for BLOB filesystem:     * @see #setBlobFSBlockSize(String)     */    private int blobFSBlockSize = 0;    /**     * Default initial cache size for BLOB filesystem: 100, req. 25KB     * @see #setBlobFSInitialCacheSize(String)     */    private int blobFSInitialCache = 100;    /**     * Default max cache size for BLOB filesystem: 4000, req. 1000KB     * @see #setBlobFSMaximumCacheSize(String)     */    private int blobFSMaximumCache = 4000;    /**     * Default blocksize for item filesystem:     * @see #setItemFSBlockSize(String)     */    private int itemFSBlockSize = 0;    /**     * Default initial cache size for item filesystem: 100, req. 25KB     * @see #setItemFSInitialCacheSize(String)     */    private int itemFSInitialCache = 100;    /**     * Default max cache size for item filesystem: 4000, req. 1000KB     * @see #setItemFSMaximumCacheSize(String)     */    private int itemFSMaximumCache = 4000;    /**     * the minimum size of a property until it gets written to the blob store     * @see #setMinBlobSize(String)     */    private int minBlobSize = 0x1000;    /**     * the filesystem where the items are stored     */    private FileSystem itemFs;    /**     * flag for error handling     */    protected ErrorHandling errorHandling = new ErrorHandling();    /**     * the bundle binding     */    protected BundleBinding binding;    /**     * the name of this persistence manager     */    private String name = super.toString();    /**     * Returns the configured block size of the blob cqfs     * @return the block size.     */    public String getBlobFSBlockSize() {        return String.valueOf(blobFSBlockSize);    }    /**     * Sets the block size of the blob fs and controlls how blobs are handled.     * <br>     * If the size is > 0, it must be a power of 2 and is used as blocksize     * for the cqfs. blobs are then stored within that cqfs. A call to     * {@link #useCqFsBlobStore()} will return <code>true</code>.     * <br>     * If the size is 0, the cqfs is not used at all, and the blobs are stored     * within the workspace's physical filesystem. A call to     * {@link #useLocalFsBlobStore()} will return <code>true</code>.     * <br>     * If the size is &lt; 0, the cqfs is not used at all, and the blobls are     * stored within the item filesystem. A call to     * {@link #useItemBlobStore()} will return <code>true</code>.     * <br>     * Please note that not all binary properties are considered as blobs. They     * are only stored in the respective blob store, if their size exceeds     * {@link #getMinBlobSize()}.     *     * @param size the block size     */    public void setBlobFSBlockSize(String size) {        this.blobFSBlockSize = Integer.decode(size).intValue();    }    /**     * Returns <code>true</code> if the blobs are stored in the DB.     * @return <code>true</code> if the blobs are stored in the DB.     */    public boolean useItemBlobStore() {        return blobFSBlockSize < 0;    }    /**     * Returns <code>true</code> if the blobs are stored in the local fs.     * @return <code>true</code> if the blobs are stored in the local fs.     */    public boolean useLocalFsBlobStore() {        return blobFSBlockSize == 0;    }    /**     * Returns <code>true</code> if the blobs are stored in the cqfs.     * @return <code>true</code> if the blobs are stored in the cqfs.     */    public boolean useCqFsBlobStore() {        return blobFSBlockSize > 0;    }    /**     * Returns the configured inital cache size of the blobfs.     * @return the configured inital cache size of the blobfs.     */    public String getBlobFSInitialCacheSize() {        return String.valueOf(blobFSInitialCache);    }    /**     * Sets the initial cache size of the blob fs. This only applies to cqfs     * base blobstores, i.e. if {@link #useCqFsBlobStore()} returns     * <code>true</code>.     * @param size the initial size     */    public void setBlobFSInitialCacheSize(String size) {        this.blobFSInitialCache = Integer.decode(size).intValue();    }    /**     * Returns the configured maximal size of the blobfs.     * @return the configured maximal size of the blobfs.     */    public String getBlobFSMaximumCacheSize() {        return String.valueOf(blobFSMaximumCache);    }    /**     * Sets the maximal cache size of the blob fs. This only applies to cqfs     * base blobstores, i.e. if {@link #useCqFsBlobStore()} returns     * <code>true</code>.     * @param size the maximal size     */    public void setBlobFSMaximumCacheSize(String size) {        this.blobFSMaximumCache = Integer.decode(size).intValue();    }    /**     * Returns the configured block size of the item cqfs     * @return the block size.     */    public String getItemFSBlockSize() {        return String.valueOf(itemFSBlockSize);    }    /**     * Sets the block size of the item fs.     * <br>     * If the size is > 0, it must be a power of 2 and is used as blocksize     * for the cqfs. items are then stored within that cqfs.     * <br>     * If the size is 0, the cqfs is not used at all, and the items are stored     * within the workspace's physical filesystem.     *     * @param size the block size     */    public void setItemFSBlockSize(String size) {        this.itemFSBlockSize = Integer.decode(size).intValue();    }    /**     * Returns the configured inital cache size of the itemfs.     * @return the configured inital cache size of the itemfs.     */    public String getItemFSInitialCacheSize() {        return String.valueOf(itemFSInitialCache);    }    /**     * Sets the initial cache size of the item fs. This only applies to cqfs     * based item stores.     *     * @param size the initial size     */    public void setItemFSInitialCacheSize(String size) {        this.itemFSInitialCache = Integer.decode(size).intValue();    }    /**     * Returns the configured maximal size of the itemfs.     * @return the configured maximal size of the itemfs.     */    public String getItemFSMaximumCacheSize() {        return String.valueOf(itemFSMaximumCache);    }    /**     * Sets the maximal cache size of the item fs. This only applies to cqfs     * base item storea.     * @param size the maximal size     */    public void setItemFSMaximumCacheSize(String size) {        this.itemFSMaximumCache = Integer.decode(size).intValue();    }    /**     * Returns the miminum blob size.     * @return the miminum blob size.     */    public int getMinBlobSize() {        return minBlobSize;    }    /**     * Sets the minumum blob size. This size defines the threshhold of which     * size a property is included in the bundle or is stored in the blob store.     *     * @param minBlobSize     */    public void setMinBlobSize(String minBlobSize) {        this.minBlobSize = Integer.decode(minBlobSize).intValue();    }    /**     * Sets the error handling behaviour of this manager. See {@link ErrorHandling}     * for details about the flags.     *     * @param errorHandling     */    public void setErrorHandling(String errorHandling) {        this.errorHandling = new ErrorHandling(errorHandling);    }    /**     * Returns the error handling configuration of this manager     * @return the error handling configuration of this manager     */    public String getErrorHandling() {        return errorHandling.toString();    }    /**     * {@inheritDoc}     */    public void init(PMContext context) throws Exception {        if (initialized) {            throw new IllegalStateException("already initialized");        }        super.init(context);

⌨️ 快捷键说明

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