本文整理汇总了C#中Orleans.Runtime.Message.IsExpirableMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Message.IsExpirableMessage方法的具体用法?C# Message.IsExpirableMessage怎么用?C# Message.IsExpirableMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orleans.Runtime.Message
的用法示例。
在下文中一共展示了Message.IsExpirableMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRequestMessage
private void SendRequestMessage(GrainReference target, Message message, TaskCompletionSource<object> context, Action<Message, TaskCompletionSource<object>> callback, string debugContext = null, InvokeMethodOptions options = InvokeMethodOptions.None, string genericArguments = null)
{
var targetGrainId = target.GrainId;
var oneWay = (options & InvokeMethodOptions.OneWay) != 0;
message.SendingGrain = CurrentActivationAddress.Grain;
message.SendingActivation = CurrentActivationAddress.Activation;
message.TargetGrain = targetGrainId;
if (!String.IsNullOrEmpty(genericArguments))
message.GenericGrainType = genericArguments;
if (targetGrainId.IsSystemTarget)
{
// If the silo isn't be supplied, it will be filled in by the sender to be the gateway silo
message.TargetSilo = target.SystemTargetSilo;
if (target.SystemTargetSilo != null)
{
message.TargetActivation = ActivationId.GetSystemActivation(targetGrainId, target.SystemTargetSilo);
}
}
// Client sending messages to another client (observer). Yes, we support that.
if (target.IsObserverReference)
{
message.TargetObserverId = target.ObserverId;
}
if (debugContext != null)
{
message.DebugContext = debugContext;
}
if (message.IsExpirableMessage(config))
{
// don't set expiration for system target messages.
message.Expiration = DateTime.UtcNow + responseTimeout + Constants.MAXIMUM_CLOCK_SKEW;
}
if (!oneWay)
{
var callbackData = new CallbackData(callback, TryResendMessage, context, message, () => UnRegisterCallback(message.Id), config);
callbacks.TryAdd(message.Id, callbackData);
callbackData.StartTimer(responseTimeout);
}
if (logger.IsVerbose2) logger.Verbose2("Send {0}", message);
transport.SendMessage(message);
}
示例2: SendRequestMessage
private void SendRequestMessage(
GrainReference target,
Message message,
TaskCompletionSource<object> context,
Action<Message, TaskCompletionSource<object>> callback,
string debugContext,
InvokeMethodOptions options,
string genericArguments = null)
{
// fill in sender
if (message.SendingSilo == null)
message.SendingSilo = MySilo;
if (!String.IsNullOrEmpty(genericArguments))
message.GenericGrainType = genericArguments;
SchedulingContext schedulingContext = RuntimeContext.Current != null ?
RuntimeContext.Current.ActivationContext as SchedulingContext : null;
ActivationData sendingActivation = null;
if (schedulingContext == null)
{
throw new InvalidExpressionException(
String.Format("Trying to send a message {0} on a silo not from within grain and not from within system target (RuntimeContext is not set to SchedulingContext) "
+ "RuntimeContext.Current={1} TaskScheduler.Current={2}",
message,
RuntimeContext.Current == null ? "null" : RuntimeContext.Current.ToString(),
TaskScheduler.Current));
}
switch (schedulingContext.ContextType)
{
case SchedulingContextType.SystemThread:
throw new ArgumentException(
String.Format("Trying to send a message {0} on a silo not from within grain and not from within system target (RuntimeContext is of SchedulingContextType.SystemThread type)", message), "context");
case SchedulingContextType.Activation:
message.SendingActivation = schedulingContext.Activation.ActivationId;
message.SendingGrain = schedulingContext.Activation.Grain;
sendingActivation = schedulingContext.Activation;
break;
case SchedulingContextType.SystemTarget:
message.SendingActivation = schedulingContext.SystemTarget.ActivationId;
message.SendingGrain = schedulingContext.SystemTarget.GrainId;
break;
}
// fill in destination
var targetGrainId = target.GrainId;
message.TargetGrain = targetGrainId;
if (targetGrainId.IsSystemTarget)
{
SiloAddress targetSilo = (target.SystemTargetSilo ?? MySilo);
message.TargetSilo = targetSilo;
message.TargetActivation = ActivationId.GetSystemActivation(targetGrainId, targetSilo);
message.Category = targetGrainId.Equals(Constants.MembershipOracleId) ?
Message.Categories.Ping : Message.Categories.System;
}
if (target.IsObserverReference)
{
message.TargetObserverId = target.ObserverId;
}
if (debugContext != null)
message.DebugContext = debugContext;
var oneWay = (options & InvokeMethodOptions.OneWay) != 0;
if (context == null && !oneWay)
logger.Warn(ErrorCode.IGC_SendRequest_NullContext, "Null context {0}: {1}", message, new StackTrace());
if (message.IsExpirableMessage(Config.Globals))
message.Expiration = DateTime.UtcNow + ResponseTimeout + Constants.MAXIMUM_CLOCK_SKEW;
if (!oneWay)
{
var callbackData = new CallbackData(
callback,
TryResendMessage,
context,
message,
() => UnRegisterCallback(message.Id),
Config.Globals);
callbacks.TryAdd(message.Id, callbackData);
callbackData.StartTimer(ResponseTimeout);
}
if (targetGrainId.IsSystemTarget)
{
// Messages to system targets bypass the task system and get sent "in-line"
dispatcher.TransportMessage(message);
}
else
{
dispatcher.SendMessage(message, sendingActivation);
}
}