Class ServiceClientHub
Represents a centralized manager and client factory for obtaining ISkyServiceClient-implementing instances
that are most likely Glue-based but do not have to be.
Custom solutions may derive from this class and override specifics (i.e. inject some policies in all service call clients)
Inheritance
System.Object
ServiceClientHub
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Azos.Sky.dll
Syntax
public class ServiceClientHub : ApplicationComponent, IDisposable, IApplicationComponent
Constructors
ServiceClientHub(IApplication, IConfigSectionNode)
Override to configure custom members.
The default implementation populates the CacheMap registry
Declaration
protected ServiceClientHub(IApplication app, IConfigSectionNode config)
Parameters
Fields
CONFIG_GLOBAL_SECTION
Declaration
public const string CONFIG_GLOBAL_SECTION = "global"
Field Value
Type |
Description |
System.String |
|
CONFIG_LOCAL_SECTION
Declaration
public const string CONFIG_LOCAL_SECTION = "local"
Field Value
Type |
Description |
System.String |
|
CONFIG_MAP_CLIENT_CONTRACT_ATTR
Declaration
public const string CONFIG_MAP_CLIENT_CONTRACT_ATTR = "client-contract"
Field Value
Type |
Description |
System.String |
|
CONFIG_MAP_IMPLEMENTOR_ATTR
Declaration
public const string CONFIG_MAP_IMPLEMENTOR_ATTR = "implementor"
Field Value
Type |
Description |
System.String |
|
CONFIG_MAP_SECTION
Declaration
public const string CONFIG_MAP_SECTION = "map"
Field Value
Type |
Description |
System.String |
|
CONFIG_OPTIONS_SECTION
Declaration
public const string CONFIG_OPTIONS_SECTION = "options"
Field Value
Type |
Description |
System.String |
|
CONFIG_SERVICE_CLIENT_HUB_SECTION
Declaration
public const string CONFIG_SERVICE_CLIENT_HUB_SECTION = "service-client-hub"
Field Value
Type |
Description |
System.String |
|
CTOR_SIG_GLUE_ENDPOINT
Declaration
protected static readonly Type[] CTOR_SIG_GLUE_ENDPOINT
Field Value
Type |
Description |
System.Type[] |
|
Properties
App
Declaration
public ISkyApplication App { get; }
Property Value
CachedMap
Returns the registry of cached ContractMapping instances
Declaration
public IRegistry<ServiceClientHub.ContractMapping> CachedMap { get; }
Property Value
ComponentLogTopic
Declaration
public override string ComponentLogTopic { get; }
Property Value
Type |
Description |
System.String |
|
Overrides
Methods
CallWithRetry<TServiceClient>(Action<TServiceClient>, IEnumerable<String>, Func<TServiceClient, Exception, Boolean>, String, String)
Performs a call by making the appropriate client and retries if the ClientCallException arises,
otherwise fails if no backup hosts are left
Declaration
public void CallWithRetry<TServiceClient>(Action<TServiceClient> callBody, IEnumerable<string> hosts, Func<TServiceClient, Exception, bool> abortFilter = null, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.Action<TServiceClient> |
callBody |
The body of the client call, must not be null
|
System.Collections.Generic.IEnumerable<System.String> |
hosts |
The array of hosts to retry against, left to right
|
System.Func<TServiceClient, System.Exception, System.Boolean> |
abortFilter |
Optional functor that returns true for call exceptions that should abort the retry process
|
System.String |
fromHost |
Optional
|
System.String |
svcName |
Optional
|
Type Parameters
Name |
Description |
TServiceClient |
|
CallWithRetry<TServiceClient, TResult>(Func<TServiceClient, TResult>, IEnumerable<String>, Func<TServiceClient, Exception, Boolean>, String, String)
Performs a call by making the appropriate client and retries if the ClientCallException arises,
otherwise fails if no backup hosts are left
Declaration
public TResult CallWithRetry<TServiceClient, TResult>(Func<TServiceClient, TResult> callBody, IEnumerable<string> hosts, Func<TServiceClient, Exception, bool> abortFilter = null, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.Func<TServiceClient, TResult> |
callBody |
The body of the client call, must not be null
|
System.Collections.Generic.IEnumerable<System.String> |
hosts |
The array of hosts to retry against, left to right
|
System.Func<TServiceClient, System.Exception, System.Boolean> |
abortFilter |
Optional functor that returns true for call exceptions that should abort the retry process
|
System.String |
fromHost |
Optional
|
System.String |
svcName |
Optional
|
Returns
Type Parameters
Name |
Description |
TServiceClient |
|
TResult |
|
CallWithRetryAsync<TServiceClient>(Func<TServiceClient, Task>, IEnumerable<String>, Func<TServiceClient, Exception, Boolean>, String, String)
Performs a call by making the appropriate client and retries if the ClientCallException arises,
otherwise fails if no backup hosts are left
Declaration
public Task CallWithRetryAsync<TServiceClient>(Func<TServiceClient, Task> callBody, IEnumerable<string> hosts, Func<TServiceClient, Exception, bool> abortFilter = null, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.Func<TServiceClient, System.Threading.Tasks.Task> |
callBody |
The body of the client call, must not be null
|
System.Collections.Generic.IEnumerable<System.String> |
hosts |
The array of hosts to retry against, left to right
|
System.Func<TServiceClient, System.Exception, System.Boolean> |
abortFilter |
Optional functor that returns true for call exceptions that should abort the retry process
|
System.String |
fromHost |
Optional
|
System.String |
svcName |
Optional
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Type Parameters
Name |
Description |
TServiceClient |
|
CallWithRetryAsync<TServiceClient, TResult>(Func<TServiceClient, Task<TResult>>, IEnumerable<String>, Func<TServiceClient, Exception, Boolean>, String, String)
Performs a call by making the appropriate client and retries if the ClientCallException arises,
otherwise fails if no backup hosts are left
Declaration
public Task<TResult> CallWithRetryAsync<TServiceClient, TResult>(Func<TServiceClient, Task<TResult>> callBody, IEnumerable<string> hosts, Func<TServiceClient, Exception, bool> abortFilter = null, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.Func<TServiceClient, System.Threading.Tasks.Task<TResult>> |
callBody |
The body of the client call, must not be null
|
System.Collections.Generic.IEnumerable<System.String> |
hosts |
The array of hosts to retry against, left to right
|
System.Func<TServiceClient, System.Exception, System.Boolean> |
abortFilter |
Optional functor that returns true for call exceptions that should abort the retry process
|
System.String |
fromHost |
Optional
|
System.String |
svcName |
Optional
|
Returns
Type |
Description |
System.Threading.Tasks.Task<TResult> |
|
Type Parameters
Name |
Description |
TServiceClient |
|
TResult |
|
DoMakeClientInstance<TServiceClient>(ServiceClientHub.ContractMapping, Boolean, Node)
Override to make an instance of client per ContractMapping.
The default implementation uses activator
Declaration
protected virtual TServiceClient DoMakeClientInstance<TServiceClient>(ServiceClientHub.ContractMapping mapping, bool isGlobal, Node node)
where TServiceClient : ISkyServiceClient
Parameters
Returns
Type |
Description |
TServiceClient |
|
Type Parameters
Name |
Description |
TServiceClient |
|
DoMapContractToImplementation(Type)
Override to map tContract into ContractMapping object. The default implementation uses cached registry of mappings
Declaration
protected virtual ServiceClientHub.ContractMapping DoMapContractToImplementation(Type tContract)
Parameters
Type |
Name |
Description |
System.Type |
tContract |
|
Returns
DoResolveNetworkService(ServiceClientHub.ContractMapping, String, String, String, out Boolean)
Override to resolve ContractMapping into physical connection parameters.
The default implementation uses metabase's ResolveNetworkService
Declaration
protected virtual Node DoResolveNetworkService(ServiceClientHub.ContractMapping mapping, string toHost, string fromHost, string svcName, out bool isGlobal)
Parameters
Returns
DoSetupClientInstance(ServiceClientHub.ContractMapping, Boolean, ISkyServiceClient, String, String)
Override to setup the instance of client after it has been allocated.
The default implementation injects headers, timeouts, and inspectors for Glue.ClientEndPoints
Declaration
protected virtual void DoSetupClientInstance(ServiceClientHub.ContractMapping mapping, bool isGlobal, ISkyServiceClient instance, string toHost, string fromHost)
Parameters
MakeClientInstance<TServiceClient>(ServiceClientHub.ContractMapping, Boolean, Node)
Declaration
protected TServiceClient MakeClientInstance<TServiceClient>(ServiceClientHub.ContractMapping mapping, bool isGlobal, Node node)
where TServiceClient : ISkyServiceClient
Parameters
Returns
Type |
Description |
TServiceClient |
|
Type Parameters
Name |
Description |
TServiceClient |
|
Makes an appropriate implementor for requested service client contract type.
Pass svcName parameter in cases when the requested contract may get implemented by more than one network service.
The call is thread-safe. The caller should Dispose() the returned instance after it has been used
Declaration
public TServiceClient MakeNew<TServiceClient>(Metabank.SectionHost toHost, Metabank.SectionHost fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Returns
Type |
Description |
TServiceClient |
|
Type Parameters
Name |
Description |
TServiceClient |
|
MakeNew<TServiceClient>(String, String, String)
Makes a client for the call to the specified contract on the specified host
Declaration
public TServiceClient MakeNew<TServiceClient>(string toHost, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.String |
toHost |
|
System.String |
fromHost |
|
System.String |
svcName |
|
Returns
Type |
Description |
TServiceClient |
|
Type Parameters
Name |
Description |
TServiceClient |
|
MapContractToImplementation(Type)
Declaration
protected ServiceClientHub.ContractMapping MapContractToImplementation(Type tContract)
Parameters
Type |
Name |
Description |
System.Type |
tContract |
|
Returns
ResolveNetworkService(ServiceClientHub.ContractMapping, String, String, String, out Boolean)
Declaration
protected Node ResolveNetworkService(ServiceClientHub.ContractMapping mapping, string toHost, string fromHost, string svcName, out bool isGlobal)
Parameters
Returns
RunTestSetupOf<TServiceClient>(String, String, String)
Tries to resolve contract type to implementor and tests network service resolvability. Throws in case of error
Declaration
public void RunTestSetupOf<TServiceClient>(string toHost, string fromHost = null, string svcName = null)
where TServiceClient : class, ISkyServiceClient
Parameters
Type |
Name |
Description |
System.String |
toHost |
|
System.String |
fromHost |
|
System.String |
svcName |
|
Type Parameters
Name |
Description |
TServiceClient |
|
SetupClientInstance(ServiceClientHub.ContractMapping, Boolean, ISkyServiceClient, String, String)
Declaration
protected void SetupClientInstance(ServiceClientHub.ContractMapping mapping, bool isGlobal, ISkyServiceClient instance, string toHost, string fromHost)
Parameters
Implements
System.IDisposable
Extension Methods