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     */
017    package org.apache.activemq.store.amq;
018    
019    import java.io.File;
020    import org.apache.activemq.kaha.impl.async.AsyncDataManager;
021    import org.apache.activemq.kaha.impl.index.hash.HashIndex;
022    import org.apache.activemq.store.PersistenceAdapter;
023    import org.apache.activemq.store.PersistenceAdapterFactory;
024    import org.apache.activemq.store.ReferenceStoreAdapter;
025    import org.apache.activemq.thread.TaskRunnerFactory;
026    import org.apache.activemq.util.IOHelper;
027    
028    /**
029     * An implementation of {@link PersistenceAdapterFactory}
030     * 
031     * @org.apache.xbean.XBean element="amqPersistenceAdapterFactory"
032     * 
033     * 
034     */
035    public class AMQPersistenceAdapterFactory implements PersistenceAdapterFactory {
036        static final int DEFAULT_MAX_REFERNCE_FILE_LENGTH=2*1024*1024;
037        private File dataDirectory;
038        private int journalThreadPriority = Thread.MAX_PRIORITY;
039        private String brokerName = "localhost";
040        private ReferenceStoreAdapter referenceStoreAdapter;
041        private boolean syncOnWrite;
042        private boolean syncOnTransaction=true;
043        private boolean persistentIndex=true;
044        private boolean useNio = true;
045        private int maxFileLength = AsyncDataManager.DEFAULT_MAX_FILE_LENGTH;
046        private long cleanupInterval = AsyncDataManager.DEFAULT_CLEANUP_INTERVAL;
047        private int indexBinSize = HashIndex.DEFAULT_BIN_SIZE;
048        private int indexKeySize = HashIndex.DEFAULT_KEY_SIZE;
049        private int indexPageSize = HashIndex.DEFAULT_PAGE_SIZE;
050        private int indexMaxBinSize = HashIndex.MAXIMUM_CAPACITY;
051        private int indexLoadFactor = HashIndex.DEFAULT_LOAD_FACTOR;
052        private int maxReferenceFileLength=DEFAULT_MAX_REFERNCE_FILE_LENGTH;
053        private boolean recoverReferenceStore=true;
054        private boolean forceRecoverReferenceStore=false;
055        private long checkpointInterval = 1000 * 20;
056        private boolean useDedicatedTaskRunner;
057        private TaskRunnerFactory taskRunnerFactory;
058    
059    
060        /**
061         * @return a AMQPersistenceAdapter
062         * @see org.apache.activemq.store.PersistenceAdapterFactory#createPersistenceAdapter()
063         */
064        public PersistenceAdapter createPersistenceAdapter() {
065            AMQPersistenceAdapter result = new AMQPersistenceAdapter();
066            result.setDirectory(getDataDirectory());
067            result.setTaskRunnerFactory(getTaskRunnerFactory());
068            result.setBrokerName(getBrokerName());
069            result.setSyncOnWrite(isSyncOnWrite());
070            result.setPersistentIndex(isPersistentIndex());
071            result.setReferenceStoreAdapter(getReferenceStoreAdapter());
072            result.setUseNio(isUseNio());
073            result.setMaxFileLength(getMaxFileLength());
074            result.setCleanupInterval(getCleanupInterval());
075            result.setCheckpointInterval(getCheckpointInterval());
076            result.setIndexBinSize(getIndexBinSize());
077            result.setIndexKeySize(getIndexKeySize());
078            result.setIndexPageSize(getIndexPageSize());
079            result.setIndexMaxBinSize(getIndexMaxBinSize());
080            result.setIndexLoadFactor(getIndexLoadFactor());
081            result.setMaxReferenceFileLength(getMaxReferenceFileLength());
082            result.setForceRecoverReferenceStore(isForceRecoverReferenceStore());
083            result.setRecoverReferenceStore(isRecoverReferenceStore());
084            result.setUseDedicatedTaskRunner(isUseDedicatedTaskRunner());
085            result.setJournalThreadPriority(getJournalThreadPriority());
086            return result;
087        }
088    
089        public long getCleanupInterval() {
090            return cleanupInterval;
091        }
092        
093        public void setCleanupInterval(long val) {
094            cleanupInterval = val;
095        }
096    
097        /**
098         * @return the dataDirectory
099         */
100        public File getDataDirectory() {
101            if (this.dataDirectory == null) {
102                this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName));
103            }
104            return this.dataDirectory;
105        }
106    
107        /**
108         * @param dataDirectory the dataDirectory to set
109         */
110        public void setDataDirectory(File dataDirectory) {
111            this.dataDirectory = dataDirectory;
112        }
113    
114        public boolean isUseDedicatedTaskRunner() {
115            return useDedicatedTaskRunner;
116        }
117        
118        public void setUseDedicatedTaskRunner(boolean useDedicatedTaskRunner) {
119            this.useDedicatedTaskRunner = useDedicatedTaskRunner;
120        }
121        
122        /**
123         * @return the taskRunnerFactory
124         */
125        public TaskRunnerFactory getTaskRunnerFactory() {
126            return taskRunnerFactory;
127        }
128    
129        /**
130         * @param taskRunnerFactory the taskRunnerFactory to set
131         */
132        public void setTaskRunnerFactory(TaskRunnerFactory taskRunnerFactory) {
133            this.taskRunnerFactory = taskRunnerFactory;
134        }
135    
136        /**
137         * @return the journalThreadPriority
138         */
139        public int getJournalThreadPriority() {
140            return this.journalThreadPriority;
141        }
142    
143        /**
144         * @param journalThreadPriority the journalThreadPriority to set
145         */
146        public void setJournalThreadPriority(int journalThreadPriority) {
147            this.journalThreadPriority = journalThreadPriority;
148        }
149    
150        /**
151         * @return the brokerName
152         */
153        public String getBrokerName() {
154            return this.brokerName;
155        }
156    
157        /**
158         * @param brokerName the brokerName to set
159         */
160        public void setBrokerName(String brokerName) {
161            this.brokerName = brokerName;
162        }
163    
164        /**
165         * @return the referenceStoreAdapter
166         */
167        public ReferenceStoreAdapter getReferenceStoreAdapter() {
168            return this.referenceStoreAdapter;
169        }
170    
171        /**
172         * @param referenceStoreAdapter the referenceStoreAdapter to set
173         */
174        public void setReferenceStoreAdapter(ReferenceStoreAdapter referenceStoreAdapter) {
175            this.referenceStoreAdapter = referenceStoreAdapter;
176        }
177        
178        public boolean isPersistentIndex() {
179                    return persistentIndex;
180            }
181    
182            public void setPersistentIndex(boolean persistentIndex) {
183                    this.persistentIndex = persistentIndex;
184            }
185    
186            public boolean isSyncOnWrite() {
187                    return syncOnWrite;
188            }
189    
190            public void setSyncOnWrite(boolean syncOnWrite) {
191                    this.syncOnWrite = syncOnWrite;
192            }
193            
194            public boolean isSyncOnTransaction() {
195            return syncOnTransaction;
196        }
197    
198        public void setSyncOnTransaction(boolean syncOnTransaction) {
199            this.syncOnTransaction = syncOnTransaction;
200        }
201    
202            public boolean isUseNio() {
203                    return useNio;
204            }
205    
206            public void setUseNio(boolean useNio) {
207                    this.useNio = useNio;
208            }
209    
210            public int getMaxFileLength() {
211                    return maxFileLength;
212            }
213    
214            public void setMaxFileLength(int maxFileLength) {
215                    this.maxFileLength = maxFileLength;
216            }
217    
218        /**
219         * @return the indexBinSize
220         */
221        public int getIndexBinSize() {
222            return indexBinSize;
223        }
224    
225        /**
226         * @param indexBinSize the indexBinSize to set
227         */
228        public void setIndexBinSize(int indexBinSize) {
229            this.indexBinSize = indexBinSize;
230        }
231    
232        /**
233         * @return the indexKeySize
234         */
235        public int getIndexKeySize() {
236            return indexKeySize;
237        }
238    
239        /**
240         * @param indexKeySize the indexKeySize to set
241         */
242        public void setIndexKeySize(int indexKeySize) {
243            this.indexKeySize = indexKeySize;
244        }
245    
246        /**
247         * @return the indexPageSize
248         */
249        public int getIndexPageSize() {
250            return indexPageSize;
251        }
252    
253        /**
254         * @param indexPageSize the indexPageSize to set
255         */
256        public void setIndexPageSize(int indexPageSize) {
257            this.indexPageSize = indexPageSize;
258        }
259    
260        /**
261         * @return the indexMaxBinSize
262         */
263        public int getIndexMaxBinSize() {
264            return indexMaxBinSize;
265        }
266    
267        /**
268         * @param indexMaxBinSize the indexMaxBinSize to set
269         */
270        public void setIndexMaxBinSize(int indexMaxBinSize) {
271            this.indexMaxBinSize = indexMaxBinSize;
272        }
273    
274        /**
275         * @return the indexLoadFactor
276         */
277        public int getIndexLoadFactor() {
278            return indexLoadFactor;
279        }
280    
281        /**
282         * @param indexLoadFactor the indexLoadFactor to set
283         */
284        public void setIndexLoadFactor(int indexLoadFactor) {
285            this.indexLoadFactor = indexLoadFactor;
286        }
287    
288        /**
289         * @return the maxReferenceFileLength
290         */
291        public int getMaxReferenceFileLength() {
292            return maxReferenceFileLength;
293        }
294    
295        /**
296         * @param maxReferenceFileLength the maxReferenceFileLength to set
297         */
298        public void setMaxReferenceFileLength(int maxReferenceFileLength) {
299            this.maxReferenceFileLength = maxReferenceFileLength;
300        }
301    
302        /**
303         * @return the recoverReferenceStore
304         */
305        public boolean isRecoverReferenceStore() {
306            return recoverReferenceStore;
307        }
308    
309        /**
310         * @param recoverReferenceStore the recoverReferenceStore to set
311         */
312        public void setRecoverReferenceStore(boolean recoverReferenceStore) {
313            this.recoverReferenceStore = recoverReferenceStore;
314        }
315    
316        /**
317         * @return the forceRecoverReferenceStore
318         */
319        public boolean isForceRecoverReferenceStore() {
320            return forceRecoverReferenceStore;
321        }
322    
323        /**
324         * @param forceRecoverReferenceStore the forceRecoverReferenceStore to set
325         */
326        public void setForceRecoverReferenceStore(boolean forceRecoverReferenceStore) {
327            this.forceRecoverReferenceStore = forceRecoverReferenceStore;
328        }
329    
330        /**
331         * @return the checkpointInterval
332         */
333        public long getCheckpointInterval() {
334            return checkpointInterval;
335        }
336    
337        /**
338         * @param checkpointInterval the checkpointInterval to set
339         */
340        public void setCheckpointInterval(long checkpointInterval) {
341            this.checkpointInterval = checkpointInterval;
342        }
343    }