Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef34fe
commit 3d9af7b
Showing
13 changed files
with
869 additions
and
0 deletions.
There are no files selected for viewing
438 changes: 438 additions & 0 deletions
438
plugin-container/src/main/java/org/jboss/forge/container/AddonUtil.java
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
plugin-container/src/main/java/org/jboss/forge/container/ServiceRegistryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.jboss.forge.container; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
import org.jboss.forge.container.event.Startup; | ||
import org.jboss.forge.container.services.ContainerServiceExtension; | ||
import org.jboss.forge.container.services.RemoteInstanceImpl; | ||
import org.jboss.forge.container.services.ServiceRegistry; | ||
import org.jboss.modules.Module; | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
* | ||
*/ | ||
public class ServiceRegistryManager | ||
{ | ||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public void registerServices(@Observes Startup event, BeanManager manager, | ||
ContainerServiceExtension extension, ServiceRegistry registry, AddonRegistry global) | ||
{ | ||
for (Class<?> serviceType : extension.services) | ||
{ | ||
registry.addService(serviceType, new RemoteInstanceImpl(manager, serviceType)); | ||
} | ||
|
||
global.addServices(Module.forClassLoader(Thread.currentThread().getContextClassLoader(), false), registry); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...container/src/main/java/org/jboss/forge/container/services/ContainerServiceExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2012 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.container.services; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentSkipListSet; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.Extension; | ||
import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
import javax.enterprise.inject.spi.ProcessInjectionPoint; | ||
import javax.enterprise.inject.spi.ProcessProducer; | ||
|
||
/** | ||
* One classloader/thread/weld container per plugin module. One primary executor container running, fires events to each | ||
* plugin-container. | ||
* | ||
* Multi-threaded bootstrap. Loads primary container, then attaches individual plugin containers as they come up. | ||
* | ||
* Ideas: | ||
* | ||
* Addons may depend on other addons beans, but these beans must be explicitly exposed via the {@link Remote} and | ||
* {@link Service} API. | ||
*/ | ||
public class ContainerServiceExtension implements Extension | ||
{ | ||
public Set<Class<?>> services = new HashSet<Class<?>>(); | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public void processRemotes(@Observes ProcessAnnotatedType<?> event) | ||
{ | ||
if (event.getAnnotatedType().getJavaClass().isAnnotationPresent(Remote.class)) | ||
{ | ||
event.setAnnotatedType(new RemoteAnnotatedType(event.getAnnotatedType())); | ||
services.add(event.getAnnotatedType().getJavaClass()); | ||
} | ||
} | ||
|
||
public void processRemoteInjectionPoint(@Observes ProcessInjectionPoint<?, ?> event) | ||
{ | ||
if (event.getInjectionPoint().getAnnotated().isAnnotationPresent(Service.class)) | ||
event.setInjectionPoint(new RemoteInjectionPoint(event.getInjectionPoint())); | ||
} | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public void processProducerHooks(@Observes ProcessProducer<?, ?> event, BeanManager manager) | ||
{ | ||
if (event.getAnnotatedMember().isAnnotationPresent(Remote.class)) | ||
event.setProducer(new RemoteProxyBeanProducer(event.getProducer())); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
plugin-container/src/main/java/org/jboss/forge/container/services/RemoteInstanceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.jboss.forge.container.services; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
public class RemoteInstanceImpl<R> implements RemoteInstance<R> | ||
{ | ||
private BeanManager manager; | ||
private Class<R> type; | ||
private CreationalContext<R> context; | ||
|
||
public RemoteInstanceImpl(BeanManager manager, Class<R> type) | ||
{ | ||
this.manager = manager; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public R get() | ||
{ | ||
Bean<R> bean = (Bean<R>) manager.resolve(manager.getBeans(type)); | ||
context = manager.createCreationalContext(bean); | ||
return (R) manager.getReference(bean, type, context); | ||
} | ||
|
||
@Override | ||
public void release(R instance) | ||
{ | ||
context.release(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ainer/src/main/java/org/jboss/forge/container/services/RemoteProxyBeanProducerMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jboss.forge.container.services; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Member; | ||
import java.lang.reflect.Method; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
import net.sf.cglib.proxy.Enhancer; | ||
|
||
import org.jboss.forge.container.AddonRegistry; | ||
import org.jboss.forge.container.exception.ContainerException; | ||
|
||
public class RemoteProxyBeanProducerMethod | ||
{ | ||
@Produces | ||
@Service | ||
public static Object produceRemoteService(AddonRegistry registry, InjectionPoint ip) | ||
{ | ||
if (ip == null) | ||
throw new IllegalStateException( | ||
"Cannot perform dynamic lookup of @" | ||
+ Remote.class.getName() | ||
+ " instances - they must be injected directly into a field or as a method/constructor parameter."); | ||
|
||
Member member = ip.getMember(); | ||
Class<?> type = null; | ||
if (member instanceof Method) | ||
{ | ||
type = ((Method) member).getReturnType(); | ||
} | ||
else if (member instanceof Field) | ||
{ | ||
type = ((Field) member).getType(); | ||
} | ||
else | ||
throw new ContainerException("Cannot handle producer for non-Field and non-Method member type"); | ||
|
||
return Enhancer.create((Class<?>) type, new RemoteServiceCallback(registry, type)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ntainer/src/test/java/test/org/jboss/forge/container/ContainerLifecycleEventObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.forge.container.event.PostStartup; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
@Singleton | ||
public class ContainerLifecycleEventObserver | ||
{ | ||
private boolean observedPostStartup; | ||
|
||
public void postStartup(@Observes PostStartup event) | ||
{ | ||
this.observedPostStartup = true; | ||
} | ||
|
||
public boolean isObservedPostStartup() | ||
{ | ||
return observedPostStartup; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
plugin-container/src/test/java/test/org/jboss/forge/container/ContainerLifecycleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import javax.enterprise.inject.spi.Extension; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.forge.container.services.ContainerServiceExtension; | ||
import org.jboss.forge.test.AbstractForgeTest; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
public class ContainerLifecycleTest extends AbstractForgeTest | ||
{ | ||
@Deployment | ||
public static JavaArchive getDeployment() | ||
{ | ||
return AbstractForgeTest.getDeployment().addAsServiceProvider(Extension.class, ContainerServiceExtension.class) | ||
.addClasses(ContainerLifecycleEventObserver.class); | ||
} | ||
|
||
@Inject | ||
private ContainerLifecycleEventObserver observer; | ||
|
||
@Test | ||
public void testContainerStartup() | ||
{ | ||
Assert.assertTrue(observer.isObservedPostStartup()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
plugin-container/src/test/java/test/org/jboss/forge/container/LocalService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import org.jboss.forge.container.services.Remote; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
@Remote | ||
public class LocalService | ||
{ | ||
public void invoke() | ||
{ | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ntainer/src/test/java/test/org/jboss/forge/container/LocalServicesImproperAccessTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import javax.enterprise.inject.spi.Extension; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.forge.container.services.ContainerServiceExtension; | ||
import org.jboss.forge.container.services.Service; | ||
import org.jboss.forge.test.AbstractForgeTest; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
public class LocalServicesImproperAccessTest extends AbstractForgeTest | ||
{ | ||
@Deployment | ||
public static JavaArchive getDeployment() | ||
{ | ||
return AbstractForgeTest.getDeployment().addAsServiceProvider(Extension.class, ContainerServiceExtension.class); | ||
} | ||
|
||
@Inject | ||
@Service | ||
private LocalService remoteLocal; | ||
|
||
@Test | ||
public void testRemoteInjectionOfLocalService() | ||
{ | ||
Assert.assertNotNull(remoteLocal); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testRemoteInvocationOfLocalServiceFails() | ||
{ | ||
Assert.assertNotNull(remoteLocal); | ||
remoteLocal.invoke(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
plugin-container/src/test/java/test/org/jboss/forge/container/LocalServicesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import javax.enterprise.inject.spi.Extension; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.forge.container.services.ContainerServiceExtension; | ||
import org.jboss.forge.container.services.Service; | ||
import org.jboss.forge.test.AbstractForgeTest; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
public class LocalServicesTest extends AbstractForgeTest | ||
{ | ||
@Deployment | ||
public static JavaArchive getDeployment() | ||
{ | ||
return AbstractForgeTest.getDeployment().addAsServiceProvider(Extension.class, ContainerServiceExtension.class) | ||
.addClasses(LocalService.class); | ||
} | ||
|
||
@Inject | ||
@Service | ||
private LocalService remoteLocal; | ||
|
||
@Inject | ||
private LocalService localLocal; | ||
|
||
@Test | ||
public void testLocalInjectionOfLocalService() | ||
{ | ||
Assert.assertNotNull(localLocal); | ||
} | ||
|
||
@Test | ||
public void testRemoteInjectionOfLocalService() | ||
{ | ||
Assert.assertNotNull(remoteLocal); | ||
} | ||
|
||
@Test | ||
public void testLocalInvocationOfLocalService() | ||
{ | ||
Assert.assertNotNull(localLocal); | ||
localLocal.invoke(); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testRemoteInvocationOfLocalServiceFails() | ||
{ | ||
Assert.assertNotNull(remoteLocal); | ||
remoteLocal.invoke(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
plugin-container/src/test/java/test/org/jboss/forge/container/RemoteService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package test.org.jboss.forge.container; | ||
|
||
import javax.enterprise.inject.Typed; | ||
|
||
import org.jboss.forge.container.services.Remote; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
@Remote | ||
@Typed() | ||
public class RemoteService | ||
{ | ||
public void invoke() | ||
{ | ||
} | ||
} |
Oops, something went wrong.