Example usage for org.joda.time DateTimeZone UTC

List of usage examples for org.joda.time DateTimeZone UTC

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone UTC.

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.ning.billing.util.clock.OldClockMock.java

License:Apache License

@Override
public LocalDate getUTCToday() {
    return new LocalDate(getUTCNow(), DateTimeZone.UTC);
}

From source file:com.ning.billing.util.dao.LowerToCamelBeanMapper.java

License:Apache License

public T map(final int row, final ResultSet rs, final StatementContext ctx) throws SQLException {
    final T bean;
    try {/*from w ww.  j a v  a 2 s . com*/
        bean = type.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e);
    }

    final Class beanClass = bean.getClass();
    final ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
        final String name = metadata.getColumnLabel(i).toLowerCase();

        final PropertyDescriptor descriptor = properties.get(name);

        if (descriptor != null) {
            final Class<?> type = descriptor.getPropertyType();

            Object value;

            if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
                value = rs.getBoolean(i);
            } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) {
                value = rs.getByte(i);
            } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) {
                value = rs.getShort(i);
            } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) {
                value = rs.getInt(i);
            } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) {
                value = rs.getLong(i);
            } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) {
                value = rs.getFloat(i);
            } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) {
                value = rs.getDouble(i);
            } else if (type.isAssignableFrom(BigDecimal.class)) {
                value = rs.getBigDecimal(i);
            } else if (type.isAssignableFrom(DateTime.class)) {
                final Timestamp timestamp = rs.getTimestamp(i);
                value = timestamp == null ? null : new DateTime(timestamp).toDateTime(DateTimeZone.UTC);
            } else if (type.isAssignableFrom(Time.class)) {
                value = rs.getTime(i);
            } else if (type.isAssignableFrom(LocalDate.class)) {
                final Date date = rs.getDate(i);
                value = date == null ? null : new LocalDate(date, DateTimeZone.UTC);
            } else if (type.isAssignableFrom(DateTimeZone.class)) {
                final String dateTimeZoneString = rs.getString(i);
                value = dateTimeZoneString == null ? null : DateTimeZone.forID(dateTimeZoneString);
            } else if (type.isAssignableFrom(String.class)) {
                value = rs.getString(i);
            } else if (type.isAssignableFrom(UUID.class)) {
                final String uuidString = rs.getString(i);
                value = uuidString == null ? null : UUID.fromString(uuidString);
            } else if (type.isEnum()) {
                final String enumString = rs.getString(i);
                //noinspection unchecked
                value = enumString == null ? null : Enum.valueOf((Class<Enum>) type, enumString);
            } else {
                value = rs.getObject(i);
            }

            if (rs.wasNull() && !type.isPrimitive()) {
                value = null;
            }

            try {
                final Method writeMethod = descriptor.getWriteMethod();
                if (writeMethod != null) {
                    writeMethod.invoke(bean, value);
                } else {
                    final String camelCasedName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
                    final Field field = getField(beanClass, camelCasedName);
                    field.setAccessible(true); // Often private...
                    field.set(bean, value);
                }
            } catch (NoSuchFieldException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to find field for " + "property, %s", name), e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to access setter for " + "property, %s", name), e);
            } catch (InvocationTargetException e) {
                throw new IllegalArgumentException(String.format(
                        "Invocation target exception trying to " + "invoker setter for the %s property", name),
                        e);
            } catch (NullPointerException e) {
                throw new IllegalArgumentException(
                        String.format("No appropriate method to " + "write value %s ", value.toString()), e);
            }
        }
    }

    return bean;
}

From source file:com.ning.billing.util.dao.MapperBase.java

License:Apache License

protected LocalDate getDate(final ResultSet rs, final String fieldName) throws SQLException {
    final Date resultStamp = rs.getDate(fieldName);
    return rs.wasNull() ? null : new LocalDate(resultStamp, DateTimeZone.UTC);
}

From source file:com.ning.billing.util.dao.MapperBase.java

License:Apache License

protected DateTime getDateTime(final ResultSet rs, final String fieldName) throws SQLException {
    final Timestamp resultStamp = rs.getTimestamp(fieldName);
    return rs.wasNull() ? null : new DateTime(resultStamp).toDateTime(DateTimeZone.UTC);
}

From source file:com.ning.jaxrs.DateTimeParameter.java

License:Apache License

public DateTimeParameter(final String value) {
    if (value != null && !value.isEmpty()) {
        this.value = new DateTime(value);
    } else {/*  www . j  a v a 2s .c  o  m*/
        // Default value is "now".
        this.value = new DateTime(DateTimeZone.UTC);
    }
}

From source file:com.ning.jetty.eventtracker.CollectorTracker.java

License:Apache License

@Override
public void trackRequest(final RequestLog request) {
    try {//from   w  w  w .  ja  v  a 2 s.co m
        controller.offerEvent(SmileEnvelopeEvent.fromPOJO(eventName, Granularity.HOURLY,
                new DateTime(DateTimeZone.UTC), request));
    } catch (IOException e) {
        log.warn("Got I/O exception trying to send RequestLog [{}]: {}", request, e.toString());
    }
}

From source file:com.ning.jetty.eventtracker.filters.TrackerFilter.java

License:Apache License

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        chain.doFilter(request, response);
        return;/*  ww  w  . j  a v a 2s.  co m*/
    }

    final long start = new DateTime(DateTimeZone.UTC).getMillis();
    final PeepingTomResponseWrapper wrappedResponse = new PeepingTomResponseWrapper(response);

    try {
        chain.doFilter(request, wrappedResponse);
    } finally {
        try {
            logEvent(start, (HttpServletRequest) request, wrappedResponse);
        } catch (Throwable t) {
            filterConfig.getServletContext().log("Unable to capture request event", t);
        }
    }
}

From source file:com.ning.metrics.collector.processing.counter.RollUpCounterProcessor.java

License:Apache License

public void rollUpStreamingDailyCounters(String namespace) {
    try {//w  w  w.j av a2s  .c  om
        if (!isProcessing.compareAndSet(false, true)) {
            log.info("Asked to do counter roll up, but we're already processing!");
            return;
        }

        log.info(String.format("Running roll up process for Counter Subscription [%s]", namespace));

        final DateTime toDateTime = new DateTime(DateTimeZone.UTC);
        Map<String, RolledUpCounter> rolledUpCounterMap = streamAndProcessDailyCounterData(namespace,
                toDateTime);

        postRollUpProcess(namespace, toDateTime, rolledUpCounterMap);

        log.info(String.format("Roll up process for Counter Subscription [%s] completed successfully!",
                namespace));
    } catch (Exception e) {
        log.error(String.format("Exception occurred while performing counter roll up for [%s]", namespace), e);
    } finally {
        isProcessing.set(false);
    }

}

From source file:com.ning.metrics.collector.processing.counter.RollUpCounterProcessor.java

License:Apache License

public void rollUpDailyCounters(String namespace) {
    try {// w w w .ja v a 2 s.c o  m
        if (!isProcessing.compareAndSet(false, true)) {
            log.info("Asked to do counter roll up, but we're already processing!");
            return;
        }
        final DateTime toDateTime = new DateTime(DateTimeZone.UTC);
        final Integer recordFetchLimit = config.getMaxCounterEventFetchCount();
        Integer recordOffSetCounter = 0;
        boolean fetchMoreRecords = true;

        Map<String, RolledUpCounter> rolledUpCounterMap = new ConcurrentHashMap<String, RolledUpCounter>();

        log.info(String.format("Running roll up process for namespace [%s]", namespace));

        while (fetchMoreRecords) {
            // Load daily counters stored for the respective subscription limiting to now() and getMaxCounterEventFetchCount
            Iterator<CounterEventData> dailyCounterList = counterStorage
                    .loadBufferedMetricsPaged(namespace, toDateTime, recordFetchLimit, recordOffSetCounter)
                    .iterator();
            if (Objects.equal(null, dailyCounterList) || !dailyCounterList.hasNext()) {
                fetchMoreRecords = false;
                break;
            }

            log.info(String.format("Processing counter events for %s on offset %d", namespace,
                    recordOffSetCounter));

            // increment recordOffset to fetch next getMaxCounterEventFetchCount
            recordOffSetCounter += recordFetchLimit;

            while (dailyCounterList.hasNext()) {
                processCounterEventData(namespace, rolledUpCounterMap, dailyCounterList.next());
            }

            log.info(String.format("Roll up completed %s on offset %d", namespace, recordOffSetCounter));

        }

        postRollUpProcess(namespace, toDateTime, rolledUpCounterMap);

        log.info(String.format("Roll up process for Counter Subscription [%s] completed successfully!",
                namespace));
    } catch (Exception e) {
        log.error(String.format("Exception occurred while performing counter roll up for [%s]", namespace), e);
    } finally {
        isProcessing.set(false);
    }

}

From source file:com.ning.metrics.collector.processing.counter.RollUpCounterProcessor.java

License:Apache License

public List<RolledUpCounter> loadAggregatedRolledUpCounters(final String namespace,
        final Optional<String> fromDateOpt, final Optional<String> toDateOpt,
        final Optional<Set<String>> counterTypesOpt, final Optional<Set<CompositeCounter>> compositeCountersOpt,
        final boolean aggregateByMonth, final boolean aggregateEntireRange, final boolean excludeDistribution,
        final Optional<Set<String>> uniqueIdsOpt, final Optional<Integer> distributionLimit) {

    DateTime fromDate = fromDateOpt.isPresent()
            ? new DateTime(RolledUpCounter.DATE_FORMATTER.parseMillis(fromDateOpt.get()), DateTimeZone.UTC)
            : null;//from w w w  .  ja v a  2  s .  com
    DateTime toDate = toDateOpt.isPresent()
            ? new DateTime(RolledUpCounter.DATE_FORMATTER.parseMillis(toDateOpt.get()), DateTimeZone.UTC)
            : null;

    // If we aggregate the entire date range don't want to limit the
    // distribution returned in the individual time slices.  Instead
    // We want to get everything from each time slice and sort and limit on
    // the aggregated result.
    //
    // Similarly if we are asking for any composite counters, we don't
    // want to limit the distribution before we can accurately compute the
    // the composites for each time slice
    //
    // We don't need to limit the distribution if a set of unique
    // ids is given
    boolean overrideDistributionLimit = (aggregateEntireRange
            || (uniqueIdsOpt != null && uniqueIdsOpt.isPresent() && !uniqueIdsOpt.get().isEmpty())
            || (compositeCountersOpt != null && compositeCountersOpt.isPresent()
                    && !compositeCountersOpt.get().isEmpty()));

    // For the method that aggregates over all time, the distribution needs
    // to not be sent if we are adding any composite counters afterward.
    boolean overrideDistributionLimitInAggregator = (compositeCountersOpt != null
            && compositeCountersOpt.isPresent() && !compositeCountersOpt.get().isEmpty());

    // If we want to aggregate the entire range correctly we need to reteive
    // the distribution for each time slice regardless of whether the caller
    // requested it.  Without the distribution of each time slice, we cannot
    // accurately determine the aggregate unique count.  uniqueIds have no
    // bearing on this.
    boolean overrideExcludeDistribution = aggregateEntireRange;

    List<RolledUpCounter> rolledUpCounterResult = counterStorage.queryDailyRolledUpCounters(namespace, fromDate,
            toDate, counterTypesOpt, (overrideExcludeDistribution ? false : excludeDistribution),
            (overrideDistributionLimit ? null : distributionLimit), uniqueIdsOpt);

    if (Objects.equal(null, rolledUpCounterResult) || rolledUpCounterResult.isEmpty()) {
        return ImmutableList.of();
    }

    if (aggregateByMonth) {
        // TODO - Write the routine to aggregate the data by month
    }

    if (aggregateEntireRange) {
        RolledUpCounter aggregate = aggregateEntireRange(rolledUpCounterResult, excludeDistribution,
                overrideDistributionLimitInAggregator ? null : distributionLimit);

        rolledUpCounterResult = ImmutableList.of(aggregate);
    }

    // Generate composite counters for each timeslice.  Performing this
    // opertion here allows us to operate on the normal list if we are not
    // aggregating or the aggregated list if we are.
    if (compositeCountersOpt != null && compositeCountersOpt.isPresent()
            && !compositeCountersOpt.get().isEmpty()) {
        addCompositeCounters(compositeCountersOpt.get(), rolledUpCounterResult, distributionLimit);
    }

    return rolledUpCounterResult;
}