Author: cschneider Date: Wed Apr 11 10:24:33 2012 New Revision: 1324686 URL: http://svn.apache.org/viewvc?rev=1324686&view=rev Log: KARAF-1302 Use aries jmx for scr module
Added: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrsMBean.java - copied, changed from r1324616, karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/Scrs.java - copied, changed from r1324616, karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/ karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml Removed: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java Modified: karaf/trunk/scr/management/pom.xml Modified: karaf/trunk/scr/management/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/pom.xml?rev=1324686&r1=1324685&r2=1324686&view=diff ============================================================================== --- karaf/trunk/scr/management/pom.xml (original) +++ karaf/trunk/scr/management/pom.xml Wed Apr 11 10:24:33 2012 @@ -90,12 +90,6 @@ <Export-Package> org.apache.karaf.scr.management </Export-Package> - <Import-Package> - !org.apache.karaf.scr.management, - javax.management, - javax.management.loading, - * - </Import-Package> <Private-Package> org.apache.karaf.scr.management.internal </Private-Package> Copied: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrsMBean.java (from r1324616, karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java) URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrsMBean.java?p2=karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrsMBean.java&p1=karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java&r1=1324616&r2=1324686&rev=1324686&view=diff ============================================================================== --- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java (original) +++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrsMBean.java Wed Apr 11 10:24:33 2012 @@ -1,29 +1,29 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.scr.management; - -public interface ScrServiceMBean { - - String[] listComponents() throws Exception; - - boolean isComponentActive(String componentName) throws Exception; - - void activateComponent(String componentName) throws Exception; - - void deactiveateComponent(String componentName) throws Exception; - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.scr.management; + +public interface ScrsMBean { + + String[] listComponents() throws Exception; + + boolean isComponentActive(String componentName) throws Exception; + + void activateComponent(String componentName) throws Exception; + + void deactiveateComponent(String componentName) throws Exception; + +} Copied: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/Scrs.java (from r1324616, karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java) URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/Scrs.java?p2=karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/Scrs.java&p1=karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java&r1=1324616&r2=1324686&rev=1324686&view=diff ============================================================================== --- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java (original) +++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/Scrs.java Wed Apr 11 10:24:33 2012 @@ -1,146 +1,80 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.scr.management.internal; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import javax.management.MBeanServer; -import javax.management.NotCompliantMBeanException; -import javax.management.StandardMBean; - -import org.apache.felix.scr.Component; -import org.apache.felix.scr.ScrService; -import org.apache.karaf.management.MBeanRegistrer; -import org.apache.karaf.scr.management.ScrServiceMBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import aQute.bnd.annotation.component.Activate; -import aQute.bnd.annotation.component.Deactivate; - -@aQute.bnd.annotation.component.Component(name = ScrServiceMBeanImpl.COMPONENT_NAME, enabled = true, immediate = true) -public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBean { - - public static final String COMPONENT_NAME = "ScrServiceMBean"; - - public static final String COMPONENT_LABEL = "Apache Karaf SCR Service MBean"; - - private static final Logger LOGGER = LoggerFactory.getLogger(ScrServiceMBeanImpl.class); - - private MBeanServer mBeanServer; - - private ScrService scrService; - - private MBeanRegistrer mBeanRegistrer; - - private ReadWriteLock lock = new ReentrantReadWriteLock(); - - /** - * Creates new Declarative Services mbean. - * - * @throws NotCompliantMBeanException - */ - public ScrServiceMBeanImpl() throws NotCompliantMBeanException { - super(ScrServiceMBean.class); - } - - @Activate - public void activate() throws Exception { - LOGGER.info("Activating the " + COMPONENT_LABEL); - Map<Object, String> mbeans = new HashMap<Object, String>(); - String karafName = System.getProperty("karaf.name", "root"); - mbeans.put(this, "org.apache.karaf:type=scr,name=" + karafName); - try { - lock.writeLock().lock(); - mBeanRegistrer = new MBeanRegistrer(); - mBeanRegistrer.setMbeans(mbeans); - mBeanRegistrer.registerMBeanServer(mBeanServer); - } finally { - lock.writeLock().unlock(); - } - } - - @Deactivate - public void deactivate() throws Exception { - LOGGER.info("Deactivating the " + COMPONENT_LABEL); - try { - lock.writeLock().lock(); - mBeanRegistrer.unregisterMBeanServer(mBeanServer); - mBeanRegistrer = null; - } finally { - lock.writeLock().unlock(); - } - } - - public String[] listComponents() throws Exception { - Component[] components = safe(scrService.getComponents()); - String[] componentNames = new String[components.length]; - for (int i = 0; i < componentNames.length; i++) { - componentNames[i] = components[i].getName(); - } - return componentNames; - } - - public boolean isComponentActive(String componentName) throws Exception { - boolean state = false; - Component[] components = scrService.getComponents(componentName); - for (Component component : safe(components)) { - state = (component.getState() == Component.STATE_ACTIVE)?true:false; - } - return state; - } - - public void activateComponent(String componentName) throws Exception { - if (scrService.getComponents(componentName) != null) { - Component[] components = scrService.getComponents(componentName); - for (Component component : safe(components)) { - component.enable(); - } - } - } - - public void deactiveateComponent(String componentName) throws Exception { - if (scrService.getComponents(componentName) != null) { - Component[] components = scrService.getComponents(componentName); - for (Component component : safe(components)) { - component.disable(); - } - } - } - - private Component[] safe( Component[] components ) { - return components == null ? new Component[0] : components; - } - - /** - * @param mBeanServer the mBeanServer to set - */ - public void setmBeanServer(MBeanServer mBeanServer) { - this.mBeanServer = mBeanServer; - } - - /** - * @param scrService the scrService to set - */ - public void setScrService(ScrService scrService) { - this.scrService = scrService; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.scr.management.internal; + +import javax.management.NotCompliantMBeanException; +import javax.management.StandardMBean; + +import org.apache.felix.scr.Component; +import org.apache.felix.scr.ScrService; +import org.apache.karaf.scr.management.ScrsMBean; + +public class Scrs extends StandardMBean implements ScrsMBean { + + private ScrService scrService; + + /** + * Creates new Declarative Services mbean. + * + * @throws NotCompliantMBeanException + */ + public Scrs(ScrService scrService) throws NotCompliantMBeanException { + super(ScrsMBean.class); + this.scrService = scrService; + } + + public String[] listComponents() throws Exception { + Component[] components = safe(scrService.getComponents()); + String[] componentNames = new String[components.length]; + for (int i = 0; i < componentNames.length; i++) { + componentNames[i] = components[i].getName(); + } + return componentNames; + } + + public boolean isComponentActive(String componentName) throws Exception { + boolean state = false; + Component[] components = scrService.getComponents(componentName); + for (Component component : safe(components)) { + state = (component.getState() == Component.STATE_ACTIVE)?true:false; + } + return state; + } + + public void activateComponent(String componentName) throws Exception { + if (scrService.getComponents(componentName) != null) { + Component[] components = scrService.getComponents(componentName); + for (Component component : safe(components)) { + component.enable(); + } + } + } + + public void deactiveateComponent(String componentName) throws Exception { + if (scrService.getComponents(componentName) != null) { + Component[] components = scrService.getComponents(componentName); + for (Component component : safe(components)) { + component.disable(); + } + } + } + + private Component[] safe( Component[] components ) { + return components == null ? new Component[0] : components; + } + +} Added: karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1324686&view=auto ============================================================================== --- karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml (added) +++ karaf/trunk/scr/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml Wed Apr 11 10:24:33 2012 @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" + xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"> + + <ext:property-placeholder /> + + <reference id="scrService" interface="org.apache.felix.scr.ScrService"/> + + <bean id="scrsMBean" class="org.apache.karaf.scr.management.internal.Scrs"> + <argument ref="scrService" /> + </bean> + + <service ref="scrsMBean" interface="org.apache.karaf.scr.management.ScrsMBean"> + <service-properties> + <entry key="jmx.objectname" value="org.apache.karaf:type=scr,name=${karaf.name}"/> + </service-properties> + </service> +</blueprint>