首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >呼叫侦听-如何确定呼叫是否是系统呼叫

呼叫侦听-如何确定呼叫是否是系统呼叫
EN

Stack Overflow用户
提问于 2018-08-13 19:23:03
回答 1查看 91关注 0票数 0

我正在尝试创建一个只处理非系统调用的拦截方法。根据医生们,系统和非系统呼叫都被截获:

对于对一个谷物的所有方法调用,都会调用传出的谷物调用过滤器,这包括对OR良所做的系统方法的调用。

然而,我无法用任何公共方法或财产来区分。我是不是遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-13 21:46:54

我可以想出两种解释一个系统调用可能是什么:

  1. ISystemTarget的任何调用
  2. 对一个在新奥尔良程序集中定义的接口的调用。

在这两种情况下,确定调用是否符合该条件的最简单方法是使用传递给调用筛选器的上下文的InterfaceMethod属性来检查该MethodInfoDeclaringType

例如:

代码语言:javascript
复制
siloBuilder.AddOutgoingGrainCallFilter(async context =>
{
    var declaringType = context.InterfaceMethod?.DeclaringType;

    // Check if the type being called belongs to one of the Orleans assemblies
    // systemAssemblies here is a HashSet<Assembly> containing the Orleans assemblies
    var isSystemAssembly = declaringType != null
      && systemAssemblies.Contains(declaringType.Assembly);

    // Check if the type is an ISystemTarget
    var systemTarget = declaringType != null
      && typeof(ISystemTarget).IsAssignableFrom(declaringType);

    if (isSystemAssembly || systemTarget)
    {
        // This is a system call, so just continue invocation without any further action
        await context.Invoke();
    }
    else
    {
        // This is an application call

        // ... Inspect/modify the arguments here ...

        await context.Invoke();

        // ... inspect/modify return value here ...
    }
})
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51829240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档