Skip to content

Commit

Permalink
Merge pull request #742 from tristantarrant/JGRP-2736/instant
Browse files Browse the repository at this point in the history
JGRP-2736 Use Instant instead of Date
  • Loading branch information
belaban authored Oct 13, 2023
2 parents 60deb37 + 901197b commit 7164ac7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/org/jgroups/blocks/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public String toString() {
if(expiration_time <= 0)
sb.append(expiration_time);
else {
sb.append(new Date(expiration_time));
sb.append(Util.utcEpoch(expiration_time));
}
sb.append(")\n");
}
Expand Down
5 changes: 2 additions & 3 deletions src/org/jgroups/blocks/GridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Set;

/**
Expand Down Expand Up @@ -360,8 +359,8 @@ public String toString() {
StringBuilder sb=new StringBuilder();
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(", len=").append(Util.printBytes(length)).append(", chunk_size=").append(chunk_size);
sb.append(", mod_time=").append(Util.utcEpoch(modification_time));
return sb.toString();
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/FD_HOST.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,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(Util.utcEpoch(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
}
return sb.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/jgroups/protocols/FD_SOCK.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,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", Util.utcNow(), suspect)));

suspected_mbrs.addAll(suspects);
List<Address> eligible_mbrs=new ArrayList<>(this.members);
Expand Down Expand Up @@ -752,7 +752,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", Util.utcNow(), suspected_mbr));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/FD_SOCK2.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,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", Util.utcNow(), suspect)));
suspected_mbrs.add(suspects);
Collection<Address> suspects_copy=suspected_mbrs.getMembers(); // returns a copy
if(suspects_copy.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/FailureDetection.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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(Util.utcEpoch(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
}
return sb.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/SOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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(),
Util.utcNow(), tp.getAddress(), tp.getPhysicalAddress(),
Version.printVersion(), tp.view());
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/pbcast/GMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public synchronized void installView(View new_view, Digest digest) {

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

Expand Down
4 changes: 2 additions & 2 deletions src/org/jgroups/protocols/pbcast/ViewHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,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= Util.utcNow() + ": " + req;
lock.lock();
try {
if(!requests.contains(req)) { // non-null check already performed (above)
Expand Down Expand Up @@ -212,7 +212,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(Util.utcNow() + ": " + req);
}
}
return processing.compareAndSet(false, true);
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/stack/GossipRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,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 " + Util.utcNow());

System.out.print("Listening on port " + port);
System.out.println(" bound on address " + server.localAddress());
Expand Down
13 changes: 13 additions & 0 deletions src/org/jgroups/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import java.nio.channels.SocketChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -110,6 +114,7 @@ public enum AddressScope {GLOBAL,SITE_LOCAL,LINK_LOCAL,LOOPBACK,NON_LOOPBACK}
private static final StackType ip_stack_type=_getIpStackType();
public static final boolean can_bind_to_mcast_addr;
protected static ResourceBundle resource_bundle;
static DateTimeFormatter UTF_FORMAT = DateTimeFormatter.ofPattern("E MMM d H:m:s 'UTC' y");

static {
String tmp;
Expand Down Expand Up @@ -5009,4 +5014,12 @@ public static Collection<String> otherSites(View bridge_view, String excluding_s
return ret;
}

public static String utcNow() {
return UTF_FORMAT.format(LocalDateTime.now(ZoneOffset.UTC));
}

public static String utcEpoch(long milliseconds) {
return UTF_FORMAT.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), ZoneOffset.UTC));
}

}

0 comments on commit 7164ac7

Please sign in to comment.