Example usage for java.time Duration toMillis

List of usage examples for java.time Duration toMillis

Introduction

In this page you can find the example usage for java.time Duration toMillis.

Prototype

public long toMillis() 

Source Link

Document

Converts this duration to the total length in milliseconds.

Usage

From source file:com.publictransitanalytics.scoregenerator.output.NetworkAccessibility.java

public NetworkAccessibility(final int taskCount, final ScoreCard scoreCard, final Grid grid,
        final Set<Sector> centerSectors, final LocalDateTime startTime, final LocalDateTime endTime,
        final Duration tripDuration, final Duration samplingInterval, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.NETWORK_ACCESSIBILITY;

    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    boundsCenter = new Point(grid.getBounds().getCenter());
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, Integer> countBuilder = ImmutableMap.builder();
    for (final Sector sector : sectors) {
        if (scoreCard.hasPath(sector)) {
            final Bounds bounds = new Bounds(sector);
            countBuilder.put(bounds, scoreCard.getReachedCount(sector));
        }//from   w  w w . jav a 2 s.  c om
    }
    sectorCounts = countBuilder.build();

    this.centerPoints = centerSectors.stream().map(sector -> new Point(sector.getBounds().getCenter()))
            .collect(Collectors.toSet());
    sampleCount = centerPoints.size();

    inServiceSeconds = inServiceTime.getSeconds();
}

From source file:com.publictransitanalytics.scoregenerator.output.PointAccessibility.java

public PointAccessibility(final int taskCount, final PathScoreCard scoreCard, final Grid grid,
        final PointLocation centerPoint, final LocalDateTime startTime, final LocalDateTime lastTime,
        final Duration samplingInterval, final Duration tripDuration, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint);
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = lastTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, SectorReachInformation> informationBuilder = ImmutableMap.builder();

    for (final Sector sector : sectors) {
        final Map<LogicalTask, MovementPath> taskPaths = scoreCard.getBestPaths(sector);
        if (!taskPaths.isEmpty()) {
            final ImmutableSet.Builder<MovementPath> bestPathsBuilder = ImmutableSet.builder();
            int count = 0;
            for (final MovementPath taskPath : taskPaths.values()) {
                if (taskPath != null) {
                    bestPathsBuilder.add(taskPath);
                    count++;/*from w ww.  java 2s .c  o m*/
                }
            }
            final Bounds bounds = new Bounds(sector);
            final Set<LocalDateTime> reachTimes = scoreCard.getReachedTimes(sector);
            final SectorReachInformation information = new SectorReachInformation(bestPathsBuilder.build(),
                    count, reachTimes);
            informationBuilder.put(bounds, information);
        }
    }
    sectorPaths = informationBuilder.build();

    inServiceSeconds = inServiceTime.getSeconds();
}

From source file:ai.grakn.engine.controller.TasksControllerTest.java

@Test
public void afterSendingTaskWithInterval_ItIsRecurringInStorage() {
    Duration interval = Duration.ofSeconds(1);
    send(Collections.emptyMap(),/*from  w  w  w  . j a va2  s.co m*/
            ImmutableMap.of(TASK_CLASS_NAME_PARAMETER, ShortExecutionMockTask.class.getName(),
                    TASK_CREATOR_PARAMETER, this.getClass().getName(), TASK_RUN_AT_PARAMETER,
                    Long.toString(now().toEpochMilli()), TASK_RUN_INTERVAL_PARAMETER,
                    Long.toString(interval.toMillis())));

    verify(manager).addTask(argThat(argument -> argument.schedule().interval().isPresent()), any());
    verify(manager).addTask(argThat(argument -> argument.schedule().isRecurring()), any());
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativeTimeQualifiedPointAccessibility.java

public ComparativeTimeQualifiedPointAccessibility(final PathScoreCard scoreCard,
        final PathScoreCard trialScoreCard, final Grid grid, final Center centerPoint, final LocalDateTime time,
        LocalDateTime trialTime, final Duration tripDuration, final boolean backward, final String name,
        final String trialName, final Duration inServiceTime, final Duration trialInServiceTime)
        throws InterruptedException {

    type = AccessibilityType.COMPARATIVE_TIME_QUALIFIED_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint.getLogicalCenter().getPointRepresentation());
    this.time = time.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialTime = trialTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);
    final ImmutableMap.Builder<Bounds, ComparativeFullSectorReachInformation> builder = ImmutableMap.builder();

    final Set<Sector> sectors = grid.getAllSectors();

    final TaskIdentifier task = new TaskIdentifier(time, centerPoint);
    for (final Sector sector : sectors) {
        final MovementPath sectorPath = scoreCard.getBestPath(sector, task);
        final MovementPath trialSectorPath = trialScoreCard.getBestPath(sector, task);
        if (sectorPath != null || trialSectorPath != null) {
            final Bounds sectorBounds = new Bounds(sector);

            builder.put(sectorBounds, new ComparativeFullSectorReachInformation(sectorPath, trialSectorPath));
        }/*  w  w  w . j a va2s  .c o  m*/
    }
    sectorPaths = builder.build();
    totalSectors = grid.getReachableSectors().size();
    this.name = name;
    this.trialName = trialName;
    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}

From source file:org.eclipse.hono.service.amqp.AmqpServiceBase.java

/**
 * Processes a peer's AMQP <em>open</em> frame.
 * <p>//from   w  w w. j  a v  a2  s  . c  o  m
 * This default implementation
 * <ol>
 * <li>adds a unique connection identifier to the connection's attachments
 * under key {@link Constants#KEY_CONNECTION_ID}</li>
 * <li>invokes {@link #processDesiredCapabilities(ProtonConnection, Symbol[])}</li>
 * <li>sets a timer that closes the connection once the client's token
 * has expired</li>
 * <li>sends the AMQP <em>open</em> frame to the peer</li>
 * </ol>
 * 
 * @param connection The connection to open.
 */
protected void processRemoteOpen(final ProtonConnection connection) {

    final HonoUser clientPrincipal = Constants.getClientPrincipal(connection);
    LOG.debug("client [container: {}, user: {}] connected", connection.getRemoteContainer(),
            clientPrincipal.getName());
    // attach an ID so that we can later inform downstream components when connection is closed
    connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString());
    processDesiredCapabilities(connection, connection.getRemoteDesiredCapabilities());
    final Duration delay = Duration.between(Instant.now(), clientPrincipal.getExpirationTime());
    final WeakReference<ProtonConnection> conRef = new WeakReference<>(connection);
    vertx.setTimer(delay.toMillis(), timerId -> {
        if (conRef.get() != null) {
            closeExpiredConnection(conRef.get());
        }
    });
    connection.open();
}

From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java

/**
  * //  w w w. ja v  a  2s.c o  m
  * From server to client. One packet for each row in the result set.
  * 
  * <pre>
  * Bytes                   Name
  * -----                   ----
  * n (Length Coded String) (column value)
  * ...
  * 
  * (column value):         The data in the column, as a character string.
  *                         If a column is defined as non-character, the
  *                         server converts the value into a character
  *                         before sending it. Since the value is a Length
  *                         Coded String, a NULL can be represented with a
  *                         single byte containing 251(see the description
  *                         of Length Coded Strings in section "Elements" above).
  * 
  * @see http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Row_Data_Packet
  * </pre>
  * 
  * @param buffer
  * @param nColumns 
  * @param rowRec
  */
public void writeRowTextBody(ByteBuf buffer, long pRecord, int nColumns) {
    for (int i = 0; i < nColumns; i++) {
        Object fv = Record.getValue(pRecord, i);
        if (fv instanceof Boolean) {
            // mysql has no boolean it is actually tinyint
            fv = ((Boolean) fv) ? 1 : 0;
        }
        if (fv == null) {
            // null mark is 251
            buffer.writeByte((byte) 251);
        } else if (fv instanceof Duration) {
            Duration t = (Duration) fv;
            String text = DurationFormatUtils.formatDuration(t.toMillis(), "HH:mm:ss");
            BufferUtils.writeLenString(buffer, text, this.cs);
        } else if (fv instanceof Timestamp) {
            // @see ResultSetRow#getDateFast, mysql jdbc driver only take precision 19,21,29 if callers wants
            // to get a Date from a datetime column
            Timestamp ts = (Timestamp) fv;
            if (ts.getTime() == Long.MIN_VALUE) {
                // mysql '0000-00-00 00:00:00' is treated as null in jdbc
                buffer.writeByte((byte) 251);
            } else {
                String text;
                if (ts.getNanos() == 0) {
                    text = TIMESTAMP19_FORMAT.format(ts);
                } else {
                    text = TIMESTAMP29_FORMAT.format(ts);
                }
                BufferUtils.writeLenString(buffer, text, this.cs);
            }
        } else if (fv instanceof byte[]) {
            BufferUtils.writeWithLength(buffer, (byte[]) fv);
        } else if ((fv instanceof Date) && (((Date) fv).getTime() == Long.MIN_VALUE)) {
            // mysql '0000-00-00' is treated as null in jdbc
            buffer.writeByte((byte) 251);
        } else {
            String val = fv.toString();
            if (val.length() == 0) {
                // empty mark is 0
                buffer.writeByte((byte) 0);
            } else {
                BufferUtils.writeLenString(buffer, val, this.cs);
            }
        }
    }
}

From source file:io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager.java

/**
 * Create a new {@link PrometheusPushGatewayManager} instance.
 * @param pushGateway the source push gateway
 * @param registry the collector registry to push
 * @param scheduler the scheduler used for operations
 * @param pushRate the rate at which push operations occur
 * @param job the job ID for the operation
 * @param groupingKey an optional set of grouping keys for the operation
 * @param shutdownOperation the shutdown operation that should be performed when
 * context is closed.//from w w  w. j a  va2 s .  co  m
 */
public PrometheusPushGatewayManager(PushGateway pushGateway, CollectorRegistry registry,
        TaskScheduler scheduler, Duration pushRate, String job, Map<String, String> groupingKey,
        ShutdownOperation shutdownOperation) {
    Assert.notNull(pushGateway, "PushGateway must not be null");
    Assert.notNull(registry, "Registry must not be null");
    Assert.notNull(scheduler, "Scheduler must not be null");
    Assert.notNull(pushRate, "PushRate must not be null");
    Assert.hasLength(job, "Job must not be empty");
    this.pushGateway = pushGateway;
    this.registry = registry;
    this.job = job;
    this.groupingKey = groupingKey;
    this.shutdownOperation = (shutdownOperation != null) ? shutdownOperation : ShutdownOperation.NONE;
    this.scheduler = scheduler;
    this.scheduled = this.scheduler.scheduleAtFixedRate(this::push, pushRate.toMillis());
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativeNetworkAccessibility.java

public ComparativeNetworkAccessibility(final int taskCount, final int trialTaskCount, final ScoreCard scoreCard,
        final ScoreCard trialScoreCard, final Grid grid, final Set<Sector> centerSectors,
        final LocalDateTime startTime, final LocalDateTime endTime, final LocalDateTime trialStartTime,
        final LocalDateTime trialEndTime, final Duration tripDuration, final Duration samplingInterval,
        final boolean backward, final String trialName, final Duration inServiceTime,
        final Duration trialInServiceTime) throws InterruptedException {
    type = AccessibilityType.COMPARATIVE_NETWORK_ACCESSIBILITY;

    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    boundsCenter = new Point(grid.getBounds().getCenter());
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialStartTime = trialStartTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialEndTime = trialEndTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;
    this.trialTaskCount = trialTaskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, CountComparison> countBuilder = ImmutableMap.builder();
    for (final Sector sector : sectors) {
        final int count = scoreCard.hasPath(sector) ? scoreCard.getReachedCount(sector) : 0;
        final int trialCount = trialScoreCard.hasPath(sector) ? trialScoreCard.getReachedCount(sector) : 0;

        if (count != 0 && trialCount != 0) {
            final Bounds bounds = new Bounds(sector);
            final CountComparison comparison = new CountComparison(count, trialCount);
            countBuilder.put(bounds, comparison);
        }/*from w w  w  .  j a v  a  2 s  .c o  m*/
    }

    sectorCounts = countBuilder.build();

    this.centerPoints = centerSectors.stream().map(sector -> new Point(sector.getBounds().getCenter()))
            .collect(Collectors.toSet());
    sampleCount = centerPoints.size();

    this.trialName = trialName;

    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativePointAccessibility.java

public ComparativePointAccessibility(final int taskCount, final int trialTaskCount,
        final PathScoreCard scoreCard, final PathScoreCard trialScoreCard, final Grid grid,
        final PointLocation centerPoint, final LocalDateTime startTime, final LocalDateTime endTime,
        final LocalDateTime trialStartTime, final LocalDateTime trialEndTime, final Duration samplingInterval,
        final Duration tripDuration, final boolean backward, final String trialName,
        final Duration inServiceTime, final Duration trialInServiceTime) throws InterruptedException {
    type = AccessibilityType.COMPARATIVE_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint);
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialStartTime = trialStartTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialEndTime = trialEndTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;
    this.trialTaskCount = trialTaskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, ComparativeSectorReachInformation> informationBuilder = ImmutableMap
            .builder();//from ww  w  .  ja  v  a  2  s.  c o  m

    for (final Sector sector : sectors) {
        final Map<LogicalTask, MovementPath> bestPaths = scoreCard.getBestPaths(sector);
        final Map<LogicalTask, MovementPath> trialBestPaths = trialScoreCard.getBestPaths(sector);
        if (!bestPaths.isEmpty() || !trialBestPaths.isEmpty()) {
            final Set<MovementPath> bestPathSet = getBestPathSet(bestPaths);
            final Set<LocalDateTime> reachTimes = scoreCard.getReachedTimes(sector);
            final Set<MovementPath> trialBestPathSet = getBestPathSet(trialBestPaths);
            final Set<LocalDateTime> trialReachTimes = trialScoreCard.getReachedTimes(sector);
            int numBestPaths = bestPathSet.size();
            int numTrialBestPaths = trialBestPathSet.size();

            final Bounds bounds = new Bounds(sector);
            final ComparativeSectorReachInformation information = new ComparativeSectorReachInformation(
                    bestPathSet, numBestPaths, reachTimes, trialBestPathSet, numTrialBestPaths,
                    trialReachTimes);
            informationBuilder.put(bounds, information);
        }
    }
    sectorPaths = informationBuilder.build();
    this.trialName = trialName;

    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}