Interface Network


public interface Network
Network represents a network of nodes that are members of a specific Fabric channel. Network instances are obtained from a Gateway using the Gateway.getNetwork(String) method.

The Network provides the ability for applications to:

To safely handle connection errors during eventing, it is recommended to use a checkpointer to track eventing progress. This allows eventing to be resumed with no loss or duplication of events.

Chaincode events example


     Checkpointer checkpointer = new InMemoryCheckpointer();
     while (true) {
         ChaincodeEventsRequest request = network.newChaincodeEventsRequest("chaincodeName")
                 .checkpoint(checkpointer)
                 .startBlock(blockNumber) // Ignored if the checkpointer has checkpoint state
                 .build();
         try (CloseableIterator<ChaincodeEvent> events = request.getEvents()) {
             events.forEachRemaining(event -> {
                 // Process then checkpoint event
                 checkpointer.checkpointChaincodeEvent(event);
             });
         } catch (GatewayRuntimeException e) {
             // Connection error
         }
     }
 

Block events example


     Checkpointer checkpointer = new InMemoryCheckpointer();
     while (true) {
         ChaincodeEventsRequest request = network.newBlockEventsRequest()
                 .checkpoint(checkpointer)
                 .startBlock(blockNumber) // Ignored if the checkpointer has checkpoint state
                 .build();
         try (CloseableIterator<Block> events = request.getEvents()) {
             events.forEachRemaining(event -> {
                 // Process then checkpoint block
                 checkpointer.checkpointBlock(event.getHeader().getNumber());
             });
         } catch (GatewayRuntimeException e) {
             // Connection error
         }
     }
 
  • Method Details

    • getContract

      Contract getContract(String chaincodeName)
      Get an instance of a contract on the current network.
      Parameters:
      chaincodeName - The name of the chaincode that implements the smart contract.
      Returns:
      The contract object.
      Throws:
      NullPointerException - if the chaincode name is null.
    • getContract

      Contract getContract(String chaincodeName, String contractName)
      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:
      chaincodeName - The name of the chaincode that implements the smart contract.
      contractName - The name of the smart contract within the chaincode.
      Returns:
      The contract object.
      Throws:
      NullPointerException - if the chaincode name is null.
    • getName

      String getName()
      Get the name of the network channel.
      Returns:
      The network name.
    • getChaincodeEvents

      default CloseableIterator<ChaincodeEvent> getChaincodeEvents(String chaincodeName)
      Get events emitted by transaction functions of a specific chaincode from the next committed block. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      chaincodeName - A chaincode name.
      Returns:
      Ordered sequence of events.
      Throws:
      NullPointerException - if the chaincode name is null.
      See Also:
    • getChaincodeEvents

      CloseableIterator<ChaincodeEvent> getChaincodeEvents(String chaincodeName, UnaryOperator<CallOptions> options)
      Get events emitted by transaction functions of a specific chaincode from the next committed block. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      chaincodeName - A chaincode name.
      options - Function that transforms call options.
      Returns:
      Ordered sequence of events.
      Throws:
      NullPointerException - if the chaincode name is null.
      See Also:
    • getChaincodeEvents

      @Deprecated default CloseableIterator<ChaincodeEvent> getChaincodeEvents(String chaincodeName, CallOption... options)
      Get events emitted by transaction functions of a specific chaincode from the next committed block. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      chaincodeName - A chaincode name.
      options - Call options.
      Returns:
      Ordered sequence of events.
      Throws:
      NullPointerException - if the chaincode name is null.
    • newChaincodeEventsRequest

      ChaincodeEventsRequest.Builder newChaincodeEventsRequest(String chaincodeName)
      Build a new chaincode events request, which can be used to obtain events emitted by transaction functions of a specific chaincode. This can be used to specify a specific ledger start position. Supports offline signing flow.
      Parameters:
      chaincodeName - A chaincode name.
      Returns:
      A chaincode events request builder.
      Throws:
      NullPointerException - if the chaincode name is null.
    • getBlockEvents

      default CloseableIterator<org.hyperledger.fabric.protos.common.Block> getBlockEvents()
      Get block events. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Returns:
      Ordered sequence of events.
      See Also:
    • getBlockEvents

      CloseableIterator<org.hyperledger.fabric.protos.common.Block> getBlockEvents(UnaryOperator<CallOptions> options)
      Get block events. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      options - Function that transforms call options.
      Returns:
      Ordered sequence of events.
      See Also:
    • newBlockEventsRequest

      BlockEventsRequest.Builder newBlockEventsRequest()
      Build a request to receive block events. This can be used to specify a specific ledger start position. Supports offline signing flow.
      Returns:
      A block events request builder.
      Throws:
      NullPointerException - if the chaincode name is null.
    • getFilteredBlockEvents

      default CloseableIterator<org.hyperledger.fabric.protos.peer.FilteredBlock> getFilteredBlockEvents()
      Get filtered block events. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Returns:
      Ordered sequence of events.
      See Also:
    • getFilteredBlockEvents

      CloseableIterator<org.hyperledger.fabric.protos.peer.FilteredBlock> getFilteredBlockEvents(UnaryOperator<CallOptions> options)
      Get filtered block events. The Java gRPC implementation may not begin reading events until the first use of the returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      options - Function that transforms call options.
      Returns:
      Ordered sequence of events.
      See Also:
    • newFilteredBlockEventsRequest

      FilteredBlockEventsRequest.Builder newFilteredBlockEventsRequest()
      Build a request to receive filtered block events. This can be used to specify a specific ledger start position. Supports offline signing flow.
      Returns:
      A filtered block events request builder.
      Throws:
      NullPointerException - if the chaincode name is null.
    • getBlockAndPrivateDataEvents

      default CloseableIterator<org.hyperledger.fabric.protos.peer.BlockAndPrivateData> getBlockAndPrivateDataEvents()
      Get block and private data events. The Java gRPC implementation may not begin reading events until the first use of the* returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Returns:
      Ordered sequence of events.
      See Also:
    • getBlockAndPrivateDataEvents

      CloseableIterator<org.hyperledger.fabric.protos.peer.BlockAndPrivateData> getBlockAndPrivateDataEvents(UnaryOperator<CallOptions> options)
      Get block and private data events. The Java gRPC implementation may not begin reading events until the first use of the* returned iterator.

      Note that the returned iterator may throw StatusRuntimeException during iteration if a gRPC connection error occurs.

      Parameters:
      options - Function that transforms call options.
      Returns:
      Ordered sequence of events.
      See Also:
    • newBlockAndPrivateDataEventsRequest

      BlockAndPrivateDataEventsRequest.Builder newBlockAndPrivateDataEventsRequest()
      Build a request to receive block and private data events. This can be used to specify a specific ledger start position. Supports offline signing flow.
      Returns:
      A block and private data events request builder.
      Throws:
      NullPointerException - if the chaincode name is null.