// Path: src/main/java/net/floodlightcontroller/debugcounter/IDebugCounter.java
// public interface IDebugCounter {
//     /**
//      * Increments the counter by 1 thread-locally, and immediately flushes to
//      * the global counter storage. This method should be used for counters that
//      * are updated outside the OF message processing pipeline.
//      */
//     void updateCounterWithFlush();
// 
//     /**
//      * Increments the counter by 1 thread-locally. Flushing to the global
//      * counter storage is delayed (happens with flushCounters() in IDebugCounterService),
//      * resulting in higher performance. This method should be used for counters
//      * updated in the OF message processing pipeline.
//      */
//     void updateCounterNoFlush();
// 
//     /**
//      * Increments the counter thread-locally by the 'incr' specified, and immediately
//      * flushes to the global counter storage. This method should be used for counters
//      * that are updated outside the OF message processing pipeline.
//      */
//     void updateCounterWithFlush(int incr);
// 
//     /**
//      * Increments the counter thread-locally by the 'incr' specified. Flushing to the global
//      * counter storage is delayed (happens with flushCounters() in IDebugCounterService),
//      * resulting in higher performance. This method should be used for counters
//      * updated in the OF message processing pipeline.
//      */
//     void updateCounterNoFlush(int incr);
// 
//     /**
//      * Retrieve the value of the counter from the global counter store
//      */
//     long getCounterValue();
// }
// 
// Path: src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java
// protected static class NodeMessage extends Pair<Short,SyncMessage> {
//     private static final long serialVersionUID = -3443080461324647922L;
// 
//     public NodeMessage(Short first, SyncMessage second) {
//         super(first, second);
//     }
// }


import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Map.Entry;
import net.floodlightcontroller.core.annotations.LogMessageCategory;
import net.floodlightcontroller.core.annotations.LogMessageDoc;
import net.floodlightcontroller.debugcounter.IDebugCounter;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.sdnplatform.sync.IClosableIterator;
import org.sdnplatform.sync.IStoreClient;
import org.sdnplatform.sync.IVersion;
import org.sdnplatform.sync.Versioned;
import org.sdnplatform.sync.ISyncService.Scope;
import org.sdnplatform.sync.error.AuthException;
import org.sdnplatform.sync.error.ObsoleteVersionException;
import org.sdnplatform.sync.error.SyncException;
import org.sdnplatform.sync.internal.Cursor;
import org.sdnplatform.sync.internal.SyncManager;
import org.sdnplatform.sync.internal.config.AuthScheme;
import org.sdnplatform.sync.internal.config.ClusterConfig;
import org.sdnplatform.sync.internal.config.Node;
import org.sdnplatform.sync.internal.config.SyncStoreCCProvider;
import org.sdnplatform.sync.internal.rpc.RPCService.NodeMessage;
import org.sdnplatform.sync.internal.store.IStorageEngine;
import org.sdnplatform.sync.internal.util.ByteArray;
import org.sdnplatform.sync.internal.util.CryptoUtil;
import org.sdnplatform.sync.internal.version.VectorClock;
import org.sdnplatform.sync.thrift.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    @Override
    protected void handleSyncRequest(SyncRequestMessage request,
                                     Channel channel) {
        rpcService.messageAcked(MessageType.SYNC_OFFER, getRemoteNodeId());
        if (!request.isSetKeys()) return;

        String storeName = request.getStore().getStoreName();
        try {
            IStorageEngine<ByteArray, byte[]> store =
                    syncManager.getRawStore(storeName);

            SyncMessage bsm =
                    TProtocolUtil.getTSyncValueMessage(request.getStore());
            SyncValueMessage svm = bsm.getSyncValue();
            svm.setResponseTo(request.getHeader().getTransactionId());
            svm.getHeader().setTransactionId(rpcService.getTransactionId());

            for (ByteBuffer key : request.getKeys()) {
                ByteArray keyArray = new ByteArray(key.array());
                List<Versioned<byte[]>> values =
                        store.get(keyArray);
                if (values == null || values.size() == 0) continue;
                KeyedValues kv =
                        TProtocolUtil.getTKeyedValues(keyArray, values);
                svm.addToValues(kv);
            }

            if (svm.isSetValues()) {
                updateCounter(SyncManager.counterSentValues,
                              svm.getValuesSize());
// Path: src/main/java/net/floodlightcontroller/debugcounter/IDebugCounter.java
// public interface IDebugCounter {
//     /**
//      * Increments the counter by 1 thread-locally, and immediately flushes to
//      * the global counter storage. This method should be used for counters that
//      * are updated outside the OF message processing pipeline.
//      */
//     void updateCounterWithFlush();
// 
//     /**
//      * Increments the counter by 1 thread-locally. Flushing to the global
//      * counter storage is delayed (happens with flushCounters() in IDebugCounterService),
//      * resulting in higher performance. This method should be used for counters
//      * updated in the OF message processing pipeline.
//      */
//     void updateCounterNoFlush();
// 
//     /**
//      * Increments the counter thread-locally by the 'incr' specified, and immediately
//      * flushes to the global counter storage. This method should be used for counters
//      * that are updated outside the OF message processing pipeline.
//      */
//     void updateCounterWithFlush(int incr);
// 
//     /**
//      * Increments the counter thread-locally by the 'incr' specified. Flushing to the global
//      * counter storage is delayed (happens with flushCounters() in IDebugCounterService),
//      * resulting in higher performance. This method should be used for counters
//      * updated in the OF message processing pipeline.
//      */
//     void updateCounterNoFlush(int incr);
// 
//     /**
//      * Retrieve the value of the counter from the global counter store
//      */
//     long getCounterValue();
// }
// 
// Path: src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java
// protected static class NodeMessage extends Pair<Short,SyncMessage> {
//     private static final long serialVersionUID = -3443080461324647922L;
// 
//     public NodeMessage(Short first, SyncMessage second) {
//         super(first, second);
//     }
// }


// Path: src/main/java/org/sdnplatform/sync/internal/rpc/RPCChannelHandler.java
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Map.Entry;
import net.floodlightcontroller.core.annotations.LogMessageCategory;
import net.floodlightcontroller.core.annotations.LogMessageDoc;
import net.floodlightcontroller.debugcounter.IDebugCounter;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.sdnplatform.sync.IClosableIterator;
import org.sdnplatform.sync.IStoreClient;
import org.sdnplatform.sync.IVersion;
import org.sdnplatform.sync.Versioned;
import org.sdnplatform.sync.ISyncService.Scope;
import org.sdnplatform.sync.error.AuthException;
import org.sdnplatform.sync.error.ObsoleteVersionException;
import org.sdnplatform.sync.error.SyncException;
import org.sdnplatform.sync.internal.Cursor;
import org.sdnplatform.sync.internal.SyncManager;
import org.sdnplatform.sync.internal.config.AuthScheme;
import org.sdnplatform.sync.internal.config.ClusterConfig;
import org.sdnplatform.sync.internal.config.Node;
import org.sdnplatform.sync.internal.config.SyncStoreCCProvider;
import org.sdnplatform.sync.internal.rpc.RPCService.NodeMessage;
import org.sdnplatform.sync.internal.store.IStorageEngine;
import org.sdnplatform.sync.internal.util.ByteArray;
import org.sdnplatform.sync.internal.util.CryptoUtil;
import org.sdnplatform.sync.internal.version.VectorClock;
import org.sdnplatform.sync.thrift.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

    @Override
    protected void handleSyncRequest(SyncRequestMessage request,
                                     Channel channel) {
        rpcService.messageAcked(MessageType.SYNC_OFFER, getRemoteNodeId());
        if (!request.isSetKeys()) return;

        String storeName = request.getStore().getStoreName();
        try {
            IStorageEngine<ByteArray, byte[]> store =
                    syncManager.getRawStore(storeName);

            SyncMessage bsm =
                    TProtocolUtil.getTSyncValueMessage(request.getStore());
            SyncValueMessage svm = bsm.getSyncValue();
            svm.setResponseTo(request.getHeader().getTransactionId());
            svm.getHeader().setTransactionId(rpcService.getTransactionId());

            for (ByteBuffer key : request.getKeys()) {
                ByteArray keyArray = new ByteArray(key.array());
                List<Versioned<byte[]>> values =
                        store.get(keyArray);
                if (values == null || values.size() == 0) continue;
                KeyedValues kv =
                        TProtocolUtil.getTKeyedValues(keyArray, values);
                svm.addToValues(kv);
            }

            if (svm.isSetValues()) {
                updateCounter(SyncManager.counterSentValues,
                              svm.getValuesSize());
                rpcService.syncQueue.add(new NodeMessage(getRemoteNodeId(),