Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.bazaarvoice.dropwizard.caching.CachedResponse.java

License:Apache License

/**
 * Get the date the response was generated.
 * <p/>/*from w  ww  .j  a v  a2 s . c o m*/
 * Retrieves the {@link HttpHeaders#DATE} header or current time if no date header is found.
 *
 * @return response date
 */
public DateTime getDate() {
    if (_date == null) {
        String dateString = _responseHeaders.getFirst(DATE);

        if (dateString != null) {
            try {
                _date = HttpHeaderUtils.parseDate(dateString);
            } catch (Exception ex) {
                LOG.debug("Failed to parse date header: value={}", dateString, ex);
            }
        }

        if (_date == null) {
            _date = DateTime.now();
        }
    }

    return _date;
}

From source file:com.bazaarvoice.dropwizard.caching.ResponseCache.java

License:Apache License

public Optional<Response> get(CacheRequestContext request) {
    // If request allows a cached response to be returned
    if (isServableFromCache(request)) {
        String cacheKey = buildKey(request);
        StoreLoader loader = new StoreLoader(_store, cacheKey);
        CachedResponse cachedResponse = _localCache.get(cacheKey, loader);

        if (cachedResponse != null && cachedResponse.hasExpiration()) {
            DateTime now = DateTime.now();

            // If cached response is acceptable for request cache control options
            if (isCacheAcceptable(request, now, cachedResponse)) {
                return buildResponse(request, cacheKey, cachedResponse, now);
            } else if (!loader.invoked && cachedResponse.isExpired(now)) {
                // Check if the backing store has a fresher copy of the response

                _localCache.invalidate(cacheKey);
                cachedResponse = _localCache.get(cacheKey, loader);

                if (cachedResponse != null && cachedResponse.hasExpiration()
                        && isCacheAcceptable(request, now, cachedResponse)) {
                    return buildResponse(request, cacheKey, cachedResponse, now);
                }//from w  w w  .j  a v a  2  s . c  om
            }
        }
    }

    _misses.inc();

    if (isOnlyCacheAllowed(request)) {
        return Optional.of(Response.status(HttpUtils.GATEWAY_TIMEOUT).build());
    } else {
        return Optional.absent();
    }
}

From source file:com.bazaarvoice.dropwizard.caching.ResponseCache.java

License:Apache License

public void put(CacheRequestContext request, CacheResponseContext response, byte[] content) {
    if (isResponseCacheable(request) && isResponseCacheable(response)) {
        DateTime responseDate = response.getDate().orNull();

        if (responseDate == null) {
            responseDate = DateTime.now();
            response.setDate(responseDate);
            response.setAge(0);/*  w  w w  .j  a v a 2s.c o m*/
        } else {
            response.setAge(responseDate, DateTime.now());
        }

        response.setExpires(responseDate.plusSeconds(response.getSharedCacheMaxAge()));

        CachedResponse cachedResponse = CachedResponse.build(response.getStatusCode(),
                response.getHttpContext().getHttpHeaders(), content);
        String cacheKey = buildKey(request);

        _localCache.put(cacheKey, cachedResponse);
        _store.put(cacheKey, cachedResponse);
    }
}

From source file:com.bbva.arq.devops.ae.mirrorgate.collectors.jira.service.CollectorStatusServiceImpl.java

License:Apache License

public DateTime getLastExecutionDate() {
    Date date = collectorApi.getUpdatedDate();
    return date == null ? DateTime.now().minusMonths(monthsOfHistory) : new DateTime(date);
}

From source file:com.bearded.common.time.TimeUtils.java

License:Apache License

/**
 * Obtains the number of milliseconds from a given timestamp.
 *
 * @param timestamp in UTC./* w  ww . j  ava2  s . c o  m*/
 * @return {@link long} with the number of milliseconds.
 */
public static long millisecondsFromNow(long timestamp) {
    return DateTime.now().getMillis() - timestamp;
}

From source file:com.bearded.common.time.TimeUtils.java

License:Apache License

/**
 * Obtains an ISO 8601 {@link java.lang.String} from now.
 *
 * @return {@link java.lang.String} with the date in seconds following the ISO 8601 conventions.
 *//*  w  w  w  .  ja v a 2s.c o m*/
@NonNull
public static String nowToISOString() {
    return DateTime.now().toString();
}

From source file:com.beginner.core.quartz.BaseJob.java

License:Apache License

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDetailImpl jobDetail = (JobDetailImpl) context.getJobDetail();
    logger.info(",JobKey:[" + jobDetail.getKey() + "],:"
            + DateTime.now().toString(DateTimeFormat.fullDateTime()));
    jobHandler(context.getMergedJobDataMap());
    logger.info("?,JobKey:[" + jobDetail.getKey() + "],?:"
            + DateTime.now().toString(DateTimeFormat.fullDateTime()));
}

From source file:com.beginner.core.utils.UUIDUtil.java

License:Apache License

/**
  * ???ID//  w w w . j  a v a2s . c  o  m
  * @return <br>
  * 20160219133512314<br>
  * 2016021913351231401<br>
  */
public static synchronized long getLongId() {
    String id = DateTime.now().toString("yyyyMMddHHmmssS");
    if (num >= 99)
        num = 0l;
    ++num;
    if (num < 10)
        id = id + 00 + num;
    else
        id += num;
    return Long.valueOf(id);
}

From source file:com.bibliotecaFUSMbackend.rest.auth.SecurityFilter.java

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    SecurityContext originalContext = requestContext.getSecurityContext();
    String authHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
    if (authHeader == null || authHeader.isEmpty() || authHeader.split(" ").length != 2) {
        Authorizer authorizer = new Authorizer(new ArrayList<Rol>(), "", originalContext.isSecure());
        requestContext.setSecurityContext(authorizer);

    } else {//  www  . ja  va2s.c om
        JWTClaimsSet claimSet = null;
        try {
            claimSet = (JWTClaimsSet) AuthUtils.decodeToken(authHeader);
        } catch (ParseException e) {
            throw new IOException("Error al codificar JW");

        } catch (JOSEException e) {
            throw new IOException("Token invalido");
        }

        // ensure that the token is not expired
        if (new DateTime(claimSet.getExpirationTime()).isBefore(DateTime.now())) {
            throw new IOException("El token no ha expirado");
        } else {
            Usuario user = usuarioSession.find(Integer.parseInt(claimSet.getSubject()));
            Authorizer authorizer = new Authorizer(user.getRolList(), user.getEmail(),
                    originalContext.isSecure());
            requestContext.setSecurityContext(authorizer);
        }
    }
}

From source file:com.bitalino.server.dao.BITalinoReadingDao.java

License:Apache License

/**
 * Finds all {@link BITalinoReading} related to a time interval.
 * /*from   w  w w  .j  a  va2 s  .  c om*/
 * @param since
 * 
 * @return a list of all {@link BITalinoReading} related to a time interval.
 */
public List<BITalinoReading> find_all_readings_since(final long since) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<BITalinoReading> cq = cb.createQuery(BITalinoReading.class);
    Root<BITalinoReading> reading = cq.from(BITalinoReading.class);

    Predicate interval = cb.between(reading.get(BITalinoReading_.timestamp), since, DateTime.now().getMillis());
    cq.where(interval);

    return getEntityManager().createQuery(cq).getResultList();
}