net.corda.core.node

## Interface ServiceHub

- All Superinterfaces:
    ServicesForResolution
  All Known Subinterfaces:
    PluginServiceHub
  All Known Implementing Classes:
    ServiceHubInternal

      public ServiceHub
      extends ServicesForResolution

  A service hub simply vends references to the other services a node has. Some of those services may be missing or mocked out. This class is useful to pass to chunks of pluggable code that might have need of many different kinds of functionality and you don't want to hard-code which types in the interface.

  Any services exposed to flows (public view) need to implement SerializeAsToken or similar to avoid their internal state from being serialized in checkpoints.

  See Also:
    SerializeAsToken

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `ServiceHub.DefaultImpls` A service hub simply vends references to the other services a node has. Some of those services may be missing or mocked out. This class is useful to pass to chunks of pluggable code that might have need of many different kinds of functionality and you don't want to hard-code which types in the interface.

  - ### Method Summary

    All Methods Instance Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.time.Clock` | `getClock()`
    `KeyManagementService` | `getKeyManagementService()`
    `java.security.KeyPair` | `getLegalIdentityKey()` Helper property to shorten code for fetching the Node's KeyPair associated with the public legalIdentity Party from the key management service. Typical use is during signing in flows and for unit test signing.
    `NodeInfo` | `getMyInfo()`
    `NetworkMapCache` | `getNetworkMapCache()`
    `MessagingService` | `getNetworkService()`
    `java.security.KeyPair` | `getNotaryIdentityKey()` Helper property to shorten code for fetching the Node's KeyPair associated with the public notaryIdentity Party from the key management service. It is assumed that this is only used in contexts where the Node knows it is hosting a Notary Service. Otherwise, it will throw an IllegalArgumentException. Typical use is during signing in flows and for unit test signing.
    `SchedulerService` | `getSchedulerService()`
    `StorageService` | `getStorageService()`
    `VaultService` | `getVaultService()`
    `<T> FlowStateMachine<T>` | `invokeFlowAsync(java.lang.Class<? extends net.corda.core.flows.FlowLogic<? extends T>> logicType, java.lang.Object args)` Will check logicType and args against a whitelist and if acceptable then construct and initiate the flow. Note that you must be on the server thread to call this method.
    `TransactionState<?>` | `loadState(StateRef stateRef)` Given a `class StateRef` loads the referenced transaction and looks up the specified output `interface ContractState`.
    `void` | `recordTransactions(java.lang.Iterable<net.corda.core.transactions.SignedTransaction> txs)` Given a `class SignedTransaction`, writes it to the local storage for validated transactions and then sends them to the vault for further processing. Expects to be run within a database transaction.
    `void` | `recordTransactions(net.corda.core.transactions.SignedTransaction txs)` Given some `class SignedTransaction`s, writes them to the local storage for validated transactions and then sends them to the vault for further processing.
    `<T extends ContractState> StateAndRef<T>` | `toStateAndRef(StateRef ref)` Will check logicType and args against a whitelist and if acceptable then construct and initiate the protocol.

    - ### Methods inherited from interface net.corda.core.node.ServicesForResolution

      `getIdentityService, getStorageService, loadState`

- - ### Method Detail

    - #### getVaultService

          VaultService getVaultService()

    - #### getKeyManagementService

          KeyManagementService getKeyManagementService()

    - #### getNetworkService

          MessagingService getNetworkService()

    - #### getStorageService

          StorageService getStorageService()

    - #### getNetworkMapCache

          NetworkMapCache getNetworkMapCache()

    - #### getSchedulerService

          SchedulerService getSchedulerService()

    - #### getClock

          java.time.Clock getClock()

    - #### getMyInfo

          NodeInfo getMyInfo()

    - #### recordTransactions

          void recordTransactions(java.lang.Iterable<net.corda.core.transactions.SignedTransaction> txs)

      Given a `class SignedTransaction`, writes it to the local storage for validated transactions and then sends them to the vault for further processing. Expects to be run within a database transaction.

      Parameters:
        `txs` - The transactions to record.
      See Also:
        `class SignedTransaction`

    - #### recordTransactions

          void recordTransactions(net.corda.core.transactions.SignedTransaction txs)

      Given some `class SignedTransaction`s, writes them to the local storage for validated transactions and then sends them to the vault for further processing.

      Parameters:
        `txs` - The transactions to record.
      See Also:
        `class SignedTransaction`

    - #### loadState

          TransactionState<?> loadState(StateRef stateRef)

      Given a `class StateRef` loads the referenced transaction and looks up the specified output `interface ContractState`.

      Throws:
        - if the `class StateRef` points to a non-existent transaction.
      See Also:
        `class StateRef`, `interface ContractState`

    - #### toStateAndRef

          <T extends ContractState> StateAndRef<T> toStateAndRef(StateRef ref)

      Will check logicType and args against a whitelist and if acceptable then construct and initiate the protocol.

      Throws:
        - or IllegalArgumentException if there are problems with the logicType or args.
      See Also:
        logicType, args

    - #### invokeFlowAsync

          <T> FlowStateMachine<T> invokeFlowAsync(java.lang.Class<? extends net.corda.core.flows.FlowLogic<? extends T>> logicType,
                                                  java.lang.Object args)

      Will check logicType and args against a whitelist and if acceptable then construct and initiate the flow. Note that you must be on the server thread to call this method.

      Throws:
        - or IllegalArgumentException if there are problems with the logicType or args.

    - #### getLegalIdentityKey

          java.security.KeyPair getLegalIdentityKey()

      Helper property to shorten code for fetching the Node's KeyPair associated with the public legalIdentity Party from the key management service. Typical use is during signing in flows and for unit test signing.

      TODO: legalIdentity can now be composed of multiple keys, should we return a list of keyPairs here? Right now the logic assumes the legal identity has a composite key with only one node

    - #### getNotaryIdentityKey

          java.security.KeyPair getNotaryIdentityKey()

      Helper property to shorten code for fetching the Node's KeyPair associated with the public notaryIdentity Party from the key management service. It is assumed that this is only used in contexts where the Node knows it is hosting a Notary Service. Otherwise, it will throw an IllegalArgumentException. Typical use is during signing in flows and for unit test signing.