Example usage for org.joda.time Duration millis

List of usage examples for org.joda.time Duration millis

Introduction

In this page you can find the example usage for org.joda.time Duration millis.

Prototype

public static Duration millis(long millis) 

Source Link

Document

Create a duration with the specified number of milliseconds.

Usage

From source file:$.ExampleUtils.java

License:Apache License

/**
     * Sets up external resources that are required by the example,
     * such as Pub/Sub topics and BigQuery tables.
     *// w  w w.  ja  v  a 2 s .  c  o m
     * @throws IOException if there is a problem setting up the resources
     */
    public void setup() throws IOException {
        Sleeper sleeper = Sleeper.DEFAULT;
        BackOff backOff = FluentBackoff.DEFAULT.withMaxRetries(3).withInitialBackoff(Duration.millis(200))
                .backoff();
        Throwable lastException = null;
        try {
            do {
                try {
                    setupPubsub();
                    setupBigQueryTable();
                    return;
                } catch (GoogleJsonResponseException e) {
                    lastException = e;
                }
            } while (BackOffUtils.next(sleeper, backOff));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            // Ignore InterruptedException
        }
        throw new RuntimeException(lastException);
    }

From source file:actors.FileSourcesManager.java

License:Apache License

/**
 * Public constructor./*from  w w w  .ja v a2s .c  om*/
 *
 * @param configuration Play app configuration
 * @param streamContextActor <code>ActorRef</code> for the singleton stream context actor
 */
@Inject
public FileSourcesManager(final Configuration configuration,
        @Named("StreamContext") final ActorRef streamContextActor) {
    _fileSourceIntervalMilliseconds = Duration.millis(configuration.getLong("fileSource.interval", 500L));

    _streamContextActor = streamContextActor;
}

From source file:com.aliakseipilko.flightdutytracker.presenter.impl.HourPresenter.java

License:Open Source License

@Override
public void subscribeAllCallbacks() {
    getMultipleFlightsDutyHoursCallback = new IFlightRepository.OnGetMultipleFlightsCallback() {
        @Override/*from   w  w  w  . j a  va2s  . c  om*/
        public void OnSuccess(RealmResults<Flight> flights) {
            double dutyMillis = 0;

            for (Flight flight : flights) {
                dutyMillis += (flight.getEndDutyTime().getTime() - flight.getStartDutyTime().getTime());
            }

            Duration dutyDuration = Duration.millis((long) dutyMillis);
            long hours = dutyDuration.getStandardHours();
            long minutes = dutyDuration.minus(hours * 60 * 60 * 1000).getStandardMinutes();
            if (minutes < 10) {
                view.showDutyHours(hours + ":0" + minutes, dutyMillis);
            } else {
                view.showDutyHours(hours + ":" + minutes, dutyMillis);
            }
        }

        @Override
        public void OnError(String message) {
            view.showError(message);
        }
    };
    getMultipleFlightsFlightHoursCallback = new IFlightRepository.OnGetMultipleFlightsCallback() {
        @Override
        public void OnSuccess(RealmResults<Flight> flights) {
            double flightMillis = 0;

            for (Flight flight : flights) {
                flightMillis += (flight.getEndFlightTime().getTime() - flight.getStartFlightTime().getTime());
            }

            Duration dutyDuration = Duration.standardSeconds((long) (flightMillis / 1000));
            long hours = dutyDuration.getStandardHours();
            long minutes = dutyDuration.minus(hours * 60 * 60 * 1000).getStandardMinutes();
            if (minutes < 10) {
                view.showFlightHours(hours + ":0" + minutes, flightMillis);
            } else {
                view.showFlightHours(hours + ":" + minutes, flightMillis);
            }
        }

        @Override
        public void OnError(String message) {
            view.showError(message);
        }
    };
}

From source file:com.amazon.kinesis.streaming.agent.tailing.FileTailer.java

License:Open Source License

/**
 *
 * @param forceRefresh If {@code true}, the file tracker will force a
 *        refresh of the current snapshot.
 * @return {@code true} if there's a file currently being parser, and
 *         {@code false} otherwise./*from w  w w.ja  v a 2  s . com*/
 * @throws IOException
 */
protected synchronized boolean updateRecordParser(boolean forceRefresh) throws IOException {
    if (isRunning()) {
        boolean resetParsing = false;
        boolean refreshed = false;
        long elapsedSinceLastRefresh = System.currentTimeMillis() - fileTracker.getLastRefreshTimestamp();
        // Refresh sparingly to save CPU cycles and unecessary IO...
        if (forceRefresh || elapsedSinceLastRefresh >= maxTimeBetweenFileTrackerRefreshMillis
                || fileTracker.mustRefresh()) {
            LOGGER.trace("{} is refreshing current tailed file.", serviceName());
            if (fileTracker.getLastRefreshTimestamp() > 0)
                LOGGER.trace("{}: Time since last refresh: {}", serviceName(),
                        Duration.millis(elapsedSinceLastRefresh));
            resetParsing = !fileTracker.refresh();
            refreshed = true;
        }
        // Only update the parser if something changed
        if (refreshed || (!parser.isParsing() && fileTracker.getCurrentOpenFile() != null)) {
            TrackedFile currentFile = parser.getCurrentFile();
            TrackedFile newFile = fileTracker.getCurrentOpenFile();
            if (LOGGER.isDebugEnabled()) {
                if (currentFile != null) {
                    if (newFile.getId().equals(currentFile.getId())
                            && newFile.getPath().equals(currentFile.getPath())) {
                        LOGGER.trace("{}: Continuing to tail current file {}.", serviceName(),
                                currentFile.getPath());
                    } else {
                        LOGGER.debug(
                                "{}: Switching files. Rotation might have happened.\nOld file: {}\nNew file: {}",
                                serviceName(), currentFile, newFile);
                    }
                } else if (newFile != null)
                    LOGGER.debug("{}: Found file to tail: {}", serviceName(), newFile);
            }
            if (resetParsing) {
                if (currentFile != null) {
                    LOGGER.warn("{}: Parsing was reset when switching to new file {} (from {})!", serviceName(),
                            newFile, currentFile);
                }
                parser.switchParsingToFile(newFile);
            } else {
                parser.continueParsingWithFile(newFile);
            }
        }
    }
    return parser.isParsing();
}

From source file:com.anrisoftware.simplerest.core.AbstractRepeatSimpleGetWorker.java

License:Open Source License

/**
 *
 * @param parent/*from w ww . jav  a2  s. c om*/
 *            the worker {@link Object} parent.
 *
 * @param requestUri
 *            the requests {@link URI} URI.
 *
 * @param httpClient
 *            the {@link CloseableHttpClient} HTTP client or {@code null}.
 *
 * @param parseResponse
 *            the {@link ParseResponse} to parse the response.
 *
 * @param parseErrorResponse
 *            the {@link ParseResponse} to parse the error response.
 */
protected AbstractRepeatSimpleGetWorker(Object parent, URI requestUri, CloseableHttpClient httpClient,
        ParseResponse<T> parseResponse, ParseResponse<? extends Message> parseErrorResponse) {
    super(parent, requestUri, httpClient, parseResponse, parseErrorResponse);
    this.requestsRepeateMax = 3;
    this.requestsRepeateWaitDuration = Duration.millis(500);
}

From source file:com.arpnetworking.metrics.proxy.actors.FileSourcesManager.java

License:Apache License

/**
 * Public constructor.// w w w .  j a  v a 2  s .c  o m
 *
 * @param streamContextActor <code>ActorRef</code> for the singleton stream context actor
 */
@Inject
public FileSourcesManager(@Named("StreamContext") final ActorRef streamContextActor) {
    _fileSourceInterval = Duration.millis(500L);
    _streamContextActor = streamContextActor;
}

From source file:com.cubeia.games.poker.tournament.PokerTournament.java

License:Open Source License

private void scheduleTournamentStart() {
    if (pokerState.shouldScheduleTournamentStart(dateFetcher.date())) {
        MttObjectAction action = new MttObjectAction(instance.getId(), TournamentTrigger.START_TOURNAMENT);
        long timeToTournamentStart = pokerState.getTimeUntilTournamentStart(dateFetcher.date());
        log.debug(/*w  w  w  .j a  va  2 s  .  c om*/
                "Scheduling tournament start in " + Duration.millis(timeToTournamentStart).getStandardMinutes()
                        + " minutes, for tournament " + instance);
        instance.getScheduler().scheduleAction(action, timeToTournamentStart);
    } else {
        log.debug("Won't schedule tournament start because the life cycle says no.");
    }
}

From source file:com.dataartisans.flink.dataflow.examples.streaming.StreamingPipeline.java

License:Apache License

public static void main(String[] args) {

    Options options = PipelineOptionsFactory.fromArgs(args).as(Options.class);
    options.setRunner(FlinkPipelineRunner.class);

    options.setStreaming(true);/*from w ww .  ja v a2 s  .  co  m*/

    Pipeline p = Pipeline.create(options);

    p.apply(TextIO.Read.named("ReadLines").from(options.getInput())).apply(ParDo.of(new Tokenizer()))
            .apply(Window.<String>into(FixedWindows.of(Duration.millis(1)))).apply(Count.<String>perElement())
            .apply(ParDo.of(new FormatCountsFn())).apply(TextIO.Write.named("WriteCounts")
                    .to(options.getOutput()).withNumShards(options.getNumShards()));

    p.run();
}

From source file:com.datatorrent.benchmark.state.ManagedStateBenchmarkApp.java

License:Apache License

public ManagedTimeUnifiedStateImpl createStore(Configuration conf) {
    String basePath = getStoreBasePath(conf);
    ManagedTimeUnifiedStateImpl store = new ManagedTimeUnifiedStateImpl();
    ((TFileImpl.DTFileImpl) store.getFileAccess()).setBasePath(basePath);
    store.getTimeBucketAssigner().setBucketSpan(Duration.millis(10000));
    return store;
}

From source file:com.datatorrent.benchmark.window.AbstractWindowedOperatorBenchmarkApp.java

License:Apache License

protected O createWindowedOperator(Configuration conf) {
    SpillableStateStore store = createStore(conf);
    try {/*  ww  w  .j  av a 2s  .c om*/
        O windowedOperator = this.windowedOperatorClass.newInstance();
        SpillableComplexComponentImpl sccImpl = new SpillableComplexComponentImpl(store);
        windowedOperator.addComponent("SpillableComplexComponent", sccImpl);

        windowedOperator.setDataStorage(createDataStorage(sccImpl));
        windowedOperator.setRetractionStorage(createRetractionStorage(sccImpl));
        windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage());
        setUpdatedKeyStorage(windowedOperator, conf, sccImpl);
        windowedOperator.setAccumulation(createAccumulation());

        windowedOperator.setAllowedLateness(Duration.millis(ALLOWED_LATENESS));
        windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1)));
        //accumulating mode
        windowedOperator.setTriggerOption(
                TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.standardSeconds(1))
                        .accumulatingFiredPanes().firingOnlyUpdatedPanes());
        windowedOperator.setFixedWatermark(30000);
        //windowedOperator.setTriggerOption(TriggerOption.AtWatermark());

        return windowedOperator;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}