14
14
package org .hyperledger .fabric .sdk ;
15
15
16
16
import java .util .ArrayList ;
17
- import java .util .Date ;
18
17
import java .util .Iterator ;
19
18
import java .util .List ;
20
19
21
20
import com .google .protobuf .InvalidProtocolBufferException ;
22
- import com .google .protobuf .Timestamp ;
23
21
import org .hyperledger .fabric .protos .common .Common .Block ;
22
+ import org .hyperledger .fabric .protos .orderer .Ab ;
24
23
import org .hyperledger .fabric .protos .peer .PeerEvents .Event ;
25
24
import org .hyperledger .fabric .sdk .exception .InvalidProtocolBufferRuntimeException ;
26
- import org .hyperledger .fabric .sdk .transaction .ProtoUtils ;
27
25
28
26
/**
29
27
* A wrapper for the Block returned in an Event
30
28
*
31
29
* @see Block
32
30
*/
33
31
public class BlockEvent extends BlockInfo {
34
- // private static final Log logger = LogFactory.getLog(BlockEvent.class);
35
32
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);
44
34
45
35
private final EventHub eventHub ;
36
+ private final Peer peer ;
46
37
private final Event event ;
47
38
48
- /**
49
- * Raw proto buff event.
50
- *
51
- * @return Return raw protobuf event.
52
- */
53
-
54
- public Event getEvent () {
55
- return event ;
56
- }
57
-
58
39
/**
59
40
* creates a BlockEvent object by parsing the input Block and retrieving its constituent Transactions
60
41
*
@@ -65,27 +46,75 @@ public Event getEvent() {
65
46
BlockEvent (EventHub eventHub , Event event ) throws InvalidProtocolBufferException {
66
47
super (event .getBlock ());
67
48
this .eventHub = eventHub ;
49
+ this .peer = null ;
68
50
this .event = event ;
69
51
}
70
52
71
- public Date getTimestamp () {
53
+ BlockEvent (Peer peer , Ab .DeliverResponse resp ) {
54
+ super (resp .getBlock ());
72
55
73
- Date ret = null ;
56
+ eventHub = null ;
57
+ this .peer = peer ;
58
+ this .event = null ;
74
59
75
- Timestamp timestamp = event .getTimestamp ();
76
- if (null != timestamp ) {
77
- ret = ProtoUtils .getDateFromTimestamp (timestamp );
78
- }
60
+ }
79
61
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
+ }
81
71
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 ;
82
94
}
83
95
84
96
TransactionEvent getTransactionEvent (int index ) throws InvalidProtocolBufferException {
85
97
86
98
return new TransactionEvent ((TransactionEnvelopeInfo ) getEnvelopeInfo (index ), index );
87
99
}
88
100
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
+
89
118
public class TransactionEvent extends TransactionEnvelopeInfo {
90
119
TransactionEvent (TransactionEnvelopeInfo transactionEnvelopeInfo , int index ) {
91
120
super (transactionEnvelopeInfo .getTransactionDeserializer (), index );
@@ -94,35 +123,30 @@ public class TransactionEvent extends TransactionEnvelopeInfo {
94
123
/**
95
124
* The event hub that received this event.
96
125
*
97
- * @return
126
+ * @return May return null if peer eventing service detected the event.
127
+ * @deprecated use new peer eventing services {@link #getPeer()}
98
128
*/
99
129
100
130
public EventHub getEventHub () {
101
131
102
132
return BlockEvent .this .getEventHub ();
103
133
}
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
- }
116
134
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
+ */
118
140
119
- return new TransactionEventIterable ();
141
+ public Peer getPeer () {
120
142
143
+ return BlockEvent .this .getPeer ();
144
+ }
121
145
}
122
146
123
147
class TransactionEventIterator implements Iterator <TransactionEvent > {
124
- int ci = 0 ;
125
148
final int max ;
149
+ int ci = 0 ;
126
150
127
151
TransactionEventIterator () {
128
152
max = getEnvelopeCount ();
0 commit comments