// Path: src/org/jgroups/raft/RaftHandle.java
// public class RaftHandle implements Settable {
//     protected JChannel     ch;
//     protected RAFT         raft;
//     protected Settable     settable; // usually REDIRECT (at the top of the stack)
// 
//     /**
//      * Creates a RaftHandle instance.
//      * @param ch The channel over which to create the RaftHandle. Must be non-null, but doesn't yet need to be connected
//      * @param sm An implementation of {@link StateMachine}.
//      *           Can be null, ie. if it is set later via {@link #stateMachine(StateMachine)}.
//      */
//     public RaftHandle(JChannel ch, StateMachine sm) {
//         if((this.ch=ch) == null)
//             throw new IllegalStateException("channel must not be null");
//         if((raft=RAFT.findProtocol(RAFT.class, ch.getProtocolStack().getTopProtocol(),true)) == null)
//             throw new IllegalStateException("RAFT protocol was not found");
//         if((settable=RAFT.findProtocol(Settable.class, ch.getProtocolStack().getTopProtocol(),true)) == null)
//             throw new IllegalStateException("did not find a protocol implementing Settable (e.g. REDIRECT or RAFT)");
//         stateMachine(sm);
//     }
// 
//     public JChannel     channel()                                    {return ch;}
//     public RAFT         raft()                                       {return raft;}
//     public String       raftId()                                     {return raft.raftId();}
//     public RaftHandle   raftId(String id)                            {raft.raftId(id); return this;}
//     public Address      leader()                                     {return raft.leader();}
//     public boolean      isLeader()                                   {return raft.isLeader();}
//     public StateMachine stateMachine()                               {return raft.stateMachine();}
//     public RaftHandle   stateMachine(StateMachine sm)                {raft.stateMachine(sm); return this;}
//     public RaftHandle   addRoleListener(RAFT.RoleChange listener)    {raft.addRoleListener(listener); return this;}
//     public RaftHandle   removeRoleListener(RAFT.RoleChange listener) {raft.remRoleListener(listener); return this;}
//     public int          currentTerm()                                {return raft.currentTerm();}
//     public int          lastApplied()                                {return raft.lastAppended();}
//     public int          commitIndex()                                {return raft.commitIndex();}
//     public void         snapshot() throws Exception                  {raft.snapshot();}
//     public Log          log()                                        {return raft.log();}
//     public int          logSize()                                    {return raft.logSize();}
// 
//     public void logEntries(ObjIntConsumer<LogEntry> func) {
//         raft.logEntries(func);
//     }
// 
//     @Override
//     public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length) throws Exception {
//         return settable.setAsync(buf, offset, length);
//     }
// 
// 
// }


import org.jgroups.JChannel;
import org.jgroups.blocks.atomic.Counter;
import org.jgroups.protocols.raft.*;
import org.jgroups.raft.RaftHandle;
import org.jgroups.util.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
            if(val != null)
                return val;
            counters.put(name, initial_value);
            return initial_value;
        }
    }

    protected void _delete(String name) {
        synchronized(counters) {
            counters.remove(name);
        }
    }


    protected long _get(String name) {
        synchronized(counters) {
            Long retval=counters.get(name);
            return retval != null? (long)retval : 0;
        }
    }

    protected void _set(String name, long new_val) {
        synchronized(counters) {
            counters.put(name, new_val);
        }
    }

    protected boolean _cas(String name, long expected, long value) {
        synchronized(counters) {
            Long existing_value=counters.get(name);
// Path: src/org/jgroups/raft/RaftHandle.java
// public class RaftHandle implements Settable {
//     protected JChannel     ch;
//     protected RAFT         raft;
//     protected Settable     settable; // usually REDIRECT (at the top of the stack)
// 
//     /**
//      * Creates a RaftHandle instance.
//      * @param ch The channel over which to create the RaftHandle. Must be non-null, but doesn't yet need to be connected
//      * @param sm An implementation of {@link StateMachine}.
//      *           Can be null, ie. if it is set later via {@link #stateMachine(StateMachine)}.
//      */
//     public RaftHandle(JChannel ch, StateMachine sm) {
//         if((this.ch=ch) == null)
//             throw new IllegalStateException("channel must not be null");
//         if((raft=RAFT.findProtocol(RAFT.class, ch.getProtocolStack().getTopProtocol(),true)) == null)
//             throw new IllegalStateException("RAFT protocol was not found");
//         if((settable=RAFT.findProtocol(Settable.class, ch.getProtocolStack().getTopProtocol(),true)) == null)
//             throw new IllegalStateException("did not find a protocol implementing Settable (e.g. REDIRECT or RAFT)");
//         stateMachine(sm);
//     }
// 
//     public JChannel     channel()                                    {return ch;}
//     public RAFT         raft()                                       {return raft;}
//     public String       raftId()                                     {return raft.raftId();}
//     public RaftHandle   raftId(String id)                            {raft.raftId(id); return this;}
//     public Address      leader()                                     {return raft.leader();}
//     public boolean      isLeader()                                   {return raft.isLeader();}
//     public StateMachine stateMachine()                               {return raft.stateMachine();}
//     public RaftHandle   stateMachine(StateMachine sm)                {raft.stateMachine(sm); return this;}
//     public RaftHandle   addRoleListener(RAFT.RoleChange listener)    {raft.addRoleListener(listener); return this;}
//     public RaftHandle   removeRoleListener(RAFT.RoleChange listener) {raft.remRoleListener(listener); return this;}
//     public int          currentTerm()                                {return raft.currentTerm();}
//     public int          lastApplied()                                {return raft.lastAppended();}
//     public int          commitIndex()                                {return raft.commitIndex();}
//     public void         snapshot() throws Exception                  {raft.snapshot();}
//     public Log          log()                                        {return raft.log();}
//     public int          logSize()                                    {return raft.logSize();}
// 
//     public void logEntries(ObjIntConsumer<LogEntry> func) {
//         raft.logEntries(func);
//     }
// 
//     @Override
//     public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length) throws Exception {
//         return settable.setAsync(buf, offset, length);
//     }
// 
// 
// }


// Path: src/org/jgroups/raft/blocks/CounterService.java
import org.jgroups.JChannel;
import org.jgroups.blocks.atomic.Counter;
import org.jgroups.protocols.raft.*;
import org.jgroups.raft.RaftHandle;
import org.jgroups.util.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

            if(val != null)
                return val;
            counters.put(name, initial_value);
            return initial_value;
        }
    }

    protected void _delete(String name) {
        synchronized(counters) {
            counters.remove(name);
        }
    }


    protected long _get(String name) {
        synchronized(counters) {
            Long retval=counters.get(name);
            return retval != null? (long)retval : 0;
        }
    }

    protected void _set(String name, long new_val) {
        synchronized(counters) {
            counters.put(name, new_val);
        }
    }

    protected boolean _cas(String name, long expected, long value) {
        synchronized(counters) {
            Long existing_value=counters.get(name);
            if(existing_value == null) return false;