Package emissary.grpc
Class GrpcRoutingPlace
- java.lang.Object
-
- emissary.directory.DirectoryProviderPlace
-
- emissary.place.ServiceProviderPlace
-
- emissary.grpc.GrpcRoutingPlace
-
- All Implemented Interfaces:
IGrpcRoutingPlace,IServiceProviderPlace,ServiceProviderPlaceMBean
- Direct Known Subclasses:
GrpcConnectionPlace,GrpcSampleServicePlace
public abstract class GrpcRoutingPlace extends ServiceProviderPlace implements IGrpcRoutingPlace
Place for processing data using gRPC connections to external services. Supports multiple end-points with shared configurations, where each endpoint is identified by a given target ID.Configuration Keys:
GRPC_HOST_{Target-ID}- gRPC service hostname or DNS target, whereTarget-IDis the unique identifier for the given host:portGRPC_PORT_{Target-ID}- gRPC service port, whereTarget-IDis the unique identifier for the given host:port- See
ConnectionFactoryfor supported pooling and gRPC channel configuration keys and defaults. - See
RetryHandlerfor supported retry configuration keys and defaults.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,org.apache.commons.pool2.ObjectPool<io.grpc.ManagedChannel>>channelPoolTablestatic StringGRPC_HOSTstatic StringGRPC_PORTprotected GrpcInvokergrpcInvokerprotected Map<String,String>hostnameTableprotected Map<String,Integer>portNumberTable-
Fields inherited from class emissary.place.ServiceProviderPlace
configG, configLocs, heavyDutyMethodImplemented, kff, placeLocation, processMethodImplemented, slogger
-
Fields inherited from class emissary.directory.DirectoryProviderPlace
denyList, dirPlace, keys, localDirPlace, logger, myKey, placeName, serviceCost, serviceDescription, serviceQuality
-
Fields inherited from interface emissary.place.IServiceProviderPlace
DOT, SPROUT_KEY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedGrpcRoutingPlace()protectedGrpcRoutingPlace(Configurator configs)protectedGrpcRoutingPlace(InputStream configStream)protectedGrpcRoutingPlace(InputStream configStream, String placeLocation)protectedGrpcRoutingPlace(InputStream configStream, String theDir, String thePlaceLocation)protectedGrpcRoutingPlace(String thePlaceLocation)protectedGrpcRoutingPlace(String configFile, String placeLocation)protectedGrpcRoutingPlace(String configFile, String theDir, String thePlaceLocation)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringgetHostname(String targetId)protected Map<String,String>getHostnameConfigs()intgetPortNumber(String targetId)protected Map<String,Integer>getPortNumberConfigs()protected <Q extends com.google.protobuf.GeneratedMessageV3,R extends com.google.protobuf.GeneratedMessageV3,S extends io.grpc.stub.AbstractBlockingStub<S>>
RinvokeGrpc(String targetId, Function<io.grpc.ManagedChannel,S> stubFactory, BiFunction<S,Q,R> callLogic, Q request)Wrapper method forGrpcInvoker.invoke(ObjectPool, Function, BiFunction, GeneratedMessageV3)that executes a unary gRPC call to a given endpoint.protected <Q extends com.google.protobuf.GeneratedMessageV3,R extends com.google.protobuf.GeneratedMessageV3,S extends io.grpc.stub.AbstractFutureStub<S>>
CompletableFuture<R>invokeGrpcAsync(String targetId, Function<io.grpc.ManagedChannel,S> stubFactory, BiFunction<S,Q,com.google.common.util.concurrent.ListenableFuture<R>> callLogic, Q request)Wrapper method forGrpcInvoker.invokeAsync(ObjectPool, Function, BiFunction, GeneratedMessageV3)that executes a unary gRPC call to a given endpoint and returns afuture.protected voidpassivateConnection(io.grpc.ManagedChannel managedChannel)Called after a gRPC call to clean up the channel.protected <T> TtableLookup(Map<String,T> table, String targetId)protected abstract booleanvalidateConnection(io.grpc.ManagedChannel managedChannel)Validates whether a givenManagedChannelis capable of successfully communicating with its associated gRPC server.-
Methods inherited from class emissary.place.ServiceProviderPlace
agentProcessCall, agentProcessHeavyDuty, agentProcessHeavyDuty, changesPrimaryView, createsExtractedRecords, dumpPlaceStats, dumpRunningConfig, getAgent, getAlternateViewsModified, getConfigurator, getFileTypes, getOutputForms, getParametersModified, getPlaceStats, getResourceLimitMillis, getRunningConfig, getTld, initKff, process, processHeavyDuty, rehash, setConfigLocations, setPlaceLocation, setupPlace, setupPlace, sproutsChildren, verifyProcessImplementationProvided
-
Methods inherited from class emissary.directory.DirectoryProviderPlace
addKey, addServiceProxy, configureServicePlace, deregisterFromDirectory, getDirectoryEntry, getKey, getKeys, getPlaceName, getPrimaryProxy, getProxies, isDenied, nextKeys, nukeMyProxies, register, register, registerWithDirectory, removeKey, removeServiceProxy, setLogger, setupPlacePostHook, shutDown, toString, unbindFromNamespace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface emissary.place.IServiceProviderPlace
addKey, addServiceProxy, agentProcessCall, agentProcessHeavyDuty, agentProcessHeavyDuty, getAgent, getDirectoryEntry, getKey, getKeys, getPlaceName, getPrimaryProxy, getProxies, getResourceLimitMillis, isDenied, loadConfigurator, loadConfigurator, loadConfigurator, loadConfigurator, nextKeys, process, processHeavyDuty, removeKey, removeServiceProxy, setConfigLocations, setPlaceLocation, shutDown
-
-
-
-
Field Detail
-
GRPC_HOST
public static final String GRPC_HOST
- See Also:
- Constant Field Values
-
GRPC_PORT
public static final String GRPC_PORT
- See Also:
- Constant Field Values
-
grpcInvoker
protected GrpcInvoker grpcInvoker
-
-
Constructor Detail
-
GrpcRoutingPlace
protected GrpcRoutingPlace() throws IOException- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(String thePlaceLocation) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(InputStream configStream) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(String configFile, String placeLocation) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(InputStream configStream, String placeLocation) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(String configFile, @Nullable String theDir, String thePlaceLocation) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(InputStream configStream, @Nullable String theDir, String thePlaceLocation) throws IOException
- Throws:
IOException
-
GrpcRoutingPlace
protected GrpcRoutingPlace(@Nullable Configurator configs) throws IOException- Throws:
IOException
-
-
Method Detail
-
validateConnection
protected abstract boolean validateConnection(io.grpc.ManagedChannel managedChannel)
Validates whether a givenManagedChannelis capable of successfully communicating with its associated gRPC server.- Parameters:
managedChannel- the gRPC channel to validate- Returns:
trueif the channel is healthy and the server responds successfully, elsefalse
-
passivateConnection
protected void passivateConnection(io.grpc.ManagedChannel managedChannel)
Called after a gRPC call to clean up the channel. No-op by default, since gRPC channels are designed to remain ready for reuse. Override this if using a stub that requires channels be reset or cleared between uses.- Parameters:
managedChannel- the gRPC channel to clean up
-
invokeGrpc
protected <Q extends com.google.protobuf.GeneratedMessageV3,R extends com.google.protobuf.GeneratedMessageV3,S extends io.grpc.stub.AbstractBlockingStub<S>> R invokeGrpc(String targetId, Function<io.grpc.ManagedChannel,S> stubFactory, BiFunction<S,Q,R> callLogic, Q request)
Wrapper method forGrpcInvoker.invoke(ObjectPool, Function, BiFunction, GeneratedMessageV3)that executes a unary gRPC call to a given endpoint.- Type Parameters:
Q- the protobuf request typeR- the protobuf response typeS- the gRPC stub type- Parameters:
targetId- the identifier used in the configs for the given gRPC endpointstubFactory- function that creates the appropriate gRPC stub from aManagedChannelcallLogic- function that performs the actual gRPC call using the stub and requestrequest- the protobuf request message to send- Returns:
- the response returned by the gRPC call
-
invokeGrpcAsync
protected <Q extends com.google.protobuf.GeneratedMessageV3,R extends com.google.protobuf.GeneratedMessageV3,S extends io.grpc.stub.AbstractFutureStub<S>> CompletableFuture<R> invokeGrpcAsync(String targetId, Function<io.grpc.ManagedChannel,S> stubFactory, BiFunction<S,Q,com.google.common.util.concurrent.ListenableFuture<R>> callLogic, Q request)
Wrapper method forGrpcInvoker.invokeAsync(ObjectPool, Function, BiFunction, GeneratedMessageV3)that executes a unary gRPC call to a given endpoint and returns afuture.- Type Parameters:
Q- the protobuf request typeR- the protobuf response typeS- the gRPC stub type- Parameters:
targetId- the identifier used in the configs for the given gRPC endpointstubFactory- function that creates the appropriate gRPC stub from aManagedChannelcallLogic- function that performs the actual gRPC call using the stub and requestrequest- the protobuf request message to send- Returns:
- the future that waits for the response returned by the gRPC call
-
getPortNumber
public int getPortNumber(String targetId)
-
-