diff --git a/pom.xml b/pom.xml index 50ac2dd4..939fd38b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,10 @@ JGroups RAFT implementation + UTF-8 11 11 + 11 true @@ -344,7 +346,7 @@ run - + @@ -356,7 +358,7 @@ - + @@ -469,7 +471,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.0 + 3.12.1 org.apache.maven.plugins diff --git a/src/org/jgroups/perf/CounterPerf.java b/src/org/jgroups/perf/CounterPerf.java index 9432b6a1..2f88af10 100644 --- a/src/org/jgroups/perf/CounterPerf.java +++ b/src/org/jgroups/perf/CounterPerf.java @@ -108,8 +108,8 @@ public void init(String props, String name, int bind_port, boolean use_fibers, S System.out.println("Histogram enabled! Will be stored into " + histogramPath); } thread_factory=new DefaultThreadFactory("updater", false, true) - .useFibers(use_fibers); - if(use_fibers && Util.fibersAvailable()) + .useVirtualThreads(use_fibers); + if(use_fibers && Util.virtualThreadsAvailable()) System.out.println("-- using fibers instead of threads"); channel=new JChannel(props).setName(name); diff --git a/src/org/jgroups/protocols/raft/ELECTION.java b/src/org/jgroups/protocols/raft/ELECTION.java index a815b7e9..77596a15 100644 --- a/src/org/jgroups/protocols/raft/ELECTION.java +++ b/src/org/jgroups/protocols/raft/ELECTION.java @@ -51,7 +51,6 @@ public class ELECTION extends BaseElection { protected void handleView(View v) { Majority result=Utils.computeMajority(view, v, raft().majority(), raft.leader()); log.debug("%s: existing view: %s, new view: %s, result: %s", local_addr, this.view, v, result); - System.out.printf("%s: existing view: %s, new view: %s, result: %s%n", local_addr, this.view, v, result); List
joiners=View.newMembers(this.view, v); boolean has_new_members=joiners != null && !joiners.isEmpty(); this.view=v; diff --git a/src/org/jgroups/protocols/raft/RAFT.java b/src/org/jgroups/protocols/raft/RAFT.java index a66680a9..d205a0f6 100644 --- a/src/org/jgroups/protocols/raft/RAFT.java +++ b/src/org/jgroups/protocols/raft/RAFT.java @@ -420,6 +420,7 @@ public long createNewTerm() { return raft_state.advanceTermForElection(); } + @SuppressWarnings("unchecked") public static T findProtocol(Class clazz, final Protocol start, boolean down) { Protocol prot=start; while(prot != null && clazz != null) { diff --git a/src/org/jgroups/protocols/raft/election/BaseElection.java b/src/org/jgroups/protocols/raft/election/BaseElection.java index 8d8a8975..2bf7501c 100644 --- a/src/org/jgroups/protocols/raft/election/BaseElection.java +++ b/src/org/jgroups/protocols/raft/election/BaseElection.java @@ -104,7 +104,7 @@ public void resetStats() { public void init() throws Exception { super.init(); - raft=findProtocol(RAFT.class); + raft=RAFT.findProtocol(RAFT.class, this, false); } public void stop() { @@ -326,12 +326,4 @@ public synchronized BaseElection stopVotingThread() { } return this; } - - protected T findProtocol(Class clazz) { - for(Protocol p=up_prot; p != null; p=p.getUpProtocol()) { - if(clazz.isAssignableFrom(p.getClass())) - return (T)p; - } - throw new IllegalStateException(clazz.getSimpleName() + " not found above " + this.getClass().getSimpleName()); - } } diff --git a/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java b/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java index 1c550917..92e73589 100644 --- a/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java +++ b/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java @@ -275,7 +275,7 @@ protected V invoke(byte command, K key, V val, boolean ignore_return_value) thro byte[] buf=out.buffer(); byte[] rsp=raft.set(buf, 0, out.position(), repl_timeout, TimeUnit.MILLISECONDS); - return ignore_return_value || rsp == null ? null: (V)Util.objectFromByteBuffer(rsp, 0, rsp.length, class_loader); + return ignore_return_value || rsp == null ? null: Util.objectFromByteBuffer(rsp, 0, rsp.length, class_loader); } protected void notifyPut(K key, V val, V old_val) { diff --git a/src/org/jgroups/raft/testfwk/PartitionedRaftCluster.java b/src/org/jgroups/raft/testfwk/PartitionedRaftCluster.java index 6d8dc5d6..5964b028 100644 --- a/src/org/jgroups/raft/testfwk/PartitionedRaftCluster.java +++ b/src/org/jgroups/raft/testfwk/PartitionedRaftCluster.java @@ -21,15 +21,15 @@ public class PartitionedRaftCluster extends MockRaftCluster { protected final Map nodes = new ConcurrentHashMap<>(); @Override - public PartitionedRaftCluster clear() { + public T clear() { nodes.clear(); return self(); } @Override - public PartitionedRaftCluster add(Address addr, RaftNode node) { + public T add(Address addr, RaftNode node) { nodes.put(addr, node); - return this; + return self(); } @Override @@ -73,7 +73,7 @@ public int size() { } @Override - public PartitionedRaftCluster remove(Address addr) { + public T remove(Address addr) { nodes.remove(addr); return self(); } diff --git a/src/org/jgroups/raft/testfwk/RaftCluster.java b/src/org/jgroups/raft/testfwk/RaftCluster.java index 9d140504..1fbcd17b 100644 --- a/src/org/jgroups/raft/testfwk/RaftCluster.java +++ b/src/org/jgroups/raft/testfwk/RaftCluster.java @@ -23,16 +23,23 @@ public class RaftCluster extends MockRaftCluster { protected boolean async; @Override - public RaftCluster add(Address addr, RaftNode node) { + public T add(Address addr, RaftNode node) { nodes.put(addr, node); - return this; + return self(); } @Override - public RaftCluster remove(Address addr) {nodes.remove(addr); return this;} + public T remove(Address addr) { + nodes.remove(addr); + return self(); + } @Override - public RaftCluster clear() {nodes.clear(); return this;} + public T clear() { + nodes.clear(); + return self(); + } + public boolean dropTraffic() {return !dropped_members.isEmpty();} public RaftCluster dropTrafficTo(Address a) {move(a, nodes, dropped_members); return this;} public RaftCluster clearDroppedTrafficTo(Address a) {move(a, dropped_members, nodes); return this;} diff --git a/src/org/jgroups/raft/testfwk/RaftNode.java b/src/org/jgroups/raft/testfwk/RaftNode.java index be280326..ee2845de 100644 --- a/src/org/jgroups/raft/testfwk/RaftNode.java +++ b/src/org/jgroups/raft/testfwk/RaftNode.java @@ -129,6 +129,7 @@ public String toString() { } + @SuppressWarnings("unchecked") protected T find(Class cl) { for(Protocol p: prots) { if(p.getClass().isAssignableFrom(cl)) diff --git a/src/org/jgroups/raft/util/AnalyzeLog.java b/src/org/jgroups/raft/util/AnalyzeLog.java index 09d06444..ebe43b48 100644 --- a/src/org/jgroups/raft/util/AnalyzeLog.java +++ b/src/org/jgroups/raft/util/AnalyzeLog.java @@ -26,6 +26,7 @@ public class AnalyzeLog { protected Function snapshot_reader=CounterService::readAndDumpSnapshot; protected PersistentState persistent_state; + @SuppressWarnings("unchecked") public AnalyzeLog logClass(String cl) throws ClassNotFoundException { log_class=(Class)Class.forName(cl); return this; diff --git a/src/org/jgroups/raft/util/ArrayRingBuffer.java b/src/org/jgroups/raft/util/ArrayRingBuffer.java index 51052a20..9cc514c1 100644 --- a/src/org/jgroups/raft/util/ArrayRingBuffer.java +++ b/src/org/jgroups/raft/util/ArrayRingBuffer.java @@ -27,7 +27,7 @@ public ArrayRingBuffer(final long headSequence) { } public ArrayRingBuffer(final int initialSize, final long headSequence) { - this.elements = (T[]) (initialSize == 0 ? EMPTY : new Object[initialSize]); + this.elements = allocate(initialSize); this.headSequence = headSequence; this.tailSequence = headSequence; if (headSequence < 0) { @@ -282,7 +282,7 @@ private void growCapacity(int delta) { // see ArrayList::newCapacity throw new OutOfMemoryError(); } - final T[] newElements = (T[]) new Object[newCapacity]; + final T[] newElements = allocate(newCapacity); final int size = size(); final long headSequence = this.headSequence; long oldIndex = headSequence; @@ -305,4 +305,9 @@ private void growCapacity(int delta) { private static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); } + + @SuppressWarnings("unchecked") + private static T[] allocate(int capacity) { + return (T[]) (capacity == 0 ? EMPTY : new Object[capacity]); + } } diff --git a/tests/junit-functional/org/jgroups/tests/SynchronousTests.java b/tests/junit-functional/org/jgroups/tests/SynchronousTests.java index 09bbebd0..12da3b14 100644 --- a/tests/junit-functional/org/jgroups/tests/SynchronousTests.java +++ b/tests/junit-functional/org/jgroups/tests/SynchronousTests.java @@ -55,6 +55,7 @@ public class SynchronousTests extends BaseRaftClusterTest { } @Override + @SuppressWarnings("unchecked") protected void passDataProviderParameters(Object[] args) { logClass = (Class) args[0]; } diff --git a/tests/junit-functional/org/jgroups/tests/harness/BaseRaftClusterTest.java b/tests/junit-functional/org/jgroups/tests/harness/BaseRaftClusterTest.java index 196163d8..6d26096a 100644 --- a/tests/junit-functional/org/jgroups/tests/harness/BaseRaftClusterTest.java +++ b/tests/junit-functional/org/jgroups/tests/harness/BaseRaftClusterTest.java @@ -289,6 +289,7 @@ private Address createAddress(String name) { return ExtendedUUID.randomUUID(name).put(RAFT.raft_id_key, Util.stringToBytes(name)); } + @SuppressWarnings("unchecked") private

P findProtocol(Protocol[] stack, Class

clazz) { for (Protocol protocol : stack) { if (clazz.isAssignableFrom(protocol.getClass())) diff --git a/tests/junit-functional/org/jgroups/tests/harness/BaseStateMachineTest.java b/tests/junit-functional/org/jgroups/tests/harness/BaseStateMachineTest.java index 2095ed2b..4b4d5f5e 100644 --- a/tests/junit-functional/org/jgroups/tests/harness/BaseStateMachineTest.java +++ b/tests/junit-functional/org/jgroups/tests/harness/BaseStateMachineTest.java @@ -92,8 +92,8 @@ protected final T stateMachine(int index) { * @param r: {@link RAFT} instance to retrieve the {@link StateMachine}. * @return The {@link StateMachine} cast to type T. */ + @SuppressWarnings("unchecked") protected final T stateMachine(RAFT r) { - // noinspection unchecked return (T) r.stateMachine(); }