Skip to content

Commit

Permalink
FAB-6066 Channel service_events
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cr22rc committed Jan 8, 2018
1 parent c4957fd commit 41ec4c3
Show file tree
Hide file tree
Showing 18 changed files with 1,875 additions and 889 deletions.
114 changes: 69 additions & 45 deletions src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,28 @@
package org.hyperledger.fabric.sdk;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Timestamp;
import org.hyperledger.fabric.protos.common.Common.Block;
import org.hyperledger.fabric.protos.orderer.Ab;
import org.hyperledger.fabric.protos.peer.PeerEvents.Event;
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;
import org.hyperledger.fabric.sdk.transaction.ProtoUtils;

/**
* A wrapper for the Block returned in an Event
*
* @see Block
*/
public class BlockEvent extends BlockInfo {
// private static final Log logger = LogFactory.getLog(BlockEvent.class);

/**
* Get the Event Hub that received the event.
*
* @return an Event Hub.
*/
public EventHub getEventHub() {
return eventHub;
}
// private static final Log logger = LogFactory.getLog(BlockEvent.class);

private final EventHub eventHub;
private final Peer peer;
private final Event event;

/**
* Raw proto buff event.
*
* @return Return raw protobuf event.
*/

public Event getEvent() {
return event;
}

/**
* creates a BlockEvent object by parsing the input Block and retrieving its constituent Transactions
*
Expand All @@ -65,27 +46,75 @@ public Event getEvent() {
BlockEvent(EventHub eventHub, Event event) throws InvalidProtocolBufferException {
super(event.getBlock());
this.eventHub = eventHub;
this.peer = null;
this.event = event;
}

public Date getTimestamp() {
BlockEvent(Peer peer, Ab.DeliverResponse resp) {
super(resp.getBlock());

Date ret = null;
eventHub = null;
this.peer = peer;
this.event = null;

Timestamp timestamp = event.getTimestamp();
if (null != timestamp) {
ret = ProtoUtils.getDateFromTimestamp(timestamp);
}
}

return ret;
/**
* Get the Event Hub that received the event.
*
* @return an Event Hub. Maybe null if new peer eventing services is being used.
* @deprecated Use new peer eventing services
*/
public EventHub getEventHub() {
return eventHub;
}

/**
* The Peer that received this event.
*
* @return Peer that received this event. Maybe null if source is legacy event hub.
*/
public Peer getPeer() {
return peer;
}

// /**
// * Raw proto buff event.
// *
// * @return Return raw protobuf event.
// */
//
// public Event getEvent() {
// return event;
// }

boolean isBlockEvent() {

return event == null || event.getEventCase() == Event.EventCase.BLOCK;
}

TransactionEvent getTransactionEvent(int index) throws InvalidProtocolBufferException {

return new TransactionEvent((TransactionEnvelopeInfo) getEnvelopeInfo(index), index);
}

List<TransactionEvent> getTransactionEventsList() {

ArrayList<TransactionEvent> ret = new ArrayList<TransactionEvent>(getEnvelopeCount());
for (TransactionEvent transactionEvent : getTransactionEvents()) {
ret.add(transactionEvent);
}

return ret;

}

public Iterable<TransactionEvent> getTransactionEvents() {

return new TransactionEventIterable();

}

public class TransactionEvent extends TransactionEnvelopeInfo {
TransactionEvent(TransactionEnvelopeInfo transactionEnvelopeInfo, int index) {
super(transactionEnvelopeInfo.getTransactionDeserializer(), index);
Expand All @@ -94,35 +123,30 @@ public class TransactionEvent extends TransactionEnvelopeInfo {
/**
* The event hub that received this event.
*
* @return
* @return May return null if peer eventing service detected the event.
* @deprecated use new peer eventing services {@link #getPeer()}
*/

public EventHub getEventHub() {

return BlockEvent.this.getEventHub();
}
}

List<TransactionEvent> getTransactionEventsList() {

ArrayList<TransactionEvent> ret = new ArrayList<TransactionEvent>(getEnvelopeCount());
for (TransactionEvent transactionEvent : getTransactionEvents()) {
ret.add(transactionEvent);
}

return ret;

}

public Iterable<TransactionEvent> getTransactionEvents() {
/**
* The peer that received this event.
*
* @return May return null if deprecated eventhubs are still being used, otherwise return the peer.
*/

return new TransactionEventIterable();
public Peer getPeer() {

return BlockEvent.this.getPeer();
}
}

class TransactionEventIterator implements Iterator<TransactionEvent> {
int ci = 0;
final int max;
int ci = 0;

TransactionEventIterator() {
max = getEnvelopeCount();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/ChaincodeID.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public String getVersion() {

}

@Override
public String toString() {
return "ChaincodeID(" + getName() + ":" + getPath() + ":" + getVersion() + ")";
}

/**
* Build a new ChaincodeID
*/
Expand Down
Loading

0 comments on commit 41ec4c3

Please sign in to comment.