Search in sources :

Example 1 with CloseHook

use of org.apache.solr.core.CloseHook in project lucene-solr by apache.

the class SearchHandler method inform.

/**
   * Initialize the components based on name.  Note, if using <code>INIT_FIRST_COMPONENTS</code> or <code>INIT_LAST_COMPONENTS</code>,
   * then the {@link DebugComponent} will always occur last.  If this is not desired, then one must explicitly declare all components using
   * the <code>INIT_COMPONENTS</code> syntax.
   */
@Override
@SuppressWarnings("unchecked")
public void inform(SolrCore core) {
    this.core = core;
    Set<String> missing = new HashSet<>();
    List<String> c = (List<String>) initArgs.get(INIT_COMPONENTS);
    missing.addAll(core.getSearchComponents().checkContains(c));
    List<String> first = (List<String>) initArgs.get(INIT_FIRST_COMPONENTS);
    missing.addAll(core.getSearchComponents().checkContains(first));
    List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS);
    missing.addAll(core.getSearchComponents().checkContains(last));
    if (!missing.isEmpty())
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Missing SearchComponents named : " + missing);
    if (c != null && (first != null || last != null))
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "First/Last components only valid if you do not declare 'components'");
    if (shfInfo == null) {
        shardHandlerFactory = core.getCoreContainer().getShardHandlerFactory();
    } else {
        shardHandlerFactory = core.createInitInstance(shfInfo, ShardHandlerFactory.class, null, null);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                shardHandlerFactory.close();
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : CloseHook(org.apache.solr.core.CloseHook) SolrCore(org.apache.solr.core.SolrCore) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SolrException(org.apache.solr.common.SolrException) HashSet(java.util.HashSet)

Example 2 with CloseHook

use of org.apache.solr.core.CloseHook in project lucene-solr by apache.

the class StreamHandler method inform.

public void inform(SolrCore core) {
    /* The stream factory will always contain the zkUrl for the given collection
     * Adds default streams with their corresponding function names. These 
     * defaults can be overridden or added to in the solrConfig in the stream 
     * RequestHandler def. Example config override
     *  <lst name="streamFunctions">
     *    <str name="group">org.apache.solr.client.solrj.io.stream.ReducerStream</str>
     *    <str name="count">org.apache.solr.client.solrj.io.stream.RecordCountStream</str>
     *  </lst>
     * */
    String defaultCollection;
    String defaultZkhost;
    CoreContainer coreContainer = core.getCoreContainer();
    this.coreName = core.getName();
    if (coreContainer.isZooKeeperAware()) {
        defaultCollection = core.getCoreDescriptor().getCollectionName();
        defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
        streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
        streamFactory.withDefaultZkHost(defaultZkhost);
        modelCache = new ModelCache(250, defaultZkhost, clientCache);
    }
    streamFactory.withFunctionName("search", CloudSolrStream.class).withFunctionName("facet", FacetStream.class).withFunctionName("update", UpdateStream.class).withFunctionName("jdbc", JDBCStream.class).withFunctionName("topic", TopicStream.class).withFunctionName("commit", CommitStream.class).withFunctionName("random", RandomStream.class).withFunctionName("knn", KnnStream.class).withFunctionName("merge", MergeStream.class).withFunctionName("unique", UniqueStream.class).withFunctionName("top", RankStream.class).withFunctionName("group", GroupOperation.class).withFunctionName("reduce", ReducerStream.class).withFunctionName("parallel", ParallelStream.class).withFunctionName("rollup", RollupStream.class).withFunctionName("stats", StatsStream.class).withFunctionName("innerJoin", InnerJoinStream.class).withFunctionName("leftOuterJoin", LeftOuterJoinStream.class).withFunctionName("hashJoin", HashJoinStream.class).withFunctionName("outerHashJoin", OuterHashJoinStream.class).withFunctionName("intersect", IntersectStream.class).withFunctionName("complement", ComplementStream.class).withFunctionName(SORT, SortStream.class).withFunctionName("train", TextLogitStream.class).withFunctionName("features", FeaturesSelectionStream.class).withFunctionName("daemon", DaemonStream.class).withFunctionName("shortestPath", ShortestPathStream.class).withFunctionName("gatherNodes", GatherNodesStream.class).withFunctionName("nodes", GatherNodesStream.class).withFunctionName("select", SelectStream.class).withFunctionName("shortestPath", ShortestPathStream.class).withFunctionName("gatherNodes", GatherNodesStream.class).withFunctionName("nodes", GatherNodesStream.class).withFunctionName("scoreNodes", ScoreNodesStream.class).withFunctionName("model", ModelStream.class).withFunctionName("classify", ClassifyStream.class).withFunctionName("fetch", FetchStream.class).withFunctionName("executor", ExecutorStream.class).withFunctionName("null", NullStream.class).withFunctionName("priority", PriorityStream.class).withFunctionName("significantTerms", SignificantTermsStream.class).withFunctionName("cartesianProduct", CartesianProductStream.class).withFunctionName("shuffle", ShuffleStream.class).withFunctionName("calc", CalculatorStream.class).withFunctionName("eval", EvalStream.class).withFunctionName("echo", EchoStream.class).withFunctionName("cell", CellStream.class).withFunctionName("list", ListStream.class).withFunctionName("let", LetStream.class).withFunctionName("get", GetStream.class).withFunctionName("timeseries", TimeSeriesStream.class).withFunctionName("tuple", TupStream.class).withFunctionName("sql", SqlStream.class).withFunctionName("col", ColumnEvaluator.class).withFunctionName("predict", PredictEvaluator.class).withFunctionName("regress", RegressionEvaluator.class).withFunctionName("cov", CovarianceEvaluator.class).withFunctionName("conv", ConvolutionEvaluator.class).withFunctionName("normalize", NormalizeEvaluator.class).withFunctionName("rev", ReverseEvaluator.class).withFunctionName("length", LengthEvaluator.class).withFunctionName("rank", RankEvaluator.class).withFunctionName("scale", ScaleEvaluator.class).withFunctionName("distance", DistanceEvaluator.class).withFunctionName("copyOf", CopyOfEvaluator.class).withFunctionName("copyOfRange", CopyOfRangeEvaluator.class).withFunctionName("percentile", PercentileEvaluator.class).withFunctionName("empiricalDistribution", EmpiricalDistributionEvaluator.class).withFunctionName("describe", DescribeEvaluator.class).withFunctionName("finddelay", FindDelayEvaluator.class).withFunctionName("sequence", SequenceEvaluator.class).withFunctionName("array", ArrayEvaluator.class).withFunctionName("hist", HistogramEvaluator.class).withFunctionName("anova", AnovaEvaluator.class).withFunctionName("movingAvg", MovingAverageEvaluator.class).withFunctionName("min", MinMetric.class).withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class).withFunctionName("sum", SumMetric.class).withFunctionName("count", CountMetric.class).withFunctionName("replace", ReplaceOperation.class).withFunctionName("concat", ConcatOperation.class).withFunctionName("group", GroupOperation.class).withFunctionName("distinct", DistinctOperation.class).withFunctionName("having", HavingStream.class).withFunctionName("val", RawValueEvaluator.class).withFunctionName("and", AndEvaluator.class).withFunctionName("eor", ExclusiveOrEvaluator.class).withFunctionName("eq", EqualsEvaluator.class).withFunctionName("gt", GreaterThanEvaluator.class).withFunctionName("gteq", GreaterThanEqualToEvaluator.class).withFunctionName("lt", LessThanEvaluator.class).withFunctionName("lteq", LessThanEqualToEvaluator.class).withFunctionName("not", NotEvaluator.class).withFunctionName("or", OrEvaluator.class).withFunctionName(TemporalEvaluatorYear.FUNCTION_NAME, TemporalEvaluatorYear.class).withFunctionName(TemporalEvaluatorMonth.FUNCTION_NAME, TemporalEvaluatorMonth.class).withFunctionName(TemporalEvaluatorDay.FUNCTION_NAME, TemporalEvaluatorDay.class).withFunctionName(TemporalEvaluatorDayOfYear.FUNCTION_NAME, TemporalEvaluatorDayOfYear.class).withFunctionName(TemporalEvaluatorHour.FUNCTION_NAME, TemporalEvaluatorHour.class).withFunctionName(TemporalEvaluatorMinute.FUNCTION_NAME, TemporalEvaluatorMinute.class).withFunctionName(TemporalEvaluatorSecond.FUNCTION_NAME, TemporalEvaluatorSecond.class).withFunctionName(TemporalEvaluatorEpoch.FUNCTION_NAME, TemporalEvaluatorEpoch.class).withFunctionName(TemporalEvaluatorWeek.FUNCTION_NAME, TemporalEvaluatorWeek.class).withFunctionName(TemporalEvaluatorQuarter.FUNCTION_NAME, TemporalEvaluatorQuarter.class).withFunctionName(TemporalEvaluatorDayOfQuarter.FUNCTION_NAME, TemporalEvaluatorDayOfQuarter.class).withFunctionName("abs", AbsoluteValueEvaluator.class).withFunctionName("add", AddEvaluator.class).withFunctionName("div", DivideEvaluator.class).withFunctionName("mult", MultiplyEvaluator.class).withFunctionName("sub", SubtractEvaluator.class).withFunctionName("log", NaturalLogEvaluator.class).withFunctionName("pow", PowerEvaluator.class).withFunctionName("mod", ModuloEvaluator.class).withFunctionName("ceil", CeilingEvaluator.class).withFunctionName("floor", FloorEvaluator.class).withFunctionName("sin", SineEvaluator.class).withFunctionName("asin", ArcSineEvaluator.class).withFunctionName("sinh", HyperbolicSineEvaluator.class).withFunctionName("cos", CosineEvaluator.class).withFunctionName("acos", ArcCosineEvaluator.class).withFunctionName("cosh", HyperbolicCosineEvaluator.class).withFunctionName("tan", TangentEvaluator.class).withFunctionName("atan", ArcTangentEvaluator.class).withFunctionName("tanh", HyperbolicTangentEvaluator.class).withFunctionName("round", RoundEvaluator.class).withFunctionName("sqrt", SquareRootEvaluator.class).withFunctionName("cbrt", CubedRootEvaluator.class).withFunctionName("coalesce", CoalesceEvaluator.class).withFunctionName("uuid", UuidEvaluator.class).withFunctionName("corr", CorrelationEvaluator.class).withFunctionName("if", IfThenElseEvaluator.class).withFunctionName("analyze", AnalyzeEvaluator.class).withFunctionName("convert", ConversionEvaluator.class);
    // This pulls all the overrides and additions from the config
    List<PluginInfo> pluginInfos = core.getSolrConfig().getPluginInfos(Expressible.class.getName());
    for (PluginInfo pluginInfo : pluginInfos) {
        Class<? extends Expressible> clazz = core.getMemClassLoader().findClass(pluginInfo.className, Expressible.class);
        streamFactory.withFunctionName(pluginInfo.name, clazz);
    }
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void postClose(SolrCore core) {
            clientCache.close();
        }
    });
}
Also used : GatherNodesStream(org.apache.solr.client.solrj.io.graph.GatherNodesStream) CoreContainer(org.apache.solr.core.CoreContainer) PluginInfo(org.apache.solr.core.PluginInfo) CloseHook(org.apache.solr.core.CloseHook) ShortestPathStream(org.apache.solr.client.solrj.io.graph.ShortestPathStream) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) SolrCore(org.apache.solr.core.SolrCore) ModelCache(org.apache.solr.client.solrj.io.ModelCache) ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) GroupOperation(org.apache.solr.client.solrj.io.ops.GroupOperation) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric)

Example 3 with CloseHook

use of org.apache.solr.core.CloseHook in project lucene-solr by apache.

the class ReplicationHandler method registerCloseHook.

/**
   * register a closehook
   */
private void registerCloseHook() {
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
            // we don't wait for shutdown - this can deadlock core reload
            if (executorService != null)
                executorService.shutdown();
        }

        @Override
        public void postClose(SolrCore core) {
            if (pollingIndexFetcher != null) {
                pollingIndexFetcher.destroy();
            }
            if (currentIndexFetcher != null && currentIndexFetcher != pollingIndexFetcher) {
                currentIndexFetcher.destroy();
            }
        }
    });
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
            ExecutorUtil.shutdownAndAwaitTermination(restoreExecutor);
            if (restoreFuture != null) {
                restoreFuture.cancel(false);
            }
        }

        @Override
        public void postClose(SolrCore core) {
        }
    });
}
Also used : CloseHook(org.apache.solr.core.CloseHook) SolrCore(org.apache.solr.core.SolrCore)

Example 4 with CloseHook

use of org.apache.solr.core.CloseHook in project lucene-solr by apache.

the class ZkController method registerConfListenerForCore.

/**
   * This will give a callback to the listener whenever a child is modified in the
   * conf directory. It is the responsibility of the listener to check if the individual
   * item of interest has been modified.  When the last core which was interested in
   * this conf directory is gone the listeners will be removed automatically.
   */
public void registerConfListenerForCore(final String confDir, SolrCore core, final Runnable listener) {
    if (listener == null) {
        throw new NullPointerException("listener cannot be null");
    }
    synchronized (confDirectoryListeners) {
        final Set<Runnable> confDirListeners = getConfDirListeners(confDir);
        confDirListeners.add(listener);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                unregisterConfListener(confDir, listener);
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : CloseHook(org.apache.solr.core.CloseHook) SolrCore(org.apache.solr.core.SolrCore)

Example 5 with CloseHook

use of org.apache.solr.core.CloseHook in project lucene-solr by apache.

the class SolrSuggester method init.

/**
   * Uses the <code>config</code> and the <code>core</code> to initialize the underlying 
   * Lucene suggester
   * */
public String init(NamedList<?> config, SolrCore core) {
    LOG.info("init: " + config);
    // read the config
    name = config.get(NAME) != null ? (String) config.get(NAME) : DEFAULT_DICT_NAME;
    sourceLocation = (String) config.get(LOCATION);
    lookupImpl = (String) config.get(LOOKUP_IMPL);
    dictionaryImpl = (String) config.get(DICTIONARY_IMPL);
    String store = (String) config.get(STORE_DIR);
    if (lookupImpl == null) {
        lookupImpl = LookupFactory.DEFAULT_FILE_BASED_DICT;
        LOG.info("No " + LOOKUP_IMPL + " parameter was provided falling back to " + lookupImpl);
    }
    contextFilterQueryAnalyzer = new TokenizerChain(new StandardTokenizerFactory(Collections.EMPTY_MAP), null);
    // initialize appropriate lookup instance
    factory = core.getResourceLoader().newInstance(lookupImpl, LookupFactory.class);
    lookup = factory.create(config, core);
    if (lookup != null && lookup instanceof Closeable) {
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                try {
                    ((Closeable) lookup).close();
                } catch (IOException e) {
                    LOG.warn("Could not close the suggester lookup.", e);
                }
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
    // if store directory is provided make it or load up the lookup with its content
    if (store != null && !store.isEmpty()) {
        storeDir = new File(store);
        if (!storeDir.isAbsolute()) {
            storeDir = new File(core.getDataDir() + File.separator + storeDir);
        }
        if (!storeDir.exists()) {
            storeDir.mkdirs();
        } else if (getStoreFile().exists()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("attempt reload of the stored lookup from file " + getStoreFile());
            }
            try {
                lookup.load(new FileInputStream(getStoreFile()));
            } catch (IOException e) {
                LOG.warn("Loading stored lookup data failed, possibly not cached yet");
            }
        }
    }
    // dictionary configuration
    if (dictionaryImpl == null) {
        dictionaryImpl = (sourceLocation == null) ? DictionaryFactory.DEFAULT_INDEX_BASED_DICT : DictionaryFactory.DEFAULT_FILE_BASED_DICT;
        LOG.info("No " + DICTIONARY_IMPL + " parameter was provided falling back to " + dictionaryImpl);
    }
    dictionaryFactory = core.getResourceLoader().newInstance(dictionaryImpl, DictionaryFactory.class);
    dictionaryFactory.setParams(config);
    LOG.info("Dictionary loaded with params: " + config);
    return name;
}
Also used : CloseHook(org.apache.solr.core.CloseHook) TokenizerChain(org.apache.solr.analysis.TokenizerChain) SolrCore(org.apache.solr.core.SolrCore) Closeable(java.io.Closeable) StandardTokenizerFactory(org.apache.lucene.analysis.standard.StandardTokenizerFactory) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

CloseHook (org.apache.solr.core.CloseHook)9 SolrCore (org.apache.solr.core.SolrCore)9 Closeable (java.io.Closeable)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 SolrException (org.apache.solr.common.SolrException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Properties (java.util.Properties)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 SolrInformationServer (org.alfresco.solr.SolrInformationServer)1 SolrKeyResourceLoader (org.alfresco.solr.SolrKeyResourceLoader)1 SOLRAPIClient (org.alfresco.solr.client.SOLRAPIClient)1 SOLRAPIClientFactory (org.alfresco.solr.client.SOLRAPIClientFactory)1