Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 41ec4c3

Browse files
committed
FAB-6066 Channel service_events
Patch Set: 024 Rebased on network config. 025 Minor code cleanup and added Javadoc where needed. Change-Id: Iaf3f37ee7d1062ead7e2cc66de630268324d3575 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent c4957fd commit 41ec4c3

File tree

18 files changed

+1875
-889
lines changed

18 files changed

+1875
-889
lines changed

src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,28 @@
1414
package org.hyperledger.fabric.sdk;
1515

1616
import java.util.ArrayList;
17-
import java.util.Date;
1817
import java.util.Iterator;
1918
import java.util.List;
2019

2120
import com.google.protobuf.InvalidProtocolBufferException;
22-
import com.google.protobuf.Timestamp;
2321
import org.hyperledger.fabric.protos.common.Common.Block;
22+
import org.hyperledger.fabric.protos.orderer.Ab;
2423
import org.hyperledger.fabric.protos.peer.PeerEvents.Event;
2524
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;
26-
import org.hyperledger.fabric.sdk.transaction.ProtoUtils;
2725

2826
/**
2927
* A wrapper for the Block returned in an Event
3028
*
3129
* @see Block
3230
*/
3331
public class BlockEvent extends BlockInfo {
34-
// private static final Log logger = LogFactory.getLog(BlockEvent.class);
3532

36-
/**
37-
* Get the Event Hub that received the event.
38-
*
39-
* @return an Event Hub.
40-
*/
41-
public EventHub getEventHub() {
42-
return eventHub;
43-
}
33+
// private static final Log logger = LogFactory.getLog(BlockEvent.class);
4434

4535
private final EventHub eventHub;
36+
private final Peer peer;
4637
private final Event event;
4738

48-
/**
49-
* Raw proto buff event.
50-
*
51-
* @return Return raw protobuf event.
52-
*/
53-
54-
public Event getEvent() {
55-
return event;
56-
}
57-
5839
/**
5940
* creates a BlockEvent object by parsing the input Block and retrieving its constituent Transactions
6041
*
@@ -65,27 +46,75 @@ public Event getEvent() {
6546
BlockEvent(EventHub eventHub, Event event) throws InvalidProtocolBufferException {
6647
super(event.getBlock());
6748
this.eventHub = eventHub;
49+
this.peer = null;
6850
this.event = event;
6951
}
7052

71-
public Date getTimestamp() {
53+
BlockEvent(Peer peer, Ab.DeliverResponse resp) {
54+
super(resp.getBlock());
7255

73-
Date ret = null;
56+
eventHub = null;
57+
this.peer = peer;
58+
this.event = null;
7459

75-
Timestamp timestamp = event.getTimestamp();
76-
if (null != timestamp) {
77-
ret = ProtoUtils.getDateFromTimestamp(timestamp);
78-
}
60+
}
7961

80-
return ret;
62+
/**
63+
* Get the Event Hub that received the event.
64+
*
65+
* @return an Event Hub. Maybe null if new peer eventing services is being used.
66+
* @deprecated Use new peer eventing services
67+
*/
68+
public EventHub getEventHub() {
69+
return eventHub;
70+
}
8171

72+
/**
73+
* The Peer that received this event.
74+
*
75+
* @return Peer that received this event. Maybe null if source is legacy event hub.
76+
*/
77+
public Peer getPeer() {
78+
return peer;
79+
}
80+
81+
// /**
82+
// * Raw proto buff event.
83+
// *
84+
// * @return Return raw protobuf event.
85+
// */
86+
//
87+
// public Event getEvent() {
88+
// return event;
89+
// }
90+
91+
boolean isBlockEvent() {
92+
93+
return event == null || event.getEventCase() == Event.EventCase.BLOCK;
8294
}
8395

8496
TransactionEvent getTransactionEvent(int index) throws InvalidProtocolBufferException {
8597

8698
return new TransactionEvent((TransactionEnvelopeInfo) getEnvelopeInfo(index), index);
8799
}
88100

101+
List<TransactionEvent> getTransactionEventsList() {
102+
103+
ArrayList<TransactionEvent> ret = new ArrayList<TransactionEvent>(getEnvelopeCount());
104+
for (TransactionEvent transactionEvent : getTransactionEvents()) {
105+
ret.add(transactionEvent);
106+
}
107+
108+
return ret;
109+
110+
}
111+
112+
public Iterable<TransactionEvent> getTransactionEvents() {
113+
114+
return new TransactionEventIterable();
115+
116+
}
117+
89118
public class TransactionEvent extends TransactionEnvelopeInfo {
90119
TransactionEvent(TransactionEnvelopeInfo transactionEnvelopeInfo, int index) {
91120
super(transactionEnvelopeInfo.getTransactionDeserializer(), index);
@@ -94,35 +123,30 @@ public class TransactionEvent extends TransactionEnvelopeInfo {
94123
/**
95124
* The event hub that received this event.
96125
*
97-
* @return
126+
* @return May return null if peer eventing service detected the event.
127+
* @deprecated use new peer eventing services {@link #getPeer()}
98128
*/
99129

100130
public EventHub getEventHub() {
101131

102132
return BlockEvent.this.getEventHub();
103133
}
104-
}
105-
106-
List<TransactionEvent> getTransactionEventsList() {
107-
108-
ArrayList<TransactionEvent> ret = new ArrayList<TransactionEvent>(getEnvelopeCount());
109-
for (TransactionEvent transactionEvent : getTransactionEvents()) {
110-
ret.add(transactionEvent);
111-
}
112-
113-
return ret;
114-
115-
}
116134

117-
public Iterable<TransactionEvent> getTransactionEvents() {
135+
/**
136+
* The peer that received this event.
137+
*
138+
* @return May return null if deprecated eventhubs are still being used, otherwise return the peer.
139+
*/
118140

119-
return new TransactionEventIterable();
141+
public Peer getPeer() {
120142

143+
return BlockEvent.this.getPeer();
144+
}
121145
}
122146

123147
class TransactionEventIterator implements Iterator<TransactionEvent> {
124-
int ci = 0;
125148
final int max;
149+
int ci = 0;
126150

127151
TransactionEventIterator() {
128152
max = getEnvelopeCount();

src/main/java/org/hyperledger/fabric/sdk/ChaincodeID.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public String getVersion() {
4343

4444
}
4545

46+
@Override
47+
public String toString() {
48+
return "ChaincodeID(" + getName() + ":" + getPath() + ":" + getVersion() + ")";
49+
}
50+
4651
/**
4752
* Build a new ChaincodeID
4853
*/

0 commit comments

Comments
 (0)