Example usage for org.joda.time Duration standardSeconds

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

Introduction

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

Prototype

public static Duration standardSeconds(long seconds) 

Source Link

Document

Create a duration with the specified number of seconds assuming that there are the standard number of milliseconds in a second.

Usage

From source file:org.hawkular.metrics.core.service.transformers.MetricIdentifierFromFullDataRowTransformer.java

License:Apache License

public MetricIdentifierFromFullDataRowTransformer(int defaultTTL) {
    this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays();
}

From source file:org.hawkular.metrics.core.service.transformers.MetricsIndexRowTransformer.java

License:Apache License

public MetricsIndexRowTransformer(String tenantId, MetricType<T> type, int defaultTTL) {
    this.type = type;
    this.tenantId = tenantId;
    this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays();
}

From source file:org.jbpm.process.core.timer.DateTimeUtils.java

License:Apache License

public static long[] parseRepeatableDateTime(String dateTimeStr) {
    long[] result = new long[3];
    if (isRepeatable(dateTimeStr)) {

        String[] parsed = parseISORepeatable(dateTimeStr);
        String repeats = parsed[0];
        String delayIn = parsed[1];
        String periodIn = parsed[2];

        DateTime startAtDelay = ISODateTimeFormat.dateTimeParser().parseDateTime(delayIn);
        Duration startAtDelayDur = new Duration(System.currentTimeMillis(), startAtDelay.getMillis());
        if (startAtDelayDur.getMillis() <= 0) {
            // need to introduce delay to allow all initialization
            startAtDelayDur = Duration.standardSeconds(1);
        }//from ww w .ja  v  a 2 s .  c  o  m
        Period period = ISOPeriodFormat.standard().parsePeriod(periodIn);
        result[0] = Long.parseLong(repeats.length() == 0 ? "-1" : repeats);
        result[1] = startAtDelayDur.getMillis();
        result[2] = period.toStandardDuration().getMillis();

        return result;
    } else {

        int index = dateTimeStr.indexOf("###");
        if (index != -1) {
            String period = dateTimeStr.substring(index + 3);
            String delay = dateTimeStr.substring(0, index);
            result = new long[] { TimeUtils.parseTimeString(delay), TimeUtils.parseTimeString(period) };

            return result;
        }
        result = new long[] { TimeUtils.parseTimeString(dateTimeStr) };
        return result;
    }
}

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())/*w ww .  j  a  v a 2s.  c om*/

            .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();//  w ww .  ja va 2 s .c  o m
}

From source file:org.obm.push.backend.PolicyConfigurationServiceFileImpl.java

License:Open Source License

@Override
public Policy getPolicy() {
    return new Policy() {

        @Override/*from   w ww. java 2s. co m*/
        public boolean requireStorageCardEncryption() {
            return iniFile.getBooleanValue("requireStorageCardEncryption",
                    defaultPolicy.requireStorageCardEncryption());
        }

        @Override
        public boolean requireSignedSMIMEMessages() {
            return iniFile.getBooleanValue("requireSignedSMIMEMessages",
                    defaultPolicy.requireSignedSMIMEMessages());
        }

        @Override
        public boolean requireSignedSMIMEAlgorithm() {
            return iniFile.getBooleanValue("requireSignedSMIMEAlgorithm",
                    defaultPolicy.requireSignedSMIMEAlgorithm());
        }

        @Override
        public boolean requireManualSyncWhenRoaming() {
            return iniFile.getBooleanValue("requireManualSyncWhenRoaming",
                    defaultPolicy.requireManualSyncWhenRoaming());
        }

        @Override
        public boolean requireEncryptionSMIMEAlgorithm() {
            return iniFile.getBooleanValue("requireEncryptionSMIMEAlgorithm",
                    defaultPolicy.requireEncryptionSMIMEAlgorithm());
        }

        @Override
        public boolean requireEncryptedSMIMEMessages() {
            return iniFile.getBooleanValue("requireEncryptedSMIMEMessages",
                    defaultPolicy.requireEncryptedSMIMEMessages());
        }

        @Override
        public boolean requireDeviceEncryption() {
            return iniFile.getBooleanValue("requireDeviceEncryption", defaultPolicy.requireDeviceEncryption());
        }

        @Override
        public boolean passwordRecoveryEnabled() {
            return iniFile.getBooleanValue("passwordRecoveryEnabled", defaultPolicy.passwordRecoveryEnabled());
        }

        @Override
        public int minDevicePasswordLength() {
            return iniFile.getIntValue("minDevicePasswordLength", defaultPolicy.minDevicePasswordLength());
        }

        @Override
        public int minDevicePasswordComplexCharacters() {
            return iniFile.getIntValue("minDevicePasswordComplexCharacters",
                    defaultPolicy.minDevicePasswordComplexCharacters());
        }

        @Override
        public Duration maxInactivityTimeDeviceLock() {
            return Duration.standardSeconds(iniFile.getIntValue("maxInactivityTimeDeviceLock",
                    defaultPolicy.maxInactivityTimeDeviceLock().toStandardSeconds().getSeconds()));
        }

        @Override
        public int maxEmailHTMLBodyTruncationSize() {
            return iniFile.getIntValue("maxEmailHTMLBodyTruncationSize",
                    defaultPolicy.maxEmailHTMLBodyTruncationSize());
        }

        @Override
        public int maxEmailBodyTruncationSize() {
            return iniFile.getIntValue("maxEmailBodyTruncationSize",
                    defaultPolicy.maxEmailBodyTruncationSize());
        }

        @Override
        public int maxEmailAgeFilter() {
            return iniFile.getIntValue("maxEmailAgeFilter", defaultPolicy.maxEmailAgeFilter());
        }

        @Override
        public int maxDevicePasswordFailedAttempts() {
            return iniFile.getIntValue("maxDevicePasswordFailedAttempts",
                    defaultPolicy.maxDevicePasswordFailedAttempts());
        }

        @Override
        public int maxCalendarAgeFilter() {
            return iniFile.getIntValue("maxCalendarAgeFilter", defaultPolicy.maxCalendarAgeFilter());
        }

        @Override
        public Integer maxAttachmentSize() {
            return iniFile.getIntegerValue("maxAttachmentSize", defaultPolicy.maxAttachmentSize());
        }

        @Override
        public boolean devicePasswordHistory() {
            return iniFile.getBooleanValue("devicePasswordHistory", defaultPolicy.devicePasswordHistory());
        }

        @Override
        public Boolean devicePasswordExpiration() {
            return iniFile.getNullableBooleanValue("devicePasswordExpiration",
                    defaultPolicy.devicePasswordExpiration());
        }

        @Override
        public boolean devicePasswordEnabled() {
            return iniFile.getBooleanValue("devicePasswordEnabled", defaultPolicy.devicePasswordEnabled());
        }

        @Override
        public boolean deviceEncryptionEnabled() {
            return iniFile.getBooleanValue("deviceEncryptionEnabled", defaultPolicy.deviceEncryptionEnabled());
        }

        @Override
        public boolean attachmentsEnabled() {
            return iniFile.getBooleanValue("attachmentsEnabled", defaultPolicy.attachmentsEnabled());
        }

        @Override
        public boolean alphaNumericDevicePasswordRequired() {
            return iniFile.getBooleanValue("alphaNumericDevicePasswordRequired",
                    defaultPolicy.alphaNumericDevicePasswordRequired());
        }

        @Override
        public boolean allowWiFi() {
            return iniFile.getBooleanValue("allowWiFi", defaultPolicy.allowWiFi());
        }

        @Override
        public boolean allowUnsignedInstallationPackages() {
            return iniFile.getBooleanValue("allowUnsignedInstallationPackages",
                    defaultPolicy.allowUnsignedInstallationPackages());
        }

        @Override
        public boolean allowUnsignedApplications() {
            return iniFile.getBooleanValue("allowUnsignedApplications",
                    defaultPolicy.allowUnsignedApplications());
        }

        @Override
        public boolean allowTextMessaging() {
            return iniFile.getBooleanValue("allowTextMessaging", defaultPolicy.allowTextMessaging());
        }

        @Override
        public boolean allowStorageCard() {
            return iniFile.getBooleanValue("allowStorageCard", defaultPolicy.allowStorageCard());
        }

        @Override
        public boolean allowSimpleDevicePassword() {
            return iniFile.getBooleanValue("allowSimpleDevicePassword",
                    defaultPolicy.allowSimpleDevicePassword());
        }

        @Override
        public boolean allowSMIMESoftCerts() {
            return iniFile.getBooleanValue("allowSMIMESoftCerts", defaultPolicy.allowSMIMESoftCerts());
        }

        @Override
        public int allowSMIMEEncryptionAlgorithmNegotiation() {
            return iniFile.getIntValue("allowSMIMEEncryptionAlgorithmNegotiation",
                    defaultPolicy.allowSMIMEEncryptionAlgorithmNegotiation());
        }

        @Override
        public boolean allowRemoteDesktop() {
            return iniFile.getBooleanValue("allowRemoteDesktop", defaultPolicy.allowRemoteDesktop());
        }

        @Override
        public boolean allowPOPIMAPEmail() {
            return iniFile.getBooleanValue("allowPOPIMAPEmail", defaultPolicy.allowPOPIMAPEmail());
        }

        @Override
        public boolean allowIrDA() {
            return iniFile.getBooleanValue("allowIrDA", defaultPolicy.allowIrDA());
        }

        @Override
        public boolean allowInternetSharing() {
            return iniFile.getBooleanValue("allowInternetSharing", defaultPolicy.allowInternetSharing());
        }

        @Override
        public boolean allowHTMLEmail() {
            return iniFile.getBooleanValue("allowHTMLEmail", defaultPolicy.allowHTMLEmail());
        }

        @Override
        public boolean allowDesktopSync() {
            return iniFile.getBooleanValue("allowDesktopSync", defaultPolicy.allowDesktopSync());
        }

        @Override
        public boolean allowConsumerEmail() {
            return iniFile.getBooleanValue("allowConsumerEmail", defaultPolicy.allowConsumerEmail());
        }

        @Override
        public boolean allowCamera() {
            return iniFile.getBooleanValue("allowCamera", defaultPolicy.allowCamera());
        }

        @Override
        public boolean allowBrowser() {
            return iniFile.getBooleanValue("allowBrowser", defaultPolicy.allowBrowser());
        }

        @Override
        public int allowBluetooth() {
            return iniFile.getIntValue("allowBluetooth", defaultPolicy.allowBluetooth());
        }

    };
}

From source file:org.obm.push.DefaultPolicy.java

License:Open Source License

@Override
public Duration maxInactivityTimeDeviceLock() {
    return Duration.standardSeconds(900);
}

From source file:org.obm.push.mail.ICalendarConverter.java

License:Open Source License

@VisibleForTesting
Long reminder(ICalendarEvent iCalendarEvent) {
    Long firstAlarmInSeconds = iCalendarEvent.firstAlarmInSeconds();
    if (firstAlarmInSeconds != null && firstAlarmInSeconds <= 0) {
        return Duration.standardSeconds(Math.abs(firstAlarmInSeconds)).getStandardMinutes();
    }//from w ww. j a  v a  2  s . c  o  m
    return null;
}

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

License:Open Source License

private void startTimer() {
    if (!mRunning) {
        showTime(Duration.ZERO);/*from  ww  w. j  av  a2s .co  m*/
        mStartStopButton.setImageResource(ICON_STOP);
        mRunning = true;
        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.smartdeveloperhub.harvesters.it.backend.crawler.jira.factories.IssueFactory.java

License:Apache License

private Set<Item> buildChangeLogItem(ChangelogItem jiraItem, Map<String, Contributor> contributors,
        DateTime timestamp, Stack<DateTime> openDate, Stack<DateTime> closeDate) {

    Set<Item> items = new HashSet<>();
    String field = jiraItem.getField();
    if (ChangeLogProperty.STATUS.is(field)) {

        Status oldStatus = fromMap(jiraItem.getFromString(), statusMapping);
        Status newStatus = fromMap(jiraItem.getToString(), statusMapping);

        if (!oldStatus.equals(newStatus)) {

            if (oldStatus.equals(Status.CLOSED)) {

                items.add(Item.builder().openedDate().oldValue(openDate.pop())
                        .newValue(openDate.push(timestamp)).build());

                items.add(Item.builder().closedDate().oldValue(closeDate.pop()).newValue(closeDate.peek())
                        .build());//from w  ww .  j a  v a2  s  .c om

            } else if (newStatus.equals(Status.CLOSED)) {

                items.add(Item.builder().closedDate().oldValue(closeDate.peek())
                        .newValue(closeDate.push(timestamp)).build());
            }

            items.add(Item.builder().status().oldValue(oldStatus).newValue(newStatus).build());
        }

    } else if (ChangeLogProperty.PRIORITY.is(field)) {

        Item item = Item.builder().priority().oldValue(fromMap(jiraItem.getFromString(), priorityMapping))
                .newValue(fromMap(jiraItem.getToString(), priorityMapping)).build();
        items.add(item);

    } else if (ChangeLogProperty.SEVERITY.is(field)) {

        Item item = Item.builder().severity().oldValue(fromMap(jiraItem.getFromString(), severityMapping))
                .newValue(fromMap(jiraItem.getToString(), severityMapping)).build();
        items.add(item);

    } else if (ChangeLogProperty.ISSUE_TYPE.is(field)) {

        Item item = Item.builder().type().oldValue(fromMap(jiraItem.getFromString(), typeMapping))
                .newValue(fromMap(jiraItem.getToString(), typeMapping)).build();
        items.add(item);

    } else if (ChangeLogProperty.DUE_DATE.is(field)) {

        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SS").withZoneUTC();

        DateTime fromDate = (jiraItem.getFromString() != null
                ? formatter.parseDateTime(jiraItem.getFromString())
                : null);
        DateTime toDate = (jiraItem.getFromString() != null ? formatter.parseDateTime(jiraItem.getToString())
                : null);

        Item item = Item.builder().dueToDate().oldValue(fromDate).newValue(toDate).build();
        items.add(item);

    } else if (ChangeLogProperty.ESTIMATED_TIME.is(field)) {

        Duration oldDuration = (jiraItem.getFrom() != null
                ? Duration.standardSeconds(Integer.valueOf(jiraItem.getFrom()))
                : null);
        Duration newDuration = (jiraItem.getTo() != null
                ? Duration.standardSeconds(Integer.valueOf(jiraItem.getTo()))
                : null);

        Item item = Item.builder().estimatedTime().oldValue(oldDuration).newValue(newDuration).build();
        items.add(item);

    } else if (ChangeLogProperty.BLOCKERS.is(field)) {

        // Remove null values
        String fromValue = (jiraItem.getFromString() != null ? jiraItem.getFromString() : "");
        String toValue = (jiraItem.getToString() != null ? jiraItem.getToString() : "");

        // Only takes the "is blocked" relation
        String oldLink = (fromValue.contains("This issue is blocked by") ? jiraItem.getFrom() : null);
        String newLink = (toValue.contains("This issue is blocked by") ? jiraItem.getTo() : null);

        if (oldLink != null || newLink != null) {

            Item item = Item.builder().blockedIssues().oldValue(oldLink).newValue(newLink).build();
            items.add(item);
        }

    } else if (ChangeLogProperty.TAGS.is(field)) {

        Set<String> oldTags = Sets.newHashSet(jiraItem.getFromString().split(" "));
        Set<String> newTags = Sets.newHashSet(jiraItem.getToString().split(" "));

        // For these cases where there is no tag
        oldTags.remove("");
        newTags.remove("");

        Set<String> toAdd = Sets.difference(newTags, oldTags);
        Set<String> toDel = Sets.difference(oldTags, newTags);

        for (String tag : toAdd) {
            Item item = Item.builder().tags().newValue(tag).build();
            items.add(item);
        }

        for (String tag : toDel) {
            Item item = Item.builder().tags().oldValue(tag).build();
            items.add(item);
        }

    } else if (ChangeLogProperty.COMPONENT.is(field)) {

        Item item = Item.builder().components().oldValue(jiraItem.getFrom()).newValue(jiraItem.getTo()).build();
        items.add(item);

    } else if (ChangeLogProperty.TITLE.is(field)) {

        Item item = Item.builder().title().oldValue(jiraItem.getFromString()).newValue(jiraItem.getToString())
                .build();
        items.add(item);

    } else if (ChangeLogProperty.VERSION.is(field)) {

        Item item = Item.builder().versions().oldValue(jiraItem.getFrom()).newValue(jiraItem.getTo()).build();
        items.add(item);

    } else if (ChangeLogProperty.ASSIGNEE.is(field)) {

        String oldAssignee = null;
        String newAssignee = null;

        if (jiraItem.getFromString() != null) {
            oldAssignee = selectContributorByName(contributors, jiraItem.getFromString()).getId();
        }

        if (jiraItem.getToString() != null) {
            newAssignee = selectContributorByName(contributors, jiraItem.getToString()).getId();
        }

        Item item = Item.builder().assignee().oldValue(oldAssignee).newValue(newAssignee).build();
        items.add(item);

    } else if (ChangeLogProperty.DESCRIPTION.is(field)) {

        Item item = Item.builder().description().oldValue(jiraItem.getFromString())
                .newValue(jiraItem.getToString()).build();
        items.add(item);

    }

    return items;
}