Skip to content

Commit

Permalink
JGRP-2736 Use Instant instead of Date
Browse files Browse the repository at this point in the history
* Avoids triggering of the JDK TZ rule caching
* Uses consistent ISO-8601 format
  • Loading branch information
tristantarrant committed Oct 12, 2023
1 parent dfc9012 commit 887e1b9
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/org/jgroups/blocks/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -202,7 +203,7 @@ public String toString() {
if(expiration_time <= 0)
sb.append(expiration_time);
else {
sb.append(new Date(expiration_time));
sb.append(Instant.ofEpochMilli(expiration_time));
}
sb.append(")\n");
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/blocks/GridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jgroups.annotations.Experimental;

import java.io.*;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -361,7 +362,7 @@ public String toString() {
sb.append(getType());
if(is_file)
sb.append(", len=" + Util.printBytes(length) + ", chunk_size=" + chunk_size);
sb.append(", mod_time=" + new Date(modification_time));
sb.append(", mod_time=" + Instant.ofEpochMilli(modification_time));
return sb.toString();
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/protocols/FD_HOST.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jgroups.util.*;

import java.net.InetAddress;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -108,7 +109,7 @@ public FD_HOST setCommand(String command) {
public String printSuspectHistory() {
StringBuilder sb=new StringBuilder();
for(Tuple<InetAddress,Long> tmp: suspect_history) {
sb.append(new Date(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
sb.append(Instant.ofEpochMilli(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
}
return sb.toString();
}
Expand Down
5 changes: 3 additions & 2 deletions src/org/jgroups/protocols/FD_SOCK.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.*;
import java.net.*;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -525,7 +526,7 @@ protected void suspect(Set<Address> suspects) {
return;

suspects.remove(local_addr);
suspects.forEach(suspect -> suspect_history.add(String.format("%s: %s", new Date(), suspect)));
suspects.forEach(suspect -> suspect_history.add(String.format("%s: %s", Instant.now(), suspect)));

suspected_mbrs.addAll(suspects);
List<Address> eligible_mbrs=new ArrayList<>(this.members);
Expand Down Expand Up @@ -752,7 +753,7 @@ protected void broadcastSuspectMessage(Address suspected_mbr) {
bcast_task.addSuspectedMember(suspected_mbr);
if(stats) {
num_suspect_events++;
suspect_history.add(String.format("%s: %s", new Date(), suspected_mbr));
suspect_history.add(String.format("%s: %s", Instant.now(), suspected_mbr));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/protocols/FD_SOCK2.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.DataOutput;
import java.io.IOException;
import java.net.InetAddress;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.Future;
import java.util.function.Supplier;
Expand Down Expand Up @@ -473,7 +474,7 @@ protected void suspect(Collection<Address> suspects) {
return;

suspects.remove(local_addr);
suspects.forEach(suspect -> suspect_history.add(String.format("%s: %s", new Date(), suspect)));
suspects.forEach(suspect -> suspect_history.add(String.format("%s: %s", Instant.now(), suspect)));
suspected_mbrs.add(suspects);
Collection<Address> suspects_copy=suspected_mbrs.getMembers(); // returns a copy
if(suspects_copy.isEmpty())
Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/protocols/FailureDetection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.DataInput;
import java.io.DataOutput;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -118,7 +119,7 @@ public void stopFailureDetection() {
public String printSuspectHistory() {
StringBuilder sb=new StringBuilder();
for(Tuple<Address,Long> tmp: suspect_history) {
sb.append(new Date(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
sb.append(Instant.ofEpochMilli(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
}
return sb.toString();
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/protocols/SOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jgroups.util.Util;

import java.io.*;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -107,7 +108,7 @@ public String exec() {
protected String getMetadata() {
TP tp=stack.getTransport();
return String.format("\nDate: %s, member: %s (%s), version: %s\nview: %s\n",
new Date(), tp.getAddress(), tp.getPhysicalAddress(),
Instant.now(), tp.getAddress(), tp.getPhysicalAddress(),
Version.printVersion(), tp.view());
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/protocols/pbcast/GMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -692,7 +693,7 @@ public synchronized void installView(View new_view, Digest digest) {

if(stats) {
num_views++;
prev_views.add(new Date() + ": " + new_view);
prev_views.add(Instant.now() + ": " + new_view);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/org/jgroups/protocols/pbcast/ViewHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jgroups.util.BoundedList;
import org.jgroups.util.Util;

import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -177,7 +178,7 @@ protected boolean _add(R req) {
log().trace("%s: queue is suspended; request %s is discarded", gms.getAddress(), req);
return false;
}
String log=new Date() + ": " + req;
String log= Instant.now() + ": " + req;
lock.lock();
try {
if(!requests.contains(req)) { // non-null check already performed (above)
Expand Down Expand Up @@ -212,7 +213,7 @@ protected boolean _add(Collection<R> reqs) {
for(R req: reqs) {
if(req != null && !requests.contains(req)) {
requests.add(req);
history.add(new Date() + ": " + req);
history.add(Instant.now() + ": " + req);
}
}
return processing.compareAndSet(false, true);
Expand Down
3 changes: 2 additions & 1 deletion src/org/jgroups/stack/GossipRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -752,7 +753,7 @@ public Entry(Address client_addr, PhysicalAddress phys_addr, String logical_name
* Prints startup information.
*/
private void printStartupInfo() {
System.out.println("GossipRouter started at " + new Date());
System.out.println("GossipRouter started at " + Instant.now());

System.out.print("Listening on port " + port);
System.out.println(" bound on address " + server.localAddress());
Expand Down

0 comments on commit 887e1b9

Please sign in to comment.