API Key作为一个参数在URL中传递, 在Rob Jacobs的WCFWebHttpLibrary.APIKeyAuthorization的方法string GetAPIKey(OperationContext operationContext)的代码如下: 1: public string GetAPIKey(OperationContext operationContext) 2: { 3: // Get the request message 4: var request = operationContext.RequestContext.RequestMessage; OnStartProcessingRequest(ProcessRequestArgs args) 2: { 3: var queryParams = HttpUtility.ParseQueryString(args.OperationContext.AbsoluteRequestUri.Query string apiKey = queryParams[APIKEY]; 5: if (apiKey == null) 6: { 7: apiKey = args.OperationContext.RequestHeaders
我们可以借助System.ServiceModel.OperationContext实现这样的功能。 注: OperationContext代表服务操作执行的上下文。通过OperationContext可以得到出栈和入栈消息的SOAP报头列表、消息属性或者HTTP报头。 对于Duplex服务,在服务端可以通过OperationContext得到回调对象。此外通过OperationContext还可以得到基于当前执行的安全方面的属性一起的其他相关信息。 1: public sealed class OperationContext : IExtensibleObject<OperationContext> 2: { 3: // 对于客户端来说,当前的OperationContext生命周期和OperationContextScope一样,一旦成功创建OperationContextScope,就会创建当前的OperationContext
MongoDB原生服务端超时原理 当一个用户请求到达 mongos 或者 mongod 时,会生成一个对应的 OperationContext 对象,来记录这个请求从开始到结束期间的完整上下文信息。 标记为了终止状态; 3.用户通过 maxTimeMS 参数给 OperationContext 配置了超时 Deadline,然后检测到 hasDeadlineExpired() 为 true; 一个请求在执行过程中会多次调用 备注2:终止OperationContext 和 kill 进程/线程行为不同。OperationContext 自己检测和主动退出的机制使得 killOp 和 maxTimeMS 不会绝对精确。 下图展示一个写请求在mongos 上的执行路径,比较关键的点有: 在 runCommand 函数中,会从命令中解析 maxTimeMS(客户指定的),并设置 OperationContext 的 deadline 只能跟踪 1 个请求在 1 个进程中的执行信息,也就是说 mongos 和 mongod 各自有自己独立的 OperationContext。
class ServiceAuthorizationManager 2: { 3: //其他成员 4: public virtual bool CheckAccess(OperationContext operationContext); 5: public virtual bool CheckAccess(OperationContext operationContext, ref Message message); 6: protected virtual bool CheckAccessCore(OperationContext operationContext) operationContext) 4: { 5: //其他操作 6: AuthorizationContext authorizationContext = operationContext.ServiceSecurityContext.AuthorizationContext; 7: authorizationContext.Properties
Status MigrationSourceManager::awaitToCatchUp(OperationContext* opCtx) { // Block until the cloner Status MigrationSourceManager::enterCriticalSection(OperationContext* opCtx) { //表明当前分片上的该集合进入X锁阶段 Status MigrationSourceManager::commitChunkOnRecipient(OperationContext* opCtx) { //发送"_recvChunkCommit void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx) { { //to shard开始之后的第一步 auto assertNotAborted = [&](OperationContext* opCtx) { opCtx->checkForInterrupt();
而锁的定义在 OperationContext 中是这样定义的: // operation_context.h class OperationContext : public Interruptible , public Decorable<OperationContext> { OperationContext(const OperationContext&) = delete; OperationContext & operator=(const OperationContext&) = delete; public: ...... // Interface for locking. 同时通过 OperationContext->lockState()->lock() 接口获取对应的 Database 资源锁。 这里继续看 _lockComplete() 的实现: // lock_state.cpp void LockerImpl::_lockComplete(OperationContext* opCtx,
而锁的定义在 OperationContext 中是这样定义的: // operation_context.h class OperationContext : public Interruptible , public Decorable<OperationContext> { OperationContext(const OperationContext&) = delete; OperationContext & operator=(const OperationContext&) = delete; public: ...... // Interface for locking. 同时通过 OperationContext->lockState()->lock() 接口获取对应的 Database 资源锁。 这里继续看 _lockComplete() 的实现: // lock_state.cpp void LockerImpl::_lockComplete(OperationContext* opCtx,
单行事务的实现 OperationContext与RecoveryUnit 客户端的每个请求(insert/update/delete/find/getmore),会生成一个唯一的OperationContext 记录执行的上下文,OperationContext从请求解析时创建,到请求执行完成时释放。 OperationContext创建时,会初始化RecoveryUnit。 ? RecoveryUnit封装了wiredTiger层的事务。 它是对OperationContext和RecoveryUnit的封装。 ? ? Mongodb通过实现事务框架(RecoveryUnit,OperationContext, WriteUnitOfWork)将细节封装。
而锁的定义在 OperationContext 中是这样定义的: // operation_context.h class OperationContext : public Interruptible , public Decorable<OperationContext> { OperationContext(const OperationContext&) = delete; OperationContext & operator=(const OperationContext&) = delete; public: ...... // Interface for locking. 同时通过 OperationContext->lockState()->lock() 接口获取对应的 Database 资源锁。 这里继续看 _lockComplete() 的实现: // lock_state.cpp void LockerImpl::_lockComplete(OperationContext* opCtx,
{ Name = "sdf", Age = 12 }; } public string ClientIpAndPort() { OperationContext context = OperationContext.Current; MessageProperties properties = context.IncomingMessageProperties
MongoDB原生服务端超时原理 当一个用户请求到达 mongos 或者 mongod 时,会生成一个对应的 OperationContext 对象,来记录这个请求从开始到结束期间的完整上下文信息。 标记为了终止状态; 3.用户通过 maxTimeMS 参数给 OperationContext 配置了超时 Deadline,然后检测到 hasDeadlineExpired() 为 true; 一个请求在执行过程中会多次调用 备注2:终止OperationContext 和 kill 进程/线程行为不同。OperationContext 自己检测和主动退出的机制使得 killOp 和 maxTimeMS 不会绝对精确。 下图展示一个写请求在mongos 上的执行路径,比较关键的点有: 在 runCommand 函数中,会从命令中解析 maxTimeMS(客户指定的),并设置 OperationContext 的 deadline 只能跟踪 1 个请求在 1 个进程中的执行信息,也就是说 mongos 和 mongod 各自有自己独立的 OperationContext。
MongoDB原生服务端超时原理 当一个用户请求到达 mongos 或者 mongod 时,会生成一个对应的 OperationContext 对象,来记录这个请求从开始到结束期间的完整上下文信息。 标记为了终止状态; 3.用户通过 maxTimeMS 参数给 OperationContext 配置了超时 Deadline,然后检测到 hasDeadlineExpired() 为 true; 一个请求在执行过程中会多次调用 备注2:终止OperationContext 和 kill 进程/线程行为不同。OperationContext 自己检测和主动退出的机制使得 killOp 和 maxTimeMS 不会绝对精确。 下图展示一个写请求在mongos 上的执行路径,比较关键的点有: 在 runCommand 函数中,会从命令中解析 maxTimeMS(客户指定的),并设置 OperationContext 的 deadline 只能跟踪 1 个请求在 1 个进程中的执行信息,也就是说 mongos 和 mongod 各自有自己独立的 OperationContext。
name = "Operation") private int operation; /** * 操作 Context */ @Column(name = "OperationContext ", nullable = false) private String operationContext; } appId + clusterName + namespaceName = Maps.newHashMap(); 39: operationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish previousReleaseId); // 上一个 Release 编号 20: releaseHistory.setOperation(operation); 21: if (operationContext /default empty object 23: } else { 24: releaseHistory.setOperationContext(gson.toJson(operationContext
processInstanceId(task.getProcessInstanceId()) .moveActivityIdTo(task.getTaskDefinitionKey(), operationContext.getTargetNodeId ()) .processVariables(operationContext.getFormData()).changeState(); 确实这样简单及方便多了!
在WCF中,回调对象通过当前OperationContext的GetCallback<T>方法获得(T代表回调契约的类型)。 ? OperationContext在WCF中是一个非常重要、也是一个十分有用的对象,它代表服务操作执行的上下文。 我们可以通过静态属性Current(OperationContext.Current)得到当前的OperationContext。 借助OperationContext,我们可以在服务端或者客户端获取或设置一些上下文,比如在客户端可以通过它为出栈消息(outgoing message)添加SOAP报头,以及HTTP报头(比如Cookie
Soap Header的插入和获取: 我们可以通过下面的方式获得当前Operation Context的Incoming Message Headers和Outgoing Message Headers OperationContext.Current.IncomingMessageHeaders OperationContext.Current.OutgoingMessageHeaders 如果我们要把一个OrderResponseContext 对象插入到当前Operation Context (); MessageHeader<OrderResponseContext> header = new MessageHeader<OrderResponseContext>( context); OperationContext.Current.OutgoingMessageHeaders.Add 相应的,我们可以通过下面的代码从Outgoing Message Headers OrderResponseContext的数据获取的内容: OrderResponseContext context = OperationContext.Current.IncomingMessageHeaders.GetHeader public static OrderResponseContext Current { get { if (OperationContext.Current
方法很简单,在OperationContext中存在InstanceContext,而这个属性包含一个ReleaseServiceInstance方法,在这个方法调用之后服务将会被释放: [OperationBehavior (ReleaseInstanceMode=ReleaseInstanceMode.AfterCall)] public void Close() { lockBox(); OperationContext.Current.InstanceContext.ReleaseServiceInstance
operateNamespaceItems = getNamespaceItems(namespace); 18: 19: // 创建 Map ,用于 ReleaseHistory 对象的 `operationContext 20: Map<String, Object> operationContext = Maps.newHashMap(); 21: operationContext.put(ReleaseOperationContext.SOURCE_BRANCH , branchName); 22: operationContext.put(ReleaseOperationContext.BASE_RELEASE_ID, branchReleaseId ); 23: operationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish); 第 11 至 23 行:创建 Map ,并设置需要的 KV ,用于 ReleaseHistory 对象的 operationContext 属性。
//Callback 12: EventMonitor.Send(EventType.StartCallback); 13: int clientId = OperationContext.Current.IncomingMessageHeaders.GetHeader ); 14: MessageHeader<int> messageHeader = new MessageHeader<int>(clientId); 15: OperationContext.Current.OutgoingMessageHeaders.Add messageHeader.GetUntypedHeader(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace)); 16: OperationContext.Current.GetCallbackChannel MessageHeader<int> messageHeader = new MessageHeader<int>(clientId); 34: OperationContext.Current.OutgoingMessageHeaders.Add
SimpleServiceAuthorizationManager : ServiceAuthorizationManager 7: { 8: protected override bool CheckAccessCore(OperationContext operationContext) 9: { 10: string action = operationContext.RequestContext.RequestMessage.Headers.Action ; 11: foreach (ClaimSet claimSet in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets GenericIdentity identity = new GenericIdentity(""); 20: operationContext.ServiceSecurityContext.AuthorizationContext.Properties