Java Code Examples for org.threeten.bp.Instant#now()
The following examples show how to use
org.threeten.bp.Instant#now() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongPositionVector.java From geonetworking with Apache License 2.0 | 6 votes |
/** Returns the nearest to now instant that will have given amount of TAI millis since 2004. */ public static Instant millisMod32ToInstant(int intMillisX) { long millisX = Long.parseLong(Integer.toBinaryString(intMillisX), 2); // unsigned int... Instant now = Instant.now(); long millisNow = instantToTaiMillisSince2004Mod32(now); long delta = millisNow - millisX; // Small positive delta is what we expect. // Small negative delta is fine too, it would mean that the packet came from the future, // which can be explained by our clock being a little behind. // Huge negative delta is from previous mod32, and should be changed to small positive. // Huge positive delta might come from a packet a little from the future and next mod32, // we want instead a small negative delta. if (delta < -(1L << 31)) { delta += (1L << 32); } if (delta > (1L << 31)) { delta -= (1L << 32); } Instant instantX = now.minusMillis(delta); return instantX; }
Example 2
Source File: FindingSnippets.java From google-cloud-java with Apache License 2.0 | 6 votes |
/** * Updates a finding's state to INACTIVE. * * @param findingName The finding to update. */ // [START 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); } }
Example 3
Source File: LongPositionVectorTest.java From geonetworking with Apache License 2.0 | 5 votes |
@Test public void test() { LongPositionVector v1 = new LongPositionVector( Address.random(true, StationType.Unknown, 240), Instant.now(), new Position(13, 17), true, 22, 15 ); roundTrip(v1); }
Example 4
Source File: FindingSnippets.java From google-cloud-java with Apache License 2.0 | 5 votes |
/** * Create a finding under a source. * * @param sourceName The source for the finding. */ // [START create_finding] static Finding createFinding(SourceName sourceName, String findingId) { try (SecurityCenterClient client = SecurityCenterClient.create()) { // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/ // "423432321"); // String findingId = "samplefindingid"; // Use the current time as the finding "event time". Instant eventTime = Instant.now(); // The resource this finding applies to. The CSCC UI can link // the findings for a resource to the corresponding Asset of a resource // if there are matches. String resourceName = "//cloudresourcemanager.googleapis.com/organizations/11232"; // Start setting up a request to create a finding in a source. Finding finding = Finding.newBuilder() .setParent(sourceName.toString()) .setState(State.ACTIVE) .setResourceName(resourceName) .setEventTime( Timestamp.newBuilder() .setSeconds(eventTime.getEpochSecond()) .setNanos(eventTime.getNano())) .setCategory("MEDIUM_RISK_ONE") .build(); // Call the API. Finding response = client.createFinding(sourceName, findingId, finding); System.out.println("Created Finding: " + response); return response; } catch (IOException e) { throw new RuntimeException("Couldn't create client.", e); } }
Example 5
Source File: GeonetStation.java From geonetworking with Apache License 2.0 | 4 votes |
private Instant timeInstantNow() { return Instant.now(); // Add clock here for non-real-time. }
Example 6
Source File: BasicSocketTestOverUdp.java From geonetworking with Apache License 2.0 | 4 votes |
@Test(timeout=3000) public void test() throws IOException, InterruptedException { int client1 = 4440; int server1 = 4441; int client2 = 4450; int server2 = 4451; UdpDuplicator d = new UdpDuplicator(); d.add(server1, new InetSocketAddress(InetAddress.getLoopbackAddress(), client1)); d.add(server2, new InetSocketAddress(InetAddress.getLoopbackAddress(), client2)); boolean hasEthernetHeader = false; LinkLayer l1 = new LinkLayerUdpToEthernet(client1, new InetSocketAddress(InetAddress.getLoopbackAddress(), server1), hasEthernetHeader); LinkLayer l2 = new LinkLayerUdpToEthernet(client2, new InetSocketAddress(InetAddress.getLoopbackAddress(), server2), hasEthernetHeader); StationConfig config1 = new StationConfig(); StationConfig config2 = new StationConfig(); final Optional<Address> emptyAddress = Optional.empty(); PositionProvider pos = new PositionProvider() { @Override public LongPositionVector getLatestPosition() { return new LongPositionVector(emptyAddress, Instant.now(), new Position(57.7169943, 12.0200253), false, 22, 0); } }; BtpSocket socket1 = BtpSocket.on(config1, l1, pos); BtpSocket socket2 = BtpSocket.on(config2, l2, pos); byte[] data = new byte[] { 0x10, 0x13, 0x7F }; int port = 2000; BtpPacket packet1 = BtpPacket.singleHop(data, (short) port); socket1.send(packet1); BtpPacket packet2 = socket2.receive(); assertEquals("ports", packet1.destinationPort(), packet2.destinationPort()); assertArrayEquals("data and sender payload", data, packet1.payload()); assertArrayEquals("data and receiver payload", data, packet2.payload()); byte[] data2 = new byte[] { 0x13, 0x14, 0x7F }; BtpPacket packet21 = BtpPacket.singleHop(data2, (short) port); socket1.send(packet21); BtpPacket packet22 = socket2.receive(); assertEquals("ports", packet21.destinationPort(), packet22.destinationPort()); assertArrayEquals("data and sender payload", data2, packet21.payload()); assertArrayEquals("data and receiver payload", data2, packet22.payload()); }
Example 7
Source File: BasicSocketTest.java From geonetworking with Apache License 2.0 | 4 votes |
@Test(timeout=8000) public void test() throws IOException, InterruptedException { DuplicatorLinkLayer d = new DuplicatorLinkLayer(); LinkLayer l1 = d.get(); LinkLayer l2 = d.get(); StationConfig config1 = new StationConfig(); StationConfig config2 = new StationConfig(); final Optional<Address> emptyAddress = Optional.empty(); PositionProvider pos = new PositionProvider() { @Override public LongPositionVector getLatestPosition() { return new LongPositionVector(emptyAddress, Instant.now(), new Position(57.7169943, 12.0200253), false, 22, 0); } }; BtpSocket socket1 = BtpSocket.on(config1, l1, pos); BtpSocket socket2 = BtpSocket.on(config2, l2, pos); byte[] data = new byte[] {0x10, 0x13, 0x7F}; int port = 2000; BtpPacket packet1 = BtpPacket.singleHop(data, (short) port); socket1.send(packet1); BtpPacket packet2 = socket2.receive(); assertEquals("ports", packet1.destinationPort(), packet2.destinationPort()); assertArrayEquals("data and sender payload", data, packet1.payload()); assertArrayEquals("data and receiver payload", data, packet2.payload()); socket1.send(packet1); BtpPacket packet3 = socket2.receive(); assertEquals("ports", packet1.destinationPort(), packet3.destinationPort()); assertArrayEquals("data and sender payload", data, packet1.payload()); assertArrayEquals("data and receiver payload", data, packet3.payload()); }
Example 8
Source File: Examples.java From ThreeTenABP with Apache License 2.0 | 4 votes |
public Instant now() { return Instant.now(); }
Example 9
Source File: ContentDownloadService.java From Hentoid with Apache License 2.0 | 4 votes |
private void logErrorRecord(long contentId, ErrorType type, String url, String contentPart, String description) { ErrorRecord record = new ErrorRecord(contentId, type, url, contentPart, description, Instant.now()); if (contentId > 0) dao.insertErrorRecord(record); }
Example 10
Source File: LogUtil.java From Hentoid with Apache License 2.0 | 4 votes |
public LogEntry(@NonNull String message) { this.timestamp = Instant.now(); this.message = message; }
Example 11
Source File: FindingSnippets.java From google-cloud-java with Apache License 2.0 | 4 votes |
/** * Create a finding with source properties under a source. * * @param sourceName The source for the finding. */ // [START create_finding_with_source_properties] static Finding createFindingWithSourceProperties(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/ // "423432321"); // Use the current time as the finding "event time". Instant eventTime = Instant.now(); // Controlled by caller. String findingId = "samplefindingid2"; // The resource this finding applies to. The CSCC UI can link // the findings for a resource to the corresponding Asset of a resource // if there are matches. String resourceName = "//cloudresourcemanager.googleapis.com/organizations/11232"; // Define source properties values as protobuf "Value" objects. Value stringValue = Value.newBuilder().setStringValue("stringExample").build(); Value numValue = Value.newBuilder().setNumberValue(1234).build(); ImmutableMap<String, Value> sourceProperties = ImmutableMap.of("stringKey", stringValue, "numKey", numValue); // Start setting up a request to create a finding in a source. Finding finding = Finding.newBuilder() .setParent(sourceName.toString()) .setState(State.ACTIVE) .setResourceName(resourceName) .setEventTime( Timestamp.newBuilder() .setSeconds(eventTime.getEpochSecond()) .setNanos(eventTime.getNano())) .putAllSourceProperties(sourceProperties) .build(); // Call the API. Finding response = client.createFinding(sourceName, findingId, finding); System.out.println("Created Finding with Source Properties: " + response); return response; } catch (IOException e) { throw new RuntimeException("Couldn't create client.", e); } }
Example 12
Source File: FindingSnippets.java From google-cloud-java with Apache License 2.0 | 4 votes |
/** * Update a finding's source properties. * * @param findingName The finding to update. */ // [START update_finding] static Finding updateFinding(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(); // Define source properties values as protobuf "Value" objects. Value stringValue = Value.newBuilder().setStringValue("value").build(); FieldMask updateMask = FieldMask.newBuilder() .addPaths("event_time") .addPaths("source_properties.stringKey") .build(); Finding finding = Finding.newBuilder() .setName(findingName.toString()) .setEventTime( Timestamp.newBuilder() .setSeconds(eventTime.getEpochSecond()) .setNanos(eventTime.getNano())) .putSourceProperties("stringKey", stringValue) .build(); UpdateFindingRequest.Builder request = UpdateFindingRequest.newBuilder().setFinding(finding).setUpdateMask(updateMask); // Call the API. Finding response = client.updateFinding(request.build()); System.out.println("Updated Finding: " + response); return response; } catch (IOException e) { throw new RuntimeException("Couldn't create client.", e); } }