當前位置: 首頁>>代碼示例>>Java>>正文


Java Timer類代碼示例

本文整理匯總了Java中javax.ejb.Timer的典型用法代碼示例。如果您正苦於以下問題:Java Timer類的具體用法?Java Timer怎麽用?Java Timer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timer類屬於javax.ejb包,在下文中一共展示了Timer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTimerWithPeriod

import javax.ejb.Timer; //導入依賴的package包/類
void createTimerWithPeriod(TimerService timerService, TimerType timerType,
        long timerOffset, Period period) {
    if (isTimerCreated(timerType, timerService)) {
        return;
    }
    TimerConfig config = new TimerConfig();
    config.setInfo(timerType);
    Date startDate = getDateForNextTimerExpiration(period, timerOffset);
    ScheduleExpression schedleExpression = getExpressionForPeriod(period,
            startDate);
    Timer timer = timerService.createCalendarTimer(schedleExpression,
            config);
    Date nextStart = timer.getNextTimeout();
    SimpleDateFormat sdf = new SimpleDateFormat();
    logger.logInfo(Log4jLogger.SYSTEM_LOG,
            LogMessageIdentifier.INFO_TIMER_CREATED,
            String.valueOf(timerType), sdf.format(nextStart));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:TimerServiceBean.java

示例2: fireUpTimer

import javax.ejb.Timer; //導入依賴的package包/類
public BatchJobConfiguration fireUpTimer(BatchJobConfiguration jobConfig) {
    if (jobConfig.isActive()) {
        logger.debug("Configured batch job " + jobConfig.getType().getDisplayName());
        TimerConfig timerConf = new TimerConfig(jobConfig, false);
        String[] splittedCronJob = jobConfig.getCronJobExpression().split(" ");
        ScheduleExpression schedExp = new ScheduleExpression();
        schedExp.second(splittedCronJob[0]);
        schedExp.minute(splittedCronJob[1]);
        schedExp.hour(splittedCronJob[2]);
        schedExp.dayOfMonth(splittedCronJob[3]);
        schedExp.month(splittedCronJob[4]);
        schedExp.year(splittedCronJob[5]);
        schedExp.dayOfWeek(splittedCronJob[6]);
        Timer timer = timerService.createCalendarTimer(schedExp, timerConf);
        jobConfig.setNextTimeout(timer.getNextTimeout());
        jobConfig = batchJobConfigurationDAO.update(jobConfig);
    }
    return jobConfig;
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:20,代碼來源:BatchJobService.java

示例3: programmaticTimeout

import javax.ejb.Timer; //導入依賴的package包/類
public void programmaticTimeout() {
	logger.info("TimerEJB: programmatic timeout occurred");
	timeoutDone = false;
	long duration = 60;
	Timer timer = timerService.createSingleActionTimer(duration, new TimerConfig());
	timer.getInfo();
	try {
		timer.getSchedule();
	} catch (IllegalStateException e) {
		logger.log(SEVERE, "it is not a scheduler", e);
	}
	TimerHandle timerHandle = timer.getHandle();
	timerHandle.getTimer();
	timer.isCalendarTimer();
	timer.isPersistent();
	timer.getTimeRemaining();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:18,代碼來源:TimerBean.java

示例4: initTimers_internal

import javax.ejb.Timer; //導入依賴的package包/類
/**
 * Initialize the timer for polling for the services
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void initTimers_internal() {
    Collection<Timer> timers = timerService.getTimers();
    boolean appTimerExist = false;
    for (Timer timerAPP : timers) {
    	if (APP_TIMER_INFO.equals(timerAPP.getInfo())) {
    		appTimerExist = true;
    	}
    }
    if (!appTimerExist) {
        logger.info("Timer create.");
        try {
            String timerIntervalSetting = configService
                    .getProxyConfigurationSetting(
                            PlatformConfigurationKey.APP_TIMER_INTERVAL);
            long interval = Long.parseLong(timerIntervalSetting);
            timerService.createTimer(0, interval, APP_TIMER_INFO);
        } catch (ConfigurationException e) {
            timerService.createTimer(0, DEFAULT_TIMER_INTERVAL,
                    APP_TIMER_INFO);
            logger.info(
                    "Timer interval not set, switch to default 15 sec.");
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:29,代碼來源:APPTimerServiceBean.java

示例5: setTimer

import javax.ejb.Timer; //導入依賴的package包/類
@PostConstruct
public void setTimer() {
	Collection<Timer> timers = timerService.getTimers();
	for (Timer timerVM : timers) {
		if (VM_TIMER_INFO.equals(timerVM.getInfo())) {
			timerVM.cancel();
		}
	}
	logger.info("Timer for subscription VMs will be created.");
	try {
		String timerIntervalSetting = configService
				.getProxyConfigurationSetting(PlatformConfigurationKey.APP_TIMER_REFRESH_SUBSCRIPTIONS);
		long interval = Long.parseLong(timerIntervalSetting);
		timerService.createTimer(0, interval, VM_TIMER_INFO);
		// timerService.createIntervalTimer(new Date(), interval,
		// new TimerConfig());
	} catch (ConfigurationException e) {
		timerService.createTimer(0, DEFAULT_TIMER_INTERVAL, VM_TIMER_INFO);
		logger.info("Timer interval for refreshing subcription VMs not set, switch to default 10 min.");
	}
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:22,代碼來源:TimerRefreshSubscriptions.java

示例6: execute

import javax.ejb.Timer; //導入依賴的package包/類
@Timeout
public void execute(Timer timer) {
	if (!VM_TIMER_INFO.equals(timer.getInfo())) {
		return;
	}
	List<ServiceInstance> instances = serviceInstanceService.getInstances();
	for (ServiceInstance serviceInstance : instances) {
		try {
			final APPlatformController controller = APPlatformControllerFactory
					.getInstance(serviceInstance.getControllerId());

			int vmsNumber = controller.getServersNumber(serviceInstance.getInstanceId(),
					serviceInstance.getSubscriptionId(), serviceInstance.getOrganizationId());

			ServiceInstance updatedServiceInstance = serviceInstanceService.updateVmsNumber(serviceInstance,
					vmsNumber);
			serviceInstanceService.notifySubscriptionAboutVmsNumber(updatedServiceInstance);
		} catch (APPlatformException e) {
			logger.error("Subscription cannot be notified about VMs number: ", e);
		}
	}
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:23,代碼來源:TimerRefreshSubscriptions.java

示例7: setUp

import javax.ejb.Timer; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    testElm = new Initializer();
    controllerAccess = Mockito.mock(ControllerAccess.class);
    Mockito.when(controllerAccess.getControllerId()).thenReturn(
            "ess.common");
    testElm.setControllerAccess(controllerAccess);

    timerService = Mockito.mock(TimerService.class);
    Collection<Timer> timers = new ArrayList<Timer>();
    Mockito.when(timerService.getTimers()).thenReturn(timers);

    // Set timer resource
    Field field = testElm.getClass().getDeclaredField("timerService");
    field.setAccessible(true);
    field.set(testElm, timerService);

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:InitializerTest.java

示例8: isTimerCreated

import javax.ejb.Timer; //導入依賴的package包/類
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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:TimerServiceBean.java

示例9: cancelObsoleteTimer

import javax.ejb.Timer; //導入依賴的package包/類
/**
 * 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));
        }
    }

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:TimerServiceBean.java

示例10: getCurrentTimerExpirationDates

import javax.ejb.Timer; //導入依賴的package包/類
@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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:21,代碼來源:TimerServiceBean.java

示例11: handleTimer_handleTimerPeriodicVerifyNoReinitialization

import javax.ejb.Timer; //導入依賴的package包/類
@Test
public void handleTimer_handleTimerPeriodicVerifyNoReinitialization()
        throws Exception {
    TimerStub timer = new TimerStub();
    TimerType timerType = TimerType.ORGANIZATION_UNCONFIRMED;
    timer.setInfo(timerType);
    tss.createTimer(new Date(), timerType);

    tm.handleTimer(timer);

    Iterable<Timer> timers = ParameterizedTypes.iterable(tss.getTimers(),
            Timer.class);
    List<Timer> timerList = new ArrayList<Timer>();
    for (Timer t : timers) {
        timerList.add(t);
    }

    assertEquals(
            "No additional timer must have been initialized, as the present one is already periodid with a fix interval",
            1, timerList.size());
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:TimerServiceBean2Test.java

示例12: initTimers_getCurrentTimerExpirationDates

import javax.ejb.Timer; //導入依賴的package包/類
@Test
public void initTimers_getCurrentTimerExpirationDates()
        throws ValidationException {

    tss = new TimerServiceStub() {
        @Override
        public Timer createTimer(Date arg0, Serializable arg1)
                throws IllegalArgumentException, IllegalStateException,
                EJBException {
            initTimer((TimerType) arg1, arg0);
            getTimers().add(timer);
            return null;
        }
    };
    when(ctx.getTimerService()).thenReturn(tss);
    List<VOTimerInfo> expirationDates;
    tm.initTimers();
    expirationDates = tm.getCurrentTimerExpirationDates();
    tm.initTimers();
    assertEquals(7, expirationDates.size());
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:TimerServiceBean2Test.java

示例13: initTimers_nextExpirationDateNegative

import javax.ejb.Timer; //導入依賴的package包/類
@Test(expected = ValidationException.class)
public void initTimers_nextExpirationDateNegative()
        throws ValidationException {

    tss = new TimerServiceStub() {
        @Override
        public Timer createTimer(Date arg0, Serializable arg1)
                throws IllegalArgumentException, IllegalStateException,
                EJBException {
            initTimer((TimerType) arg1, arg0);
            getTimers().add(timer);
            return null;
        }
    };
    when(ctx.getTimerService()).thenReturn(tss);
    cfs.setConfigurationSetting(
            ConfigurationKey.TIMER_INTERVAL_ORGANIZATION,
            "9223372036854775807");

    tm.initTimers();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:TimerServiceBean2Test.java

示例14: initTimers_nextExpirationDateNegative_userCount

import javax.ejb.Timer; //導入依賴的package包/類
@Test(expected = ValidationException.class)
public void initTimers_nextExpirationDateNegative_userCount()
        throws ValidationException {
    // given
    tss = new TimerServiceStub() {
        @Override
        public Timer createTimer(Date arg0, Serializable arg1)
                throws IllegalArgumentException, IllegalStateException,
                EJBException {
            initTimer((TimerType) arg1, arg0);
            getTimers().add(timer);
            return null;
        }
    };
    when(ctx.getTimerService()).thenReturn(tss);
    cfs.setConfigurationSetting(ConfigurationKey.TIMER_INTERVAL_USER_COUNT,
            "9223372036854775807");
    // when
    tm.initTimers();

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:TimerServiceBean2Test.java

示例15: timeout

import javax.ejb.Timer; //導入依賴的package包/類
@Timeout
public void timeout(Timer timer) 
{
  LOGGER.info("timeout() - (ENTER)");
  
  Properties policy = policyProvider.getProperties(POLICY_SUBJECT);
  int ttlSession = policyProvider.getIntProperty(policy, "account.maxSessionDuration", 0);

  if (ttlSession > 0) {
    Date startedBefore = new Date(System.currentTimeMillis() - 
                           (ttlSession * ONE_SECOND));
    LOGGER.info("startedBefore: " + startedBefore);
    
    List<String> expired = findExpiredSessions(startedBefore);
    for (String sessionId : expired) {
      
      LOGGER.info("deleteing expired session: " + sessionId);
      deleteSession(sessionId);
    }
  }
  
  LOGGER.info("timeout() - (LEAVE)");
}
 
開發者ID:UnionVMS,項目名稱:USM,代碼行數:24,代碼來源:InMemorySessionDao.java


注:本文中的javax.ejb.Timer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。