Permalink
Browse files

Add the example subsystem to git

  • Loading branch information...
1 parent f808812 commit 017f15d8c1e405e1d66c1e320bb7adf7b7ee60a1 @kabir kabir committed Sep 14, 2011
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~ Copyright 2010, 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.
+ --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- parent>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-parent</artifactId>
+ </parent -->
+
+ <groupId>com.acme.corp</groupId>
+ <artifactId>acme-subsystem</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>JBoss Application Server: Subsystem Artifact</name>
+
+ <packaging>jar</packaging>
+
+ <properties>
+ <version.jboss.as>7.0.1.Final</version.jboss.as>
+ <version.junit>4.8.2</version.junit>
+ <module.name>com.acme.corp.tracker</module.name>
+ </properties>
+
+
+ <build>
+ <!-- Maven will append the version to the finalName (which is the name
+ given to the generated war, and hence the context root) -->
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.8.1</version>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <enableAssertions>true</enableAssertions>
+ <argLine>-Xmx512m</argLine>
+ <systemProperties>
+ <property>
+ <name>jboss.home</name>
+ <value>${jboss.home}</value>
+ </property>
+ </systemProperties>
+ <includes>
+ <include>**/*TestCase.java</include>
+ </includes>
+ <forkMode>once</forkMode>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2.1</version>
+ <configuration>
+ <filters>
+ <filter>src/assemble/filter.properties</filter>
+ </filters>
+ <descriptors>
+ <descriptor>src/assemble/distribution.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <inherited>false</inherited>
+ <version>1.6</version>
+ <executions>
+ <execution>
+ <id>build-dist</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <target>
+ <!-- Replace the '.' in ${module.name} with '/' to get its path -->
+ <tempfile property="temp.file" />
+ <echo message="${module.name}" file="${temp.file}" />
+ <replace file="${temp.file}" token="." value="/" />
+ <loadfile srcfile="${temp.file}" property="module.path" />
+ <delete file="${temp.file}" />
+
+ <delete dir="target/module" />
+ <property name="module.dir" value="target/module/${module.path}/main" />
+
+ <copy file="src/main/resources/module/main/module.xml" tofile="${module.dir}/module.xml" />
+ <copy file="target/${project.artifactId}.jar" todir="${module.dir}" />
+
+ <echo>Module ${module.name} has been created in the target/module directory. Copy to your JBoss AS 7 installation.</echo>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-controller</artifactId>
+ <version>${version.jboss.as}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-server</artifactId>
+ <version>${version.jboss.as}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-subsystem-test</artifactId>
+ <version>${version.jboss.as}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ <version>${version.junit}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-subsystem-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,75 @@
+package com.acme.corp.tracker.deployment;
+
+import org.jboss.as.server.AbstractDeploymentChainStep;
+import org.jboss.as.server.deployment.Attachments;
+import org.jboss.as.server.deployment.DeploymentPhaseContext;
+import org.jboss.as.server.deployment.DeploymentUnit;
+import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
+import org.jboss.as.server.deployment.DeploymentUnitProcessor;
+import org.jboss.as.server.deployment.Phase;
+import org.jboss.as.server.deployment.module.ResourceRoot;
+import org.jboss.logging.Logger;
+import org.jboss.msc.service.ServiceController;
+import org.jboss.msc.service.ServiceRegistry;
+import org.jboss.vfs.VirtualFile;
+
+import com.acme.corp.tracker.extension.TrackerService;
+
+/**
+ * An example deployment unit processor that does nothing. To add more deployment
+ * processors copy this class, and add to the {@link AbstractDeploymentChainStep}
+ * {@link SubsystemAdd#performBoottime(org.jboss.as.controller.OperationContext, org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, org.jboss.as.controller.ServiceVerificationHandler, java.util.List)}
+ *
+ * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
+ */
+public class SubsystemDeploymentProcessor implements DeploymentUnitProcessor {
+
+ Logger log = Logger.getLogger(SubsystemDeploymentProcessor.class);
+
+ /**
+ * See {@link Phase} for a description of the different phases
+ */
+ public static final Phase PHASE = Phase.DEPENDENCIES;
+
+ /**
+ * The relative order of this processor within the {@link #PHASE}.
+ * The current number is large enough for it to happen after all
+ * the standard deployment unit processors that come with JBoss AS.
+ */
+ public static final int PRIORITY = 0x4000;
+
+ @Override
+ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
+ String name = phaseContext.getDeploymentUnit().getName();
+ ResourceRoot root = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
+ TrackerService service = getTrackerService(phaseContext.getServiceRegistry(), name);
+ if (service != null) {
+ VirtualFile cool = root.getRoot().getChild("META-INF/cool.txt");
+ service.addDeployment(name);
+ if (cool.exists()) {
+ service.addCoolDeployment(name);
+ }
+ }
+ }
+
+ @Override
+ public void undeploy(DeploymentUnit context) {
+ context.getServiceRegistry();
+ String name = context.getName();
+ TrackerService service = getTrackerService(context.getServiceRegistry(), name);
+ if (service != null) {
+ service.removeDeployment(name);
+ }
+ }
+
+ private TrackerService getTrackerService(ServiceRegistry registry, String name) {
+ int last = name.lastIndexOf(".");
+ String suffix = name.substring(last + 1);
+ ServiceController<?> container = registry.getService(TrackerService.createServiceName(suffix));
+ if (container != null) {
+ TrackerService service = (TrackerService)container.getValue();
+ return service;
+ }
+ return null;
+ }
+}
@@ -0,0 +1,56 @@
+package com.acme.corp.tracker.extension;
+
+import java.util.List;
+
+import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
+import org.jboss.as.controller.OperationContext;
+import org.jboss.as.controller.OperationFailedException;
+import org.jboss.as.controller.ServiceVerificationHandler;
+import org.jboss.as.server.AbstractDeploymentChainStep;
+import org.jboss.as.server.DeploymentProcessorTarget;
+import org.jboss.dmr.ModelNode;
+import org.jboss.logging.Logger;
+import org.jboss.msc.service.ServiceController;
+
+import com.acme.corp.tracker.deployment.SubsystemDeploymentProcessor;
+
+/**
+ * Handler responsible for adding the subsystem resource to the model
+ *
+ * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
+ */
+class SubsystemAdd extends AbstractBoottimeAddStepHandler {
+
+ static final SubsystemAdd INSTANCE = new SubsystemAdd();
+
+ private final Logger log = Logger.getLogger(SubsystemAdd.class);
+
+ private SubsystemAdd() {
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
+ log.info("Populating the model");
+ //Initialize the 'type' child node
+ model.get("type").setEmptyObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void performBoottime(OperationContext context, ModelNode operation, ModelNode model,
+ ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
+ throws OperationFailedException {
+
+ //Add deployment processors here
+ //Remove this if you don't need to hook into the deployers, or you can add as many as you like
+ //see SubDeploymentProcessor for explanation of the phases
+ context.addStep(new AbstractDeploymentChainStep() {
+ public void execute(DeploymentProcessorTarget processorTarget) {
+ processorTarget.addDeploymentProcessor(SubsystemDeploymentProcessor.PHASE, SubsystemDeploymentProcessor.PRIORITY, new SubsystemDeploymentProcessor());
+
+ }
+ }, OperationContext.Stage.RUNTIME);
+
+ }
+}
Oops, something went wrong.

0 comments on commit 017f15d

Please sign in to comment.