Search in sources :

Example 1 with Instant

use of org.threeten.bp.Instant in project google-cloud-java by GoogleCloudPlatform.

the class MessageDispatcher method processReceivedMessages.

public void processReceivedMessages(List<ReceivedMessage> messages, Runnable doneCallback) {
    if (messages.isEmpty()) {
        doneCallback.run();
        return;
    }
    messagesWaiter.incrementPendingMessages(messages.size());
    OutstandingMessagesBatch outstandingBatch = new OutstandingMessagesBatch(doneCallback);
    final ArrayList<AckHandler> ackHandlers = new ArrayList<>(messages.size());
    for (ReceivedMessage message : messages) {
        AckHandler ackHandler = new AckHandler(message.getAckId(), message.getMessage().getSerializedSize());
        ackHandlers.add(ackHandler);
        outstandingBatch.addMessage(message, ackHandler);
    }
    Instant expiration = Instant.ofEpochMilli(clock.millisTime()).plusSeconds(messageDeadlineSeconds);
    synchronized (outstandingAckHandlers) {
        outstandingAckHandlers.add(new ExtensionJob(Instant.ofEpochMilli(clock.millisTime()), expiration, INITIAL_ACK_DEADLINE_EXTENSION_SECONDS, ackHandlers));
    }
    setupNextAckDeadlineExtensionAlarm(expiration);
    synchronized (outstandingMessageBatches) {
        outstandingMessageBatches.add(outstandingBatch);
    }
    processOutstandingBatches();
}
Also used : Instant(org.threeten.bp.Instant) ArrayList(java.util.ArrayList) ReceivedMessage(com.google.pubsub.v1.ReceivedMessage)

Example 2 with Instant

use of org.threeten.bp.Instant in project ThreeTenABP by JakeWharton.

the class ExamplesTest method proguardHappened.

/**
 * Assert that ProGuard has run and obfuscated a library type. This implicitly also tests the
 * embedded ProGuard rules in the library are correct since currently ProGuard fails without them.
 */
@Test
public void proguardHappened() {
    Examples activity = examplesActivity.getActivity();
    Instant now = activity.now();
    assertNotEquals("Instant", now.getClass().getSimpleName());
}
Also used : Instant(org.threeten.bp.Instant) Test(org.junit.Test)

Example 3 with Instant

use of org.threeten.bp.Instant in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method setFindingState.

// [END securitycenter_update_finding_source_properties]
/**
 * Updates a finding's state to INACTIVE.
 *
 * @param findingName The finding to update.
 */
// [START securitycenter_update_finding_state]
static Finding setFindingState(FindingName findingName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // FindingName findingName = FindingName.of(/*organization=*/"123234324",
        // /*source=*/"423432321", /*findingId=*/"samplefindingid2");
        // Use the current time as the finding "event time".
        Instant eventTime = Instant.now();
        Finding response = client.setFindingState(findingName, State.INACTIVE, Timestamp.newBuilder().setSeconds(eventTime.getEpochSecond()).setNanos(eventTime.getNano()).build());
        System.out.println("Updated Finding: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) Finding(com.google.cloud.securitycenter.v1.Finding) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 4 with Instant

use of org.threeten.bp.Instant in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method groupActiveFindingsWithSourceAtTime.

// [END securitycenter_group_active_findings_with_source]
/**
 * Group active findings under an organization and a source by their specified properties (e.g.
 * category) at a specified time.
 *
 * @param sourceName The source to limit the findings to.
 */
// [START securitycenter_group_active_findings_with_source_at_time]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        // 1 day ago
        Instant oneDayAgo = Instant.now().minusSeconds(60 * 60 * 24);
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category").setFilter("state=\"ACTIVE\"").setReadTime(Timestamp.newBuilder().setSeconds(oneDayAgo.getEpochSecond()).setNanos(oneDayAgo.getNano()));
        // Call the API.
        GroupFindingsPagedResponse response = client.groupFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings
        // this can cause out of memory issues.  You can process them batches by returning
        // the Iterable returned response.iterateAll() directly.
        ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 5 with Instant

use of org.threeten.bp.Instant in project SeriesGuide by UweTrottmann.

the class TimeTools method isSameWeekDay.

public static boolean isSameWeekDay(Date episodeDateTime, @Nullable Date showDateTime, int weekDay) {
    if (weekDay == RELEASE_WEEKDAY_DAILY) {
        return true;
    }
    if (showDateTime == null || weekDay == RELEASE_WEEKDAY_UNKNOWN) {
        return false;
    }
    Instant showInstant = Instant.ofEpochMilli(showDateTime.getTime());
    DayOfWeek showDayOfWeek = LocalDateTime.ofInstant(showInstant, ZoneId.systemDefault()).getDayOfWeek();
    Instant episodeInstant = Instant.ofEpochMilli(episodeDateTime.getTime());
    DayOfWeek episodeDayOfWeek = LocalDateTime.ofInstant(episodeInstant, ZoneId.systemDefault()).getDayOfWeek();
    return episodeDayOfWeek == showDayOfWeek;
}
Also used : DayOfWeek(org.threeten.bp.DayOfWeek) Instant(org.threeten.bp.Instant)

Aggregations

Instant (org.threeten.bp.Instant)17 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)6 IOException (java.io.IOException)6 Test (org.junit.Test)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 ZonedDateTime (org.threeten.bp.ZonedDateTime)4 Value (com.google.protobuf.Value)2 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)1 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)1 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)1 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)1 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)1 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)1 UpdateFindingRequest (com.google.cloud.securitycenter.v1.UpdateFindingRequest)1 FieldMask (com.google.protobuf.FieldMask)1 ReceivedMessage (com.google.pubsub.v1.ReceivedMessage)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Clock (org.threeten.bp.Clock)1 DayOfWeek (org.threeten.bp.DayOfWeek)1