In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the CoreHandler compilation method of Ray-Handler". In the daily operation, I believe that many people have doubts about what the CoreHandler compilation method of Ray-Handler is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the CoreHandler compilation method of Ray-Handler?" Next, please follow the editor to study!
There are two types of Handler in Ray (SubHandler and PartSubHandler). In use, the CoreHandler,PartSubHandler of SubHandler derives from Actor and the ToReadHandler of Actor is derived from SQLToReadHandler,SQLToReadHandler, and Ray is mainly used to write CoreHandler and ToReadHandler of Actor.
CoreHandler is a composite message router, including: message router, message processor, message splitter, message aggregator, message filter, message richer, replica synchronization coordinator.
Message Router:
The Switch block in the Tell method, for different Event types, distributes the data in Event events to different event handling methods CoreHandler, which acts as a message router. The code is as follows:
Public override Task Tell (byte [] bytes, IActorOwnMessage data, MessageInfo msg) {switch (data) {case CoinAddressGeneratingResponse value: return AcceptCoinAddressAsync (value); case CoinWithdrawWithholdingFailedMsg value: return RollbackWithholdingAsync (value); case CoinWithdrawWithheldEvent value: return CreateWithdrawAsync (value); case CoinOrderCreatedEvent value: return CreateOrderAsync (value); case CoinOrderCreatedEventV1 value: return CreateOrderAsyncV1 (value); case CoinPlanOrderCreatedEvent value: return CreatePlanOrderAsync (value); case CoinDepositIncreasedEvent value: return CoinDepositIncreased (value); case CoinIcoEvent value: return CoinIcoEventHandle (value) Default: return Task.CompletedTask;}} message processor:
For different Event types, the event is handled in the CoreHandler of the Actor, and CoreHandler is responsible for the role of the message processor. In the following code, the AmountAddEventHandler method handles the AmountTransferEvent event.
In the event handling code, the code you can write is as follows:
Can be handled only for the current event.
You can get other actor references and call other actor methods (including actor's read-only methods and write operation methods).
You can call the data access layer to read and write the database. (the writing method is recommended in ToReadHandler).
Public override Task Tell (byte [] bytes, IActorOwnMessage data, MessageInfo msg) {switch (data) {case AmountTransferEvent value: return AmountAddEventHandler (value); default: return Task.CompletedTask;}} public Task AmountAddEventHandler (AmountTransferEvent value) {var toActor = HandlerStart.Client.GetGrain (value.ToAccountId); return toActor.AddAmount (value.Amount, value.Id);} message splitter:
When you need to split a larger message into separate parts and use these separate parts as parameters for other actor processing, CoreHandler acts as a splitter.
Message aggregator:
When the data in different types of messages needs to be aggregated and counted, CoreHandler acts as a message aggregator.
For example, in the encrypted currency trading scenario, there are different markets for ETH, BTC and USDT, and EOS has transactions in all three markets. To count the transaction volume of each user's EOS this week, you can do the following:
Public override Task Tell (byte [] bytes, IActorOwnMessage data, MessageInfo msg) {switch (data) {case CoinTradeSoldEvent value: return ActivitySellStatistic (value); case CoinTradeBoughtEvent value: return ActivityBuyStatistic (value); default: return Task.CompletedTask;}} message filter:
When it is possible for CoreHandler to receive messages that it is not interested in and need to discard these useless messages, CoreHandler can act as a message filter.
Public override Task Tell (byte [] bytes, IActorOwnMessage data, MessageInfo msg) {switch (data) {case AmountTransferEvent value: return AmountAddEventHandler (value); default: return Task.CompletedTask;// message filtering}} message richer:
When it is necessary to further enrich the received messages and use the enriched messages as parameters for other actor processing, CoreHandler acts as a message richer.
Copy synchronization Coordinator:
There are two types of actor in the Ray: the primary actor and the replica actor. The replica actor is used to share the pressure of the primary actor and perform some asynchronous operations. When you use the replica actor, and you need the master actor to synchronize with the replica actor, you need the CoreHandler to hand over the events of concern to the replica actor. At this time, CoreHandler acts as the replica synchronization coordinator.
Public override Task Tell (byte [] bytes, IActorOwnMessage data, MessageInfo msg) {var replicatedRef = HandlerStart.Client.GetGrain (data.StateId); / / get a copy actor var task = replicatedRef.Tell (bytes); / / notify copy synchronization switch (data) {case AmountTransferEvent value: return Task.WhenAll (task, AmountAddEventHandler (value)); default: return task }} at this point, the study on "what is the CoreHandler writing method of Ray-Handler" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.