Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2011 Alexey Ragozin
*
* Licensed 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.gridkit.coherence.search;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.gridkit.coherence.search.IndexUpdateEvent.Type;
import com.tangosol.io.Serializer;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
import com.tangosol.net.BackingMapContext;
import com.tangosol.net.NamedCache;
import com.tangosol.util.Binary;
import com.tangosol.util.BinaryEntry;
import com.tangosol.util.ExternalizableHelper;
import com.tangosol.util.Filter;
import com.tangosol.util.MapIndex;
import com.tangosol.util.SimpleMapIndex;
import com.tangosol.util.ValueExtractor;
import com.tangosol.util.extractor.IndexAwareExtractor;
import com.tangosol.util.filter.IndexAwareFilter;
/**
* Central class in Coherence-Search API. It is used as a factory to
* produce query filters and index extractors.
*
* @author Alexey Ragozin ([email protected])
*
* @param index instance type (see {@link PlugableSearchIndex})
* @param index config type (see {@link PlugableSearchIndex})
* @param query type (see {@link PlugableSearchIndex})
*/
@SuppressWarnings("rawtypes")
public class SearchFactory {
protected PlugableSearchIndex indexPlugin;
protected IC indexConfig;
protected ValueExtractor extractor;
protected IndexEngineConfig engineConfig = new DefaultIndexEngineConfig();
protected Object token;
/**
* @param plugin search index plugin
* @param config config for this instance of index
* @param extractor extractor to extract indexed attribute from object
*/
public SearchFactory(PlugableSearchIndex plugin, IC config, ValueExtractor extractor) {
this.indexPlugin = plugin;
this.indexConfig = config;
this.extractor = extractor;
this.token = plugin.createIndexCompatibilityToken(indexConfig);
}
/**
* @return mutable {@link IndexEngineConfig} which can be used to tune options
*/
public IndexEngineConfig getEngineConfig() {
return engineConfig;
}
/**
* Creates index for provided {@link NamedCache}
* @param cache
*/
public void createIndex(NamedCache cache) {
SearchIndexExtractor extractor = createConfiguredExtractor();
cache.addIndex(extractor, false, null);
}
protected SearchIndexExtractor createConfiguredExtractor() {
return new SearchIndexExtractor(indexPlugin, token, indexConfig, engineConfig, extractor);
}
protected SearchIndexExtractor createFilterExtractor() {
return new SearchIndexExtractor(indexPlugin, token, extractor);
}
/**
* Create query based filter. An index should be created using {@link #createIndex(NamedCache)} before using of such filter.
* @param query search query, specific to plugin
* @return Coherence filter
*/
public Filter createFilter(Q query) {
return new QueryFilter(createFilterExtractor(), query);
}
public static interface SearchIndexWrapper extends MapIndex, IndexInvocationContext {
public R callCoreIndex(SearchIndexCallable callable);
}
public static interface SearchIndexCallable {
public R execute(I index);
}
static class SearchIndexEngine implements MapIndex, IndexInvocationContext, SearchIndexWrapper {
private static Timer INDEX_TIMER = new Timer("IndexFlushTimer", true);
private PlugableSearchIndex psi;
private ValueExtractor attributeExtrator;
private I coreIndex;
private MapIndex attributeIndex;
private TimerTask flushTask;
private Map