Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.bitbreeds.webrtc.sctp.impl.HeartBeatService.java

License:Open Source License

/**
 * Calculates RTT value//www.j a  va 2 s .  co  m
 * Resets shutdown timers
 *
 * @param heartBeatInfo from ack
 */
public void receiveHeartBeatAck(byte[] heartBeatInfo) {

    UUID uuid = new UUID(bytesToLong(copyRange(heartBeatInfo, new ByteRange(0, 8))),
            bytesToLong(copyRange(heartBeatInfo, new ByteRange(8, 16))));

    DateTime time = rttMap.get(uuid);
    if (time == null) {
        throw new IllegalArgumentException("Ack with unkown uuid: " + uuid + " map contains: " + rttMap);
    } else {
        rttMillis = DateTime.now().getMillis() - time.getMillis();
        synchronized (mutex) {
            rttMap = rttMap.minus(uuid);
        }
    }
}

From source file:com.bitbreeds.webrtc.sctp.impl.HeartBeatService.java

License:Open Source License

/**
 * @return heartbeat message//from www.  j ava  2s . co  m
 */
public SCTPMessage createHeartBeat(SCTPHeader header) {

    UUID id = UUID.randomUUID();
    byte[] heartBeatInfo = SignalUtil.joinBytesArrays(SignalUtil.longToBytes(id.getMostSignificantBits()),
            SignalUtil.longToBytes(id.getLeastSignificantBits()));

    Map<SCTPAttributeType, SCTPAttribute> variableAttr = new HashMap<>();
    variableAttr.put(SCTPAttributeType.HERTBEAT_INFO,
            new SCTPAttribute(SCTPAttributeType.HERTBEAT_INFO, heartBeatInfo));

    int sum = variableAttr.values().stream().map(SCTPAttribute::getLength).reduce(0, Integer::sum);

    SCTPChunk heartBeat = new SCTPChunk(SCTPMessageType.HEARTBEAT, SCTPFlags.fromValue((byte) 0), 4 + sum,
            new HashMap<>(), variableAttr, new byte[] {});
    SCTPMessage msg = new SCTPMessage(header, Collections.singletonList(heartBeat));

    SCTPMessage out = SCTPUtil.addChecksum(msg);
    synchronized (mutex) {
        rttMap = rttMap.plus(id, DateTime.now());
    }
    return out;
}

From source file:com.bitbreeds.webrtc.sctp.impl.SendService.java

License:Open Source License

/**
 * @param tsn tsn for this message/*from www. j  a  va 2 s  .co  m*/
 * @param data data to send
 */
public void addMessageToSend(long tsn, byte[] data) {
    DateTime datePlusMillis = DateTime.now().plusMillis(resendMillis);
    TimeData timeData = new TimeData(datePlusMillis, data);
    synchronized (dataMutex) {
        sentTSNS = sentTSNS.plus(tsn, timeData);
    }
}

From source file:com.bitbreeds.webrtc.sctp.impl.SendService.java

License:Open Source License

/**
 * This decides what messages are to be resent.
 * It is decided based on whether the time passed since the message was
 * sent is above resendMillis.//  w ww.  j  a v a2 s  . c om
 *
 * The time can be substantially larger then resendMillis if resending thread
 * has trouble sending.
 *
 * @return list of data that should be sent again since no ack has been received
 */
public List<byte[]> getMessagesForResend() {
    List<Long> forResend = sentTSNS.entrySet().stream().filter(i -> DateTime.now().isAfter(i.getValue().time))
            .map(Map.Entry::getKey).collect(Collectors.toList());

    logger.debug("Got these TSNs for resend {}", forResend);

    return sentTSNS.values().stream().filter(i -> DateTime.now().isAfter(i.time)).map(i -> i.data)
            .collect(Collectors.toList());
}

From source file:com.bitplan.rest.RestServerImpl.java

License:Apache License

/**
 * stop this server/*from   w ww .  java  2 s  .c om*/
 * 
 * @see com.bitplan.rest.RestServer#stop()
 */
@Override
public void stop() {
    if (httpServer != null) {
        httpServer.shutdown();
        httpServer = null;
        running = false;
        stopTime = DateTime.now();
        Seconds secs = Seconds.secondsBetween(startTime, stopTime);
        System.out.println("finished after " + secs.getSeconds() + " secs");
        // if someone is waiting for us let him continue ..
        informStarter();
    }
}

From source file:com.bitplan.rest.RestServerImpl.java

License:Apache License

@Override
public RestServer startServer(String[] args) {
    settings.parseArguments(args);//from   w ww . java2  s .c o m
    startTime = DateTime.now();
    serverThread = new Thread(this);
    serverThread.setUncaughtExceptionHandler(this);
    serverThread.start();
    return this;
}

From source file:com.bitsofproof.btc1k.server.vault.PendingTransaction.java

License:Apache License

public PendingTransaction(Transaction transaction, BigDecimal amount, Address targetAddress, String title) {
    this.id = UUID.randomUUID();
    this.transaction = transaction;
    this.title = title;
    this.amount = amount;
    this.targetAddress = targetAddress;
    this.createdAt = DateTime.now();
}

From source file:com.blackducksoftware.bdio.model.CreationInfo.java

License:Apache License

public static CreationInfo currentTool() {
    Class<?> currentToolClass;
    try {/* ww  w.  j  ava2  s  .c o  m*/
        currentToolClass = currentToolClass();
    } catch (ClassNotFoundException e) {
        currentToolClass = CreationInfo.class;
    }

    CreationInfo result = new CreationInfo();
    result.setCreated(DateTime.now().withMillisOfSecond(0).withZone(DateTimeZone.UTC));
    result.setCreator(ImmutableList.of(Joiner.on('-').skipNulls().appendTo(new StringBuilder("Tool: "),
            firstNonNull(currentToolClass.getPackage().getImplementationTitle(),
                    currentToolClass.getSimpleName()),
            currentToolClass.getPackage().getImplementationVersion()).toString()));
    return result;
}

From source file:com.blackducksoftware.integration.hub.cli.SimpleScanService.java

License:Apache License

/**
 * This method can be overridden to provide a more appropriate directory name for the logs of a specific scan
 * execution./*from w w w .  j  a  v a 2s.  c om*/
 */
public String getSpecificScanExecutionLogDirectory() {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd_HH-mm-ss-SSS").withZoneUTC();
    String timeString = DateTime.now().withZone(DateTimeZone.UTC).toString(dateTimeFormatter);
    return timeString;
}

From source file:com.blackducksoftware.integration.jira.task.JiraSettingsService.java

License:Apache License

public void addHubError(final String errorMessage, final String hubProject, final String hubProjectVersion,
        final String jiraProject, final String jiraAdminUsername, final String jiraIssueCreatorUsername,
        final String methodAttempt) {

    logger.debug("Sending error to UI");
    List<TicketCreationError> ticketErrors = expireOldErrors(settings);
    if (ticketErrors == null) {
        ticketErrors = new ArrayList<>();
    }//  w w w.  jav  a 2 s  .c om

    final StringBuilder suffixBuilder = new StringBuilder();
    if (StringUtils.isNotBlank(hubProject)) {
        suffixBuilder.append("Hub Project : ");
        suffixBuilder.append(hubProject);
        suffixBuilder.append(" / ");
    }
    if (StringUtils.isNotBlank(hubProjectVersion)) {
        suffixBuilder.append("Version : ");
        suffixBuilder.append(hubProjectVersion);
        suffixBuilder.append(" / ");
    }
    if (StringUtils.isNotBlank(jiraProject)) {
        suffixBuilder.append("JIRA Project : ");
        suffixBuilder.append(jiraProject);
        suffixBuilder.append(" / ");
    }
    if (StringUtils.isNotBlank(jiraAdminUsername)) {
        suffixBuilder.append("JIRA Admin User : ");
        suffixBuilder.append(jiraAdminUsername);
        suffixBuilder.append(" / ");
    }
    if (StringUtils.isNotBlank(jiraIssueCreatorUsername)) {
        suffixBuilder.append("JIRA Issue Creator User : ");
        suffixBuilder.append(jiraIssueCreatorUsername);
        suffixBuilder.append(" / ");
    }
    suffixBuilder.append("Method : ");
    suffixBuilder.append(methodAttempt);

    final StringBuilder finalErrorBuilder = new StringBuilder();
    finalErrorBuilder.append(errorMessage.trim());
    finalErrorBuilder.append("\n");
    finalErrorBuilder.append(suffixBuilder.toString());

    final TicketCreationError error = new TicketCreationError();
    error.setStackTrace(finalErrorBuilder.toString());
    error.setTimeStamp(DateTime.now().toString(TicketCreationError.ERROR_TIME_FORMAT));

    ticketErrors.add(error);

    final int maxErrorSize = 20;
    if (ticketErrors.size() > maxErrorSize) {
        Collections.sort(ticketErrors);
        ticketErrors.subList(maxErrorSize, ticketErrors.size()).clear();
    }
    logger.debug("Saving " + ticketErrors.size() + " error messages to settings");
    settings.put(HubJiraConstants.HUB_JIRA_ERROR, TicketCreationError.toJson(ticketErrors));
}