internal SerializationService(IInputOutputFactory inputOutputFactory, int version, IDictionary <int, IDataSerializableFactory> dataSerializableFactories, IDictionary <int, IPortableFactory> portableFactories, ICollection <IClassDefinition> classDefinitions, bool checkClassDefErrors, IManagedContext managedContext, IPartitioningStrategy partitionStrategy, int initialOutputBufferSize, bool enableCompression, bool enableSharedObject) { _inputOutputFactory = inputOutputFactory; _managedContext = managedContext; GlobalPartitioningStrategy = partitionStrategy; _outputBufferSize = initialOutputBufferSize; _bufferPoolThreadLocal = new BufferPoolThreadLocal(this); _portableContext = new PortableContext(this, version); _dataSerializerAdapter = CreateSerializerAdapterByGeneric <IIdentifiedDataSerializable>( new DataSerializer(dataSerializableFactories)); _portableSerializer = new PortableSerializer(_portableContext, portableFactories); _portableSerializerAdapter = CreateSerializerAdapterByGeneric <IPortable>(_portableSerializer); _nullSerializerAdapter = CreateSerializerAdapterByGeneric <object>(new ConstantSerializers.NullSerializer()); _serializableSerializerAdapter = CreateSerializerAdapterByGeneric <object>(new DefaultSerializers.SerializableSerializer()); RegisterConstantSerializers(); RegisterDefaultSerializers(); RegisterClassDefinitions(classDefinitions, checkClassDefErrors); }
/// <exception cref="System.IO.IOException"/> internal IPortable ReadAndInitialize(IBufferObjectDataInput @in, int factoryId, int classId) { IPortable p = Read(@in, factoryId, classId); IManagedContext managedContext = context.GetManagedContext(); return(managedContext != null ? (IPortable)managedContext.Initialize(p) : p); }
/// <summary> /// 注册String与对象关联,对象的Name属性必须要设定并且由用户保证唯一。 /// </summary> /// <param name="playerContext">要关联的对象,其属性Name作为键值。</param> /// <returns>注册是否成功。</returns> public bool RegisterPlayerContextByString(String stringKey, IManagedContext playerContext) { if (!m_playerCtxName2CtxDic.TryAdd(stringKey, playerContext)) { return(false); } return(true); /// 不考虑Id映射字典中是否存在,该对象在创建时已经自动加入了。 }
/// <summary> /// Palyer Timer工作 /// </summary> /// <param name="cancelToken">控制取消对象</param> /// <returns></returns> private async Task PlayerCtxTimerWorkerProc(CancellationToken cancelToken) { // 检查工作状态 if (1 != m_state) { return; } try { //Int64 currentTimeTick = 0; // 没有收到取消请求时 while (!cancelToken.IsCancellationRequested) { //// 获取开始时间毫秒 //currentTimeTick = DateTime.Now.Ticks; //// 用当前时间秒查询循环容器 //IEnumerable<KeyValuePair<Int64, PlayerTimerNode>> query = // m_playerCtxTimers.Where(timer => timer.Value.m_nextCallTime <= currentTimeTick); // 有满足条件的作timer call处理以及删除 foreach (KeyValuePair <Int64, PlayerTimerNode> timerPair in GetTriggerableTimerNodeList()) { // 先删除 PlayerTimerNode playerTimer = null; m_playerCtxTimers.TryRemove(timerPair.Key, out playerTimer); if (playerTimer == null) { continue; } // 查找目标playerctx IManagedContext playerCtx = m_playerCtxManager.FindPlayerContextBySid(playerTimer.m_playerSid); if (playerCtx == null) { continue; } // 发送msg PlayerTimerMessage message = new PlayerTimerMessage(playerTimer.m_int32Data, playerTimer.m_int64Data, playerTimer.m_objData); playerCtx.PostLocalMessage(message); } // 每500毫秒轮询一次 await Task.Delay(500); } Log.Debug("TimerManager::PlayerCtxTimerWorkerProc stop"); } catch (Exception ex) { Log.Debug("TimerManager::PlayerCtxTimerWorkerProc catch Execption: " + ex.ToString()); } }
/// <summary> /// 解除底层对指定Context的管理。 /// </summary> /// <param name="context">需要解除的管理对象。</param> public void FreePlayerContext(IManagedContext context) { IManagedContext ctx; /// 解除Id关联字典 PS 由于使用了线程安全的字典所以不用担心 m_playerSid2CtxDic.TryRemove(context.ContextId, out ctx); /// 解除String关联字典 if (context.ContextStringName != null) { IManagedContext nameCtx = null; m_playerCtxName2CtxDic.TryGetValue(context.ContextStringName, out nameCtx); if (nameCtx != null && ctx != null && nameCtx.ContextId == ctx.ContextId) { m_playerCtxName2CtxDic.TryRemove(context.ContextStringName, out nameCtx); } } }
/// <summary> /// 分配一个玩家上下文对象并管理到底层中。 /// </summary> /// <returns>玩家上下文对象的实例。</returns> public IManagedContext AllocPlayerContext(UInt64 sessionId) { // 超过大小不能分配 if (GetSize() >= SizeMax) { return(null); } /// 创建一个新现场对象 IManagedContext newCtx = Activator.CreateInstance(m_contextType) as IManagedContext; /// 生成新的ContexId并绑定到新的Context对象上 /// 并且管理该新的Context对象到底层字典中 newCtx.ContextId = sessionId; if (!m_playerSid2CtxDic.TryAdd(sessionId, newCtx)) { throw new Exception("fail to add ctx in m_playerSid2CtxDic"); } return(newCtx); }
internal SerializationService(IInputOutputFactory inputOutputFactory, int version, IDictionary <int, IDataSerializableFactory> dataSerializableFactories, IDictionary <int, IPortableFactory> portableFactories, ICollection <IClassDefinition> classDefinitions, bool checkClassDefErrors, IManagedContext managedContext, IPartitioningStrategy partitionStrategy, int initialOutputBufferSize, bool enableCompression, bool enableSharedObject) { this.inputOutputFactory = inputOutputFactory; this.managedContext = managedContext; globalPartitioningStrategy = partitionStrategy; outputBufferSize = initialOutputBufferSize; dataOutputQueue = new ThreadLocalOutputCache(this); portableContext = new PortableContext(this, version); dataSerializerAdapter = CreateSerializerAdapterByGeneric <IDataSerializable>(new DataSerializer(dataSerializableFactories)); portableSerializer = new PortableSerializer(portableContext, portableFactories); portableSerializerAdapter = CreateSerializerAdapterByGeneric <IPortable>(portableSerializer); RegisterConstantSerializers(); RegisterDefaultSerializers(); RegisterClassDefinitions(classDefinitions, checkClassDefErrors); }
public void Initialize(Type playerContextType, Int32 serverId, Int32 sizeMax) { // 保存最终PlayerContext的类型 m_contextType = playerContextType; // 保存最大现场个数 m_sizeMax = sizeMax; /// 测试给定的类型是否符合规范 IManagedContext newCtx = Activator.CreateInstance(m_contextType) as IManagedContext; if (newCtx == null) { throw new ArgumentException("PlayerContextManager::Initialize The type of playerContextType is not inherit from IManagedPlayerContext。"); } // 构造sessionidFactory m_sessionIdFactory = new SessionIdFactory(serverId); /// 创建字典对象 m_playerSid2CtxDic = new ConcurrentDictionary <UInt64, IManagedContext>(); m_playerCtxName2CtxDic = new ConcurrentDictionary <String, IManagedContext>(); }
public HazelcastClientManagedContext(IHazelcastInstance instance, IManagedContext externalContext) { this.instance = instance; this.externalContext = externalContext; hasExternalContext = this.externalContext != null; }
public virtual ClientConfig SetManagedContext(IManagedContext managedContext) { _managedContext = managedContext; return(this); }
public HazelcastClientManagedContext(IHazelcastInstance instance, IManagedContext externalContext) { _instance = instance; _externalContext = externalContext; _hasExternalContext = _externalContext != null; }
public InstructionReader(byte[] bytes, IManagedContext context) { this.bytes = bytes; this.context = context; }
public ISerializationServiceBuilder SetManagedContext(IManagedContext managedContext) { _managedContext = managedContext; return(this); }
public ISerializationServiceBuilder SetManagedContext(IManagedContext managedContext) { this._managedContext = managedContext; return this; }