congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
EnginesTracker
Code IndexAdd Tabnine to your IDE (free)

How to use
EnginesTracker
in
org.apache.stanbol.enhancer.servicesapi.impl

Best Java code snippets using org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker (Showing top 16 results out of 315)

origin: apache/stanbol

public AllActiveEnginesChain(BundleContext context, String name) {
  if(context == null){
    throw new IllegalArgumentException("The parsed BundleContext MUST NOT be NULL!");
  }
  if(name == null || name.isEmpty()){
    throw new IllegalArgumentException("The parsed Chain name MUST NOT be NULL!");
  }
  this.context = context;
  this.name = name;
  Set<String> trackAll = Collections.emptySet();
  this.tracker = new EnginesTracker(context, 
    trackAll, //empty set to track all engines
    this);
  this.tracker.open();
}
  
origin: apache/stanbol

/**
 * This internally used an {@link EnginesTracker} to track currently active
 * {@link EnhancementEngine}. This will {@link EnginesTracker#close() close}
 * this tracker and also clear other member variables
 */
public void close(){
  synchronized (lock) {
    this.executionPlan = null;
    this.engineNames = null;
  }
  this.tracker.close();
  this.tracker = null;
  this.name = null;
}
@Override
origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

/**
 * Creates a new {@link EnginesTracker} for the parsed {@link BundleContext}
 * and engine names.
 * Examples:
 * <code><pre>
 *     //Track all active engines with a customiser
 *     new EnginesTracker(context,null,customiser);
 *     
 *     //Track all engines referenced by a Chain and use the customiser
 *     //to react on changes
 *     new EnginesTracker(context,chain.getEngineNames(),customiser);
 * </pre></code>
 * @param context the bundle context used to track engines
 * @param engineNames the names of the engines to track. Parse <code>null</code>
 * or an {@link Collections#emptySet()} to track all engines
 * @param customizer the {@link ServiceTrackerCustomizer} used with this tracker.
 */
public EnginesTracker(BundleContext context, Set<String> engineNames, ServiceTrackerCustomizer customizer){
  if(context == null){
    throw new IllegalArgumentException("The parsed BundleContext MUST NOT be NULL!");
  }
  initEngineTracker(context,engineNames,customizer);
}

origin: apache/stanbol

private void update() throws ChainException {
  Set<String> activeEngineNames = new HashSet<String>(tracker.getActiveEngineNames());
  if(activeEngineNames.isEmpty()){
    throw new ChainException("Currently there are no active EnhancementEngines available");
  }
  List<EnhancementEngine> activeEngines = new ArrayList<EnhancementEngine>(activeEngineNames.size());
  Iterator<String> names = activeEngineNames.iterator();
  while(names.hasNext()){
    String name = names.next();
    EnhancementEngine engine = tracker.getEngine(name);
    if(engine != null){
      activeEngines.add(engine);
    } else { //looks like the config has changed in the meantime
      names.remove();
    }
  }
  Set<String> emptySet = Collections.emptySet();
  executionPlan = calculateExecutionPlan(
    getName(),activeEngines, 
    emptySet,//this Chain does not support optional engines
    emptySet); //only active meaning that no engines are missing
  engineNames = Collections.unmodifiableSet(activeEngineNames);
}
origin: apache/stanbol

/**
 * Creates a new execution plan based on the configured {@link #chain} and
 * the currently available {@link EnhancementEngine}s. If required
 * {@link EnhancementEngine}s are missing a {@link ChainException} will be
 * thrown.
 * @return the execution plan
 * @throws ChainException if a required {@link EnhancementEngine} of the
 * configured {@link #chain} is not active.
 */
private ImmutableGraph createExecutionPlan() throws ChainException {
  List<EnhancementEngine> availableEngines = new ArrayList<EnhancementEngine>(chain.size());
  Set<String> optionalEngines = new HashSet<String>();
  Set<String> missingEngines = new HashSet<String>();
  for(Entry<String,Map<String,List<String>>> entry : chain.entrySet()){
    boolean optional = getState(entry.getValue(),"optional");
    EnhancementEngine engine = tracker.getEngine(entry.getKey());
    if(engine != null){
      availableEngines.add(engine);
    } else {
      missingEngines.add(entry.getKey());
    }
    if(optional){
      optionalEngines.add(entry.getKey());
    }
  }
  return calculateExecutionPlan(getName(),availableEngines,optionalEngines, 
    missingEngines,chainScopedEnhProps);
}
origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

@Override
public EnhancementEngine getEngine(String name){
  ServiceReference ref = getReference(name);
  return ref == null ? null : (EnhancementEngine)nameTracker.getService(ref);
}
/*
origin: apache/stanbol

@Override
public EnhancementEngine getEngine(String name){
  ServiceReference ref = getReference(name);
  return ref == null ? null : (EnhancementEngine)nameTracker.getService(ref);
}
/*
origin: org.apache.stanbol/org.apache.stanbol.enhancer.jersey

@Activate
protected void activate(ComponentContext ctx) {
  final BundleContext bc = ctx.getBundleContext();
  engineTracker = new EnginesTracker(bc, Collections.<String>emptySet(), 
    new ServiceTrackerCustomizer() {
      
      @Override
      public Object addingService(ServiceReference reference) {
        Object service = bc.getService(reference);
        if(service != null){
          _enginesCache = null; //rebuild the cache on the next call
        }
        return service;
      }
      @Override
      public void modifiedService(ServiceReference reference, Object service) {
        _enginesCache = null; //rebuild the cache on the next call
      }
      @Override
      public void removedService(ServiceReference reference, Object service) {
        if(reference != null){
          bc.ungetService(reference);
          _enginesCache = null; //rebuild the cache on the next call
        }
      }
      
    });
  engineTracker.open();
}
origin: org.apache.stanbol/org.apache.stanbol.enhancer.jersey

@Deactivate
protected void deactivate(ComponentContext ctx){
  if(engineTracker != null){
    engineTracker.close();
    engineTracker = null;
  }
}
/**
origin: apache/stanbol

/**
 * Creates a new {@link EnginesTracker} for the parsed {@link BundleContext}
 * and engine names.
 * Examples:
 * <code><pre>
 *     //Track all active engines with a customiser
 *     new EnginesTracker(context,null,customiser);
 *     
 *     //Track all engines referenced by a Chain and use the customiser
 *     //to react on changes
 *     new EnginesTracker(context,chain.getEngineNames(),customiser);
 * </pre></code>
 * @param context the bundle context used to track engines
 * @param engineNames the names of the engines to track. Parse <code>null</code>
 * or an {@link Collections#emptySet()} to track all engines
 * @param customizer the {@link ServiceTrackerCustomizer} used with this tracker.
 */
public EnginesTracker(BundleContext context, Set<String> engineNames, ServiceTrackerCustomizer customizer){
  if(context == null){
    throw new IllegalArgumentException("The parsed BundleContext MUST NOT be NULL!");
  }
  initEngineTracker(context,engineNames,customizer);
}

origin: apache/stanbol

@Activate
protected void activate(ComponentContext ctx) {
  final BundleContext bc = ctx.getBundleContext();
  engineTracker = new EnginesTracker(bc, Collections.<String>emptySet(), 
    new ServiceTrackerCustomizer() {
      
      @Override
      public Object addingService(ServiceReference reference) {
        Object service = bc.getService(reference);
        if(service != null){
          _enginesCache = null; //rebuild the cache on the next call
        }
        return service;
      }
      @Override
      public void modifiedService(ServiceReference reference, Object service) {
        _enginesCache = null; //rebuild the cache on the next call
      }
      @Override
      public void removedService(ServiceReference reference, Object service) {
        if(reference != null){
          bc.ungetService(reference);
          _enginesCache = null; //rebuild the cache on the next call
        }
      }
      
    });
  engineTracker.open();
}
origin: apache/stanbol

@Deactivate
protected void deactivate(ComponentContext ctx){
  if(engineTracker != null){
    engineTracker.close();
    engineTracker = null;
  }
}
/**
origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

protected EnginesTracker(){/* nothing to do here */ }    /**
 * Creates a new {@link EnginesTracker} for the parsed {@link BundleContext}
 * and engine names.
 * Examples:
 * <code><pre>
 *     //Track all active engines
 *     new EnginesTracker(context);
 *     
 *     //Track only the langId engine
 *     new EnginesTracker(context,langId);
 * </pre></code>
 * @param context The bundle context used to track engines
 * @param engineNames the name of the engines to track. If empty 
 * all engines are tracked.
 */
public EnginesTracker(BundleContext context, String...engineNames){
  if(context == null){
    throw new IllegalArgumentException("The parsed BundleContext MUST NOT be NULL!");
  }
  final Set<String> names;
  if(engineNames == null){
    names = Collections.emptySet();
  } else {
    names = new HashSet<String>(Arrays.asList(engineNames));
  }
  initEngineTracker(context,names,null);
}
/**
origin: apache/stanbol

tracker = new EnginesTracker(ctx.getBundleContext(), chain.keySet(),this);
tracker.open();
origin: apache/stanbol

@Override
protected void deactivate(ComponentContext ctx) {
  tracker.close();
  tracker = null;
  chainScopedEnhProps = null;
  chain = null;
  super.deactivate(ctx);
}
@Override
origin: apache/stanbol

protected EnginesTracker(){/* nothing to do here */ }    /**
 * Creates a new {@link EnginesTracker} for the parsed {@link BundleContext}
 * and engine names.
 * Examples:
 * <code><pre>
 *     //Track all active engines
 *     new EnginesTracker(context);
 *     
 *     //Track only the langId engine
 *     new EnginesTracker(context,langId);
 * </pre></code>
 * @param context The bundle context used to track engines
 * @param engineNames the name of the engines to track. If empty 
 * all engines are tracked.
 */
public EnginesTracker(BundleContext context, String...engineNames){
  if(context == null){
    throw new IllegalArgumentException("The parsed BundleContext MUST NOT be NULL!");
  }
  final Set<String> names;
  if(engineNames == null){
    names = Collections.emptySet();
  } else {
    names = new HashSet<String>(Arrays.asList(engineNames));
  }
  initEngineTracker(context,names,null);
}
/**
org.apache.stanbol.enhancer.servicesapi.implEnginesTracker

Javadoc

Utility similar to ServiceTracker that allows to track one/some/all EnhancementEngines. As convenience this also implements the EnhancementEngineManager interface however the intended usage scenarios for this utility are considerable different to the using the EnhancementEngineManager interface as a service.

This utility especially allows to

  • track only EnhancementEngine with names as parsed in the constructor. This allows e.g. a Chain implementation to keep only track of EnhancementEngine that are actually referenced by this chain.
  • A ServiceTrackerCustomizer can be parsed to this utility. The methods of this interface will be called on changes to any service tracked by this instance. This allows users of this utility to update there internal state on any change of the state of tracked engines. This might be especially useful for Chain implementations that need to update there execution plan on such changes. However this can also be used by EnhancementJobManager implementations that want to get notified about enhancement engines referenced by the Chain the are currently using to enhance an ContentItem.
Please not that calls to #open() and #close() are required to start and stop the tracking of this class. In general the same rules as for the ServiceTracker apply also to this utility.

Most used methods

  • <init>
    Creates a new EnginesTracker for the parsed BundleContextand engine names. Examples: //Track all ac
  • close
    Closes this tracker
  • open
    Starts tracking based on the configuration parsed in the constructor
  • getEngine
  • getActiveEngineNames
  • getReference
  • initEngineTracker
    Initialises the EnginesTracker by using the parsed parameter. This will create a copy of the parsed

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getApplicationContext (Context)
  • startActivity (Activity)
  • requestLocationUpdates (LocationManager)
  • Menu (java.awt)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Path (java.nio.file)
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now