Java Code Examples for javax.ejb.Timer#cancel()

The following examples show how to use javax.ejb.Timer#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
boolean isTimerCreated(TimerType timerType, TimerService timerService) {
    for (Timer timer : ParameterizedTypes.iterable(
            timerService.getTimers(), Timer.class)) {
        TimerType tType = (TimerType) timer.getInfo();
        if ((TimerType.BILLING_INVOCATION.equals(tType) && TimerType.BILLING_INVOCATION
                .equals(timerType))
                || (TimerType.DISCOUNT_END_CHECK.equals(tType) && TimerType.DISCOUNT_END_CHECK
                        .equals(timerType))) {
            long currentTime = System.currentTimeMillis();
            if (timer.getNextTimeout().getTime() - currentTime > 0) {
                return true;
            } else {
                timer.cancel();
            }
        }
    }
    return false;
}
 
Example 2
Source File: TimerServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Determines all currently queued timers and cancel timer with target type.
 * 
 * @param timerService
 *            The timer service.
 * @param timerType
 *            The timer type.
 */
private void cancelObsoleteTimer(TimerService timerService,
        TimerType timerType) {

    for (Timer timer : ParameterizedTypes.iterable(
            timerService.getTimers(), Timer.class)) {
        Serializable info = timer.getInfo();
        if (info != null && info instanceof TimerType && timerType == info) {
            TimerType type = (TimerType) info;
            timer.cancel();
            logger.logInfo(Log4jLogger.SYSTEM_LOG,
                    LogMessageIdentifier.INFO_TIMER_REMOVED,
                    String.valueOf(type));
        }
    }

}
 
Example 3
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public void stop(Timer timer) {
    String stopMessage = new StringBuilder("==========================\n")
            .append("Bot stopped at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(stopMessage);
    timer.cancel();
}
 
Example 4
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public void stop(Timer timer) {
    String stopMessage = new StringBuilder("==========================\n")
            .append("Bot stopped at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(stopMessage);
    timer.cancel();
}
 
Example 5
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public void stop(Timer timer) {
    String stopMessage = new StringBuilder("==========================\n")
            .append("Bot stopped at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(stopMessage);
    timer.cancel();
}
 
Example 6
Source File: TimerServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Determines all currently queued timers and cancels them.
 */
private void cancelAllObsoleteTimer() {
    for (Timer timer : ParameterizedTypes.iterable(ctx.getTimerService()
            .getTimers(), Timer.class)) {
        Serializable info = timer.getInfo();
        if (info != null && info instanceof TimerType) {
            TimerType type = (TimerType) info;
            timer.cancel();
            logger.logInfo(Log4jLogger.SYSTEM_LOG,
                    LogMessageIdentifier.INFO_TIMER_REMOVED,
                    String.valueOf(type));
        }
    }

}
 
Example 7
Source File: APPTimerServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void cancelTimers() {
    Collection<Timer> timers = timerService.getTimers();
    for (Timer th : timers) {
        if (APP_TIMER_INFO.equals(th.getInfo())) {
            th.cancel();
            return;
        }
    }
}
 
Example 8
Source File: EntityContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void cancelTimers(final ThreadContext threadContext) {
    final BeanContext beanContext = threadContext.getBeanContext();
    final Object primaryKey = threadContext.getPrimaryKey();

    // if we have a real timerservice, stop all timers. Otherwise, ignore...
    if (primaryKey != null) {
        final EjbTimerService timerService = beanContext.getEjbTimerService();
        if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
            for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
                timer.cancel();
            }
        }
    }
}
 
Example 9
Source File: CmpContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void cancelTimers(final ThreadContext threadContext) {
    final BeanContext beanContext = threadContext.getBeanContext();
    final Object primaryKey = threadContext.getPrimaryKey();

    // stop timers
    if (primaryKey != null && beanContext.getEjbTimerService() != null) {
        final EjbTimerService timerService = beanContext.getEjbTimerService();
        if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
            for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
                timer.cancel();
            }
        }
    }
}
 
Example 10
Source File: Business.java    From training with MIT License 4 votes vote down vote up
@PreDestroy
public void stopTimer() {
	for (Timer timer : timerService.getTimers()) {
		timer.cancel();
	}
}
 
Example 11
Source File: AutomaticSellerService.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
private void cancelTimers() {
    for (Timer timer : timerService.getTimers()) {
        timer.cancel();
    }
}
 
Example 12
Source File: AutomaticSellerService.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
private void cancelTimers() {
    for (Timer timer : timerService.getTimers()) {
        timer.cancel();
    }
}
 
Example 13
Source File: AutomaticSellerService.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
private void cancelTimers() {
    for (Timer timer : timerService.getTimers()) {
        timer.cancel();
    }
}
 
Example 14
Source File: AutomaticSellerService.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
private void cancelTimers() {
    for (Timer timer : timerService.getTimers()) {
        timer.cancel();
    }
}