001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.leveldb;
018
019import org.apache.activemq.store.PersistenceAdapter;
020import org.apache.activemq.store.PersistenceAdapterFactory;
021
022import java.io.File;
023import java.io.IOException;
024
025/**
026 * A factory which can create configured LevelDBStore objects.
027 */
028public class LevelDBStoreFactory implements PersistenceAdapterFactory {
029
030    private int asyncBufferSize = 1024*1024*4;
031    private File directory = new File("LevelDB");
032    private int flushDelay = 1000*5;
033    private int indexBlockRestartInterval = 16;
034    private int indexBlockSize = 4 * 1024;
035    private long indexCacheSize = 1024 * 1024 * 256L;
036    private String indexCompression = "snappy";
037    private String indexFactory = "org.fusesource.leveldbjni.JniDBFactory, org.iq80.leveldb.impl.Iq80DBFactory";
038    private int indexMaxOpenFiles = 1000;
039    private int indexWriteBufferSize = 1024*1024*6;
040    private String logCompression = "none";
041    private File logDirectory;
042    private long logSize = 1024 * 1024 * 100;
043    private boolean monitorStats;
044    private boolean paranoidChecks;
045    private boolean sync = true;
046    private boolean verifyChecksums;
047
048
049    @Override
050    public PersistenceAdapter createPersistenceAdapter() throws IOException {
051        LevelDBStore store = new LevelDBStore();
052        store.setVerifyChecksums(verifyChecksums);
053        store.setAsyncBufferSize(asyncBufferSize);
054        store.setDirectory(directory);
055        store.setFlushDelay(flushDelay);
056        store.setIndexBlockRestartInterval(indexBlockRestartInterval);
057        store.setIndexBlockSize(indexBlockSize);
058        store.setIndexCacheSize(indexCacheSize);
059        store.setIndexCompression(indexCompression);
060        store.setIndexFactory(indexFactory);
061        store.setIndexMaxOpenFiles(indexMaxOpenFiles);
062        store.setIndexWriteBufferSize(indexWriteBufferSize);
063        store.setLogCompression(logCompression);
064        store.setLogDirectory(logDirectory);
065        store.setLogSize(logSize);
066        store.setMonitorStats(monitorStats);
067        store.setParanoidChecks(paranoidChecks);
068        store.setSync(sync);
069        return store;
070    }
071
072    public int getAsyncBufferSize() {
073        return asyncBufferSize;
074    }
075
076    public void setAsyncBufferSize(int asyncBufferSize) {
077        this.asyncBufferSize = asyncBufferSize;
078    }
079
080    public File getDirectory() {
081        return directory;
082    }
083
084    public void setDirectory(File directory) {
085        this.directory = directory;
086    }
087
088    public int getFlushDelay() {
089        return flushDelay;
090    }
091
092    public void setFlushDelay(int flushDelay) {
093        this.flushDelay = flushDelay;
094    }
095
096    public int getIndexBlockRestartInterval() {
097        return indexBlockRestartInterval;
098    }
099
100    public void setIndexBlockRestartInterval(int indexBlockRestartInterval) {
101        this.indexBlockRestartInterval = indexBlockRestartInterval;
102    }
103
104    public int getIndexBlockSize() {
105        return indexBlockSize;
106    }
107
108    public void setIndexBlockSize(int indexBlockSize) {
109        this.indexBlockSize = indexBlockSize;
110    }
111
112    public long getIndexCacheSize() {
113        return indexCacheSize;
114    }
115
116    public void setIndexCacheSize(long indexCacheSize) {
117        this.indexCacheSize = indexCacheSize;
118    }
119
120    public String getIndexCompression() {
121        return indexCompression;
122    }
123
124    public void setIndexCompression(String indexCompression) {
125        this.indexCompression = indexCompression;
126    }
127
128    public String getIndexFactory() {
129        return indexFactory;
130    }
131
132    public void setIndexFactory(String indexFactory) {
133        this.indexFactory = indexFactory;
134    }
135
136    public int getIndexMaxOpenFiles() {
137        return indexMaxOpenFiles;
138    }
139
140    public void setIndexMaxOpenFiles(int indexMaxOpenFiles) {
141        this.indexMaxOpenFiles = indexMaxOpenFiles;
142    }
143
144    public int getIndexWriteBufferSize() {
145        return indexWriteBufferSize;
146    }
147
148    public void setIndexWriteBufferSize(int indexWriteBufferSize) {
149        this.indexWriteBufferSize = indexWriteBufferSize;
150    }
151
152    public String getLogCompression() {
153        return logCompression;
154    }
155
156    public void setLogCompression(String logCompression) {
157        this.logCompression = logCompression;
158    }
159
160    public File getLogDirectory() {
161        return logDirectory;
162    }
163
164    public void setLogDirectory(File logDirectory) {
165        this.logDirectory = logDirectory;
166    }
167
168    public long getLogSize() {
169        return logSize;
170    }
171
172    public void setLogSize(long logSize) {
173        this.logSize = logSize;
174    }
175
176    public boolean isMonitorStats() {
177        return monitorStats;
178    }
179
180    public void setMonitorStats(boolean monitorStats) {
181        this.monitorStats = monitorStats;
182    }
183
184    public boolean isParanoidChecks() {
185        return paranoidChecks;
186    }
187
188    public void setParanoidChecks(boolean paranoidChecks) {
189        this.paranoidChecks = paranoidChecks;
190    }
191
192    public boolean isSync() {
193        return sync;
194    }
195
196    public void setSync(boolean sync) {
197        this.sync = sync;
198    }
199
200    public boolean isVerifyChecksums() {
201        return verifyChecksums;
202    }
203
204    public void setVerifyChecksums(boolean verifyChecksums) {
205        this.verifyChecksums = verifyChecksums;
206    }
207
208}