Search in sources :

Example 1 with ByonClusterController

use of org.apache.whirr.ByonClusterController in project whirr by apache.

the class Activator method start.

/**
 * Called when this bundle is started so the Framework can perform the
 * bundle-specific activities necessary to start this bundle. This method
 * can be used to register services or to allocate any resources that this
 * bundle needs.
 * <p/>
 * <p/>
 * This method must complete and return to its caller in a timely manner.
 *
 * @param context The execution context of the bundle being started.
 * @throws Exception If this method throws an exception, this
 *                   bundle is marked as stopped and the Framework will remove this
 *                   bundle's listeners, unregister all services registered by this
 *                   bundle, and release all services used by this bundle.
 */
@Override
public void start(BundleContext context) throws Exception {
    // Initialize OSGi based FunctionLoader
    functionLoader = new BundleFunctionLoader(context);
    functionLoader.start();
    defaultClusterController.setHandlerMapFactory(handlerMapFactory);
    byonClusterController.setHandlerMapFactory(handlerMapFactory);
    // Register services
    clusterControllerFactoryRegistration = context.registerService(ClusterControllerFactory.class.getName(), clusterControllerFactory, null);
    handlerMapFactoryRegistration = context.registerService(DynamicHandlerMapFactory.class.getName(), handlerMapFactory, null);
    // Start tracking
    clusterControllerTracker = new ServiceTracker(context, ClusterController.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = super.addingService(reference);
            clusterControllerFactory.bind((ClusterController) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            clusterControllerFactory.unbind((ClusterController) service);
            super.removedService(reference, service);
        }
    };
    clusterControllerTracker.open();
    computeServiceTracker = new ServiceTracker(context, ComputeService.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = context.getService(reference);
            dynamicComputeCache.bind((ComputeService) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            dynamicComputeCache.unbind((ComputeService) service);
            super.removedService(reference, service);
        }
    };
    computeServiceTracker.open();
    handlerTracker = new ServiceTracker(context, ClusterActionHandler.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = context.getService(reference);
            handlerMapFactory.bind((ClusterActionHandler) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            handlerMapFactory.unbind((ClusterActionHandler) service);
            super.removedService(reference, service);
        }
    };
    handlerTracker.open();
    Properties defaultClusterControllerProperties = new Properties();
    defaultClusterControllerProperties.setProperty("name", "default");
    defaultClusterControllerRegistration = context.registerService(ClusterController.class.getName(), defaultClusterController, defaultClusterControllerProperties);
    Properties byonClusterControllerProperties = new Properties();
    byonClusterControllerProperties.setProperty("name", "byon");
    byonClusterControllerRegistration = context.registerService(ClusterController.class.getName(), byonClusterController, byonClusterControllerProperties);
}
Also used : BundleFunctionLoader(org.jclouds.scriptbuilder.functionloader.osgi.BundleFunctionLoader) ClusterController(org.apache.whirr.ClusterController) ByonClusterController(org.apache.whirr.ByonClusterController) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Properties(java.util.Properties) ComputeService(org.jclouds.compute.ComputeService) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Properties (java.util.Properties)1 ByonClusterController (org.apache.whirr.ByonClusterController)1 ClusterController (org.apache.whirr.ClusterController)1 ClusterActionHandler (org.apache.whirr.service.ClusterActionHandler)1 ComputeService (org.jclouds.compute.ComputeService)1 BundleFunctionLoader (org.jclouds.scriptbuilder.functionloader.osgi.BundleFunctionLoader)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1