Java Code Examples for javax.ejb.Timer#getInfo()
The following examples show how to use
javax.ejb.Timer#getInfo() .
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 |
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 |
/** * 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: TimerServiceBean.java From development with Apache License 2.0 | 6 votes |
@TransactionAttribute(TransactionAttributeType.MANDATORY) public List<VOTimerInfo> getCurrentTimerExpirationDates() { List<VOTimerInfo> result = new ArrayList<VOTimerInfo>(); for (Timer timer : ParameterizedTypes.iterable(ctx.getTimerService() .getTimers(), Timer.class)) { Serializable info = timer.getInfo(); if (info != null && info instanceof TimerType) { TimerType type = (TimerType) info; long expirationTime = timer.getTimeRemaining() + System.currentTimeMillis(); VOTimerInfo timerInfo = new VOTimerInfo(); timerInfo.setTimerType(type.name()); timerInfo.setExpirationDate(new Date(expirationTime)); result.add(timerInfo); } } return result; }
Example 4
Source File: TimerServiceBean.java From development with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: BasicStatelessBean.java From tomee with Apache License 2.0 | 5 votes |
public void ejbTimeout(final Timer timer) { testAllowedOperations("ejbTimeout"); try { final String name = (String) timer.getInfo(); final TimerSync timerSync = (TimerSync) ejbContext.lookup("TimerSyncBeanBusinessRemote"); timerSync.countDown(name); } catch (final Exception e) { e.printStackTrace(); } }
Example 6
Source File: BasicSingletonBean.java From tomee with Apache License 2.0 | 5 votes |
public void ejbTimeout(final Timer timer) { testAllowedOperations("ejbTimeout"); try { final String name = (String) timer.getInfo(); final TimerSync timerSync = (TimerSync) ejbContext.lookup("TimerSyncBeanBusinessRemote"); timerSync.countDown(name); } catch (final Exception e) { e.printStackTrace(); } }
Example 7
Source File: TimerServiceBean.java From development with Apache License 2.0 | 4 votes |
/** * Handles the timers as soon as they are expired and the container invokes * this callback method. If the timer is not a periodic timer, it will also * be re-initialized. * * @param timer * The expired timer provided by the system. */ @Timeout public void handleTimer(Timer timer) { logger.logInfo(Log4jLogger.SYSTEM_LOG, LogMessageIdentifier.INFO_TIMER_TIMEOUT_RETRIEVED, String.valueOf(timer.getInfo())); // initial assumption on the outcome of the business logic invocation is // to that it failed boolean outcome = false; TimerType timerType = (TimerType) timer.getInfo(); long currentTime = System.currentTimeMillis(); // 1. create the timer processing data entry in the database, required // to avoid other nodes from handling the same task TimerProcessing processingData = createTimerProcessing(timerType, currentTime); // 2. handle the timer if (processingData != null) { try { switch (timerType) { case ORGANIZATION_UNCONFIRMED: outcome = accMgmt.removeOverdueOrganizations(currentTime); break; case RESTRICTED_SUBSCRIPTION_USAGE_PERIOD: outcome = subMgmt.expireOverdueSubscriptions(currentTime); break; case TENANT_PROVISIONING_TIMEOUT: outcome = subMgmt .notifyAboutTimedoutSubscriptions(currentTime); break; case BILLING_INVOCATION: outcome = bm.startBillingRun(currentTime); outcome = ps.chargeForOutstandingBills() && outcome; break; case DISCOUNT_END_CHECK: outcome = accMgmt .sendDiscountEndNotificationMail(currentTime); break; case INACTIVE_ON_BEHALF_USERS_REMOVAL: outcome = idServiceLocal.removeInactiveOnBehalfUsers(); break; case USER_NUM_CHECK: outcome = accMgmt.checkUserNum(); break; default: logger.logError(LogMessageIdentifier.ERROR_TIMER_TIMEOUT_FOR_UNKNOWN_TYPE); } } catch (Exception e) { logger.logError(Log4jLogger.SYSTEM_LOG, e, LogMessageIdentifier.ERROR_HANDLE_TIMER_FAILED); } // 3. update the created timer processing entry, update the duration // field and the success flag updateTimerProcessing(processingData, outcome); } else { logger.logInfo(Log4jLogger.SYSTEM_LOG, LogMessageIdentifier.INFO_TIMER_NO_HANDLING); } }
Example 8
Source File: FinishSystemCreationTimer.java From development with Apache License 2.0 | 4 votes |
@Timeout public void handleTimeout(Timer timer) { String lplatformId = (String) timer.getInfo(); CreateLPlatform lplatform = cache.findLplatform(lplatformId); lplatform.setLplatformStatus("NORMAL"); }
Example 9
Source File: MyTimerBean.java From training with MIT License | 4 votes |
@Timeout public void onTimeout(Timer timer) { Long businessId = (Long) timer.getInfo(); System.out.println("Processing businessId: " + businessId); flag = true; }
Example 10
Source File: Scheduler.java From tomee with Apache License 2.0 | 4 votes |
@Timeout private void timeout(Timer timer) { final EventConfig config = (EventConfig) timer.getInfo(); beanManager.fireEvent(config.getEvent(), config.getQualifiers()); }
Example 11
Source File: InitialIntervalTimerTest.java From tomee with Apache License 2.0 | 4 votes |
@Timeout public void timeout(final Timer timer) { final long actual = System.currentTimeMillis() - ((Long) timer.getInfo() + 1000 * ok + 3000); assertEquals(0, actual, 500); ok++; }