org.hyperledger.fabric.gateway

## 接口 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)`.
  另请参阅:
    Developing Fabric Applications - Network Channel

- - ### 方法概要

    所有方法 实例方法 抽象方法
    限定符和类型 | 方法和说明
    --- | ---
    `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.
    `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(long startBlock, Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener)` Add a listener to replay block events from the network.
    `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.
    `org.hyperledger.fabric.sdk.Channel` | `getChannel()` Get the low-level chanel object associated with this network.
    `Contract` | `getContract(String chaincodeId)` Get an instance of a contract on the current network.
    `Contract` | `getContract(String chaincodeId, String name)` Get an instance of a contract on the current network.
    `Gateway` | `getGateway()` Get a reference to the owning Gateway connection.
    `void` | `removeBlockListener(Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener)` Removes a previously added block listener.
    `void` | `removeCommitListener(CommitListener listener)` Removes a previously added transaction commit listener.

- - ### 方法详细资料

    - #### getContract

          Contract getContract(String chaincodeId)

      Get an instance of a contract on the current network.
      参数:
        `chaincodeId` - The name of the chaincode that implements the smart contract.
      返回:
        The contract object.

    - #### getContract

          Contract getContract(String chaincodeId,
                               String name)

      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.
      参数:
        `chaincodeId` - The name of the chaincode that implements the smart contract.
        `name` - The class name of the smart contract within the chaincode.
      返回:
        The contract object.

    - #### getGateway

          Gateway getGateway()

      Get a reference to the owning Gateway connection.
      返回:
        The owning gateway.

    - #### getChannel

          org.hyperledger.fabric.sdk.Channel getChannel()

      Get the low-level chanel object associated with this network.
      返回:
        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.
      参数:
        `listener` - A block listener.
      返回:
        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.
      参数:
        `checkpointer` - Checkpointer to persist block position.
        `listener` - A block listener.
      返回:
        The block listener argument.
      抛出:
        `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.
      参数:
        `startBlock` - The number of the block from which events should be replayed.
        `listener` - A block listener.
      返回:
        The block listener argument.
      抛出:
        `GatewayRuntimeException` - if an underlying infrastructure failure occurs.

    - #### removeBlockListener

          void removeBlockListener(Consumer<org.hyperledger.fabric.sdk.BlockEvent> listener)

      Removes a previously added block listener.
      参数:
        `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.
      参数:
        `listener` - A transaction commit listener.
        `peers` - The peers from which to receive events.
        `transactionId` - A transaction ID.
      返回:
        The transaction commit listener argument.

    - #### removeCommitListener

          void removeCommitListener(CommitListener listener)

      Removes a previously added transaction commit listener.
      参数:
        `listener` - A block listener.

Copyright © 2023. All rights reserved.