Esempio n. 1
0
  @Override
  public synchronized void start(final StartContext context) throws StartException {

    logger.debug("Starting timerservice for timedObjectId: " + getInvoker().getTimedObjectId());
    final EJBComponent component = ejbComponentInjectedValue.getValue();
    this.transactionManager = component.getTransactionManager();
    this.tsr = component.getTransactionSynchronizationRegistry();
    final TimedObjectInvoker invoker = timedObjectInvoker.getValue();
    if (invoker == null) {
      throw MESSAGES.invokerIsNull();
    }
    final List<ScheduleTimer> timers = new ArrayList<ScheduleTimer>();

    for (Map.Entry<Method, List<AutoTimer>> entry : autoTimers.entrySet()) {
      for (AutoTimer timer : entry.getValue()) {
        timers.add(
            new ScheduleTimer(
                entry.getKey(), timer.getScheduleExpression(), timer.getTimerConfig()));
      }
    }
    // restore the timers
    started = true;
    restoreTimers(timers);
    // register ourselves to the TimerServiceRegistry (if any)
    if (timerServiceRegistry != null) {
      timerServiceRegistry.registerTimerService(this);
    }
  }
Esempio n. 2
0
 public void invokeTimeoutMethod(final Timer timer) {
   final EJBComponent component = (EJBComponent) getComponent();
   final Method method = component.getTimeoutMethod();
   if (method == null) {
     throw MESSAGES.componentTimeoutMethodNotSet(component.getComponentName());
   }
   invokeTimeoutMethod(method, timer);
 }
 @Override
 public Object getInstance() {
   // get the current invocation context and the EJBComponent out of it
   final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
   final EJBComponent ejbComponent =
       (EJBComponent) currentInvocationContext.getPrivateData(Component.class);
   if (ejbComponent == null) {
     throw MESSAGES.failToGetEjbComponent(currentInvocationContext);
   }
   return ejbComponent.getTimerService();
 }
 @Override
 public void setRollbackOnly() throws IllegalStateException {
   // NOT_SUPPORTED and NEVER will not have a transaction context, so we can ignore those
   if (getCurrentTransactionAttribute() == TransactionAttributeType.SUPPORTS) {
     throw MESSAGES.setRollbackOnlyNotAllowedForSupportsTxAttr();
   }
   super.setRollbackOnly();
 }
 @Override
 public void setRollbackOnly() throws IllegalStateException {
   // NOT_SUPPORTED and NEVER will not have a transaction context, so we can ignore those
   if (getCurrentTransactionAttribute() == TransactionAttributeType.SUPPORTS) {
     throw new IllegalStateException(
         "EJB 3.1 FR 13.6.2.9 getRollbackOnly is not allowed with SUPPORTS attribute");
   }
   super.setRollbackOnly();
 }
 private EjbComponentInstance acquireInstance() {
   final EjbComponentInstance instance;
   if (pool != null) {
     instance = pool.get();
   } else {
     instance = (EjbComponentInstance) ejbComponent.createInstance();
   }
   return instance;
 }
Esempio n. 7
0
  @Override
  public synchronized void start(final StartContext context) throws StartException {

    if (logger.isDebugEnabled()) {
      logger.debug("Starting timerservice for timedObjectId: " + getInvoker().getTimedObjectId());
    }
    final EJBComponent component = ejbComponentInjectedValue.getValue();
    this.transactionManager = component.getTransactionManager();
    this.tsr = component.getTransactionSynchronizationRegistry();
    final TimedObjectInvoker invoker = timedObjectInvoker.getValue();
    if (invoker == null) {
      throw EjbLogger.ROOT_LOGGER.invokerIsNull();
    }

    started = true;
    // register ourselves to the TimerServiceRegistry (if any)
    if (timerServiceRegistry != null) {
      timerServiceRegistry.registerTimerService(this);
    }
    listenerHandle =
        timerPersistence
            .getValue()
            .registerChangeListener(getInvoker().getTimedObjectId(), new TimerRefreshListener());
  }
 @Override
 public void callTimeout(final TimerImpl timer, final Method timeoutMethod) throws Exception {
   final EjbComponentInstance instance = acquireInstance();
   boolean discarded = false;
   try {
     instance.invokeTimeoutMethod(timeoutMethod, timer);
   } catch (Exception ex) {
     // Detect app exception
     if (ejbComponent.getApplicationException(ex.getClass(), timeoutMethod) != null) {
       // it's an application exception, just throw it back.
       throw ex;
     }
     if (ex instanceof ConcurrentAccessTimeoutException
         || ex instanceof ConcurrentAccessException) {
       throw ex;
     }
     if (ex instanceof RuntimeException || ex instanceof RemoteException) {
       discarded = true;
       if (pool != null) {
         pool.discard(instance);
       }
     }
     throw ex;
   } catch (final Error e) {
     discarded = true;
     if (pool != null) {
       pool.discard(instance);
     }
     throw e;
   } catch (final Throwable t) {
     discarded = true;
     if (pool != null) {
       pool.discard(instance);
     }
     throw new RuntimeException(t);
   } finally {
     if (!discarded) {
       releaseInstance(instance);
     }
   }
 }
 @Override
 public ClassLoader getClassLoader() {
   return ejbComponent.getComponentClass().getClassLoader();
 }
 @Override
 public void callTimeout(final TimerImpl timer) throws Exception {
   callTimeout(timer, ejbComponent.getTimeoutMethod());
 }
 @Override
 public String getTimedObjectId() {
   return deploymentString + "." + ejbComponent.getComponentName();
 }
 /**
  * Returns true if the passed <code>exceptionClass</code> is an application exception. Else
  * returns false.
  *
  * @param ejbComponent The EJB component
  * @param exceptionClass The exception class
  * @return
  */
 private boolean isApplicationException(
     final EJBComponent ejbComponent, final Class<?> exceptionClass, final Method invokedMethod) {
   return ejbComponent.getApplicationException(exceptionClass, invokedMethod) != null;
 }