| | 1 | | using System; |
| | 2 | | using System.Configuration; |
| | 3 | | using System.Reflection; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using Akka.Actor; |
| | 6 | | using Akka.Actor.Internal; |
| | 7 | | using Akka.Event; |
| | 8 | | using Akka.Routing; |
| | 9 | | using Akka.Serialization; |
| | 10 | |
|
| | 11 | | namespace SeungYongShim.Akka.OpenTelemetry |
| | 12 | | { |
| | 13 | | public sealed class TraceLocalActorRefProvider : IActorRefProvider |
| | 14 | | { |
| | 15 | | private readonly LocalActorRefProvider _localActorRefProvider; |
| | 16 | | private ActorSystemImpl _system; |
| | 17 | |
|
| | 18 | | public TraceLocalActorRefProvider(string systemName, Settings settings, EventStream eventStream) |
| 6 | 19 | | : this(systemName, settings, eventStream, null, null) |
| 6 | 20 | | { |
| 6 | 21 | | } |
| | 22 | |
|
| 6 | 23 | | public TraceLocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deploy |
| 6 | 24 | | { |
| 6 | 25 | | var rootPath = new RootActorPath(new Address("akka", systemName)); |
| 6 | 26 | | Log = Logging.GetLogger(eventStream, "TraceLocalActorRefProvider(" + rootPath.Address + ")"); |
| 6 | 27 | | _localActorRefProvider = new LocalActorRefProvider(systemName, settings, eventStream, deployer, deadLettersF |
| | 28 | |
|
| 6 | 29 | | var design = Assembly.GetAssembly(typeof(RepointableActorRef)); |
| 6 | 30 | | ActorTaskSchedulerMessageType = design?.GetType("Akka.Dispatch.SysMsg.ActorTaskSchedulerMessage"); |
| 6 | 31 | | } |
| | 32 | |
|
| 24 | 33 | | public IInternalActorRef RootGuardian => _localActorRefProvider.RootGuardian; |
| | 34 | |
|
| 20 | 35 | | public LocalActorRef Guardian => _localActorRefProvider.Guardian; |
| | 36 | |
|
| 36 | 37 | | public LocalActorRef SystemGuardian => _localActorRefProvider.SystemGuardian; |
| | 38 | |
|
| 93 | 39 | | public IActorRef DeadLetters => _localActorRefProvider.DeadLetters; |
| | 40 | |
|
| 0 | 41 | | public IActorRef IgnoreRef => _localActorRefProvider.IgnoreRef; |
| | 42 | |
|
| 0 | 43 | | public ActorPath RootPath => _localActorRefProvider.RootPath; |
| | 44 | |
|
| 39 | 45 | | public Settings Settings => _localActorRefProvider.Settings; |
| | 46 | |
|
| 36 | 47 | | public Deployer Deployer => _localActorRefProvider.Deployer; |
| | 48 | |
|
| 0 | 49 | | public IInternalActorRef TempContainer => _localActorRefProvider.TempContainer; |
| | 50 | |
|
| 6 | 51 | | public Task TerminationTask => _localActorRefProvider.TerminationTask; |
| | 52 | |
|
| 0 | 53 | | public Address DefaultAddress => _localActorRefProvider.DefaultAddress; |
| | 54 | |
|
| 0 | 55 | | public Information SerializationInformation => _localActorRefProvider.SerializationInformation; |
| | 56 | |
|
| 0 | 57 | | public Address GetExternalAddressFor(Address address) => _localActorRefProvider.GetExternalAddressFor(address); |
| | 58 | |
|
| | 59 | | public void Init(ActorSystemImpl system) |
| 6 | 60 | | { |
| 6 | 61 | | _system = system; |
| 6 | 62 | | _localActorRefProvider.Init(system); |
| 6 | 63 | | } |
| | 64 | |
|
| 15 | 65 | | public void RegisterTempActor(IInternalActorRef actorRef, ActorPath path) => _localActorRefProvider.RegisterTemp |
| | 66 | |
|
| 0 | 67 | | public IActorRef ResolveActorRef(string path) => _localActorRefProvider.ResolveActorRef(path); |
| | 68 | |
|
| 0 | 69 | | public IActorRef ResolveActorRef(ActorPath actorPath) => _localActorRefProvider.ResolveActorRef(actorPath); |
| | 70 | |
|
| 0 | 71 | | public IActorRef RootGuardianAt(Address address) => _localActorRefProvider.RootGuardianAt(address); |
| | 72 | |
|
| 15 | 73 | | public ActorPath TempPath() => _localActorRefProvider.TempPath(); |
| | 74 | |
|
| 14 | 75 | | public void UnregisterTempActor(ActorPath path) => _localActorRefProvider.UnregisterTempActor(path); |
| | 76 | |
|
| | 77 | | public ILoggingAdapter Log { get; } |
| | 78 | | public Type ActorTaskSchedulerMessageType { get; } |
| | 79 | |
|
| | 80 | | public IInternalActorRef ActorOf(ActorSystemImpl system, Props props, IInternalActorRef supervisor, ActorPath pa |
| 36 | 81 | | { |
| 36 | 82 | | if (props.Deploy.RouterConfig is NoRouter) |
| 36 | 83 | | { |
| 36 | 84 | | if (Settings.DebugRouterMisconfiguration) |
| 0 | 85 | | { |
| 0 | 86 | | var d = Deployer.Lookup(path); |
| 0 | 87 | | if (d != null && !(d.RouterConfig is NoRouter)) |
| 0 | 88 | | Log.Warning("Configuration says that [{0}] should be a router, but code disagrees. Remove the co |
| 0 | 89 | | path); |
| 0 | 90 | | } |
| | 91 | |
|
| 36 | 92 | | var props2 = props; |
| | 93 | |
|
| | 94 | | // mailbox and dispatcher defined in deploy should override props |
| 36 | 95 | | var propsDeploy = lookupDeploy ? Deployer.Lookup(path) : deploy; |
| 36 | 96 | | if (propsDeploy != null) |
| 24 | 97 | | { |
| 24 | 98 | | if (propsDeploy.Mailbox != Deploy.NoMailboxGiven) |
| 0 | 99 | | props2 = props2.WithMailbox(propsDeploy.Mailbox); |
| 24 | 100 | | if (propsDeploy.Dispatcher != Deploy.NoDispatcherGiven) |
| 0 | 101 | | props2 = props2.WithDispatcher(propsDeploy.Dispatcher); |
| 24 | 102 | | } |
| | 103 | |
|
| 36 | 104 | | if (!system.Dispatchers.HasDispatcher(props2.Dispatcher)) |
| 0 | 105 | | { |
| 0 | 106 | | throw new ConfigurationException($"Dispatcher [{props2.Dispatcher}] not configured for path {path}") |
| | 107 | | } |
| | 108 | |
|
| | 109 | | try |
| 36 | 110 | | { |
| | 111 | | // for consistency we check configuration of dispatcher and mailbox locally |
| 36 | 112 | | var dispatcher = _system.Dispatchers.Lookup(props2.Dispatcher); |
| 36 | 113 | | var mailboxType = _system.Mailboxes.GetMailboxType(props2, dispatcher.Configurator.Config); |
| | 114 | |
|
| 36 | 115 | | if (async) |
| 32 | 116 | | return |
| 32 | 117 | | new TraceRepointableActorRef(system, props2, dispatcher, |
| 32 | 118 | | mailboxType, supervisor, path, ActorTaskSchedulerMessageType).Initialize(async); |
| 4 | 119 | | return new TraceLocalActorRef(system, props2, dispatcher, |
| 4 | 120 | | mailboxType, supervisor, path, ActorTaskSchedulerMessageType); |
| | 121 | | } |
| 0 | 122 | | catch (Exception ex) |
| 0 | 123 | | { |
| 0 | 124 | | throw new ConfigurationException( |
| 0 | 125 | | $"Configuration problem while creating [{path}] with dispatcher [{props.Dispatcher}] and mailbox |
| | 126 | | } |
| | 127 | | } |
| | 128 | | else //routers!!! |
| 0 | 129 | | { |
| 0 | 130 | | throw new NotImplementedException("Router not support"); |
| | 131 | | } |
| 36 | 132 | | } |
| | 133 | | } |
| | 134 | | } |