コード例 #1
0
  @Override
  public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);

    // if a session bean is participating in a transaction, it
    // is an error for a client to invoke the remove method
    // on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
      Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
      if (viewType != null) {
        // this means it is an EJB 2.x view
        // which is not allowed to remove while enrolled in a TX
        final StatefulTransactionMarker marker =
            context.getPrivateData(StatefulTransactionMarker.class);
        if (marker != null && !marker.isFirstInvocation()) {
          throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
        }
      }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
      throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
      // proceed
      invocationResult = context.proceed();
    } catch (Exception e) {
      // Exception caught during call to @Remove method. Handle it appropriately

      // If it's an application exception and if the @Remove method has set "retainIfException" to
      // true
      // then just throw back the exception and don't remove the session instance.
      if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod())
          && this.retainIfException) {
        throw e;
      }
      // otherwise, just remove it and throw back the original exception
      final StatefulSessionComponentInstance statefulComponentInstance =
          (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
      final SessionID sessionId = statefulComponentInstance.getId();
      statefulComponent.removeSession(sessionId);
      throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance =
        (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
  }
コード例 #2
0
 @Override
 protected void componentInstanceCreated(
     final BasicComponentInstance basicComponentInstance,
     final InterceptorFactoryContext context) {
   final StatefulSessionComponentInstance instance =
       (StatefulSessionComponentInstance) basicComponentInstance;
   final Map<Object, Object> serializableInterceptors = new HashMap<Object, Object>();
   for (final Object key : serialiableInterceptorContextKeys) {
     @SuppressWarnings("unchecked")
     final AtomicReference<ManagedReference> data =
         (AtomicReference<ManagedReference>) context.getContextData().get(key);
     if (data != null) {
       serializableInterceptors.put(key, data.get().getInstance());
     }
   }
   instance.setSerializableInterceptors(serializableInterceptors);
 }
コード例 #3
0
 protected SessionID getSessionIdOf(final InterceptorContext ctx) {
   final StatefulSessionComponentInstance instance =
       (StatefulSessionComponentInstance) ctx.getPrivateData(ComponentInstance.class);
   return instance.getId();
 }
コード例 #4
0
 @Override
 public void prePassivate(StatefulSessionComponentInstance instance) {
   instance.prePassivate();
 }
コード例 #5
0
 @Override
 public void postActivate(StatefulSessionComponentInstance instance) {
   instance.postActivate();
 }
コード例 #6
0
 @Override
 public void destroyInstance(StatefulSessionComponentInstance instance) {
   instance.destroy();
 }