public EventProcessor(IEventHandlerFactory eventHandlerFactory, IJobHandler jobHandler, IActionDispatcher actionDispatcher) { _eventHandlerFactory = eventHandlerFactory; _jobHandler = jobHandler; _actionDispatcher = actionDispatcher; }
public TaskStore(IActionDispatcher actionDispatcher) { _state = new TaskState(_initTaskCount); _state.SearchTerm = _searchTerm; this.actionDispatcher = actionDispatcher; this.actionDispatcher.Subscribe(HandleActions); }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <param name="actionDispatcher"></param> /// <param name="actionId"></param> /// <param name="baseUser"></param> /// <param name="urlParam"></param> /// <param name="actionGetter"></param> /// <returns></returns> public static byte[] GetActionResponse(IActionDispatcher actionDispatcher, int actionId, IUser baseUser, string urlParam, out ActionGetter actionGetter) { int userId = baseUser != null?baseUser.GetUserId() : 0; GameSession session = GameSession.Get(userId); if (baseUser != null && session == null) { throw new Exception(string.Format("Uid {0} of session is expired.", userId)); } string sessionId = session != null ? session.SessionId : ""; string param = string.Format("MsgId={0}&St={1}&Sid={2}&Uid={3}&ActionID={4}{5}", 0, "st", sessionId, userId, actionId, urlParam); RequestPackage requestPackage = new RequestPackage(0, sessionId, actionId, userId); requestPackage.UrlParam = param; requestPackage.IsUrlParam = true; requestPackage.Bind(session); actionGetter = new HttpGet(requestPackage, session); return(GetActionResponse(actionDispatcher, actionId, baseUser, actionGetter)); }
public TriggerDispatcher(IEnumerable <ITriggerHandler> handlers, IRecipeManager recipeManager, IActionDispatcher actionDispatcher) { _handlers = handlers; _recipeManager = recipeManager; _actionDispatcher = actionDispatcher; }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <returns></returns> private static byte[] ProcessActionResponse(IActionDispatcher actionDispatcher, int actionId, ActionGetter actionGetter) { BaseStruct baseStruct = FindRoute(GameEnvironment.Setting.ActionTypeName, actionGetter, actionId); SocketGameResponse response = new SocketGameResponse(); response.WriteErrorCallback += actionDispatcher.ResponseError; baseStruct.SetPush(); baseStruct.DoInit(); if (actionGetter.Session.EnterLock(actionId)) { try { if (!baseStruct.GetError() && baseStruct.ReadUrlElement() && baseStruct.DoAction() && !baseStruct.GetError()) { baseStruct.WriteResponse(response); } else { baseStruct.WriteErrorAction(response); } } finally { actionGetter.Session.ExitLock(actionId); } } else { baseStruct.WriteLockTimeoutAction(response, false); } return(response.ReadByte()); }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <returns></returns> public static byte[] GetActionResponse(IActionDispatcher actionDispatcher, int actionId, IUser baseUser, ActionGetter actionGetter) { BaseStruct baseStruct = FindRoute(GameEnvironment.Setting.ActionTypeName, actionGetter, actionId); SocketGameResponse response = new SocketGameResponse(); response.WriteErrorCallback += actionDispatcher.ResponseError; baseStruct.SetPush(); baseStruct.DoInit(); using (ILocking locking = baseStruct.RequestLock()) { if (locking == null || locking.IsLocked) { if (!baseStruct.GetError() && baseStruct.ReadUrlElement() && baseStruct.DoAction() && !baseStruct.GetError()) { baseStruct.WriteResponse(response); } else { baseStruct.WriteErrorAction(response); } } } return(response.ReadByte()); }
/// <summary> /// /// </summary> /// <param name="actionDispatcher"></param> /// <param name="actionId"></param> /// <param name="session"></param> /// <param name="package"></param> /// <returns></returns> public static byte[] GetActionResponse(IActionDispatcher actionDispatcher, int actionId, GameSession session, RequestPackage package) { package.Bind(session); var actionGetter = new HttpGet(package, session); return(ProcessActionResponse(actionDispatcher, actionId, actionGetter)); }
public MainWindowViewModel( IObservable <RootState> state, IActionDispatcher actionDispatcher) { _stateStream = state; _actionDispatcher = actionDispatcher; }
static GameEnvironment() { try { string appConfigPath = string.Format("{0}/{1}", configPath, "AppConfig.txt"); string redisConfigPath = string.Format("{0}/{1}", configPath, "RedisConfig.txt"); string socketConfigPath = string.Format("{0}/{1}", configPath, "SocketConfig.txt"); string httpConfigPath = string.Format("{0}/{1}", configPath, "HttpConfig.txt"); string actorConfigPath = string.Format("{0}/{1}", configPath, "ActorConfig.txt"); appConfig = ReadConfig <AppConfig>(appConfigPath); redisConfig = ReadConfig <RedisConfig>(redisConfigPath); socketConfig = ReadConfig <SocketConfig>(socketConfigPath); httpConfig = ReadConfig <HttpConfig>(httpConfigPath); actorConfig = ReadConfig <ActorConfig>(actorConfigPath); MessageStructure.EnableGzip = socketConfig.EnableActionGZip; MessageStructure.EnableGzipMinByte = socketConfig.ActionGZipOutLength; actionDispatcher = new PlusDispatcher(); } catch (Exception ex) { TraceLog.WriteError("读取配置文件失败,{0},{1}", ex.Message, ex.StackTrace); } }
public ServerPipe(string name, IReducerContext reducerContext) : base() { ServerName = name; Reducers = reducerContext; Dispatcher = new Dispatchers.Dispatcher(Reducers.Items); }
public DynamicServiceService(ExternalServiceData data, IRecipeManager recipeManager, IActionDispatcher actionDispatcher, IExternalServiceManager externalServiceManager) : base(data) { _data = data; _recipeManager = recipeManager; _actionDispatcher = actionDispatcher; _externalServiceManager = externalServiceManager; }
public EpicFlow(ISchedulerProvider schedulerProvider, IEnumerable <IEpic> epics, IActionObservable actionObservable, IActionDispatcher actionDispatcher) { Epics = epics.ToList(); SchedulerProvider = schedulerProvider; ActionObservable = actionObservable; ActionDispatcher = actionDispatcher; }
public RuntimeController(IRuntimeStorage runtime, IActionDispatcher dispatcher, IGrainFactory factory, ILogger <RuntimeController> logger) { this.runtime = runtime; this.dispatcher = dispatcher; this.factory = factory; this.logger = logger; }
public Store( IActionDispatcher dispatcher, IReducer <T> reducer, IStateStreamSubject <T> stateStreamSubject, IEnumerable <IEffect <T> > effects, IExceptionHandler exceptionHandler) { _dispatcher = dispatcher; _reducer = reducer; _stateStreamSubject = stateStreamSubject; _effects = effects; _exceptionHandler = exceptionHandler; }
public async Task Run(IActionDispatcher dispatcher) { while (true) { IAction action = await Receive(); // Report($"Server received: {action.Type}"); string msg = await dispatcher.Dispatch(action); await Send(msg); } }
/// <summary> /// Convenience method for creating an HabaneroBackgroundWorker. /// </summary> /// <param name="dispatcher"></param> /// <param name="data"></param> /// <param name="backgroundWorker"></param> /// <param name="onSuccess"></param> /// <param name="onCancel"></param> /// <param name="onException"></param> /// <returns></returns> public static HabaneroBackgroundWorker Run(IActionDispatcher dispatcher, ConcurrentDictionary <string, object> data, BackgroundWorkerMethodDelegate backgroundWorker, UIWorkerMethodDelegate onSuccess, UIWorkerMethodDelegate onCancel, BackgroundWorkerExceptionHandlerDelegate onException) { var runner = new HabaneroBackgroundWorker() { ActionDispatcher = dispatcher, BackgroundWorker = backgroundWorker, OnSuccess = onSuccess, OnCancelled = onCancel, OnException = onException, Data = data }; runner.Run(); return(runner); }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <returns></returns> public static byte[] GetActionResponse(IActionDispatcher actionDispatcher, int actionId, BaseUser baseUser, string urlParam, out ActionGetter actionGetter) { int userId = baseUser != null?baseUser.GetUserId() : 0; GameSession session = GameSession.Get(userId); string sessionId = session != null ? session.SessionId : ""; string param = string.Format("MsgId={0}&St={1}&Sid={2}&Uid={3}&ActionID={4}{5}", 0, "st", sessionId, userId, actionId, urlParam); RequestPackage requestPackage = new RequestPackage(0, sessionId, actionId, userId); requestPackage.UrlParam = param; requestPackage.IsUrlParam = true; requestPackage.Session = session; requestPackage.ReceiveTime = DateTime.Now; actionGetter = new HttpGet(requestPackage); BaseStruct baseStruct = FindRoute(GameEnvironment.Setting.ActionTypeName, actionGetter, actionId); SocketGameResponse response = new SocketGameResponse(); response.WriteErrorCallback += actionDispatcher.ResponseError; baseStruct.UserFactory = uid => { return(baseUser); }; baseStruct.SetPush(); baseStruct.DoInit(); using (ILocking locking = baseStruct.RequestLock()) { if (locking.IsLocked) { if (!baseStruct.GetError() && baseStruct.ReadUrlElement() && baseStruct.DoAction() && !baseStruct.GetError()) { baseStruct.WriteResponse(response); } else { baseStruct.WriteErrorAction(response); } } } return(response.ReadByte()); }
public ApplicationService( IApplicationRepository applicationRepository, IServiceActionRepository serviceActionRepository, IPropertyRegisterClient propertyRegisterClient, INomenclaturesProvider nomenclaturesProvider, IIdempotentOperationExecutor idempotentOperationExecutor, IActionDispatcher actionDispatcher, IPaymentManager paymentManager) { ApplicationRepository = applicationRepository; ServiceActionRepository = serviceActionRepository; PropertyRegisterClient = propertyRegisterClient; NomenclaturesProvider = nomenclaturesProvider; IdempotentOperationExecutor = idempotentOperationExecutor; ActionDispatcher = actionDispatcher; PaymentManager = paymentManager; }
/// <summary> /// /// </summary> protected GameSocketHost() { ActionDispatcher = new ActionDispatcher(); int port = GameEnvironment.Setting.GamePort; IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port); int maxConnections = ConfigUtils.GetSetting("MaxConnections", 10000); int backlog = ConfigUtils.GetSetting("Backlog", 1000); int maxAcceptOps = ConfigUtils.GetSetting("MaxAcceptOps", 1000); int bufferSize = ConfigUtils.GetSetting("BufferSize", 8192); int expireInterval = ConfigUtils.GetSetting("ExpireInterval", 600) * 1000; int expireTime = ConfigUtils.GetSetting("ExpireTime", 3600) * 1000; threadPool = new SmartThreadPool(180 * 1000, 100, 5); threadPool.Start(); var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime); socketLintener = new SocketListener(socketSettings); socketLintener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived); socketLintener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted); socketLintener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected); httpListener = new HttpListener(); var httpHost = ConfigUtils.GetSetting("Game.Http.Host"); var httpPort = ConfigUtils.GetSetting("Game.Http.Port", 80); var httpName = ConfigUtils.GetSetting("Game.Http.Name", "Service.aspx"); if (!string.IsNullOrEmpty(httpHost)) { EnableHttp = true; var hosts = httpHost.Split(','); foreach (var host in hosts) { string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ? host : "http://" + host; httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, httpPort, httpName)); } } Interlocked.Exchange(ref _runningQueue, 1); queueProcessThread = new Thread(ProcessQueue); queueProcessThread.Start(); _LockedQueueChecker = new Timer(LockedQueueChecker, null, 100, 100); }
public WorkerPool(ILogger log, int numFreeWorkers = 0, int maxQueuedMessages = 1000) { Assert.IsInRange(maxQueuedMessages, nameof(maxQueuedMessages), 0, int.MaxValue); Assert.IsInRange(numFreeWorkers, nameof(numFreeWorkers), 0, 65535); _log = log; _maxQueuedMessages = maxQueuedMessages; _threadPoolDispatcher = new ThreadPoolDispatcher(_log); _dedicatedWorkers = new ConcurrentDictionary <int, MessageHandlerWorker>(); _detachedContexts = new ConcurrentDictionary <int, IWorkerContext>(); _registeredThreads = new ConcurrentDictionary <int, RegisteredManagedThread>(); var freeWorkers = new List <MessageHandlerWorker>(); _freeWorkerContext = InitializeFreeWorkers(numFreeWorkers, freeWorkers); _freeWorkers = freeWorkers; }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <returns></returns> private static byte[] ProcessActionResponse(IActionDispatcher actionDispatcher, int actionId, ActionGetter actionGetter) { BaseStruct baseStruct = FindRoute(Runtime.GameZone.Setting.ActionTypeName, actionGetter, actionId); SocketGameResponse response = new SocketGameResponse(); response.WriteErrorCallback += actionDispatcher.ResponseError; baseStruct.SetPush(); baseStruct.DoInit(); object errorTarget; long waitTimeOutNum; if (actionGetter.Session.EnterLock(actionId, actionGetter.ToString(), out errorTarget, out waitTimeOutNum)) { try { if (!baseStruct.GetError() && baseStruct.ReadUrlElement() && baseStruct.DoAction() && !baseStruct.GetError()) { baseStruct.WriteResponse(response); } else { baseStruct.WriteErrorAction(response); } } finally { actionGetter.Session.ExitLock(actionId); } } else { baseStruct.WriteLockTimeoutAction(response, errorTarget, waitTimeOutNum, false); } return(response.ReadByte()); }
public ApplicationAcceptanceService( IApplicationRepository applicationRepository, IServiceInstanceRepository serviceInstanceRepository, IApplicationDocumentRepository applicationDocumentRepository, IServiceActionRepository serviceActionRepository, IDocumentService documentService, INomenclaturesProvider nomenclaturesProvider, IIdempotentOperationExecutor idempotentOperationExecutor, IActionDispatcher actionDispatcher, IApplicationInfoResolver applicationInfoResolver) { ApplicationRepository = applicationRepository; ServiceInstanceRepository = serviceInstanceRepository; ApplicationDocumentRepository = applicationDocumentRepository; ServiceActionRepository = serviceActionRepository; DocumentService = documentService; NomenclaturesProvider = nomenclaturesProvider; IdempotentOperationExecutor = idempotentOperationExecutor; ActionDispatcher = actionDispatcher; ApplicationInfoResolver = applicationInfoResolver; }
public static void ChangePriority(this IActionDispatcher disp, IAction action, int priority) { action.Priority = priority; disp.PriorityChanged(action); }
/// <summary> /// 获取Action处理的输出字节流 /// </summary> /// <param name="actionDispatcher"></param> /// <param name="actionId"></param> /// <param name="session"></param> /// <param name="parameters"></param> /// <param name="opCode"></param> /// <param name="message"></param> /// <returns></returns> public static byte[] GetActionResponse(IActionDispatcher actionDispatcher, int actionId, GameSession session, Parameters parameters, sbyte opCode, object message = null) { var requestPackage = GetResponsePackage(actionId, session, parameters, opCode, message); return(GetActionResponse(actionDispatcher, actionId, session, requestPackage)); }
public CounterStore(IActionDispatcher actionDispatcher) { _state = new CounterState(0); this.actionDispatcher = actionDispatcher; this.actionDispatcher.Subscript(HandleActions); }
public SearchEffect(IActionDispatcher actionDispatcher) : this(actionDispatcher, TimeSpan.FromMilliseconds(400), Scheduler.Default) { // defualt scheduler => NewThread }
public SearchEffect(IActionDispatcher actionDispatcher, TimeSpan sampling, IScheduler scheduler) { _actionDispatcher = actionDispatcher; _sampling = sampling; _scheduler = scheduler; }
public static HabaneroBackgroundWorker Run(IActionDispatcher dispatcher, ConcurrentDictionary<string, object> data, BackgroundWorkerMethodDelegate backgroundWorker, UIWorkerMethodDelegate onSuccess, UIWorkerMethodDelegate onCancel, BackgroundWorkerExceptionHandlerDelegate onException) { var runner = new HabaneroBackgroundWorker() { ActionDispatcher = dispatcher, BackgroundWorker = backgroundWorker, OnSuccess = onSuccess, OnCancelled = onCancel, OnException = onException, Data = data }; runner.Run(); return runner; }
public CounterStore(IActionDispatcher dispatcher) : base(dispatcher) { _state = new CounterState(0); }
public UserView(IActionDispatcher actionDispatcher) { _isActive = true; this._actionDispatcher = actionDispatcher; _users = new UserViewModel[0]; }
public StringStore(IActionDispatcher actionDispatcher) { _state = new StringState("ciao"); this.actionDispatcher = actionDispatcher; this.actionDispatcher.Subscript(HandleActions); }