/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.apache.stanbol.enhancer.chain.weighted.impl; import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getState; import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.parseConfig; import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.calculateExecutionPlan; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.apache.clerezza.commons.rdf.ImmutableGraph; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; import org.apache.stanbol.enhancer.servicesapi.Chain; import org.apache.stanbol.enhancer.servicesapi.ChainException; import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine; import org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils; import org.apache.stanbol.enhancer.servicesapi.impl.AbstractChain; import org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker; import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.component.ComponentContext; import org.osgi.util.tracker.ServiceTrackerCustomizer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This Chain implementation takes a list of engines names as input * and uses the "org.apache.stanbol.enhancer.engine.order " metadata provided by * such engines to calculate the ExecutionGraph.
* * Similar the current WeightedJobManager implementation Engines would be * dependent to each other based on decreasing order values. Engines with the * same order value would could be executed in parallel.
* * This implementation is targeted for easy configuration - just a list of the * engine names contained within a chain - but has limited possibilities to * control the execution order within an chain. However it is expected * that it provides enough flexibility for most of the usage scenarios.
* * This engine also supports the definition of additional parameters for * Enhancement Engines. The syntax is the same as used by BND tools: *
* <engineName>;<param-name>=<param-value>
* <engineName>;<param-name>
*
* Parameter without value are interpreted as enabled boolean switch* * Currently this Chain implementation supports the following Parameter:
0.12.1
this supports EnhancementProperties
* as described by
*
* @author Rupert Westenthaler
*
*/
@Component(configurationFactory=true,metatype=true,
policy=ConfigurationPolicy.REQUIRE)
@Properties(value={
@Property(name=Chain.PROPERTY_NAME),
@Property(name=WeightedChain.PROPERTY_CHAIN, cardinality=1000),
@Property(name=AbstractChain.PROPERTY_CHAIN_PROPERTIES,cardinality=1000),
@Property(name=Constants.SERVICE_RANKING, intValue=0)
})
@Service(value=Chain.class)
public class WeightedChain extends AbstractChain implements Chain, ServiceTrackerCustomizer {
private final Logger log = LoggerFactory.getLogger(WeightedChain.class);
/**
* The list of Enhancement Engine names used to build the Execution Plan
* based on there weights.
*/
public static final String PROPERTY_CHAIN = "stanbol.enhancer.chain.weighted.chain";
/**
* the Chain configuration as parsed in the {@link #activate(ComponentContext)} method
*/
private Map