本文整理汇总了C#中IAddressable.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IAddressable.GetType方法的具体用法?C# IAddressable.GetType怎么用?C# IAddressable.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAddressable
的用法示例。
在下文中一共展示了IAddressable.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
internal async Task Invoke(IAddressable target, IInvokable invokable, Message message)
{
try
{
// Don't process messages that have already timed out
if (message.IsExpired)
{
message.DropExpiredMessage(MessagingStatisticsGroup.Phase.Invoke);
return;
}
//MessagingProcessingStatisticsGroup.OnRequestProcessed(message, "Invoked");
if (Message.WriteMessagingTraces)
message.AddTimestamp(Message.LifecycleTag.InvokeIncoming);
RequestContext.ImportFromMessage(message);
if (Config.Globals.PerformDeadlockDetection && !message.TargetGrain.IsSystemTarget)
{
UpdateDeadlockInfoInRequestContext(new RequestInvocationHistory(message));
// RequestContext is automatically saved in the msg upon send and propagated to the next hop
// in RuntimeClient.CreateMessage -> RequestContext.ExportToMessage(message);
}
var invoker = invokable.GetInvoker(message.InterfaceId, message.GenericGrainType);
object resultObject;
try
{
var request = (InvokeMethodRequest) message.BodyObject;
if (invoker is IGrainExtensionMethodInvoker
&& !(target is IGrainExtension))
{
// We are trying the invoke a grain extension method on a grain
// -- most likely reason is that the dynamic extension is not installed for this grain
// So throw a specific exception here rather than a general InvalidCastException
var error = String.Format(
"Extension not installed on grain {0} attempting to invoke type {1} from invokable {2}",
target.GetType().FullName, invoker.GetType().FullName, invokable.GetType().FullName);
var exc = new GrainExtensionNotInstalledException(error);
string extraDebugInfo = null;
#if DEBUG
extraDebugInfo = new StackTrace().ToString();
#endif
logger.Warn(ErrorCode.Stream_ExtensionNotInstalled,
string.Format("{0} for message {1} {2}", error, message, extraDebugInfo), exc);
throw exc;
}
resultObject = await invoker.Invoke(target, request.InterfaceId, request.MethodId, request.Arguments);
}
catch (Exception exc1)
{
if (invokeExceptionLogger.IsVerbose || message.Direction == Message.Directions.OneWay)
{
invokeExceptionLogger.Warn(ErrorCode.GrainInvokeException,
"Exception during Grain method call of message: " + message, exc1);
}
if (message.Direction != Message.Directions.OneWay)
{
SafeSendExceptionResponse(message, exc1);
}
return;
}
if (message.Direction == Message.Directions.OneWay) return;
SafeSendResponse(message, resultObject);
}
catch (Exception exc2)
{
logger.Warn(ErrorCode.Runtime_Error_100329, "Exception during Invoke of message: " + message, exc2);
if (message.Direction != Message.Directions.OneWay)
SafeSendExceptionResponse(message, exc2);
}
}
示例2: Invoke
internal async Task Invoke(IAddressable target, IInvokable invokable, Message message)
{
try
{
// Don't process messages that have already timed out
if (message.IsExpired)
{
message.DropExpiredMessage(MessagingStatisticsGroup.Phase.Invoke);
return;
}
RequestContext.Import(message.RequestContextData);
if (Config.Globals.PerformDeadlockDetection && !message.TargetGrain.IsSystemTarget)
{
UpdateDeadlockInfoInRequestContext(new RequestInvocationHistory(message));
// RequestContext is automatically saved in the msg upon send and propagated to the next hop
// in RuntimeClient.CreateMessage -> RequestContext.ExportToMessage(message);
}
object resultObject;
try
{
var request = (InvokeMethodRequest) message.BodyObject;
var invoker = invokable.GetInvoker(request.InterfaceId, message.GenericGrainType);
if (invoker is IGrainExtensionMethodInvoker
&& !(target is IGrainExtension))
{
// We are trying the invoke a grain extension method on a grain
// -- most likely reason is that the dynamic extension is not installed for this grain
// So throw a specific exception here rather than a general InvalidCastException
var error = String.Format(
"Extension not installed on grain {0} attempting to invoke type {1} from invokable {2}",
target.GetType().FullName, invoker.GetType().FullName, invokable.GetType().FullName);
var exc = new GrainExtensionNotInstalledException(error);
string extraDebugInfo = null;
#if DEBUG
extraDebugInfo = new StackTrace().ToString();
#endif
logger.Warn(ErrorCode.Stream_ExtensionNotInstalled,
string.Format("{0} for message {1} {2}", error, message, extraDebugInfo), exc);
throw exc;
}
// If the target has a grain-level interceptor or there is a silo-level interceptor, intercept the call.
var shouldCallSiloWideInterceptor = SiloProviderRuntime.Instance.GetInvokeInterceptor() != null && target is IGrain;
var intercepted = target as IGrainInvokeInterceptor;
if (intercepted != null || shouldCallSiloWideInterceptor)
{
// Fetch the method info for the intercepted call.
var implementationInvoker =
invocationMethodInfoMap.GetInterceptedMethodInvoker(target.GetType(), request.InterfaceId,
invoker);
var methodInfo = implementationInvoker.GetMethodInfo(request.MethodId);
if (shouldCallSiloWideInterceptor)
{
// There is a silo-level interceptor and possibly a grain-level interceptor.
var runtime = SiloProviderRuntime.Instance;
resultObject =
await runtime.CallInvokeInterceptor(methodInfo, request, target, implementationInvoker);
}
else
{
// The grain has an interceptor, but there is no silo-wide interceptor.
resultObject = await intercepted.Invoke(methodInfo, request, invoker);
}
}
else
{
// The call is not intercepted.
resultObject = await invoker.Invoke(target, request);
}
}
catch (Exception exc1)
{
if (invokeExceptionLogger.IsVerbose || message.Direction == Message.Directions.OneWay)
{
invokeExceptionLogger.Warn(ErrorCode.GrainInvokeException,
"Exception during Grain method call of message: " + message, exc1);
}
if (message.Direction != Message.Directions.OneWay)
{
SafeSendExceptionResponse(message, exc1);
}
return;
}
if (message.Direction == Message.Directions.OneWay) return;
SafeSendResponse(message, resultObject);
}
catch (Exception exc2)
{
logger.Warn(ErrorCode.Runtime_Error_100329, "Exception during Invoke of message: " + message, exc2);
if (message.Direction != Message.Directions.OneWay)
SafeSendExceptionResponse(message, exc2);
}
}
示例3: InvokeWithInterceptors
private Task<object> InvokeWithInterceptors(IAddressable target, InvokeMethodRequest request, IGrainMethodInvoker invoker)
{
// If the target has a grain-level interceptor or there is a silo-level interceptor, intercept the
// call.
var siloWideInterceptor = SiloProviderRuntime.Instance.GetInvokeInterceptor();
var grainWithInterceptor = target as IGrainInvokeInterceptor;
// Silo-wide interceptors do not operate on system targets.
var hasSiloWideInterceptor = siloWideInterceptor != null && target is IGrain;
var hasGrainLevelInterceptor = grainWithInterceptor != null;
if (!hasGrainLevelInterceptor && !hasSiloWideInterceptor)
{
// The call is not intercepted at either the silo or the grain level, so call the invoker
// directly.
return invoker.Invoke(target, request);
}
// Get an invoker which delegates to the grain's IGrainInvocationInterceptor implementation.
// If the grain does not implement IGrainInvocationInterceptor, then the invoker simply delegates
// calls to the provided invoker.
var interceptedMethodInvoker = interceptedMethodInvokerCache.GetOrCreate(
target.GetType(),
request.InterfaceId,
invoker);
var methodInfo = interceptedMethodInvoker.GetMethodInfo(request.MethodId);
if (hasSiloWideInterceptor)
{
// There is a silo-level interceptor and possibly a grain-level interceptor.
// As a minor optimization, only pass the intercepted invoker if there is a grain-level
// interceptor.
return siloWideInterceptor(
methodInfo,
request,
(IGrain)target,
hasGrainLevelInterceptor ? interceptedMethodInvoker : invoker);
}
// The grain has an invoke method, but there is no silo-wide interceptor.
return grainWithInterceptor.Invoke(methodInfo, request, invoker);
}