X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fstatistics-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fstatistics%2Fmanager%2FMultipartMessageManager.java;fp=opendaylight%2Fmd-sal%2Fstatistics-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fstatistics%2Fmanager%2FMultipartMessageManager.java;h=dfe356bdb1efbbc5ec7d299025b6cf879d820b38;hb=86f2711e18784bfd321e6409370bcc11512f4d43;hp=998d5d8faaf24fd09e10d6a5865f1a5c169e6d96;hpb=7974eb6a8ede81ed2593fe3fb5cda65cee51ee5d;p=controller.git 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 998d5d8faa..dfe356bdb1 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 @@ -7,10 +7,13 @@ */ package org.opendaylight.controller.md.statistics.manager; +import java.util.Date; +import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; /** * Main responsibility of the class is to manage multipart response @@ -27,32 +30,119 @@ public class MultipartMessageManager { * response for which it didn't send the request. */ - private static Map txIdToRequestTypeMap = new ConcurrentHashMap(); + private static Map txIdToRequestTypeMap = new ConcurrentHashMap(); /* * Map to keep track of the request tx id for flow table statistics request. * Because flow table statistics multi part response do not contains the table id. */ - private static Map txIdTotableIdMap = new ConcurrentHashMap(); + private static Map txIdTotableIdMap = new ConcurrentHashMap(); + private final int NUMBER_OF_WAIT_CYCLES =2; + + class TxIdEntry{ + private final TransactionId txId; + private final NodeId nodeId; + private final StatsRequestType requestType; + + public TxIdEntry(NodeId nodeId, 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; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + getOuterType().hashCode(); + result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); + result = prime * result + ((txId == null) ? 0 : txId.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof TxIdEntry)) { + return false; + } + TxIdEntry other = (TxIdEntry) obj; + if (!getOuterType().equals(other.getOuterType())) { + return false; + } + 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; + } + } else if (!txId.equals(other.txId)) { + return false; + } + return true; + } + private MultipartMessageManager getOuterType() { + return MultipartMessageManager.this; + } + @Override + public String toString() { + return "TxIdEntry [txId=" + txId + ", nodeId=" + nodeId + ", requestType=" + requestType + "]"; + } + } + public MultipartMessageManager(){} - public Short getTableIdForTxId(TransactionId id){ + public Short getTableIdForTxId(NodeId nodeId,TransactionId id){ - return txIdTotableIdMap.get(id); + return txIdTotableIdMap.get(new TxIdEntry(nodeId,id,null)); } - public void setTxIdAndTableIdMapEntry(TransactionId id,Short tableId){ - txIdTotableIdMap.put(id, tableId); + public void setTxIdAndTableIdMapEntry(NodeId nodeId, TransactionId id,Short tableId){ + + txIdTotableIdMap.put(new TxIdEntry(nodeId,id,null), tableId); } - public void addTxIdToRequestTypeEntry (TransactionId id,StatsRequestType type){ - txIdToRequestTypeMap.put(id, type); + 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?false:true; + } } - public StatsRequestType removeTxId(TransactionId id){ - return txIdToRequestTypeMap.remove(id); + public void addTxIdToRequestTypeEntry (NodeId nodeId, TransactionId id,StatsRequestType type){ + TxIdEntry entry = new TxIdEntry(nodeId,id,type); + txIdToRequestTypeMap.put(entry, getExpiryTime()); + } + public boolean removeTxId(NodeId nodeId, TransactionId id){ + TxIdEntry entry = new TxIdEntry(nodeId,id,null); + return txIdToRequestTypeMap.remove(entry)==null?false:true; } + private Date getExpiryTime(){ + Date expires = new Date(); + expires.setTime(expires.getTime()+StatisticsProvider.STATS_THREAD_EXECUTION_TIME*NUMBER_OF_WAIT_CYCLES); + return expires; + } + public enum StatsRequestType{ ALL_FLOW, AGGR_FLOW, @@ -64,4 +154,16 @@ public class MultipartMessageManager { GROUP_DESC, METER_CONFIG } + + public void cleanStaleTransactionIds(){ + for (Iterator it = txIdToRequestTypeMap.keySet().iterator();it.hasNext();){ + TxIdEntry txIdEntry = it.next(); + Date now = new Date(); + Date expiryTime = txIdToRequestTypeMap.get(txIdEntry); + if(now.after(expiryTime)){ + it.remove(); + txIdTotableIdMap.remove(txIdEntry); + } + } + } }