/*
 * Licensed 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.karaf.cellar.features;

import org.apache.karaf.cellar.core.control.BasicSwitch;
import org.apache.karaf.cellar.core.control.Switch;
import org.apache.karaf.cellar.core.event.EventHandler;
import org.apache.karaf.cellar.core.event.EventType;
import org.apache.karaf.features.FeatureEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Features event handler.
 */
public class FeaturesEventHandler extends FeaturesSupport implements EventHandler<RemoteFeaturesEvent> {

    private static final transient Logger LOGGER = LoggerFactory.getLogger(FeaturesSynchronizer.class);

    public static final String SWITCH_ID = "org.apache.karaf.cellar.event.features.handler";

    private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);

    @Override
    public void init() {
        super.init();
    }

    @Override
    public void destroy() {
        super.destroy();
    }

    /**
     * Features Event.
     *
     * @param event
     */
    public void handle(RemoteFeaturesEvent event) {
        String name = event.getName();
        String version = event.getVersion();
        if (isAllowed(event.getSourceGroup(), Constants.FEATURES_CATEGORY, name, EventType.INBOUND) || event.getForce()) {
            FeatureEvent.EventType type = event.getType();
            Boolean isInstalled = isInstalled(name, version);
            try {
                if (FeatureEvent.EventType.FeatureInstalled.equals(type) && !isInstalled) {
                    if (version != null) {
                        LOGGER.debug("CELLAR FEATURES: installing feature {}/{}", name, version);
                        featuresService.installFeature(name, version);
                    } else {
                        LOGGER.debug("CELLAR FEATURES: installing feature {}", name);
                        featuresService.installFeature(name);
                    }
                } else if (FeatureEvent.EventType.FeatureUninstalled.equals(type) && isInstalled) {
                    if (version != null) {
                        LOGGER.debug("CELLAR FEATURES: un-installing feature {}/{}", name, version);
                        featuresService.uninstallFeature(name, version);
                    } else {
                        LOGGER.debug("CELLAR FEATURES: un-installing feature {}", name);
                        featuresService.uninstallFeature(name);
                    }
                }
            } catch (Exception e) {
                LOGGER.error("CELLAR FEATURES: failed to handle feature event", e);
            }
        } else LOGGER.warn("CELLAR FEATURES: feature {} is marked as BLOCKED INBOUND", name);
    }

    public Class<RemoteFeaturesEvent> getType() {
        return RemoteFeaturesEvent.class;
    }

    public Switch getSwitch() {
        return eventSwitch;
    }

}

@@ -701,32 +701,90 @@
 control.Switch;%0A
+import org.apache.karaf.cellar.core.control.SwitchStatus;%0A
 import org.apach
@@ -1729,24 +1729,91 @@
 tVersion();%0A
+        if (eventSwitch.getStatus().equals(SwitchStatus.ON)) %7B%0A    
         if (
@@ -1935,16 +1935,20 @@
         
+    
 FeatureE
@@ -1982,24 +1982,28 @@
 .getType();%0A
+    
             
@@ -2068,14 +2068,22 @@
     
+  
+  
 try %7B%0A
+    
     
@@ -2162,32 +2162,36 @@
 !isInstalled) %7B%0A
+    
                 
@@ -2233,32 +2233,36 @@
                 
+    
 LOGGER.debug(%22CE
@@ -2335,32 +2335,36 @@
                 
+    
 featuresService.
@@ -2406,32 +2406,36 @@
                 
+   
+ 
 %7D else %7B%0A       
@@ -2419,32 +2419,36 @@
        %7D else %7B%0A
+    
                 
@@ -2533,32 +2533,36 @@
                 
+    
 featuresService.
@@ -2595,34 +2595,42 @@
                 
+  
-%7D%0A
+  %7D%0A    
                 
@@ -2725,32 +2725,36 @@
                 
+    
 if (version != n
@@ -2776,32 +2776,36 @@
                 
+ 
+   
 LOGGER.debug(%22CE
@@ -2881,32 +2881,36 @@
                 
+    
 featuresService.
@@ -2954,32 +2954,36 @@
                 
+   
+ 
 %7D else %7B%0A       
@@ -2967,32 +2967,36 @@
        %7D else %7B%0A
+    
                 
@@ -3084,32 +3084,36 @@
                 
+    
 featuresService.
@@ -3148,34 +3148,42 @@
                 
+  
-%7D%0A
+  %7D%0A    
                 
@@ -3176,32 +3176,36 @@
               %7D%0A
+    
             %7D ca
@@ -3236,24 +3236,28 @@
             
+ 
+   
 LOGGER.error
@@ -3316,34 +3316,42 @@
 e);%0A            
-%7D%0A
+    %7D%0A    
         %7D else L
@@ -3424,24 +3424,34 @@
 ND%22, name);%0A
+        %7D%0A
     %7D%0A%0A    p

Check the feature handler switch status