Package org.hyperledger.fabric.gateway
Interface Network
public interface Network
A Network object represents the set of peers in a Fabric network (channel).
Applications should get a Network instance from a Gateway using the
Gateway.getNetwork(String) method.
The Network object provides the ability for applications to:
- Obtain a specific smart contract deployed to the network using
getContract(String), in order to submit and evaluate transactions for that smart contract. - Listen to new block events using
addBlockListener(Consumer). - Replay previous block events using
addBlockListener(long, Consumer).
-
Method Summary
Modifier and TypeMethodDescriptionConsumer<org.hyperledger.fabric.sdk.BlockEvent>addBlockListener(long startBlock, Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Add a listener to replay block events from the network.Consumer<org.hyperledger.fabric.sdk.BlockEvent>addBlockListener(Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Add a listener to receive block events from the network.Consumer<org.hyperledger.fabric.sdk.BlockEvent>addBlockListener(Checkpointer checkpointer, Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Add a listener to receive block events from the network with checkpointing.addCommitListener(CommitListener listener, Collection<org.hyperledger.fabric.sdk.Peer> peers, String transactionId) Add a listener to receive transaction commit and peer disconnect events for a set of peers.org.hyperledger.fabric.sdk.ChannelGet the low-level chanel object associated with this network.getContract(String chaincodeId) Get an instance of a contract on the current network.getContract(String chaincodeId, String name) Get an instance of a contract on the current network.Get a reference to the owning Gateway connection.voidremoveBlockListener(Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Removes a previously added block listener.voidremoveCommitListener(CommitListener listener) Removes a previously added transaction commit listener.
-
Method Details
-
getContract
Get an instance of a contract on the current network.- Parameters:
chaincodeId- The name of the chaincode that implements the smart contract.- Returns:
- The contract object.
-
getContract
Get an instance of a contract on the current network. If the chaincode instance contains more than one smart contract class (available using the latest chaincode programming model), then an individual class can be selected.- Parameters:
chaincodeId- The name of the chaincode that implements the smart contract.name- The class name of the smart contract within the chaincode.- Returns:
- The contract object.
-
getGateway
Gateway getGateway()Get a reference to the owning Gateway connection.- Returns:
- The owning gateway.
-
getChannel
org.hyperledger.fabric.sdk.Channel getChannel()Get the low-level chanel object associated with this network.- Returns:
- A channel.
-
addBlockListener
Consumer<org.hyperledger.fabric.sdk.BlockEvent> addBlockListener(Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Add a listener to receive block events from the network. Events are received in order and without duplication.- Parameters:
listener- A block listener.- Returns:
- The block listener argument.
-
addBlockListener
Consumer<org.hyperledger.fabric.sdk.BlockEvent> addBlockListener(Checkpointer checkpointer, Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) throws IOException Add a listener to receive block events from the network with checkpointing. Re-adding a listener with the same checkpointer on subsequent application invocations will resume listening from the previous block position. Events are received in order and without duplication.- Parameters:
checkpointer- Checkpointer to persist block position.listener- A block listener.- Returns:
- The block listener argument.
- Throws:
IOException- if an error occurs establishing checkpointing.GatewayRuntimeException- if an underlying infrastructure failure occurs.
-
addBlockListener
Consumer<org.hyperledger.fabric.sdk.BlockEvent> addBlockListener(long startBlock, Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener) Add a listener to replay block events from the network. Events are received in order and without duplication.- Parameters:
startBlock- The number of the block from which events should be replayed.listener- A block listener.- Returns:
- The block listener argument.
- Throws:
GatewayRuntimeException- if an underlying infrastructure failure occurs.
-
removeBlockListener
Removes a previously added block listener.- Parameters:
listener- A block listener.
-
addCommitListener
CommitListener addCommitListener(CommitListener listener, Collection<org.hyperledger.fabric.sdk.Peer> peers, String transactionId) Add a listener to receive transaction commit and peer disconnect events for a set of peers.- Parameters:
listener- A transaction commit listener.peers- The peers from which to receive events.transactionId- A transaction ID.- Returns:
- The transaction commit listener argument.
-
removeCommitListener
Removes a previously added transaction commit listener.- Parameters:
listener- A block listener.
-