Package org.summerboot.jexpress.nio.grpc
Class GRPCClient<T extends GRPCClient<T>>
java.lang.Object
org.summerboot.jexpress.nio.grpc.GRPCClient<T>
- Type Parameters:
T-
- Author:
- Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected io.grpc.ManagedChannelprotected io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilderprotected final Lockprotected final ReadWriteLockprotected Thread -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconnect()Disconnect the current connection and build a new connection within a write lockvoidDisconnect the current connectionprotected voiddisconnect(boolean withLock) protected LockgetLock()Get the read lockprotected voidlock()Set a read lock for business method to prevent being called while connect/disconnectprotected voidBy default, just call connect() to establish a new connection with the updated settings; or do nothing to keep using current connection.protected abstract voidonConnected(io.grpc.ManagedChannel channel) protected booleantryLock()Try a read lock for business method to prevent being called while connect/disconnectprotected booleanTry a read lock in a given time period for business method to prevent being called while connect/disconnectprotected voidunlock()Release the read lock for business method to prevent being called while connect/disconnectprotected voidupdateChannelBuilder(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)
-
Field Details
-
channelBuilder
protected io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder channelBuilder -
channel
protected io.grpc.ManagedChannel channel -
rwLock
-
readLock
-
shutdownHook
-
-
Constructor Details
-
GRPCClient
public GRPCClient()
-
-
Method Details
-
withConfig
-
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
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
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
Get the read lock- Returns:
-