コード例 #1
0
public class IdlePointCron extends HttpServlet {
  /** */
  private static final long serialVersionUID = 1L;

  private static final Logger log = Logger.getLogger(IdlePointCron.class.getName());

  @Override
  @SuppressWarnings(Const.WARNING_UNCHECKED)
  public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {
    // PrintWriter out;
    // out = resp.getWriter();
    try {
      processGet();
    } catch (NimbitsException e) {
      LogHelper.logException(IdlePointCron.class, e);
    }
  }

  protected static int processGet() throws NimbitsException {
    final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities();
    log.info("Processing " + points.size() + " potentially idle points");
    for (final Entity p : points) {
      try {
        checkIdle((Point) p);
      } catch (NimbitsException e) {

        LogHelper.logException(IdlePointCron.class, e);
      }
    }
    return points.size();
  }

  protected static boolean checkIdle(final Point p) throws NimbitsException {
    final Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, p.getIdleSeconds() * -1);
    boolean retVal = false;
    final List<Entity> result =
        EntityServiceFactory.getInstance()
            .getEntityByKey(
                UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user);
    if (!result.isEmpty()) {
      final User u = (User) result.get(0);
      final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p);
      if (p.getIdleSeconds() > 0
          && !v.isEmpty()
          && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis()
          && !p.getIdleAlarmSent()) {
        p.setIdleAlarmSent(true);
        EntityServiceFactory.getInstance().addUpdateEntity(u, p);
        // PointServiceFactory.getInstance().updatePoint(u, p);
        final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert);
        SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va);
        retVal = true;
      }
    }
    return retVal;
  }
}
コード例 #2
0
  protected static int processGet() throws NimbitsException {
    final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities();
    log.info("Processing " + points.size() + " potentially idle points");
    for (final Entity p : points) {
      try {
        checkIdle((Point) p);
      } catch (NimbitsException e) {

        LogHelper.logException(IdlePointCron.class, e);
      }
    }
    return points.size();
  }