01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.needle.coherence;
18:
19: import com.tangosol.net.CacheFactory;
20: import com.tangosol.net.NamedCache;
21: import org.apache.lucene.store.Directory;
22: import org.compass.core.CompassException;
23: import org.compass.core.config.CompassConfigurable;
24: import org.compass.core.config.CompassEnvironment;
25: import org.compass.core.config.CompassSettings;
26: import org.compass.core.engine.SearchEngineException;
27: import org.compass.core.lucene.engine.store.AbstractDirectoryStore;
28: import org.compass.core.lucene.engine.store.CopyFromHolder;
29:
30: /**
31: * @author kimchy
32: */
33: public abstract class AbstractCoherenceDirectoryStore extends
34: AbstractDirectoryStore implements CompassConfigurable {
35:
36: public static final String BUCKET_SIZE_PROP = "compass.engine.store.coherence.bucketSize";
37:
38: private String indexName;
39:
40: private NamedCache cache;
41:
42: private int bucketSize;
43:
44: public void configure(CompassSettings settings)
45: throws CompassException {
46: String connection = findConnection(settings
47: .getSetting(CompassEnvironment.CONNECTION));
48: int index = connection.indexOf(':');
49: this .indexName = connection.substring(0, index);
50: String cacheName = connection.substring(index + 1);
51:
52: bucketSize = settings.getSettingAsInt(BUCKET_SIZE_PROP,
53: DataGridCoherenceDirectory.DEFAULT_BUCKET_SIZE);
54: cache = CacheFactory.getCache(cacheName);
55: }
56:
57: protected abstract String findConnection(String connection);
58:
59: protected String getIndexName() {
60: return indexName;
61: }
62:
63: protected NamedCache getCache() {
64: return cache;
65: }
66:
67: protected int getBucketSize() {
68: return bucketSize;
69: }
70:
71: public void deleteIndex(Directory dir, String subContext,
72: String subIndex) throws SearchEngineException {
73: cleanIndex(dir, subContext, subIndex);
74: }
75:
76: public void cleanIndex(Directory dir, String subContext,
77: String subIndex) throws SearchEngineException {
78: ((CoherenceDirectory) dir).deleteContent();
79: }
80:
81: public CopyFromHolder beforeCopyFrom(String subContext,
82: String subIndex, Directory dir)
83: throws SearchEngineException {
84: ((CoherenceDirectory) dir).deleteContent();
85: return new CopyFromHolder();
86: }
87:
88: public void close() {
89: // TODO Do we release here or destroy here?
90: cache.release();
91: }
92: }
|