javax.ejb.Timer类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中javax.ejb.Timer类的一些代码示例,展示了Timer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timer类的具体详情如下:
包路径:javax.ejb.Timer
类名称:Timer

Timer介绍

[英]The Timer interface contains information about a timer that was created through the EJB Timer Service
[中]计时器接口包含有关通过EJB计时器服务创建的计时器的信息

代码示例

代码示例来源:origin: javaee-samples/javaee7-samples

private void fireEvent(Timer timer) {
    pingEvent.fire(new Ping(timer.getInfo().toString()));
  }
}

代码示例来源:origin: wildfly/wildfly

private static void addNextTimeout(Timer timer, ModelNode timerNode, final String componentName) {
  try {
    final ModelNode detailNode = timerNode.get(NEXT_TIMEOUT);
    Date d = timer.getNextTimeout();
    if (d != null) {
      detailNode.set(d.getTime());
    }
  } catch (IllegalStateException e) {
    // ignore
  } catch (NoSuchObjectLocalException e) {
    // ignore
  } catch (EJBException e) {
    logTimerFailure(componentName, e);
  }
}

代码示例来源:origin: wildfly/wildfly

private static void addTimeRemaining(Timer timer, ModelNode timerNode, final String componentName) {
  try {
    final ModelNode detailNode = timerNode.get(TIME_REMAINING);
    long time = timer.getTimeRemaining();
    detailNode.set(time);
  } catch (IllegalStateException e) {
    // ignore
  } catch (NoSuchObjectLocalException e) {
    // ignore
  } catch (EJBException e) {
    logTimerFailure(componentName, e);
  }
}

代码示例来源:origin: be.fedict.eid-dss/eid-dss-model

public void cancelTimers() {
  Collection<Timer> timers = this.timerService.getTimers();
  for (Timer timer : timers) {
    if (timer.getInfo() != null) {
      if (timer.getInfo().equals(TIMER_ID)) {
        timer.cancel();
        LOG.debug("cancel timer: " + TIMER_ID);
      }
    }
  }
}

代码示例来源:origin: org.jboss.seam/jboss-seam

public Object call() 
  {
    timer.cancel();
    return null;
  }
});

代码示例来源:origin: be.fedict.eid-dss/eid-dss-model

/**
 * {@inheritDoc}
 */
@Timeout
public void timeOut(Timer timer) {
  String timerInfo = (String) timer.getInfo();
  LOG.debug("timeout: " + timerInfo);
  if (null == timerInfo) {
    LOG.error("no timer info ?? cancel timer");
    timer.cancel();
    return;
  }
  if (timerInfo.equals(TIMER_ID)) {
    cleanup();
    LOG.debug("Next cleanup: " + timer.getNextTimeout());
  }
}

代码示例来源:origin: com.evasion/Plugin-GeoLoc

timer.cancel();
      new ScheduleExpression().month(month).dayOfMonth(day).hour(hour).minute(min),
      new TimerConfig(Constante.IMPORT_TIMER_NAME, false));
  LOGGER.info("Last geoloc import: {}", timer.getNextTimeout());
} catch (IllegalArgumentException ex) {
  LOGGER.error("Illegal argument exception on " + Constante.IMPORT_TIMER_INTERVAL + " parameter", ex);

代码示例来源:origin: imixs/imixs-workflow

this.findTimer(id).cancel();
configItemCollection.replaceItemValue("statusmessage", msg);
if (timer.isCalendarTimer()) {
  configItemCollection.replaceItemValue("Schedule", timer.getSchedule().toString());
} else {
  configItemCollection.replaceItemValue("Schedule", "");

代码示例来源:origin: org.objectweb.jonas/jonas-ejb-2.1

/**
 * {@inheritDoc}
 */
public Timer restartTimer(JTimerHandleInfo info) {
  // get the Bean TimerService
  JTimerService timerservice = getJTimerService(info);
  // Recreate a Timer with recomputed initial duration.
  long newDuration = info.getDuration() + info.getStartTime() - System.currentTimeMillis();
  if (newDuration < 100) {
    newDuration = 100;
  }
  // assign new value.
  info.setDuration(newDuration);
  Timer timer = timerservice.createTimer(info.getDuration(),
                      info.getPeriod(),
                      info.getInfo());
  if (timer.getTimeRemaining() > 0) {
    TraceTimer.logger.log(BasicLevel.DEBUG, "timer restarted");
  } else {
    TraceTimer.logger.log(BasicLevel.DEBUG, "timer terminated");
    timer.cancel();
  }
  return timer;
}

代码示例来源:origin: imixs/imixs-workflow

/**
 * Updates the timer details of a running timer service. The method updates the
 * properties netxtTimeout and timeRemaining and store them into the timer
 * configuration.
 * 
 * @param configuration - the current scheduler configuration to be updated.
 */
public void updateTimerDetails(ItemCollection configuration) {
  if (configuration == null)
    return;// configuration;
  String id = configuration.getUniqueID();
  Timer timer;
  try {
    timer = this.findTimer(id);
    if (timer != null) {
      // load current timer details
      configuration.replaceItemValue("nextTimeout", timer.getNextTimeout());
      configuration.replaceItemValue("timeRemaining", timer.getTimeRemaining());
    } else {
      configuration.removeItem("nextTimeout");
      configuration.removeItem("timeRemaining");
    }
  } catch (Exception e) {
    logger.warning("unable to updateTimerDetails: " + e.getMessage());
    configuration.removeItem("nextTimeout");
    configuration.removeItem("timeRemaining");
  }
}

代码示例来源:origin: net.sf.tsl2nano/tsl2.nano.serviceaccess

/**
 * called by framework
 * 
 * @param timerHandle the timers handle
 */
public TimerHandle setTimerHandle(Timer timer) {
  assert this.timerHandle == null : "timer should only be set once!";
  this.timerHandle = timer.getHandle();
  nextStart = timer.getNextTimeout();
  LOG.info("creating timer ==> nextstart: " + nextStart
    + ", handle: "
    + timer.getHandle()
    + ", unique-name: "
    + getUniqueName());
  return timerHandle;
}

代码示例来源:origin: wildfly/wildfly

private static void addSchedule(Timer timer, ModelNode timerNode, final String componentName) {
  try {
    final ModelNode schedNode = timerNode.get(SCHEDULE);
    ScheduleExpression sched = timer.getSchedule();
    addScheduleDetailString(schedNode, sched.getYear(), YEAR);
    addScheduleDetailString(schedNode, sched.getMonth(), MONTH);
    addScheduleDetailString(schedNode, sched.getDayOfMonth(), DAY_OF_MONTH);
    addScheduleDetailString(schedNode, sched.getDayOfWeek(), DAY_OF_WEEK);
    addScheduleDetailString(schedNode, sched.getHour(), HOUR);
    addScheduleDetailString(schedNode, sched.getMinute(), MINUTE);
    addScheduleDetailString(schedNode, sched.getSecond(), SECOND);
    addScheduleDetailString(schedNode, sched.getTimezone(), TIMEZONE);
    addScheduleDetailDate(schedNode, sched.getStart(), START);
    addScheduleDetailDate(schedNode, sched.getEnd(), END);
  } catch (IllegalStateException e) {
    // ignore
  } catch (NoSuchObjectLocalException e) {
    // ignore
  } catch (EJBException e) {
    logTimerFailure(componentName, e);
  }
}

代码示例来源:origin: be.fedict.eid-trust-service/eid-trust-service-model

/**
 * {@inheritDoc}
 */
public void cancelTimers(String timerInfo) {
  Collection<Timer> timers = this.timerService.getTimers();
  for (Timer timer : timers) {
    if (timer.getInfo() != null) {
      if (timer.getInfo().equals(timerInfo)) {
        timer.cancel();
        LOG.debug("cancel timer: " + timerInfo);
      }
    }
  }
}

代码示例来源:origin: org.jbpm/jbpm-services-cdi

@PreDestroy
public void shutdown() {
  if (timer != null) {
    try {
      timer.cancel();
    } catch (NoSuchObjectLocalException e) {
      logger.debug("Timer {} is already canceled or expired", timer);
    }
  }
}

代码示例来源:origin: imixs/imixs-workflow

/**
 * Update the timer details of a running timer service. The method updates the
 * properties netxtTimeout and timeRemaining and store them into the timer
 * configuration.
 * 
 * @param configuration
 */
private ItemCollection updateTimerDetails(ItemCollection configuration) {
  if (configuration == null)
    return configuration;
  String id = configuration.getUniqueID();
  Timer timer;
  try {
    timer = this.findTimer(id);
    if (timer != null) {
      // load current timer details
      configuration.replaceItemValue("nextTimeout", timer.getNextTimeout());
      configuration.replaceItemValue("timeRemaining", timer.getTimeRemaining());
    } else {
      configuration.removeItem("nextTimeout");
      configuration.removeItem("timeRemaining");
    }
  } catch (Exception e) {
    logger.warning("unable to updateTimerDetails: " + e.getMessage());
    configuration.removeItem("nextTimeout");
    configuration.removeItem("timeRemaining");
  }
  return configuration;
}

代码示例来源:origin: eu.agilejava/snoop

public void register(final String clientId) {
  sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON());
  ScheduleExpression schedule = new ScheduleExpression();
  schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime());
  TimerConfig config = new TimerConfig();
  config.setPersistent(false);
  Timer timer = timerService.createCalendarTimer(schedule, config);
  LOGGER.config(() -> timer.getSchedule().toString());
}

代码示例来源:origin: IQSS/dataverse

public void removeHarvestTimers() {
  // Remove all the harvest timers, if exist: 
  //
  // (the logging messages below are set to level INFO; it's ok, 
  // since this code is only called on startup of the application, 
  // and it may be useful to know what existing timers were encountered).
  
  logger.log(Level.INFO,"Removing existing harvest timers..");
  
  int i = 1; 
  for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) {
         Timer timer = (Timer) it.next();
    logger.log(Level.INFO, "HarvesterService: checking timer "+i);
    
    if (timer.getInfo() instanceof HarvestTimerInfo) {
      logger.log(Level.INFO, "HarvesterService: timer "+i+" is a harvesting one; removing.");
      timer.cancel();
    }
    
    i++; 
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

@Timeout
  public void programmaticTimout(Timer timer) {
    pingEvent.fire(new Ping(timer.getInfo().toString()));
  }
}

代码示例来源:origin: org.jbpm/jbpm-services-ejb-impl

@PreDestroy
public void shutdown() {
  if (timer != null) {
    try {
      timer.cancel();
    } catch (NoSuchObjectLocalException e) {
      logger.debug("Timer {} is already canceled or expired", timer);
    }
  }
}

代码示例来源:origin: org.jboss.seam/jboss-seam

public Object call() 
  {
    return timer.getNextTimeout();
  }
});

相关文章