public void setStatefulTimeout(final StatefulTimeoutInfo statefulTimeout) {
this.statefulTimeout = statefulTimeout;
}
private void addStatefulInstanceAssociatingInterceptor(final EJBViewDescription view) {
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
//if this is a home interface we add a different interceptor
if (ejbViewDescription.getMethodIntf() == MethodIntf.HOME || ejbViewDescription.getMethodIntf() == MethodIntf.LOCAL_HOME) {
for (Method method : viewConfiguration.getProxyFactory().getCachedMethods()) {
if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) ||
method.getName().equals("equals") && method.getParameterTypes().length == 1 &&
method.getParameterTypes()[0] == Object.class) {
viewConfiguration.addClientInterceptor(method, ComponentTypeIdentityInterceptorFactory.INSTANCE, InterceptorOrder.Client.EJB_EQUALS_HASHCODE);
}
}
} else {
// interceptor factory return an interceptor which sets up the session id on component view instance creation
final InterceptorFactory sessionIdGeneratingInterceptorFactory = StatefulComponentSessionIdGeneratingInterceptor.FACTORY;
// add the session id generating interceptor to the start of the *post-construct interceptor chain of the ComponentViewInstance*
viewConfiguration.addClientPostConstructInterceptor(sessionIdGeneratingInterceptorFactory, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
for (Method method : viewConfiguration.getProxyFactory().getCachedMethods()) {
if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) ||
method.getName().equals("equals") && method.getParameterTypes().length == 1 &&
method.getParameterTypes()[0] == Object.class) {
viewConfiguration.addClientInterceptor(method, StatefulIdentityInterceptor.FACTORY, InterceptorOrder.Client.EJB_EQUALS_HASHCODE);
}
}
}
}
});
if (view.getMethodIntf() != MethodIntf.LOCAL_HOME && view.getMethodIntf() != MethodIntf.HOME) {
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
// add the instance associating interceptor to the *start of the invocation interceptor chain*
configuration.addViewInterceptor(StatefulComponentInstanceInterceptor.FACTORY, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
}