Permalink
Browse files

Reduce component instance overhead and add some checks that EJB metho…

…ds are public
  • Loading branch information...
1 parent 4652201 commit 44cb24a7679d23a52dff8f5ba19683e071defb4d @stuartwdouglas stuartwdouglas committed with bstansberry May 2, 2012
@@ -23,6 +23,7 @@
package org.jboss.as.ee.component;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.IdentityHashMap;
import java.util.Map;
@@ -70,13 +71,19 @@ public BasicComponentCreateService(final ComponentConfiguration componentConfigu
preDestroy = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPreDestroyInterceptors());
final IdentityHashMap<Method, InterceptorFactory> componentInterceptors = new IdentityHashMap<Method, InterceptorFactory>();
for (Method method : componentConfiguration.getDefinedComponentMethods()) {
- componentInterceptors.put(method, Interceptors.getChainedInterceptorFactory(componentConfiguration.getComponentInterceptors(method)));
+ if(requiresInterceptors(method, componentConfiguration)) {
+ componentInterceptors.put(method, Interceptors.getChainedInterceptorFactory(componentConfiguration.getComponentInterceptors(method)));
+ }
}
componentClass = componentConfiguration.getComponentClass();
this.componentInterceptors = componentInterceptors;
this.namespaceContextSelector = componentConfiguration.getNamespaceContextSelector();
}
+ protected boolean requiresInterceptors(final Method method, final ComponentConfiguration componentConfiguration) {
+ return Modifier.isPublic(method.getModifiers()) && componentConfiguration.getComponentDescription().isIntercepted();
+ }
+
/**
* {@inheritDoc}
*/
@@ -1,11 +1,37 @@
package org.jboss.as.ejb3;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.Set;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.ejb.ConcurrentAccessTimeoutException;
+import javax.ejb.EJBAccessException;
+import javax.ejb.EJBException;
+import javax.ejb.IllegalLoopbackException;
+import javax.ejb.LockType;
+import javax.ejb.NoMoreTimeoutsException;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.NoSuchEntityException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.ObjectNotFoundException;
+import javax.ejb.RemoveException;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.TimerHandle;
+import javax.interceptor.InvocationContext;
+import javax.naming.Context;
+import javax.transaction.xa.Xid;
+import javax.xml.stream.Location;
+
import org.jboss.as.controller.PathAddress;
import org.jboss.as.ee.component.Component;
import org.jboss.as.ee.component.ComponentCreateServiceFactory;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentInstance;
-import org.jboss.as.ejb3.cache.Identifiable;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
@@ -18,7 +44,6 @@
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
-import org.jboss.ejb.client.SessionID;
import org.jboss.invocation.InterceptorContext;
import org.jboss.logging.Cause;
import org.jboss.logging.Message;
@@ -28,32 +53,6 @@
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.StartException;
-import javax.ejb.ConcurrentAccessTimeoutException;
-import javax.ejb.EJBAccessException;
-import javax.ejb.EJBException;
-import javax.ejb.IllegalLoopbackException;
-import javax.ejb.LockType;
-import javax.ejb.NoMoreTimeoutsException;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.NoSuchEntityException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.ObjectNotFoundException;
-import javax.ejb.RemoveException;
-import javax.ejb.ScheduleExpression;
-import javax.ejb.TimerHandle;
-import javax.interceptor.InvocationContext;
-import javax.naming.Context;
-import javax.transaction.xa.Xid;
-import javax.xml.stream.Location;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.rmi.RemoteException;
-import java.util.Set;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
/**
* This module is using message IDs in the range 14100-14599. This file is using the subset 14300-14599 for
* non-logger messages. See http://community.jboss.org/docs/DOC-16810 for the full list of currently reserved
@@ -2066,6 +2065,12 @@
@Message(id = 14577, value = "Unsupported marshalling version: %d")
IllegalArgumentException unsupportedMarshallingVersion(int version);
+ @Message(id = 14578, value = "%s method %s must be public")
+ DeploymentUnitProcessingException ejbMethodMustBePublic(final String type, final Method method);
+
+ @Message(id = 14579, value = "EJB business method %s must be public")
+ DeploymentUnitProcessingException ejbBusinessMethodMustBePublic(final Method method);
+
// STOP!!! Don't add message ids greater that 14599!!! If you need more first check what EjbLogger is
// using and take more (lower) numbers from the available range for this module. If the range for the module is
// all used, go to https://community.jboss.org/docs/DOC-16810 and allocate another block for this subsystem
@@ -22,6 +22,18 @@
package org.jboss.as.ejb3.component;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.TimerService;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagementType;
+
import org.jboss.as.ee.component.BasicComponentCreateService;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ViewConfiguration;
@@ -39,17 +51,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
-import javax.ejb.TimerService;
-import javax.ejb.TransactionAttributeType;
-import javax.ejb.TransactionManagementType;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Jaikiran Pai
*/
@@ -116,10 +117,12 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
if (ejbComponentDescription.isTimerServiceApplicable()) {
Map<Method, InterceptorFactory> timeoutInterceptors = new IdentityHashMap<Method, InterceptorFactory>();
for (Method method : componentConfiguration.getDefinedComponentMethods()) {
- final InterceptorFactory interceptorFactory = Interceptors.getChainedInterceptorFactory(componentConfiguration.getAroundTimeoutInterceptors(method));
- timeoutInterceptors.put(method, interceptorFactory);
+ if ((ejbComponentDescription.getTimeoutMethod() != null && ejbComponentDescription.getTimeoutMethod().equals(method)) ||
+ ejbComponentDescription.getScheduleMethods().containsKey(method)) {
+ final InterceptorFactory interceptorFactory = Interceptors.getChainedInterceptorFactory(componentConfiguration.getAroundTimeoutInterceptors(method));
+ timeoutInterceptors.put(method, interceptorFactory);
+ }
}
-
this.timeoutInterceptors = timeoutInterceptors;
} else {
timeoutInterceptors = Collections.emptyMap();
@@ -130,19 +133,19 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
for (ViewConfiguration view : views) {
//TODO: Move this into a configurator
final EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
- final MethodIntf viewType = ejbView.getMethodIntf();
- for (Method method : view.getProxyFactory().getCachedMethods()) {
- // TODO: proxy factory exposes non-public methods, is this a bug in the no-interface view?
- if (!Modifier.isPublic(method.getModifiers()))
- continue;
- final Method componentMethod = getComponentMethod(componentConfiguration, method.getName(), method.getParameterTypes());
- if (componentMethod != null) {
- this.processTxAttr(ejbComponentDescription, viewType, componentMethod);
- } else {
- this.processTxAttr(ejbComponentDescription, viewType, method);
- }
+ final MethodIntf viewType = ejbView.getMethodIntf();
+ for (Method method : view.getProxyFactory().getCachedMethods()) {
+ // TODO: proxy factory exposes non-public methods, is this a bug in the no-interface view?
+ if (!Modifier.isPublic(method.getModifiers()))
+ continue;
+ final Method componentMethod = getComponentMethod(componentConfiguration, method.getName(), method.getParameterTypes());
+ if (componentMethod != null) {
+ this.processTxAttr(ejbComponentDescription, viewType, componentMethod);
+ } else {
+ this.processTxAttr(ejbComponentDescription, viewType, method);
}
}
+ }
}
this.timeoutMethod = ejbComponentDescription.getTimeoutMethod();
@@ -175,6 +178,19 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
this.shutDownInterceptorFactory = ejbComponentDescription.getShutDownInterceptorFactory();
}
+ @Override
+ protected boolean requiresInterceptors(final Method method, final ComponentConfiguration componentConfiguration) {
+ if(super.requiresInterceptors(method, componentConfiguration)) {
+ return true;
+ }
+ final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription)componentConfiguration.getComponentDescription();
+ if ((ejbComponentDescription.getTimeoutMethod() != null && ejbComponentDescription.getTimeoutMethod().equals(method)) ||
+ ejbComponentDescription.getScheduleMethods().containsKey(method)) {
+ return true;
+ }
+ return false;
+ }
+
private static Method getComponentMethod(final ComponentConfiguration componentConfiguration, final String name, final Class<?>[] parameterTypes) {
try {
return componentConfiguration.getComponentClass().getMethod(name, parameterTypes);
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.entity;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Collection;
import javax.ejb.Handle;
@@ -35,6 +36,7 @@
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.EjbLogger;
+import org.jboss.as.ejb3.EjbMessages;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.EjbHomeViewDescription;
import org.jboss.as.ejb3.component.MethodIntf;
@@ -109,7 +111,9 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
} else if (method.getName().startsWith("find")) {
final Method ejbFind = resolveEjbFinderMethod(componentConfiguration.getComponentClass(), deploymentReflectionIndex, method, componentConfiguration.getComponentName(), componentDescription.getPersistenceType());
-
+ if(!Modifier.isPublic(ejbFind.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMethodMustBePublic("ejbFind", ejbFind);
+ }
final EntityBeanHomeFinderInterceptorFactory interceptorFactory = createHomeFindInterceptorFactory(ejbFind, localHome);
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
@@ -147,10 +151,13 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("getHomeHandle") && method.getParameterTypes().length == 0) {
- // TODO: impl
+ //handled elsewhere
} else {
//we have a home business method
Method home = resolveEjbHomeBusinessMethod(componentConfiguration.getComponentClass(), deploymentReflectionIndex, method, componentConfiguration.getComponentName());
+ if(!Modifier.isPublic(home.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMethodMustBePublic("ejbHome", home);
+ }
configuration.addViewInterceptor(method, new EntityBeanHomeMethodInterceptorFactory(home), InterceptorOrder.View.COMPONENT_DISPATCHER);
}
}
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.entity;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
@@ -118,6 +119,9 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
if (componentMethod == null) {
handleNonBeanMethod(componentConfiguration, configuration, index, method);
} else {
+ if(!Modifier.isPublic(componentMethod.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbBusinessMethodMustBePublic(componentMethod);
+ }
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
}
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.session;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import javax.ejb.EJBException;
import javax.ejb.EJBLocalObject;
@@ -102,7 +103,11 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
handleIsIdenticalMethod(componentConfiguration, configuration, index, method);
} else {
final Method componentMethod = ClassReflectionIndexUtil.findMethod(index, componentConfiguration.getComponentClass(), MethodIdentifier.getIdentifierForMethod(method));
+
if (componentMethod != null) {
+ if(!Modifier.isPublic(componentMethod.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbBusinessMethodMustBePublic(componentMethod);
+ }
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
} else if(method.getDeclaringClass() != Object.class && method.getDeclaringClass() != WriteReplaceInterface.class) {
@@ -103,7 +103,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
@@ -115,7 +115,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
@@ -154,7 +154,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
@@ -95,7 +95,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
@@ -103,7 +103,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
@@ -139,7 +139,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
Oops, something went wrong.

0 comments on commit 44cb24a

Please sign in to comment.