Example usage for java.time ZonedDateTime plusSeconds

List of usage examples for java.time ZonedDateTime plusSeconds

Introduction

In this page you can find the example usage for java.time ZonedDateTime plusSeconds.

Prototype

public ZonedDateTime plusSeconds(long seconds) 

Source Link

Document

Returns a copy of this ZonedDateTime with the specified number of seconds added.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.plusSeconds(1234);
    System.out.println(n);//from   w w w. ja  va 2s .  c  o  m
}

From source file:org.openrepose.filters.custom.extractdeviceid.ExtractDeviceIdFilter.java

static String getRetryString(Header[] headers, int statusCode) {
    String rtn;// w w w.  j  a  v  a2 s .  c o  m
    Object[] retryHeaders = Arrays.stream(headers).filter(header -> header.getName().equals(RETRY_AFTER))
            .toArray();
    if (retryHeaders.length < 1) {
        LOG.info("Missing {} header on Auth Response status code: {}", RETRY_AFTER, statusCode);
        final ZonedDateTime zdt = ZonedDateTime.now(Clock.systemUTC());
        zdt.plusSeconds(5);
        rtn = zdt.format(RFC_1123_DATE_TIME);
    } else {
        rtn = ((Header) retryHeaders[0]).getValue();
    }
    return rtn;
}

From source file:com.example.geomesa.kafka.KafkaQuickStart.java

public static void addSimpleFeatures(SimpleFeatureType sft, FeatureStore producerFS, String visibility)
        throws InterruptedException, IOException {
    final int MIN_X = -180;
    final int MAX_X = 180;
    final int MIN_Y = -90;
    final int MAX_Y = 90;
    final int DX = 2;
    final int DY = 1;
    final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" };
    final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L;
    final Random random = new Random();
    final ZonedDateTime MIN_DATE = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft);
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();

    // creates and updates two SimpleFeatures.
    // the first time this for loop runs the two SimpleFeatures are created.
    // in the subsequent iterations of the for loop, the two SimpleFeatures are updated.
    int numFeatures = (MAX_X - MIN_X) / DX;
    for (int i = 1; i <= numFeatures; i++) {
        builder.add(PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name
        builder.add((int) Math.round(random.nextDouble() * 110)); // age
        builder.add(Date.from(/*ww w  .j a v a2  s  .  c o  m*/
                MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg
        builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MIN_Y + DY * i) + ")")); // geom
        SimpleFeature feature1 = builder.buildFeature("1");
        feature1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);

        builder.add(PEOPLE_NAMES[(i + 1) % PEOPLE_NAMES.length]); // name
        builder.add((int) Math.round(random.nextDouble() * 110)); // age
        builder.add(Date.from(
                MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg
        builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MAX_Y - DY * i) + ")")); // geom
        SimpleFeature feature2 = builder.buildFeature("2");
        feature2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);

        if (visibility != null) {
            feature1.getUserData().put("geomesa.feature.visibility", visibility);
            feature2.getUserData().put("geomesa.feature.visibility", visibility);
        }

        // write the SimpleFeatures to Kafka
        featureCollection.add(feature1);
        featureCollection.add(feature2);
        producerFS.addFeatures(featureCollection);
        featureCollection.clear();

        // wait 100 ms in between updating SimpleFeatures to simulate a stream of data
        Thread.sleep(100);
    }
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected long calculateSearchDelay(ZonedDateTime startTime) {
    long searchDelay = 0;

    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    ZonedDateTime offsetStartTime = startTime.plusSeconds(SEARCH_START_DELAY_SECONDS);

    if (now.isBefore(offsetStartTime)) {
        searchDelay = now.until(offsetStartTime, ChronoUnit.MILLIS);
    }//from w  ww.  j  av a  2 s.  co m

    return searchDelay;
}

From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java

/*******************************************************************************************************************
 *
 ******************************************************************************************************************/
@Test// ww w .  j  a va 2 s  . co  m
public void must_check_file_modification_after_expiration_time_and_still_keep_in_cache_when_no_modifications()
        throws Exception {
    // given
    ZonedDateTime nextExpectedExpirationTime = initialTime.plusSeconds(underTest.getMedatataExpirationTime());
    when(mediaFile.getLatestModificationTime()).thenReturn(initialTime.minusNanos(1));

    final Metadata metadata = underTest.findMetadataById(mediaId, siteNodeProperties);

    for (int count = 1; count <= 10; count++) {
        final ZonedDateTime now = nextExpectedExpirationTime.plusNanos(1);
        setTime(now);
        nextExpectedExpirationTime = now.plusSeconds(underTest.getMedatataExpirationTime());
        // when
        final Metadata metadata2 = underTest.findMetadataById(mediaId, siteNodeProperties);
        // then
        assertThat(metadata2, is(sameInstance(metadata)));

        final ExpirableMetadata expirableMetadata = underTest.metadataMapById.get(mediaId);
        assertThat(expirableMetadata, is(notNullValue()));
        assertThat(expirableMetadata.getMetadata(), sameInstance(metadata2));
        assertThat(expirableMetadata.getCreationTime(), is(initialTime));
        assertThat(expirableMetadata.getExpirationTime(), is(nextExpectedExpirationTime));
        log.info(">>>> next expiration time: {}", expirableMetadata.getExpirationTime());

        verify(metadataLoader, times(1)).loadMetadata(eq(mediaFile));
        verify(mediaFile, times(count)).getLatestModificationTime();
    }
}

From source file:org.thingsboard.server.service.security.model.token.JwtTokenFactory.java

/**
 * Factory method for issuing new JWT Tokens.
 *///from w  ww.  j a  v a2 s  . c  om
public AccessJwtToken createAccessJwtToken(SecurityUser securityUser) {
    if (StringUtils.isBlank(securityUser.getEmail()))
        throw new IllegalArgumentException("Cannot create JWT Token without username/email");

    if (securityUser.getAuthority() == null)
        throw new IllegalArgumentException("User doesn't have any privileges");

    UserPrincipal principal = securityUser.getUserPrincipal();
    String subject = principal.getValue();
    Claims claims = Jwts.claims().setSubject(subject);
    claims.put(SCOPES, securityUser.getAuthorities().stream().map(GrantedAuthority::getAuthority)
            .collect(Collectors.toList()));
    claims.put(USER_ID, securityUser.getId().getId().toString());
    claims.put(FIRST_NAME, securityUser.getFirstName());
    claims.put(LAST_NAME, securityUser.getLastName());
    claims.put(ENABLED, securityUser.isEnabled());
    claims.put(IS_PUBLIC, principal.getType() == UserPrincipal.Type.PUBLIC_ID);
    if (securityUser.getTenantId() != null) {
        claims.put(TENANT_ID, securityUser.getTenantId().getId().toString());
    }
    if (securityUser.getCustomerId() != null) {
        claims.put(CUSTOMER_ID, securityUser.getCustomerId().getId().toString());
    }

    ZonedDateTime currentTime = ZonedDateTime.now();

    String token = Jwts.builder().setClaims(claims).setIssuer(settings.getTokenIssuer())
            .setIssuedAt(Date.from(currentTime.toInstant()))
            .setExpiration(Date.from(currentTime.plusSeconds(settings.getTokenExpirationTime()).toInstant()))
            .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey()).compact();

    return new AccessJwtToken(token, claims);
}

From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java

/*******************************************************************************************************************
 *
 ******************************************************************************************************************/
@Test//from  w  w w  . j a v  a  2  s  .c  om
public void must_reload_metadata_after_expiration_time_when_file_has_been_changed() throws Exception {
    // given
    ZonedDateTime nextExpectedExpirationTime = initialTime.plusSeconds(underTest.getMedatataExpirationTime());
    final Metadata metadata = underTest.findMetadataById(mediaId, siteNodeProperties);

    for (int count = 1; count < 10; count++) {
        final ZonedDateTime now = nextExpectedExpirationTime.plusNanos(1);
        setTime(now);
        when(mediaFile.getLatestModificationTime()).thenReturn(now.plusNanos(1));
        nextExpectedExpirationTime = now.plusSeconds(underTest.getMedatataExpirationTime());
        // when
        final Metadata metadata2 = underTest.findMetadataById(mediaId, siteNodeProperties);
        // then
        assertThat(metadata2, is(not(sameInstance(metadata))));

        final ExpirableMetadata expirableMetadata = underTest.metadataMapById.get(mediaId);
        assertThat(expirableMetadata, is(notNullValue()));
        assertThat(expirableMetadata.getMetadata(), sameInstance(metadata2));
        assertThat(expirableMetadata.getCreationTime(), is(now));
        assertThat(expirableMetadata.getExpirationTime(), is(nextExpectedExpirationTime));
        log.info(">>>> next expiration time: {}", expirableMetadata.getExpirationTime());

        verify(metadataLoader, times(count + 1)).loadMetadata(eq(mediaFile));
        verify(mediaFile, times(count)).getLatestModificationTime();
    }
}

From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java

@Test
public void addActivity_completelyPrecedingLastRegisteredActivity_noGoalConflictMessagesCreated() {
    ZonedDateTime t1 = now();
    ZonedDateTime t2 = t1.plusSeconds(1);
    ActivityDto lastRegisteredActivity = ActivityDto.createInstance(createActivity(t2, t2));

    service.addActivity(userAnonEntity, createPayload(t1, t1), GoalDto.createInstance(gamblingGoal),
            Optional.of(lastRegisteredActivity));

    verifyNoGoalConflictMessagesCreated();
}

From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java

@Test
public void updateTimeExistingActivity_default_cacheNotUpdated() {
    ZonedDateTime t1 = now();
    ZonedDateTime t2 = t1.plusSeconds(1);
    DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t2, t2, "Lotto");
    Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId);

    service.updateTimeExistingActivity(createPayload(t1, t2), existingActivityEntity);

    verify(mockAnalysisEngineCacheService, never()).updateLastActivityForUser(any(), any(), any(), any());
}

From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java

@Test
public void updateTimeExistingActivity_default_noGoalConflictMessagesCreated() {
    ZonedDateTime t1 = now();
    ZonedDateTime t2 = t1.plusSeconds(1);
    ZonedDateTime t3 = t2.plusSeconds(1);
    DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t2, t2, "Lotto");
    Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId);

    service.updateTimeExistingActivity(createPayload(t1, t3), existingActivityEntity);

    verifyNoGoalConflictMessagesCreated();
}