Package biopb.tensor

Class Connection

java.lang.Object
biopb.tensor.Connection
All Implemented Interfaces:
AutoCloseable

public final class Connection extends Object implements AutoCloseable
One handle on the data plane: finds it, dials it, and says why when it cannot.

The Java twin of Python's biopb.tensor.Connection. It holds the live TensorFlightClient, the URL it dials and, when it has none, why. It caches nothing else: the catalog, health and sources are the plane's to answer, asked on the client.

Where the plane is comes from, in order: $BIOPB_TENSOR_URL, then the control (docs/discovery-contract.md), which also brings the plane up. An address from anywhere but the control is dialed with an explicit token or $BIOPB_TENSOR_TOKEN, never with the control's credential file.

connect() blocks on the network. Not thread-safe to call from two threads at once; readers on other threads see the previous client until the new one is ready.

  • Field Details

    • START_TIMEOUT

      public static final Duration START_TIMEOUT
      How long connect() waits for a plane it was told is coming up.
  • Constructor Details

    • Connection

      public Connection()
    • Connection

      public Connection(TlsPinStore pins)
      A connection whose first-use pins go to pins instead of the file the Python SDK shares, e.g. TlsPinStore.inMemory() to keep none on disk.
  • Method Details

    • client

      public TensorFlightClient client()
      The live client, or null until a connect() succeeds (and again after one fails).
    • url

      public String url()
      The address last dialed, or null.
    • lastMessage

      public String lastMessage()
      Why the last connect() failed, phrased for the person who has to fix it; empty on success.
    • connect

      public boolean connect()
      connect(String, String, Duration) with the control naming the plane.
    • connect

      public boolean connect(String url, String token, Duration timeout)
      Dial the data plane; true when client is ready to use. Never throws.

      With no url, $BIOPB_TENSOR_URL or else the control names the plane. A url is dialed as given, with token and nothing else.

      A plane the control named is waited on through timeout, since the control may have just started it; one named anywhere else is not, except through a scan it reports as STARTING.

      Parameters:
      url - the plane to dial, or null to discover it
      token - the bearer token for url; ignored when discovering
    • close

      public void close()
      Close the client, if any.
      Specified by:
      close in interface AutoCloseable