Skip to content

Commit

Permalink
Create a web-common module and move EE related classes
Browse files Browse the repository at this point in the history
This commit moves most of the classes that are required
for web container integration into their own module. This
is not a complete solution as yet, as OSGI and Web Services
still have a hard coded dependency on JBoss Web classes.
  • Loading branch information
stuartwdouglas committed Feb 26, 2013
1 parent 85f8069 commit 011cdd0
Show file tree
Hide file tree
Showing 79 changed files with 857 additions and 648 deletions.
4 changes: 4 additions & 0 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@
<extract-native-jar group="org.jboss.as" artifact="jbossweb-native"/>
</module-def>

<module-def name="org.jboss.as.web-common">
<maven-resource group="org.jboss.as" artifact="jboss-as-web-common"/>
</module-def>

<module-def name="org.jboss.as.webservices">
<maven-resource group="org.jboss.as" artifact="jboss-as-webservices-server-integration"/>
<maven-resource-with-classifier group="org.jboss.ws.cxf" artifact="jbossws-cxf-resources" classifier="jboss711"/>
Expand Down
5 changes: 5 additions & 0 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@
<artifactId>jboss-as-web</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-web-common</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-weld</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.ejb3"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.as.weld"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.metadata"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.threads"/>
<module name="org.jboss.as.transactions"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.common-core"/>
<module name="org.jboss.jboss-transaction-spi"/>
<module name="org.jboss.invocation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<dependencies>
<module name="com.sun.jsf-impl" slot="1.2"/>
<module name="javax.api"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.web-common"/>
<module name="javax.servlet.api"/>
<module name="org.jboss.logging"/>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<dependencies>
<module name="com.sun.jsf-impl"/>
<module name="javax.api"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.web-common"/>
<module name="javax.servlet.api"/>
<module name="org.jboss.logging"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<module name="org.jboss.as.naming"/>
<module name="org.jboss.as.osgi"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.as.transactions"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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.
-->

<module xmlns="urn:jboss:module:1.1" name="org.jboss.as.web-common">
<properties>
<property name="jboss.api" value="private"/>
</properties>

<resources>
<!-- Insert resources here -->
</resources>

<dependencies>
<module name="sun.jdk"/>
<module name="javax.annotation.api"/>
<module name="javax.api"/>
<module name="javax.security.auth.message.api"/>
<module name="javax.servlet.api"/>
<module name="javax.servlet.jsp.api"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.naming"/>
<module name="org.jboss.as.network"/>
<module name="org.jboss.as.security"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.threads"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.marshalling"/>
<module name="org.jboss.metadata"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
<module name="org.jboss.threads"/>
<module name="org.jboss.vfs"/>
<module name="org.jboss.logging"/>
<module name="org.picketbox"/>
<module name="javax.security.jacc.api"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<module name="org.jboss.as.security"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.threads"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.marshalling"/>
<module name="org.jboss.metadata"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<module name="org.jboss.as.naming"/>
<module name="org.jboss.as.security"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.threads"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<module name="org.jboss.as.security"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.transactions"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.ejb-client"/>
<module name="org.jboss.ejb3"/>
<module name="org.jboss.invocation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.jboss.msc.value.InjectedValue;

/**
*
* Setup processor that adds sets operations for the cached connection manager. These operations are run around
* incoming requests.
*
Expand Down Expand Up @@ -74,8 +73,7 @@ public void undeploy(final DeploymentUnit context) {

}


private static class CachedConnectionManagerSetupAction implements SetupAction, Service<Void> {
private static class CachedConnectionManagerSetupAction implements SetupAction, Service<Void> {

private final InjectedValue<CachedConnectionManager> cachedConnectionManager = new InjectedValue<CachedConnectionManager>();

Expand All @@ -92,7 +90,10 @@ private CachedConnectionManagerSetupAction(final ServiceName serviceName) {
@Override
public void setup(final Map<String, Object> properties) {
try {
cachedConnectionManager.getValue().pushMetaAwareObject(this, unsharable);
final CachedConnectionManager connectionManager = cachedConnectionManager.getOptionalValue();
if (connectionManager != null) {
cachedConnectionManager.getValue().pushMetaAwareObject(this, unsharable);
}
} catch (ResourceException e) {
throw new RuntimeException(e);
}
Expand All @@ -101,7 +102,10 @@ public void setup(final Map<String, Object> properties) {
@Override
public void teardown(final Map<String, Object> properties) {
try {
cachedConnectionManager.getValue().popMetaAwareObject(unsharable);
final CachedConnectionManager connectionManager = cachedConnectionManager.getOptionalValue();
if (connectionManager != null) {
connectionManager.popMetaAwareObject(unsharable);
}
} catch (ResourceException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ public class Attachments {

public static final AttachmentKey<EEResourceReferenceProcessorRegistry> RESOURCE_REFERENCE_PROCESSOR_REGISTRY = AttachmentKey.create(EEResourceReferenceProcessorRegistry.class);

public static final AttachmentKey<ComponentRegistry> COMPONENT_REGISTRY = AttachmentKey.create(ComponentRegistry.class);
}
3 changes: 3 additions & 0 deletions ee/src/main/java/org/jboss/as/ee/component/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ public interface Component {
*/
ComponentInstance createInstance();

ComponentInstance createInstance(Object instance);

NamespaceContextSelector getNamespaceContextSelector();

}
147 changes: 147 additions & 0 deletions ee/src/main/java/org/jboss/as/ee/component/ComponentRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* 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.ee.component;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;

/**
* Registry that can be used to directly look up a component, based on the component class.
* <p/>
* This is obviously not ideal, as it is possible to have multiple components for a single class,
* however it is necessary to work around problematic SPI's that expect to be able to inject / instantiate
* based only on the class type.
* <p/>
* This registry only contains simple component types that do not have a view
*
* @author Stuart Douglas
*/
public class ComponentRegistry {

public static ServiceName SERVICE_NAME = ServiceName.of("ee", "ComponentRegistry");

private final Map<Class<?>, ComponentManagedReferenceFactory> componentsByClass = new ConcurrentHashMap<Class<?>, ComponentManagedReferenceFactory>();
private final ServiceRegistry serviceRegistry;

public ComponentRegistry(final ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}

public void addComponent(final ComponentConfiguration componentConfiguration) {
componentsByClass.put(componentConfiguration.getComponentClass(), new ComponentManagedReferenceFactory(componentConfiguration.getComponentDescription().getStartServiceName()));
}

public ManagedReference createInstance(final Class<?> componentClass) {
final ManagedReferenceFactory factory = componentsByClass.get(componentClass);
if (factory == null) {
return null;
}
return factory.getReference();
}

public ManagedReference createInstance(final Object instance) {
final ComponentManagedReferenceFactory factory = componentsByClass.get(instance.getClass());
if (factory == null) {
return null;
}
return factory.getReference(instance);
}

public Map<Class<?>, ComponentManagedReferenceFactory> getComponentsByClass() {
return Collections.unmodifiableMap(componentsByClass);
}

private static class ComponentManagedReference implements ManagedReference {

private final ComponentInstance instance;
private boolean destroyed;

public ComponentManagedReference(final ComponentInstance component) {
instance = component;
}

@Override
public synchronized void release() {
if (!destroyed) {
instance.destroy();
destroyed = true;
}
}

@Override
public Object getInstance() {
return instance.getInstance();
}
}

public class ComponentManagedReferenceFactory implements ManagedReferenceFactory {

private final ServiceName serviceName;
private volatile ServiceController<Component> component;

private ComponentManagedReferenceFactory(final ServiceName serviceName) {
this.serviceName = serviceName;
}

@Override
public ManagedReference getReference() {
if (component == null) {
synchronized (this) {
if (component == null) {
component = (ServiceController<Component>) serviceRegistry.getService(serviceName);
}
}
}
if (component == null) {
return null;
}
return new ComponentManagedReference(component.getValue().createInstance());
}


public ManagedReference getReference(final Object instance) {
if (component == null) {
synchronized (this) {
if (component == null) {
component = (ServiceController<Component>) serviceRegistry.getService(serviceName);
}
}
}
if (component == null) {
return null;
}
return new ComponentManagedReference(component.getValue().createInstance(instance));
}

public ServiceName getServiceName() {
return serviceName;
}
}
}
Loading

0 comments on commit 011cdd0

Please sign in to comment.