Example usage for org.joda.time Duration ZERO

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

Introduction

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

Prototype

Duration ZERO

To view the source code for org.joda.time Duration ZERO.

Click Source Link

Document

Constant representing zero millisecond duration

Usage

From source file:org.graylog2.lookup.adapters.HTTPJSONPathDataAdapter.java

License:Open Source License

@Override
public Duration refreshInterval() {
    return Duration.ZERO;
}

From source file:org.graylog2.lookup.LookupDataAdapterRefreshService.java

License:Open Source License

/**
 * Add the given {@link LookupDataAdapter} to the refresh service.
 * <p>//from  w w w .  j a  va2  s .  c o  m
 * The {@link LookupDataAdapter#doRefresh(LookupCachePurge) refresh method} method will be called periodically
 * according to the {@link LookupDataAdapter#refreshInterval() refresh interval} of the data adapter.
 * @param dataAdapter the adapter to be added
 */
public void add(LookupDataAdapter dataAdapter) {
    if (state() == State.STOPPING || state() == State.TERMINATED) {
        LOG.debug("Service is in state <{}> - not adding new job for <{}/{}/@{}>", state(), dataAdapter.name(),
                dataAdapter.id(), objectId(dataAdapter));
        return;
    }

    final Duration interval = dataAdapter.refreshInterval();

    // No need to schedule the data adapter refresh if it doesn't implement a refresh
    if (!interval.equals(Duration.ZERO)) {
        // Using the adapter object ID here to make it possible to have multiple jobs for the same adapter
        final String instanceId = objectId(dataAdapter);

        // Manually synchronize here to avoid overwriting an existing refresh job for the given data adapter.
        // ConcurrentMap#computeIfAbsent() does not work here because scheduling a job is not idempotent.
        synchronized (futures) {
            if (!futures.containsKey(instanceId)) {
                LOG.info("Adding job for <{}/{}/@{}> [interval={}ms]", dataAdapter.name(), dataAdapter.id(),
                        instanceId, interval.getMillis());
                futures.put(instanceId, schedule(dataAdapter, interval));
            } else {
                LOG.warn("Job for <{}/{}/@{}> already exists, not adding it again.", dataAdapter.name(),
                        dataAdapter.id(), instanceId);
            }
        }
    }
}

From source file:org.myorg.quickstart.FlinkForward2016.java

License:Apache License

public static void main(String[] args) throws Exception {

    PipelineOptions options = PipelineOptionsFactory.fromArgs(args).as(FlinkPipelineOptions.class);
    options.setRunner(FlinkRunner.class);

    Pipeline p = Pipeline.create(options);

    PCollection<Long> source = p.apply(Read.from(new MySource()));

    source.apply(Window.<Long>into(FixedWindows.of(Duration.standardSeconds(3)))
            .triggering(AfterWatermark.pastEndOfWindow()).withAllowedLateness(Duration.ZERO)
            .discardingFiredPanes())//from  w ww .  j a v  a  2 s. com

            .apply(Combine.globally(new PrintWindowCounts()).withoutDefaults());

    p.run();
}

From source file:org.myorg.quickstart.FlinkForward2016Checkpointing.java

License:Apache License

public static void main(String[] args) throws Exception {

    MyOptions options = PipelineOptionsFactory.fromArgs(args).as(MyOptions.class);
    options.setRunner(FlinkRunner.class);
    options.setNumberOfExecutionRetries(Integer.MAX_VALUE);
    options.setExecutionRetryDelay(3000L);
    options.setCheckpointingInterval(1000L);

    final long failAfter = options.getFailAfter();

    Pipeline p = Pipeline.create(options);

    PCollection<Long> source = p.apply(Read.from(new MySource()));

    source.apply(ParDo.of(new CountExposer()));

    source.apply(ParDo.of(new Preprocessor(failAfter)))

            .apply(Window.<Long>into(FixedWindows.of(Duration.standardSeconds(3)))
                    .triggering(AfterWatermark.pastEndOfWindow()).withAllowedLateness(Duration.ZERO)
                    .discardingFiredPanes())

            .apply(Combine.globally(new PrintWindowCounts()).withoutDefaults());

    p.run();//from w w  w  .ja  v a  2 s .co  m
}

From source file:org.openmastery.publisher.core.timeline.TimeBandModel.java

License:Open Source License

public static Duration sumDuration(List<? extends TimeBandModel> ideaFlowBands) {
    Duration duration = Duration.ZERO;
    for (TimeBandModel ideaFlowBand : ideaFlowBands) {
        Duration bandDuration = ideaFlowBand.getDuration();
        if (bandDuration.getMillis() < 0) {
            throw new BandDurationIsNegativeException(ideaFlowBand);
        }/*from   w  w w  .  ja v a2  s.c  o m*/
        duration = duration.plus(bandDuration);
    }
    return duration;
}

From source file:org.opennms.netmgt.provision.service.DefaultProvisionService.java

License:Open Source License

private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
    Assert.notNull(node, "Node may not be null");
    final String actualForeignSource = node.getForeignSource();
    if (actualForeignSource == null && !isDiscoveryEnabled()) {
        LOG.info(/*from  w w  w . ja va  2  s.  c  om*/
                "Not scheduling node {} to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond",
                node);
        return null;
    }

    final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource;
    try {
        final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);

        final Duration scanInterval = fs.getScanInterval();
        Duration initialDelay = Duration.ZERO;
        if (node.getLastCapsdPoll() != null && !force) {
            final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
            final DateTime now = new DateTime();
            if (nextPoll.isAfter(now)) {
                initialDelay = new Duration(now, nextPoll);
            }
        }

        return new NodeScanSchedule(node.getId(), actualForeignSource, node.getForeignId(), initialDelay,
                scanInterval);
    } catch (final ForeignSourceRepositoryException e) {
        LOG.warn("unable to get foreign source '{}' from repository", effectiveForeignSource, e);
        return null;
    }
}

From source file:org.openvpms.web.workspace.customer.charge.OrderPlacer.java

License:Open Source License

/**
 * Constructs an {@link OrderPlacer}./* w  w  w  .  j a  v  a  2  s .co  m*/
 *
 * @param customer the customer
 * @param location the location
 * @param user     the user responsible for the orders
 * @param practice the practice
 * @param cache    the object cache
 * @param services the order services
 */
public OrderPlacer(Party customer, Party location, User user, Party practice, IMObjectCache cache,
        OrderServices services) {
    this.customer = customer;
    this.location = location;
    this.user = user;
    this.cache = cache;
    this.services = services;
    PracticeRules rules = services.getPracticeRules();
    Period period = rules.getPharmacyOrderDiscontinuePeriod(practice);
    discontinueOnFinalisation = period == null || period.toStandardDuration().compareTo(Duration.ZERO) < 0;
    this.pharmacies = new PharmacyProducts(services.getPharmacies(), location, cache);
}

From source file:org.samcrow.ridgesurvey.TimerFragment.java

License:Open Source License

private void startTimer() {
    if (!mRunning) {
        showTime(Duration.ZERO);
        mStartStopButton.setImageResource(ICON_STOP);
        mRunning = true;/*from   www  .java  2 s  .  co  m*/
        mTimer = new Timer();
        mNotificationManager.cancelAll();

        mCurrentDuration = Duration.ZERO;
        mTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                final Duration newDuration = mCurrentDuration.plus(Duration.standardSeconds(1));
                mCurrentDuration = newDuration;

                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showTime(newDuration);
                    }
                });

                if (newDuration.isEqual(HALF_PERIOD)) {
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            notifyHalfPeriod();
                        }
                    });
                }

                if (newDuration.isEqual(COUNT_UP_PERIOD) || newDuration.isLongerThan(COUNT_UP_PERIOD)) {
                    mTimer.cancel();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            notifyStopped();
                            stopTimer();
                        }
                    });
                }
            }
        }, 1000, 1000);
    }
}

From source file:org.stt.gui.jfx.binding.ReportBinding.java

@Override
protected Report computeValue() {
    Report report;/*  www . j  av  a 2  s .  c o  m*/
    if (reportStart.getValue() != null && reportEnd.getValue() != null) {
        report = createSummaryReportFor();
    } else {
        report = new Report(Collections.<ReportingItem>emptyList(), null, null, Duration.ZERO);
    }
    return report;
}

From source file:org.trellisldp.rosid.file.streaming.FileProcessingPipeline.java

License:Apache License

/**
 * Get the beam pipeline/*from   w  w  w . j a v  a2 s. c  o  m*/
 * @return the pipeline
 */
public Pipeline getPipeline() {

    LOGGER.debug("Building Beam Pipeline");
    final PipelineOptions options = PipelineOptionsFactory.create();
    final Pipeline p = Pipeline.create(options);

    // Add membership triples
    p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_MEMBERSHIP_ADD).withoutMetadata())
            .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferMembership.getIRIString(), true)))
            .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE));

    // Delete membership triples
    p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_MEMBERSHIP_DELETE).withoutMetadata())
            .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferMembership.getIRIString(), false)))
            .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE));

    // Add containment triples
    p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_CONTAINMENT_ADD).withoutMetadata())
            .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), true)))
            .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE));

    // Delete containment triples
    p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_CONTAINMENT_DELETE).withoutMetadata())
            .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), false)))
            .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE));

    if (aggregateSeconds > 0) {
        // Aggregate cache writes
        p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE).withoutMetadata())
                .apply(Window
                        .<KV<String, String>>into(FixedWindows.of(Duration.standardSeconds(aggregateSeconds)))
                        .triggering(AfterProcessingTime.pastFirstElementInPane()
                                .plusDelayOf(Duration.standardSeconds(aggregateSeconds)))
                        .discardingFiredPanes().withAllowedLateness(Duration.ZERO))
                .apply(Combine.perKey(x -> x.iterator().next()))
                .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE));
    } else {
        // Skip aggregation
        p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE).withoutMetadata())
                .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE));
    }

    // Write to cache and dispatch to the event bus
    p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE).withoutMetadata())
            .apply(ParDo.of(new CacheWriter(dataConfiguration)))
            .apply(ParDo.of(new EventProcessor(baseUrlConfiguration)))
            .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_EVENT));

    return p;
}