Search in sources :

Example 16 with ComponentException

use of org.osgi.service.component.ComponentException in project opencast by opencast.

the class StaticFileServiceImpl method activate.

/**
 * OSGI callback for activating this component
 *
 * @param cc
 *          the osgi component context
 */
public void activate(ComponentContext cc) {
    logger.info("Upload Static Resource Service started.");
    registerMXBean = JmxUtil.registerMXBean(staticFileStatistics, "UploadStatistics");
    rootDirPath = OsgiUtil.getContextProperty(cc, STATICFILES_ROOT_DIRECTORY_KEY);
    final File rootFile = new File(rootDirPath);
    if (!rootFile.exists()) {
        try {
            FileUtils.forceMkdir(rootFile);
        } catch (IOException e) {
            throw new ComponentException(String.format("%s does not exists and could not be created", rootFile.getAbsolutePath()));
        }
    }
    if (!rootFile.canRead())
        throw new ComponentException(String.format("Cannot read from %s", rootFile.getAbsolutePath()));
    purgeService = new PurgeTemporaryStorageService();
    purgeService.addListener(new Listener() {

        @Override
        public void failed(State from, Throwable failure) {
            logger.warn("Temporary storage purging service failed: {}", getStackTrace(failure));
        }
    }, MoreExecutors.sameThreadExecutor());
    purgeService.startAsync();
    logger.info("Purging of temporary storage section scheduled");
}
Also used : Listener(com.google.common.util.concurrent.Service.Listener) PropertyChangeListener(java.beans.PropertyChangeListener) State(com.google.common.util.concurrent.Service.State) ComponentException(org.osgi.service.component.ComponentException) IOException(java.io.IOException) File(java.io.File)

Aggregations

ComponentException (org.osgi.service.component.ComponentException)16 List (java.util.List)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)2 ComponentInstance (org.osgi.service.component.ComponentInstance)2 Listener (com.google.common.util.concurrent.Service.Listener)1 State (com.google.common.util.concurrent.Service.State)1 ShutdownException (io.fabric8.common.util.ShutdownTracker.ShutdownException)1 VertxService (io.fabric8.gateway.fabric.support.vertx.VertxService)1 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)1 Protocol (io.fabric8.gateway.handlers.detecting.Protocol)1 AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)1 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)1 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)1 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)1 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)1 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)1