Class GRPCClient<T extends GRPCClient<T>>

java.lang.Object
org.summerboot.jexpress.nio.grpc.GRPCClient<T>
Type Parameters:
T -

public abstract class GRPCClient<T extends GRPCClient<T>> extends Object
Author:
Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected io.grpc.ManagedChannel
     
    protected io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder
     
    protected final Lock
     
    protected final ReadWriteLock
     
    protected Thread
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Disconnect the current connection and build a new connection within a write lock
    void
    Disconnect the current connection
    protected void
    disconnect(boolean withLock)
     
    protected Lock
    Get the read lock
    protected void
    Set a read lock for business method to prevent being called while connect/disconnect
    protected void
    By default, just call connect() to establish a new connection with the updated settings; or do nothing to keep using current connection.
    protected abstract void
    onConnected(io.grpc.ManagedChannel channel)
     
    protected boolean
    Try a read lock for business method to prevent being called while connect/disconnect
    protected boolean
    tryLock(long time, TimeUnit unit)
    Try a read lock in a given time period for business method to prevent being called while connect/disconnect
    protected void
    Release the read lock for business method to prevent being called while connect/disconnect
    protected void
    updateChannelBuilder(io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder)
    callback when config file updated if GRPCClientConfig.addConfigUpdateListener(this);
     
    withNettyChannelBuilder(io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • channelBuilder

      protected io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder
    • channel

      protected io.grpc.ManagedChannel channel
    • rwLock

      protected final ReadWriteLock rwLock
    • readLock

      protected final Lock readLock
    • shutdownHook

      protected Thread shutdownHook
  • Constructor Details

    • GRPCClient

      public GRPCClient()
  • Method Details

    • withConfig

      public T withConfig(GRPCClientConfig cfg)
    • withNettyChannelBuilder

      public T withNettyChannelBuilder(io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder)
      Parameters:
      channelBuilder -
    • updateChannelBuilder

      protected void updateChannelBuilder(io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder)
      callback when config file updated if GRPCClientConfig.addConfigUpdateListener(this);
      Parameters:
      channelBuilder -
    • onChannelBuilderUpdated

      protected void onChannelBuilderUpdated()
      By default, just call connect() to establish a new connection with the updated settings; or do nothing to keep using current connection.
    • connect

      public T connect()
      Disconnect the current connection and build a new connection within a write lock
      Returns:
    • onConnected

      protected abstract void onConnected(io.grpc.ManagedChannel channel)
      Parameters:
      channel -
    • disconnect

      public void disconnect()
      Disconnect the current connection
    • disconnect

      protected void disconnect(boolean withLock)
    • lock

      protected void lock()
      Set a read lock for business method to prevent being called while connect/disconnect
    • tryLock

      protected boolean tryLock()
      Try a read lock for business method to prevent being called while connect/disconnect
      Returns:
    • tryLock

      protected boolean tryLock(long time, TimeUnit unit) throws InterruptedException
      Try a read lock in a given time period for business method to prevent being called while connect/disconnect
      Parameters:
      time -
      unit -
      Returns:
      Throws:
      InterruptedException
    • unlock

      protected void unlock()
      Release the read lock for business method to prevent being called while connect/disconnect
    • getLock

      protected Lock getLock()
      Get the read lock
      Returns: