events_undelivered.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "events.h"
  2. #include "actorsystem.h"
  3. namespace NActors {
  4. TString TEvents::TEvUndelivered::ToStringHeader() const {
  5. return "TSystem::Undelivered";
  6. }
  7. bool TEvents::TEvUndelivered::SerializeToArcadiaStream(TChunkSerializer *serializer) const {
  8. Y_VERIFY(!Unsure); // these are local-only events generated by Interconnect
  9. return serializer->WriteString(&Data);
  10. }
  11. void TEvents::TEvUndelivered::Out(IOutputStream& o, EReason x) {
  12. switch (x) {
  13. case ReasonActorUnknown:
  14. o << "ActorUnknown";
  15. break;
  16. case Disconnected:
  17. o << "Disconnected";
  18. break;
  19. default:
  20. o << "Undefined";
  21. break;
  22. }
  23. }
  24. bool TEvents::TEvUndelivered::IsSerializable() const {
  25. return true;
  26. }
  27. IEventBase* TEvents::TEvUndelivered::Load(TEventSerializedData* bufs) {
  28. TString str = bufs->GetString();
  29. Y_VERIFY(str.size() == (sizeof(ui32) + sizeof(ui32)));
  30. const char* p = str.data();
  31. const ui64 sourceType = ReadUnaligned<ui32>(p + 0);
  32. const ui64 reason = ReadUnaligned<ui32>(p + 4);
  33. return new TEvUndelivered(sourceType, reason);
  34. }
  35. std::unique_ptr<IEventHandle> IEventHandle::ForwardOnNondelivery(std::unique_ptr<IEventHandle>&& ev, ui32 reason, bool unsure) {
  36. if (ev->Flags & FlagForwardOnNondelivery) {
  37. const ui32 updatedFlags = ev->Flags & ~(FlagForwardOnNondelivery | FlagSubscribeOnSession);
  38. const TActorId recp = ev->OnNondeliveryHolder ? ev->OnNondeliveryHolder->Recipient : TActorId();
  39. if (ev->Event)
  40. return std::unique_ptr<IEventHandle>(new IEventHandle(recp, ev->Sender, ev->Event.Release(), updatedFlags, ev->Cookie, &ev->Recipient, std::move(ev->TraceId)));
  41. else
  42. return std::unique_ptr<IEventHandle>(new IEventHandle(ev->Type, updatedFlags, recp, ev->Sender, ev->Buffer, ev->Cookie, &ev->Recipient, std::move(ev->TraceId)));
  43. }
  44. if (ev->Flags & FlagTrackDelivery) {
  45. const ui32 updatedFlags = ev->Flags & ~(FlagTrackDelivery | FlagSubscribeOnSession | FlagGenerateUnsureUndelivered);
  46. return std::unique_ptr<IEventHandle>(new IEventHandle(ev->Sender, ev->Recipient, new TEvents::TEvUndelivered(ev->Type, reason, unsure), updatedFlags,
  47. ev->Cookie, nullptr, std::move(ev->TraceId)));
  48. }
  49. return {};
  50. }
  51. }