Class GqlConnection

java.lang.Object
dev.grafeo.gwp.GqlConnection
All Implemented Interfaces:
AutoCloseable

public class GqlConnection extends Object implements AutoCloseable
A connection to a GWP server.

Implements AutoCloseable for use with try-with-resources.


 try (GqlConnection conn = GqlConnection.connect("localhost:50051")) {
     try (GqlSession session = conn.createSession()) {
         // use the session
     }
 }
 
  • Method Details

    • connect

      public static GqlConnection connect(String target)
      Connect to a GWP server using an insecure (plaintext) channel.
      Parameters:
      target - the server address (e.g. "localhost:50051")
      Returns:
      a connected GqlConnection
      Throws:
      GqlException - if the connection fails
    • connect

      public static GqlConnection connect(String target, boolean useTls)
      Connect to a GWP server.
      Parameters:
      target - the server address (e.g. "localhost:50051")
      useTls - true to use TLS, false for plaintext
      Returns:
      a connected GqlConnection
      Throws:
      GqlException - if the connection fails
    • createSession

      public GqlSession createSession()
      Perform a handshake and return a new session.
      Returns:
      a new GqlSession
    • close

      public void close()
      Close the underlying gRPC channel.

      Initiates an orderly shutdown and waits up to 5 seconds for in-progress RPCs to complete.

      Specified by:
      close in interface AutoCloseable