diff --git a/build/build.xml b/build/build.xml index 19e12ededd4..cb5c848ad5e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -885,7 +885,11 @@ - + + + + + diff --git a/build/pom.xml b/build/pom.xml index fbc23a80124..53618c42fe7 100644 --- a/build/pom.xml +++ b/build/pom.xml @@ -995,21 +995,26 @@ jboss-as-remoting + + org.jboss.as + jboss-as-sar + + org.jboss.as jboss-as-security - + org.jboss.as jboss-as-sos - + org.jboss.as - jboss-as-sar + jboss-as-system-jmx - + org.jboss.as jboss-as-threads diff --git a/build/src/main/resources/modules/org/jboss/as/system-jmx/main/module.xml b/build/src/main/resources/modules/org/jboss/as/system-jmx/main/module.xml new file mode 100644 index 00000000000..aed7f64a0cb --- /dev/null +++ b/build/src/main/resources/modules/org/jboss/as/system-jmx/main/module.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index d8ec76c5b0b..a00ab28b0e2 100644 --- a/pom.xml +++ b/pom.xml @@ -1102,6 +1102,12 @@ jboss-as-server ${project.version} + + + org.jboss.as + jboss-as-sos + ${project.version} + org.jboss.as @@ -1111,7 +1117,7 @@ org.jboss.as - jboss-as-sos + jboss-as-system-jmx ${project.version} @@ -6084,6 +6090,7 @@ osgi pojo remoting-test + system-jmx sar security spec-api diff --git a/sar/src/main/java/org/jboss/as/service/SarModuleDependencyProcessor.java b/sar/src/main/java/org/jboss/as/service/SarModuleDependencyProcessor.java index 7660231eaa1..5bcd6911388 100644 --- a/sar/src/main/java/org/jboss/as/service/SarModuleDependencyProcessor.java +++ b/sar/src/main/java/org/jboss/as/service/SarModuleDependencyProcessor.java @@ -41,6 +41,7 @@ public class SarModuleDependencyProcessor implements DeploymentUnitProcessor { private static ModuleIdentifier JBOSS_MODULES_ID = ModuleIdentifier.create("org.jboss.modules"); + private static ModuleIdentifier JBOSS_AS_SYSTEM_JMX_ID = ModuleIdentifier.create("org.jboss.as.system-jmx"); /** * Add dependencies for modules required for manged bean deployments, if managed bean configurations are attached @@ -58,6 +59,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro } moduleSpecification.addSystemDependency(new ModuleDependency(Module.getBootModuleLoader(), JBOSS_MODULES_ID, false, false, false, false)); + moduleSpecification.addSystemDependency(new ModuleDependency(Module.getBootModuleLoader(), JBOSS_AS_SYSTEM_JMX_ID, true, false, false, false)); } public void undeploy(final DeploymentUnit context) { diff --git a/system-jmx/pom.xml b/system-jmx/pom.xml new file mode 100644 index 00000000000..7136b45f38e --- /dev/null +++ b/system-jmx/pom.xml @@ -0,0 +1,84 @@ + + + + + 4.0.0 + + + org.jboss.as + jboss-as-parent + 7.2.0.Alpha1-SNAPSHOT + + + org.jboss.as + jboss-as-system-jmx + 7.2.0.Alpha1-SNAPSHOT + + JBoss Application Server: System JMX Module + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -AgeneratedTranslationFilesPath=${project.build.directory}/generated-translation-files + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*TestCase.java + + false + + + + + + + + org.jboss.logging + jboss-logging + + + org.jboss.logging + jboss-logging-processor + + provided + true + + + junit + junit + test + + + diff --git a/system-jmx/src/main/java/org/jboss/system/Service.java b/system-jmx/src/main/java/org/jboss/system/Service.java new file mode 100644 index 00000000000..14b24964ec3 --- /dev/null +++ b/system-jmx/src/main/java/org/jboss/system/Service.java @@ -0,0 +1,54 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.system; + +/** + * The Service interface. + * + * @author Marc Fleury. + * @version $Revision: 81032 $ + */ +public interface Service { + /** + * create the service, do expensive operations etc + * + * @throws Exception for any error + */ + void create() throws Exception; + + /** + * start the service, create is already called + * + * @throws Exception for any error + */ + void start() throws Exception; + + /** + * stop the service + */ + void stop(); + + /** + * destroy the service, tear down + */ + void destroy(); +} diff --git a/system-jmx/src/main/java/org/jboss/system/ServiceMBean.java b/system-jmx/src/main/java/org/jboss/system/ServiceMBean.java new file mode 100644 index 00000000000..92c9839ea0d --- /dev/null +++ b/system-jmx/src/main/java/org/jboss/system/ServiceMBean.java @@ -0,0 +1,76 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.system; + +/** + * An interface describing a JBoss service MBean. + * + * @see Service + * @see ServiceMBeanSupport + * + * @author Rickard Oberg + * @author Andreas Schaefer + * @author Scott.Stark@jboss.org + * @version $Revision: 81033 $ + */ +public interface ServiceMBean extends Service { + // Constants ----------------------------------------------------- + + /** ServiceController notification types corresponding to service lifecycle events */ + String CREATE_EVENT = "org.jboss.system.ServiceMBean.create"; + String START_EVENT = "org.jboss.system.ServiceMBean.start"; + String STOP_EVENT = "org.jboss.system.ServiceMBean.stop"; + String DESTROY_EVENT = "org.jboss.system.ServiceMBean.destroy"; + + String[] states = { "Stopped", "Stopping", "Starting", "Started", "Failed", "Destroyed", "Created", + "Unregistered", "Registered" }; + + /** The Service.stop has completed */ + int STOPPED = 0; + /** The Service.stop has been invoked */ + int STOPPING = 1; + /** The Service.start has been invoked */ + int STARTING = 2; + /** The Service.start has completed */ + int STARTED = 3; + /** There has been an error during some operation */ + int FAILED = 4; + /** The Service.destroy has completed */ + int DESTROYED = 5; + /** The Service.create has completed */ + int CREATED = 6; + /** The MBean has been created but has not completed MBeanRegistration.postRegister */ + int UNREGISTERED = 7; + /** The MBean has been created and has completed MBeanRegistration.postRegister */ + int REGISTERED = 8; + + // Public -------------------------------------------------------- + + String getName(); + + int getState(); + + String getStateString(); + + /** Detyped lifecycle invocation */ + void jbossInternalLifecycle(String method) throws Exception; +} diff --git a/system-jmx/src/main/java/org/jboss/system/ServiceMBeanSupport.java b/system-jmx/src/main/java/org/jboss/system/ServiceMBeanSupport.java new file mode 100644 index 00000000000..654cd535f98 --- /dev/null +++ b/system-jmx/src/main/java/org/jboss/system/ServiceMBeanSupport.java @@ -0,0 +1,453 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.system; + +import javax.management.MBeanRegistration; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.jboss.logging.Logger; + +/** + * An abstract base class JBoss services can subclass to implement a service that conforms to the ServiceMBean interface. + * Subclasses must override {@link #getName} method and should override {@link #startService}, and {@link #stopService} as + * approriate. + * + * @see ServiceMBean + * + * @author Rickard Öberg + * @author Scott.Stark@jboss.org + * @author Andreas Schaefer + * @author Jason Dillon + * @author Eduardo Martins (AS7) + */ +public class ServiceMBeanSupport implements ServiceMBean, MBeanRegistration { + + protected Logger log; + + /** The MBeanServer which we have been register with. */ + protected MBeanServer server; + + /** The object name which we are registered under. */ + protected ObjectName serviceName; + + /** The current state this service is in. */ + private int state = UNREGISTERED; + + // on AS7 MBean lifecycle is CREATED -> STARTED -> REGISTERED -> UNREGISTERED -> STOP -> DESTROY, + // on previous AS versions is REGISTERED -> CREATED -> STARTED -> STOP -> DESTROYED -> UNREGISTERED + // to maintain compatibility with old ServiceMBeanSupport, we ignore some state changes, but redo + // these when proper state change happens + // the flags below are used to mark ignored lifecycle methods invocations + private boolean createIgnored = false; + private boolean startIgnored = false; + private boolean stopIgnored = false; + private boolean destroyIgnored = false; + private boolean unregisterIgnored = false; + + /** + * Construct a ServiceMBeanSupport. + * + *

+ * Sets up logging. + */ + public ServiceMBeanSupport() { + // can not call this(Class) because we need to call getClass() + this.log = Logger.getLogger(getClass().getName()); + if (log.isTraceEnabled()) { + log.trace("Constructing"); + } + } + + /** + * Construct a ServiceMBeanSupport. + * + *

+ * Sets up logging. + * + * @param type The class type to determine category name from. + */ + public ServiceMBeanSupport(final Class type) { + this(type.getName()); + } + + /** + * Construct a ServiceMBeanSupport. + * + *

+ * Sets up logging. + * + * @param category The logger category name. + */ + public ServiceMBeanSupport(final String category) { + this(Logger.getLogger(category)); + } + + /** + * Construct a ServiceMBeanSupport. + * + * @param log The logger to use. + */ + public ServiceMBeanSupport(final Logger log) { + this.log = log; + if (log.isTraceEnabled()) { + log.trace("Constructing"); + } + } + + /** + * Use the short class name as the default for the service name. + * + * @return a description of the mbean + */ + public String getName() { + final String s = log.getName(); + final int i = s.lastIndexOf("."); + return i != -1 ? s.substring(i + 1, s.length()) : s; + } + + public ObjectName getServiceName() { + return serviceName; + } + + public MBeanServer getServer() { + return server; + } + + public int getState() { + return state; + } + + public String getStateString() { + return states[state]; + } + + public Logger getLog() { + return log; + } + + // ///////////////////////////////////////////////////////////////////////// + // State Mutators // + // ///////////////////////////////////////////////////////////////////////// + + public void create() throws Exception { + jbossInternalCreate(); + } + + public void start() throws Exception { + jbossInternalStart(); + } + + public void stop() { + try { + jbossInternalStop(); + } catch (Throwable t) { + log.warn("Error in stop " + jbossInternalDescription(), t); + } + } + + public void destroy() { + try { + jbossInternalDestroy(); + } catch (Throwable t) { + log.warn("Error in destroy " + jbossInternalDescription(), t); + } + } + + protected String jbossInternalDescription() { + if (serviceName != null) + return serviceName.toString(); + else + return getName(); + } + + public void jbossInternalLifecycle(String method) throws Exception { + if (method == null) + throw new IllegalArgumentException("Null method name"); + + if (method.equals("create")) + jbossInternalCreate(); + else if (method.equals("start")) + jbossInternalStart(); + else if (method.equals("stop")) + jbossInternalStop(); + else if (method.equals("destroy")) + jbossInternalDestroy(); + else + throw new IllegalArgumentException("Unknown lifecyle method " + method); + } + + protected void jbossInternalCreate() throws Exception { + // if (state == CREATED || state == STARTING || state == STARTED + // || state == STOPPING || state == STOPPED) + if (state != REGISTERED) { + createIgnored = true; + if (log.isDebugEnabled()) { + log.debug("Ignoring create call; current state is " + getStateString()); + } + return; + } + + createIgnored = false; + if (log.isDebugEnabled()) { + log.debug("Creating " + jbossInternalDescription()); + } + + try { + createService(); + state = CREATED; + } catch (Exception e) { + log.warn("Initialization failed " + jbossInternalDescription(), e); + throw e; + } + + if (log.isDebugEnabled()) { + log.debug("Created " + jbossInternalDescription()); + } + + if (startIgnored) { + start(); + } + } + + protected void jbossInternalStart() throws Exception { + if (state != CREATED && state != STOPPED) { + startIgnored = true; + if (log.isDebugEnabled()) { + log.debug("Ignoring start call; current state is " + getStateString()); + } + return; + } + + startIgnored = false; + + state = STARTING; + if (log.isDebugEnabled()) { + log.debug("Starting " + jbossInternalDescription()); + } + + try { + startService(); + } catch (Exception e) { + state = FAILED; + log.warn("Starting failed " + jbossInternalDescription(), e); + throw e; + } + + state = STARTED; + if (log.isDebugEnabled()) { + log.debug("Started " + jbossInternalDescription()); + } + + if (stopIgnored) { + stop(); + } + } + + protected void jbossInternalStop() { + if (state != STARTED) { + stopIgnored = true; + if (log.isDebugEnabled()) { + log.debug("Ignoring stop call; current state is " + getStateString()); + } + return; + } + + stopIgnored = false; + state = STOPPING; + if (log.isDebugEnabled()) { + log.debug("Stopping " + jbossInternalDescription()); + } + + try { + stopService(); + } catch (Throwable e) { + state = FAILED; + log.warn("Stopping failed " + jbossInternalDescription(), e); + return; + } + + state = STOPPED; + if (log.isDebugEnabled()) { + log.debug("Stopped " + jbossInternalDescription()); + } + + if (destroyIgnored) { + destroy(); + } + } + + protected void jbossInternalDestroy() { + if (state != STOPPED) { + destroyIgnored = true; + if (log.isDebugEnabled()) { + log.debug("Ignoring destroy call; current state is " + getStateString()); + } + return; + } + + destroyIgnored = false; + if (log.isDebugEnabled()) { + log.debug("Destroying " + jbossInternalDescription()); + } + + try { + destroyService(); + } catch (Throwable t) { + log.warn("Destroying failed " + jbossInternalDescription(), t); + } + state = DESTROYED; + if (log.isDebugEnabled()) { + log.debug("Destroyed " + jbossInternalDescription()); + } + + if (unregisterIgnored) { + postDeregister(); + } + } + + // ///////////////////////////////////////////////////////////////////////// + // JMX Hooks // + // ///////////////////////////////////////////////////////////////////////// + + /** + * Callback method of {@link MBeanRegistration} before the MBean is registered at the JMX Agent. + * + *

+ * Attention: Always call this method when you overwrite it in a subclass because it saves the Object Name of the + * MBean. + * + * @param server Reference to the JMX Agent this MBean is registered on + * @param name Name specified by the creator of the MBean. Note that you can overwrite it when the given ObjectName is null + * otherwise the change is discarded (maybe a bug in JMX-RI). + * @return the ObjectName + * @throws Exception for any error + */ + public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { + this.server = server; + + serviceName = getObjectName(server, name); + + return serviceName; + } + + public void postRegister(Boolean registrationDone) { + if (!registrationDone.booleanValue()) { + if (log.isDebugEnabled()) { + log.debug("Registration is not done -> stop"); + } + stop(); + } else { + state = REGISTERED; + if (createIgnored) { + try { + create(); + } catch (Exception e) { + log.error(e); + } + } + } + } + + public void preDeregister() throws Exception { + } + + public void postDeregister() { + if (state != DESTROYED) { + unregisterIgnored = true; + if (log.isDebugEnabled()) { + log.debug("Ignoring postDeregister call; current state is " + getStateString()); + } + return; + } + unregisterIgnored = false; + server = null; + serviceName = null; + state = UNREGISTERED; + } + + // ///////////////////////////////////////////////////////////////////////// + // Concrete Service Overrides // + // ///////////////////////////////////////////////////////////////////////// + + /** + * Sub-classes should override this method if they only need to set their object name during MBean pre-registration. + * + * @param server the mbeanserver + * @param name the suggested name, maybe null + * @return the object name + * @throws MalformedObjectNameException for a bad object name + */ + protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws MalformedObjectNameException { + return name; + } + + /** + * Sub-classes should override this method to provide custum 'create' logic. + * + *

+ * This method is empty, and is provided for convenience when concrete service classes do not need to perform anything + * specific for this state change. + * + * @throws Exception for any error + */ + protected void createService() throws Exception { + } + + /** + * Sub-classes should override this method to provide custum 'start' logic. + * + *

+ * This method is empty, and is provided for convenience when concrete service classes do not need to perform anything + * specific for this state change. + * + * @throws Exception for any error + */ + protected void startService() throws Exception { + } + + /** + * Sub-classes should override this method to provide custum 'stop' logic. + * + *

+ * This method is empty, and is provided for convenience when concrete service classes do not need to perform anything + * specific for this state change. + * + * @throws Exception for any error + */ + protected void stopService() throws Exception { + } + + /** + * Sub-classes should override this method to provide custum 'destroy' logic. + * + *

+ * This method is empty, and is provided for convenience when concrete service classes do not need to perform anything + * specific for this state change. + * + * @throws Exception for any error + */ + protected void destroyService() throws Exception { + } + +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/ServiceMBeanSupportTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/ServiceMBeanSupportTestCase.java new file mode 100644 index 00000000000..29467775309 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/ServiceMBeanSupportTestCase.java @@ -0,0 +1,118 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.integration.sar.servicembean; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnectorFactory; + +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ContainerResource; +import org.jboss.as.arquillian.container.ManagementClient; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.system.ServiceMBean; +import org.jboss.system.ServiceMBeanSupport; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test MBeans which implement {@link ServiceMBean} and extend {@link ServiceMBeanSupport}. + * + * @author Eduardo Martins + */ +@RunWith(Arquillian.class) +@RunAsClient +public class ServiceMBeanSupportTestCase { + + private static final String UNMANAGED_SAR_DEPLOYMENT_NAME = "service-mbean-support-test"; + + @ContainerResource + private ManagementClient managementClient; + + @ArquillianResource + private Deployer deployer; + + @Deployment(name = ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME, managed = false) + public static JavaArchive geTestMBeanSar() { + final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "service-mbean-support-test.sar"); + sar.addClasses(TestServiceMBean.class, TestService.class); + sar.addAsManifestResource(ServiceMBeanSupportTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); + return sar; + } + + @Deployment + public static JavaArchive getTestResultMBeanSar() { + final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "service-mbean-support-test-result.sar"); + sar.addClasses(TestResultServiceMBean.class, TestResultService.class); + sar.addAsManifestResource(ServiceMBeanSupportTestCase.class.getPackage(), "result-jboss-service.xml", + "jboss-service.xml"); + return sar; + } + + /** + * Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful. + * + * @throws Exception + */ + @Test + public void testSarWithServiceMBeanSupport() throws Exception { + // get mbean server + final MBeanServerConnection mBeanServerConnection = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL()) + .getMBeanServerConnection(); + try { + // deploy the unmanaged sar + deployer.deploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME); + // check the unmanaged mbean state + int state = (Integer) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test"), + "State"); + Assert.assertEquals("Unexpected return state from Test MBean: " + state, ServiceMBean.STARTED, state); + } finally { + // undeploy it + deployer.undeploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME); + } + // check the result of life-cycle methods invocation, using result mbean + String attribute = "CreateServiceInvoked"; + Boolean result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), + attribute); + Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result); + attribute = "StartServiceInvoked"; + result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), + attribute); + Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result); + attribute = "StopServiceInvoked"; + result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), + attribute); + Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result); + attribute = "DestroyServiceInvoked"; + result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), + attribute); + Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result); + } + +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultService.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultService.java new file mode 100644 index 00000000000..1f710e42474 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultService.java @@ -0,0 +1,124 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.integration.sar.servicembean; + +import org.jboss.system.ServiceMBean; + +/** + * An MBean that collects results of life-cycle methods invocations of {@link TestServiceMBean}. + * + * @author Eduardo Martins + * + */ +public class TestResultService implements TestResultServiceMBean, ServiceMBean { + + private boolean createServiceInvoked; + private boolean startServiceInvoked; + private boolean stopServiceInvoked; + private boolean destroyServiceInvoked; + + @Override + public boolean isCreateServiceInvoked() { + return createServiceInvoked; + } + + @Override + public boolean isDestroyServiceInvoked() { + return destroyServiceInvoked; + } + + @Override + public boolean isStartServiceInvoked() { + return startServiceInvoked; + } + + @Override + public boolean isStopServiceInvoked() { + return stopServiceInvoked; + } + + public void setCreateServiceInvoked(boolean createServiceInvoked) { + this.createServiceInvoked = createServiceInvoked; + } + + public void setDestroyServiceInvoked(boolean destroyServiceInvoked) { + this.destroyServiceInvoked = destroyServiceInvoked; + } + + public void setStartServiceInvoked(boolean startServiceInvoked) { + this.startServiceInvoked = startServiceInvoked; + } + + public void setStopServiceInvoked(boolean stopServiceInvoked) { + this.stopServiceInvoked = stopServiceInvoked; + } + + @Override + public void create() throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void start() throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void stop() { + // TODO Auto-generated method stub + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getState() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getStateString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void jbossInternalLifecycle(String method) throws Exception { + // TODO Auto-generated method stub + + } + +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultServiceMBean.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultServiceMBean.java new file mode 100644 index 00000000000..37c5a2e3a72 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestResultServiceMBean.java @@ -0,0 +1,49 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.integration.sar.servicembean; + +/** + * MBean interface for {@link TestResultService}. + * + * @author Eduardo Martins + * + */ +public interface TestResultServiceMBean { + + public boolean isCreateServiceInvoked(); + + public boolean isStartServiceInvoked(); + + public boolean isStopServiceInvoked(); + + public boolean isDestroyServiceInvoked(); + + public void setCreateServiceInvoked(boolean createServiceInvoked); + + public void setDestroyServiceInvoked(boolean destroyServiceInvoked); + + public void setStartServiceInvoked(boolean startServiceInvoked); + + public void setStopServiceInvoked(boolean stopServiceInvoked); + +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestService.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestService.java new file mode 100644 index 00000000000..a0d1a93940c --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestService.java @@ -0,0 +1,67 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.integration.sar.servicembean; + +import javax.management.Attribute; +import javax.management.ObjectName; + +import org.jboss.system.ServiceMBeanSupport; + +/** + * An MBean that extends legacy {@link ServiceMBeanSupport}. + * + * @author Eduardo Martins + * + */ +public class TestService extends ServiceMBeanSupport implements TestServiceMBean { + + @Override + protected void createService() throws Exception { + getLog().info("createService()"); + setTestResultMBeanAttribute("CreateServiceInvoked", true); + } + + @Override + protected void startService() throws Exception { + getLog().info("startService()"); + setTestResultMBeanAttribute("StartServiceInvoked", true); + } + + @Override + protected void stopService() throws Exception { + getLog().info("stopService()"); + setTestResultMBeanAttribute("StopServiceInvoked", true); + } + + @Override + protected void destroyService() throws Exception { + getLog().info("destroyService()"); + setTestResultMBeanAttribute("DestroyServiceInvoked", true); + } + + private void setTestResultMBeanAttribute(String attributeName, boolean attributeValue) throws Exception { + server.setAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), new Attribute(attributeName, + attributeValue)); + } + +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestServiceMBean.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestServiceMBean.java new file mode 100644 index 00000000000..f9d0d2d8f26 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/TestServiceMBean.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.integration.sar.servicembean; + +/** + * MBean interface for {@link TestService}. + * + * @author Eduardo Martins + * + */ +public interface TestServiceMBean { + + public int getState(); +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/jboss-service.xml b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/jboss-service.xml new file mode 100644 index 00000000000..120fa134826 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/jboss-service.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/result-jboss-service.xml b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/result-jboss-service.xml new file mode 100644 index 00000000000..c07c32017aa --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/servicembean/result-jboss-service.xml @@ -0,0 +1,28 @@ + + + + + +