Search in sources :

Example 6 with ReadinessIndicator

use of org.opencastproject.util.ReadinessIndicator in project opencast by opencast.

the class FeedRegistrationScanner method install.

/**
 * {@inheritDoc}
 *
 * @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File)
 */
@Override
public void install(File artifact) throws Exception {
    logger.info("Installing a feed from '{}'", artifact.getName());
    Properties props = new Properties();
    FileInputStream in = null;
    try {
        in = new FileInputStream(artifact);
        props.load(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    // Always include the server URL obtained from the bundle context
    props.put("org.opencastproject.server.url", bundleContext.getProperty("org.opencastproject.server.url"));
    Class<?> clazz = getClass().getClassLoader().loadClass(props.getProperty(FEED_CLASS));
    FeedGenerator generator = (FeedGenerator) clazz.newInstance();
    generator.setSearchService(searchService);
    generator.setSeriesService(seriesService);
    generator.initialize(props);
    ServiceRegistration<?> reg = bundleContext.registerService(FeedGenerator.class.getName(), generator, null);
    generators.put(artifact, reg);
    sumInstalledFiles++;
    // Determine the number of available profiles
    String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() {

        @Override
        public boolean accept(File arg0, String name) {
            return name.endsWith(".properties");
        }
    });
    // Once all profiles have been loaded, announce readiness
    if (filesInDirectory.length == sumInstalledFiles) {
        Dictionary<String, String> properties = new Hashtable<>();
        properties.put(ARTIFACT, "feed");
        logger.debug("Indicating readiness of feed");
        bundleContext.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties);
        logger.info("All {} feeds installed", filesInDirectory.length);
    } else {
        logger.debug("{} of {} feeds installed", sumInstalledFiles, filesInDirectory.length);
    }
}
Also used : Hashtable(java.util.Hashtable) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) FilenameFilter(java.io.FilenameFilter) FeedGenerator(org.opencastproject.feed.api.FeedGenerator) ReadinessIndicator(org.opencastproject.util.ReadinessIndicator) File(java.io.File)

Aggregations

Hashtable (java.util.Hashtable)6 ReadinessIndicator (org.opencastproject.util.ReadinessIndicator)6 File (java.io.File)3 FilenameFilter (java.io.FilenameFilter)3 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)1 FeedGenerator (org.opencastproject.feed.api.FeedGenerator)1 ConfigurationException (org.opencastproject.util.ConfigurationException)1 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)1