Skip to content

Commit

Permalink
FAB-6703 ChaincodeEvent handler fired once per block
Browse files Browse the repository at this point in the history
Replace hash map with LinkedList

Change-Id: I609103ad92c4fb06cf555c347773088d764aa028
Signed-off-by: Oleg Sesov <osesov@gmail.com>
  • Loading branch information
osesov committed Oct 20, 2017
1 parent d0a28cf commit 65a94a6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,17 @@ private String registerChaincodeListenerProcessor() throws InvalidArgumentExcept

if (!chaincodeEvents.isEmpty()) {

HashMap<ChaincodeEventListenerEntry, ChaincodeEvent> matches = new HashMap<>(); //Find matches.
class MatchPair {
final ChaincodeEventListenerEntry eventListener;
final ChaincodeEvent event;

MatchPair(ChaincodeEventListenerEntry eventListener, ChaincodeEvent event) {
this.eventListener = eventListener;
this.event = event;
}
}

List<MatchPair> matches = new LinkedList<>(); //Find matches.

synchronized (chainCodeListeners) {

Expand All @@ -3061,7 +3071,7 @@ private String registerChaincodeListenerProcessor() throws InvalidArgumentExcept

if (chaincodeEventListenerEntry.isMatch(chaincodeEvent)) {

matches.put(chaincodeEventListenerEntry, chaincodeEvent);
matches.add(new MatchPair(chaincodeEventListenerEntry, chaincodeEvent));
}

}
Expand All @@ -3070,10 +3080,10 @@ private String registerChaincodeListenerProcessor() throws InvalidArgumentExcept
}

//fire events
for (Map.Entry<ChaincodeEventListenerEntry, ChaincodeEvent> match : matches.entrySet()) {
for (MatchPair match : matches) {

ChaincodeEventListenerEntry chaincodeEventListenerEntry = match.getKey();
ChaincodeEvent ce = match.getValue();
ChaincodeEventListenerEntry chaincodeEventListenerEntry = match.eventListener;
ChaincodeEvent ce = match.event;
chaincodeEventListenerEntry.fire(blockEvent, ce);

}
Expand Down

0 comments on commit 65a94a6

Please sign in to comment.