本文整理汇总了C#中Message.CreateRejectionResponse方法的典型用法代码示例。如果您正苦于以下问题:C# Message.CreateRejectionResponse方法的具体用法?C# Message.CreateRejectionResponse怎么用?C# Message.CreateRejectionResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.CreateRejectionResponse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
/// <summary>
/// Handles an incoming (proxied) message by rerouting it immediately and unconditionally,
/// after some header massaging.
/// </summary>
/// <param name="msg"></param>
/// <param name="receivedOnSocket"></param>
protected override void HandleMessage(Message msg, Socket receivedOnSocket)
{
// Don't process messages that have already timed out
if (msg.IsExpired)
{
msg.DropExpiredMessage(MessagingStatisticsGroup.Phase.Receive);
return;
}
if (Message.WriteMessagingTraces)
msg.AddTimestamp(Message.LifecycleTag.ReceiveIncoming);
gatewayTrafficCounter.Increment();
// Are we overloaded?
if ((MessageCenter.Metrics != null) && MessageCenter.Metrics.IsOverloaded)
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
Message rejection = msg.CreateRejectionResponse(Message.RejectionTypes.GatewayTooBusy, "Shedding load");
MessageCenter.TryDeliverToProxy(rejection);
if (Log.IsVerbose) Log.Verbose("Rejecting a request due to overloading: {0}", msg.ToString());
loadSheddingCounter.Increment();
return;
}
SiloAddress targetAddress = gateway.TryToReroute(msg);
msg.SendingSilo = MessageCenter.MyAddress;
if (targetAddress == null)
{
// reroute via Dispatcher
msg.RemoveHeader(Message.Header.TARGET_SILO);
msg.RemoveHeader(Message.Header.TARGET_ACTIVATION);
if (msg.TargetGrain.IsSystemTarget)
{
msg.TargetSilo = MessageCenter.MyAddress;
msg.TargetActivation = ActivationId.GetSystemActivation(msg.TargetGrain, MessageCenter.MyAddress);
}
if (Message.WriteMessagingTraces) msg.AddTimestamp(Message.LifecycleTag.RerouteIncoming);
MessagingStatisticsGroup.OnMessageReRoute(msg);
MessageCenter.RerouteMessage(msg);
}
else
{
// send directly
msg.TargetSilo = targetAddress;
MessageCenter.SendMessage(msg);
}
}
示例2: HandleMessage
/// <summary>
/// Handles an incoming (proxied) message by rerouting it immediately and unconditionally,
/// after some header massaging.
/// </summary>
/// <param name="msg"></param>
/// <param name="receivedOnSocket"></param>
protected override void HandleMessage(Message msg, Socket receivedOnSocket)
{
// Don't process messages that have already timed out
if (msg.IsExpired)
{
msg.DropExpiredMessage(MessagingStatisticsGroup.Phase.Receive);
return;
}
gatewayTrafficCounter.Increment();
// return address translation for geo clients (replace sending address cli/* with gcl/*)
if (! string.IsNullOrEmpty(Silo.CurrentSilo.ClusterId) && msg.SendingAddress.Grain.Category != UniqueKey.Category.GeoClient)
{
msg.SendingGrain = GrainId.NewClientId(msg.SendingAddress.Grain.PrimaryKey, Silo.CurrentSilo.ClusterId);
}
// Are we overloaded?
if ((MessageCenter.Metrics != null) && MessageCenter.Metrics.IsOverloaded)
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
Message rejection = msg.CreateRejectionResponse(Message.RejectionTypes.GatewayTooBusy, "Shedding load");
MessageCenter.TryDeliverToProxy(rejection);
if (Log.IsVerbose) Log.Verbose("Rejecting a request due to overloading: {0}", msg.ToString());
loadSheddingCounter.Increment();
return;
}
SiloAddress targetAddress = gateway.TryToReroute(msg);
msg.SendingSilo = MessageCenter.MyAddress;
if (targetAddress == null)
{
// reroute via Dispatcher
msg.TargetSilo = null;
msg.TargetActivation = null;
msg.ClearTargetAddress();
if (msg.TargetGrain.IsSystemTarget)
{
msg.TargetSilo = MessageCenter.MyAddress;
msg.TargetActivation = ActivationId.GetSystemActivation(msg.TargetGrain, MessageCenter.MyAddress);
}
MessagingStatisticsGroup.OnMessageReRoute(msg);
MessageCenter.RerouteMessage(msg);
}
else
{
// send directly
msg.TargetSilo = targetAddress;
MessageCenter.SendMessage(msg);
}
}
示例3: ReceiveMessage
private void ReceiveMessage(Message msg)
{
MessagingProcessingStatisticsGroup.OnImaMessageReceived(msg);
ISchedulingContext context;
// Find the activation it targets; first check for a system activation, then an app activation
if (msg.TargetGrain.IsSystemTarget)
{
SystemTarget target = directory.FindSystemTarget(msg.TargetActivation);
if (target == null)
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
Message response = msg.CreateRejectionResponse(Message.RejectionTypes.Unrecoverable,
String.Format("SystemTarget {0} not active on this silo. Msg={1}", msg.TargetGrain, msg));
messageCenter.SendMessage(response);
Log.Warn(ErrorCode.MessagingMessageFromUnknownActivation, "Received a message {0} for an unknown SystemTarget: {1}", msg, msg.TargetAddress);
return;
}
context = target.SchedulingContext;
switch (msg.Direction)
{
case Message.Directions.Request:
MessagingProcessingStatisticsGroup.OnImaMessageEnqueued(context);
scheduler.QueueWorkItem(new RequestWorkItem(target, msg), context);
break;
case Message.Directions.Response:
MessagingProcessingStatisticsGroup.OnImaMessageEnqueued(context);
scheduler.QueueWorkItem(new ResponseWorkItem(target, msg), context);
break;
default:
Log.Error(ErrorCode.Runtime_Error_100097, "Invalid message: " + msg);
break;
}
}
else
{
// Run this code on the target activation's context, if it already exists
ActivationData targetActivation = directory.FindTarget(msg.TargetActivation);
if (targetActivation != null)
{
lock (targetActivation)
{
var target = targetActivation; // to avoid a warning about nulling targetActivation under a lock on it
if (target.State.Equals(ActivationState.Valid))
{
var overloadException = target.CheckOverloaded(Log);
if (overloadException != null)
{
// Send rejection as soon as we can, to avoid creating additional work for runtime
dispatcher.RejectMessage(msg, Message.RejectionTypes.Overloaded, overloadException, "Target activation is overloaded " + target);
return;
}
// Run ReceiveMessage in context of target activation
context = new SchedulingContext(target);
}
else
{
// Can't use this activation - will queue for another activation
target = null;
context = null;
}
EnqueueReceiveMessage(msg, target, context);
}
}
else
{
// No usable target activation currently, so run ReceiveMessage in system context
EnqueueReceiveMessage(msg, null, null);
}
}
}
示例4: HandleMessage
protected virtual void HandleMessage(Message msg, Socket receivedOnSocket)
{
// See it's a Ping message, and if so, short-circuit it
object pingObj;
var requestContext = msg.RequestContextData;
if (requestContext != null &&
requestContext.TryGetValue(RequestContext.PING_APPLICATION_HEADER, out pingObj) &&
pingObj is bool &&
(bool)pingObj)
{
MessagingStatisticsGroup.OnPingReceive(msg.SendingSilo);
if (Log.IsVerbose2) Log.Verbose2("Responding to Ping from {0}", msg.SendingSilo);
if (!msg.TargetSilo.Equals(MessageCenter.MyAddress)) // got ping that is not destined to me. For example, got a ping to my older incarnation.
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
Message rejection = msg.CreateRejectionResponse(Message.RejectionTypes.Unrecoverable,
string.Format("The target silo is no longer active: target was {0}, but this silo is {1}. The rejected ping message is {2}.",
msg.TargetSilo.ToLongString(), MessageCenter.MyAddress.ToLongString(), msg));
MessageCenter.OutboundQueue.SendMessage(rejection);
}
else
{
var response = msg.CreateResponseMessage();
response.BodyObject = Response.Done;
MessageCenter.SendMessage(response);
}
return;
}
// sniff message headers for directory cache management
if (sniffIncomingMessageHandler != null)
sniffIncomingMessageHandler(msg);
// Don't process messages that have already timed out
if (msg.IsExpired)
{
msg.DropExpiredMessage(MessagingStatisticsGroup.Phase.Receive);
return;
}
// If we've stopped application message processing, then filter those out now
// Note that if we identify or add other grains that are required for proper stopping, we will need to treat them as we do the membership table grain here.
if (MessageCenter.IsBlockingApplicationMessages && (msg.Category == Message.Categories.Application) && !Constants.SystemMembershipTableId.Equals(msg.SendingGrain))
{
// We reject new requests, and drop all other messages
if (msg.Direction != Message.Directions.Request) return;
MessagingStatisticsGroup.OnRejectedMessage(msg);
var reject = msg.CreateRejectionResponse(Message.RejectionTypes.Unrecoverable, "Silo stopping");
MessageCenter.SendMessage(reject);
return;
}
// Make sure the message is for us. Note that some control messages may have no target
// information, so a null target silo is OK.
if ((msg.TargetSilo == null) || msg.TargetSilo.Matches(MessageCenter.MyAddress))
{
// See if it's a message for a client we're proxying.
if (MessageCenter.IsProxying && MessageCenter.TryDeliverToProxy(msg)) return;
// Nope, it's for us
MessageCenter.InboundQueue.PostMessage(msg);
return;
}
if (!msg.TargetSilo.Endpoint.Equals(MessageCenter.MyAddress.Endpoint))
{
// If the message is for some other silo altogether, then we need to forward it.
if (Log.IsVerbose2) Log.Verbose2("Forwarding message {0} from {1} to silo {2}", msg.Id, msg.SendingSilo, msg.TargetSilo);
MessageCenter.OutboundQueue.SendMessage(msg);
return;
}
// If the message was for this endpoint but an older epoch, then reject the message
// (if it was a request), or drop it on the floor if it was a response or one-way.
if (msg.Direction == Message.Directions.Request)
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
Message rejection = msg.CreateRejectionResponse(Message.RejectionTypes.Transient,
string.Format("The target silo is no longer active: target was {0}, but this silo is {1}. The rejected message is {2}.",
msg.TargetSilo.ToLongString(), MessageCenter.MyAddress.ToLongString(), msg));
MessageCenter.OutboundQueue.SendMessage(rejection);
if (Log.IsVerbose) Log.Verbose("Rejecting an obsolete request; target was {0}, but this silo is {1}. The rejected message is {2}.",
msg.TargetSilo.ToLongString(), MessageCenter.MyAddress.ToLongString(), msg);
}
}
示例5: SendRejection
internal void SendRejection(Message msg, Message.RejectionTypes rejectionType, string reason)
{
MessagingStatisticsGroup.OnRejectedMessage(msg);
if (string.IsNullOrEmpty(reason)) reason = String.Format("Rejection from silo {0} - Unknown reason.", MyAddress);
Message error = msg.CreateRejectionResponse(rejectionType, reason);
// rejection msgs are always originated in the local silo, they are never remote.
InboundQueue.PostMessage(error);
}