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();
}
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());
}
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);
}
}
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);
}
}
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;
}
Aggregations