Java Code Examples for org.apache.commons.lang.time.DateUtils#addSeconds()

The following examples show how to use org.apache.commons.lang.time.DateUtils#addSeconds() . 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: SendMessageTask.java    From qmq with Apache License 2.0 6 votes vote down vote up
@Override
public Void call() {
    LOG.info("{} start...", dataSourceInfo.getUrl());
    stop = false;
    String name = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName(dataSourceInfo.getUrl());
        long begin = System.currentTimeMillis();
        while ((!isStop() && !timeout(begin))) {
            Date since = DateUtils.addSeconds(new Date(), -DEFAULT_TIME_INTEL);
            List<MsgQueue> errorMessages = messageClientStore.findErrorMsg(this.dataSource, since);
            if (errorMessages == null || errorMessages.isEmpty()) {
                break;
            }
            logRemainMsg(errorMessages);
            processErrorMessages(errorMessages, since);
        }
    } catch (Exception e) {
        throw new RuntimeException("process message error, url: " + dataSourceInfo.getUrl(), e);
    } finally {
        stop = true;
        Thread.currentThread().setName(name);
        LOG.info("{} finish", dataSourceInfo.getUrl());
    }
    return null;
}
 
Example 2
Source File: ManageStartEndTime.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void run() {
  synchronized (ManageStartEndTime.class) {
    startDate = DateUtils.addSeconds(startDate, UPDATE_TIME_IN_SECONDS);
    endDate = DateUtils.addHours(startDate, 1);
  }
}
 
Example 3
Source File: SchedulerCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
private boolean fireCronTrigger(TriggerKey triggerKey, JobDetail jobDetail, String cron, boolean replace, Map<String, Object> dataMap) {
    try {
        boolean isExists = clusterScheduler.checkExists(triggerKey);
        if (isExists) {
            if (replace) {
                logger.warn("replace trigger={}:{} ", triggerKey.getName(), triggerKey.getGroup());
                clusterScheduler.unscheduleJob(triggerKey);
            } else {
                logger.info("exist trigger={}:{} ", triggerKey.getName(), triggerKey.getGroup());
                return false;
            }
        }
        Date startDate = DateUtils.addSeconds(new Date(), 20);
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(triggerKey)
                .forJob(jobDetail)
                .withSchedule(
                        CronScheduleBuilder.cronSchedule(cron)
                        .withMisfireHandlingInstructionDoNothing()// 忽略misfire处理
                )
                .startAt(startDate)
                .build();
        if (dataMap != null && dataMap.size() > 0) {
            trigger.getJobDataMap().putAll(dataMap);
        }
        clusterScheduler.scheduleJob(trigger);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return false;
    }
    return true;
}
 
Example 4
Source File: CibaRequestService.java    From oxAuth with MIT License 5 votes vote down vote up
/**
 * Uses request data and expiration sent by the client and save request data in database.
 * @param request Object containing information related to the request.
 * @param expiresIn Expiration time that end user has to answer.
 */
public void persistRequest(CibaRequestCacheControl request, int expiresIn) {
    Date expirationDate = DateUtils.addSeconds(new Date(), expiresIn);

    String authReqId = request.getAuthReqId();
    CIBARequest cibaRequest = new CIBARequest();
    cibaRequest.setDn("authReqId=" + authReqId + "," + this.cibaBaseDn());
    cibaRequest.setAuthReqId(authReqId);
    cibaRequest.setClientId(request.getClient().getClientId());
    cibaRequest.setExpirationDate(expirationDate);
    cibaRequest.setCreationDate(new Date());
    cibaRequest.setStatus(CibaRequestStatus.PENDING.getValue());
    cibaRequest.setUserId(request.getUser().getUserId());
    entryManager.persist(cibaRequest);
}
 
Example 5
Source File: MysqlMethodInvocationHandler.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
private SQLExpr invokeAddDate(SQLMethodInvokeExpr expr, boolean negative) throws SQLNonTransientException {
    List<SQLExpr> parameters = expr.getParameters();
    if (parameters.size() != 2) {
        throwSyntaxError(expr);
    }
    SQLExpr p1 = parameters.get(0);
    SQLExpr p2 = parameters.get(1);
    if (p1 instanceof SQLMethodInvokeExpr) {
        p1 = doInvoke((SQLMethodInvokeExpr) p1);
    }
    if (p1 instanceof SQLCharExpr) {
        String time = ((SQLCharExpr) p1).getText();
        Integer delta = null;
        String unit = null;
        if (p2 instanceof SQLIntegerExpr) {
            delta = (Integer) ((SQLIntegerExpr) p2).getNumber();
            unit = "DAY";
        } else if (p2 instanceof MySqlIntervalExpr) {
            SQLIntegerExpr value = (SQLIntegerExpr) ((MySqlIntervalExpr) p2).getValue();
            delta = (Integer) value.getNumber();
            unit = ((MySqlIntervalExpr) p2).getUnit().name();
        } else {
            throwSyntaxError(p2);
        }
        try {
            Date date = DateUtils.parseDate(time, SUPPORT_PATTERNS);
            Date result;
            delta = negative ? -delta : delta;
            if ("MONTH".equals(unit)) {
                result = DateUtils.addMonths(date, delta);
            } else if ("DAY".equals(unit)) {
                result = DateUtils.addDays(date, delta);
            } else if ("HOUR".equals(unit)) {
                result = DateUtils.addHours(date, delta);
            } else if ("MINUTE".equals(unit)) {
                result = DateUtils.addMinutes(date, delta);
            } else if ("SECOND".equals(unit)) {
                result = DateUtils.addSeconds(date, delta);
            } else {
                return null;
            }
            String ret = DateFormatUtils.format(result, "yyyy-MM-dd HH:mm:ss");
            return new SQLIdentifierExpr(ret);
        } catch (ParseException e) {
            LOGGER.error("",e);
        }
    }
    return null;
}
 
Example 6
Source File: CacheInfoManager.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setExpirationTime(String targetCache, String key, long expiresInSeconds) {
    Date expirationTime = DateUtils.addSeconds(new Date(), (int) expiresInSeconds);
    this.setExpirationTime(targetCache, key, expirationTime);
}
 
Example 7
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Adds a given amount of seconds to a date(you can add negative values to
 * go back in time)
 * 
 * @param src the date to use
 * @param amount number of seconds
 * 
 * @return the new date
 */
public Date addSeconds(Date src, int amount) {
	return DateUtils.addSeconds(src, amount);
}