X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fstatistics-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fstatistics%2Fmanager%2FMultipartMessageManager.java;h=36062805c875f90120a163304fd7af57b814862e;hp=2201cb3930e43427cdec6a1921a27f57538fdb04;hb=6fa3aa30c3eb47ca13520f9b4090bd03bf4e191f;hpb=7c1ced6aeaeca12da6786950c20a2133d9eb72e1 diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MultipartMessageManager.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MultipartMessageManager.java index 2201cb3930..36062805c8 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MultipartMessageManager.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MultipartMessageManager.java @@ -12,8 +12,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionAware; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; + +import com.google.common.base.Preconditions; /** * Main responsibility of the class is to manage multipart response @@ -23,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; * */ public class MultipartMessageManager { + private static final int NUMBER_OF_WAIT_CYCLES = 2; /* * Map for tx id and type of request, to keep track of all the request sent @@ -36,24 +39,17 @@ public class MultipartMessageManager { */ private final Map txIdTotableIdMap = new ConcurrentHashMap<>(); - private static final int NUMBER_OF_WAIT_CYCLES =2; - private static final class TxIdEntry { - private final TransactionId txId; - private final NodeId nodeId; private final StatsRequestType requestType; + private final TransactionId txId; - public TxIdEntry(NodeId nodeId, TransactionId txId, StatsRequestType requestType){ + public TxIdEntry(TransactionId txId, StatsRequestType requestType){ this.txId = txId; - this.nodeId = nodeId; this.requestType = requestType; } public TransactionId getTxId() { return txId; } - public NodeId getNodeId() { - return nodeId; - } public StatsRequestType getRequestType() { return requestType; } @@ -61,7 +57,6 @@ public class MultipartMessageManager { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); result = prime * result + ((txId == null) ? 0 : txId.hashCode()); return result; } @@ -78,13 +73,6 @@ public class MultipartMessageManager { } TxIdEntry other = (TxIdEntry) obj; - if (nodeId == null) { - if (other.nodeId != null) { - return false; - } - } else if (!nodeId.equals(other.nodeId)) { - return false; - } if (txId == null) { if (other.txId != null) { return false; @@ -97,36 +85,42 @@ public class MultipartMessageManager { @Override public String toString() { - return "TxIdEntry [txId=" + txId + ", nodeId=" + nodeId + ", requestType=" + requestType + "]"; + return "TxIdEntry [txId=" + txId + ", requestType=" + requestType + "]"; } } - public Short getTableIdForTxId(NodeId nodeId,TransactionId id){ - return txIdTotableIdMap.get(new TxIdEntry(nodeId,id,null)); + public void recordExpectedTableTransaction(TransactionId id, StatsRequestType type, Short tableId) { + recordExpectedTransaction(id, type); + txIdTotableIdMap.put(new TxIdEntry(id, null), Preconditions.checkNotNull(tableId)); } - public void setTxIdAndTableIdMapEntry(NodeId nodeId, TransactionId id,Short tableId){ - if(id == null) - return; - txIdTotableIdMap.put(new TxIdEntry(nodeId,id,null), tableId); - } + public Short isExpectedTableTransaction(TransactionAware transaction, Boolean more) { + if (!isExpectedTransaction(transaction, more)) { + return null; + } - public boolean isRequestTxIdExist(NodeId nodeId, TransactionId id, Boolean moreRepliesToFollow){ - TxIdEntry entry = new TxIdEntry(nodeId,id,null); - if(moreRepliesToFollow.booleanValue()){ - return txIdToRequestTypeMap.containsKey(entry); - }else{ - return txIdToRequestTypeMap.remove(entry) != null; + final TxIdEntry key = new TxIdEntry(transaction.getTransactionId(), null); + if (more != null && more.booleanValue()) { + return txIdTotableIdMap.get(key); + } else { + return txIdTotableIdMap.remove(key); } } - public void addTxIdToRequestTypeEntry (NodeId nodeId, TransactionId id,StatsRequestType type){ - if(id == null) - return; - TxIdEntry entry = new TxIdEntry(nodeId,id,type); + public void recordExpectedTransaction(TransactionId id, StatsRequestType type) { + TxIdEntry entry = new TxIdEntry(Preconditions.checkNotNull(id), Preconditions.checkNotNull(type)); txIdToRequestTypeMap.put(entry, getExpiryTime()); } + public boolean isExpectedTransaction(TransactionAware transaction, Boolean more) { + TxIdEntry entry = new TxIdEntry(transaction.getTransactionId(), null); + if (more != null && more.booleanValue()) { + return txIdToRequestTypeMap.containsKey(entry); + } else { + return txIdToRequestTypeMap.remove(entry) != null; + } + } + private static Long getExpiryTime(){ return System.nanoTime() + TimeUnit.MILLISECONDS.toNanos( StatisticsProvider.STATS_COLLECTION_MILLIS*NUMBER_OF_WAIT_CYCLES);