/// <summary>
        ///     Performs all of the initialization to get the PCF metrics forwarding engine up and running.
        /// </summary>
        /// <param name="settings">The options and settings needed to communicate with PCF.</param>
        /// <param name="system">Optional. An <see cref="ActorSystem" /> used to spawn the underlying actors needed to do the job.</param>
        /// <returns>A new <see cref="PcfMetricRecorder" /> instance.</returns>
        public static PcfMetricRecorder Create(PcfMetricForwarderSettings settings, ActorSystem system = null)
        {
            var weOwnActorSystem = false;

            if (system == null) // create our own ActorSystem if it doesn't already exist.
            {
                weOwnActorSystem = true;
                system           = ActorSystem.Create("pbpcfmetrics",
                                                      settings.DebugLogging ? DebugHocon : NormalHocon);
            }

            // spawn as a System actor, so in the event of being in a non-owned system our traces get shut down
            // only after all of the user-defined actors have terminated.
            var reporterActor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf(
                Props.Create(() => new MetricsReporterActor(settings)),
                $"pcf-reporter-{NameCounter.GetAndIncrement()}");


            var counterActor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf(
                Props.Create(() =>
                             new CounterAggregator(reporterActor, settings.TimeProvider ?? new DateTimeOffsetTimeProvider())),
                $"pcf-reporter-{NameCounter.GetAndIncrement()}");

            return(new PcfMetricRecorder(reporterActor, counterActor, weOwnActorSystem ? system : null));
        }
        public RemoteDeploySpec()
            : base(@"
            akka {
                loglevel = INFO 
                log-dead-letters-during-shutdown = false
              //  actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
                remote.helios.tcp = {
                    hostname = localhost
                    port = 0
                }

                actor.deployment {
                  /router1 {
                    router = round-robin-pool
                    nr-of-instances = 3
                  }
                  /router2 {
                    router = round-robin-pool
                    nr-of-instances = 3
                  }
                  /router3 {
                    router = round-robin-pool
                    nr-of-instances = 0
                  }
                }
            }
")
        {
            _remoteSystem = ActorSystem.Create("RemoteSystem", Sys.Settings.Config);
            _remoteAddress = _remoteSystem.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;
            var remoteAddressUid = AddressUidExtension.Uid(_remoteSystem);


        }
Example #3
0
        protected MultiNodeSpec(
            RoleName myself,
            ActorSystem system,
            ImmutableList <RoleName> roles,
            Func <RoleName, ImmutableList <string> > deployments)
            : base(new XunitAssertions(), system)
        {
            _myself      = myself;
            _log         = Logging.GetLogger(Sys, this);
            _roles       = roles;
            _deployments = deployments;
            var node = new Node()
            {
                Host = Dns.GetHostEntry(ServerName).AddressList.First(a => a.AddressFamily == AddressFamily.InterNetwork),
                Port = ServerPort
            };

            _controllerAddr = node;

            AttachConductor(new TestConductor(system));

            _replacements = _roles.ToImmutableDictionary(r => r, r => new Replacement("@" + r.Name + "@", r, this));

            InjectDeployments(system, myself);

            _myAddress = system.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;

            Log.Info("Role [{0}] started with address [{1}]", myself.Name, _myAddress);
        }
Example #4
0
        protected MultiNodeSpec(
            RoleName myself,
            ActorSystem system,
            ImmutableList <RoleName> roles,
            Func <RoleName, ImmutableList <string> > deployments)
            : base(new XunitAssertions(), system)
        {
            _myself      = myself;
            _log         = Logging.GetLogger(Sys, this);
            _roles       = roles;
            _deployments = deployments;

#if CORECLR
            var dnsTask = Dns.GetHostAddressesAsync(ServerName);
            dnsTask.Wait();
            var node = new IPEndPoint(dnsTask.Result[0], ServerPort);
#else
            var node = new IPEndPoint(Dns.GetHostAddresses(ServerName)[0], ServerPort);
#endif
            _controllerAddr = node;

            AttachConductor(new TestConductor(system));

            _replacements = _roles.ToImmutableDictionary(r => r, r => new Replacement("@" + r.Name + "@", r, this));

            InjectDeployments(system, myself);

            _myAddress = system.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;

            Log.Info("Role [{0}] started with address [{1}]", myself.Name, _myAddress);
            MultiNodeSpecBeforeAll();
        }
        public RemoteDeploySpec()
            : base(@"
            akka {
                loglevel = INFO 
                log-dead-letters-during-shutdown = false
              //  actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
                remote.helios.tcp = {
                    hostname = localhost
                    port = 0
                }

                actor.deployment {
                  /router1 {
                    router = round-robin-pool
                    nr-of-instances = 3
                  }
                  /router2 {
                    router = round-robin-pool
                    nr-of-instances = 3
                  }
                  /router3 {
                    router = round-robin-pool
                    nr-of-instances = 0
                  }
                }
            }
")
        {
            _remoteSystem  = ActorSystem.Create("RemoteSystem", Sys.Settings.Config);
            _remoteAddress = _remoteSystem.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;
            var remoteAddressUid = AddressUidExtension.Uid(_remoteSystem);
        }
Example #6
0
        private IActorRef CreateTestActor(ActorSystem system, string name)
        {
            var testActorProps = Props.Create(() => new InternalTestActor(new BlockingCollectionTestActorQueue <MessageEnvelope>(_testState.Queue)))
                                 .WithDispatcher("akka.test.test-actor.dispatcher");
            var testActor = system.AsInstanceOf <ActorSystemImpl>().SystemActorOf(testActorProps, name);

            return(testActor);
        }
Example #7
0
 public TestConductor(ActorSystem system)
 {
     _settings = new TestConductorSettings(system.Settings.Config.WithFallback(TestConductorConfigFactory.Default())
                                           .GetConfig("akka.testconductor"));
     _transport = system.AsInstanceOf <ExtendedActorSystem>().Provider.AsInstanceOf <RemoteActorRefProvider>().Transport;
     _address   = _transport.DefaultAddress;
     _system    = system;
 }
Example #8
0
 public ConsistentHashingRoutingLogic(ActorSystem system, int virtualNodesFactor,
                                      ConsistentHashMapping hashMapping)
 {
     _system      = system;
     _log         = new Lazy <ILoggingAdapter>(() => Logging.GetLogger(_system, this), true);
     _hashMapping = hashMapping;
     _selfAddress = system.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;
     _vnodes      = virtualNodesFactor == 0 ? system.Settings.DefaultVirtualNodesFactor : virtualNodesFactor;
 }
        public void ActorSystem_IgnoreRef_should_return_a_serializable_ActorRef_that_can_be_sent_between_two_ActorSystems_using_remote()
        {
            var ignoreRef    = system1.IgnoreRef;
            var remoteRefStr = ignoreRef.Path.ToSerializationFormatWithAddress(system1.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress);

            remoteRefStr.Should().Be(IgnoreActorRef.StaticPath.ToString(), "check ActorRef path stays untouched, ie: /local/ignore");

            var providerSys2 = system2.AsInstanceOf <ExtendedActorSystem>().Provider;
            var deserRef     = providerSys2.ResolveActorRef(remoteRefStr);

            deserRef.Path.Should().Be(IgnoreActorRef.StaticPath, "check ActorRef path stays untouched when deserialized by another actor system");
            deserRef.Should().BeSameAs(system2.IgnoreRef, "check ActorRef path stays untouched when deserialized by another actor system");

            var surrogate      = ignoreRef.ToSurrogate(system1);
            var fromSurrogate1 = surrogate.FromSurrogate(system1);

            fromSurrogate1.Should().BeOfType <IgnoreActorRef>();
            ((IgnoreActorRef)fromSurrogate1).Path.Should().Be(system1.IgnoreRef.Path);
        }
Example #10
0
 public void Setup(BenchmarkContext context)
 {
     _actorSystem   = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message = new SerializedMessage {
         SerializerId = 0, Message = ByteString.CopyFromUtf8("foo")
     };
     _dispatcher     = new DefaultMessageDispatcher(_actorSystem.AsInstanceOf <ExtendedActorSystem>(), RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
Example #11
0
 public static string FromActorRef(IActorRef a, ActorSystem system)
 {
     try
     {
         return(a.Path.ToStringWithAddress(system.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress));
     }
     catch // can fail if the ActorSystem (remoting) is not completely started yet
     {
         return(a.Path.ToString());
     }
 }
Example #12
0
        protected void InjectDeployments(ActorSystem system, RoleName role)
        {
            var deployer = system.AsInstanceOf <ExtendedActorSystem>().Provider.Deployer;

            foreach (var str in _deployments(role))
            {
                var deployString = _replacements.Values.Aggregate(str, (@base, r) =>
                {
                    var indexOf = @base.IndexOf(r.Tag, StringComparison.Ordinal);
                    if (indexOf == -1)
                    {
                        return(@base);
                    }
                    string replaceWith;
                    try
                    {
                        replaceWith = r.Addr;
                    }
                    catch (Exception e)
                    {
                        // might happen if all test cases are ignored (excluded) and
                        // controller node is finished/exited before r.addr is run
                        // on the other nodes
                        var unresolved = "akka://unresolved-replacement-" + r.Role.Name;
                        Log.Warning(unresolved + " due to: {0}", e.ToString());
                        replaceWith = unresolved;
                    }
                    return(@base.Replace(r.Tag, replaceWith));
                });
                foreach (var pair in ConfigurationFactory.ParseString(deployString).AsEnumerable())
                {
                    if (pair.Value.IsObject())
                    {
                        var deploy =
                            deployer.ParseConfig(pair.Key, new Config(new HoconRoot(pair.Value)));
                        deployer.SetDeploy(deploy);
                    }
                    else
                    {
                        throw new ArgumentException(String.Format("key {0} must map to deployment section, not simple value {1}",
                                                                  pair.Key, pair.Value));
                    }
                }
            }
        }
Example #13
0
        protected StreamsTransport(ActorSystem system, Config config)
        {
            System = system;
            Config = config;

            Settings = StreamsTransportSettings.Create(Config);
            Log      = Logging.GetLogger(System, GetType());

            SchemeIdentifier = (Settings.EnableSsl ? "ssl." : string.Empty) + Settings.TransportMode.ToString().ToLowerInvariant();
            StreamSupervisor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf(
                Props.Create(() => new StreamsTransportSupervisor()), Uri.EscapeUriString(SchemeIdentifier) + "-supervisor");

            // block here and get access to the materializer used for creating
            // future stream actors
            StreamMaterializer = StreamSupervisor
                                 .Ask <IMaterializer>(StreamsTransportSupervisor.GetMaterializer.Instance, Settings.ConnectTimeout)
                                 .Result;
        }
        /// <summary>
        ///     Performs all of the setup and initialization needed to get the Zipkin HTTP reporting engine up and running.
        /// </summary>
        /// <param name="options">The set of options for configuring timeouts and batch sizes.</param>
        /// <param name="actorSystem">
        ///     Optional. If using Akka.NET, you can hook your own <see cref="ActorSystem" /> into our
        ///     reporting engine.
        /// </param>
        /// <returns></returns>
        public static ZipkinHttpSpanReporter Create(ZipkinHttpReportingOptions options, ActorSystem actorSystem = null)
        {
            // force this component to explode if the end-user screwed up the URI somehow.
            var uri = ZipkinHttpApiTransmitter.GetFullZipkinUri(options.ZipkinUrl);
            var weOwnActorSystem = false;

            if (actorSystem == null) // create our own ActorSystem if it doesn't already exist.
            {
                weOwnActorSystem = true;
                actorSystem      = ActorSystem.Create("pbzipkin",
                                                      options.DebugLogging ? DebugHocon : NormalHocon);
            }

            // spawn as a System actor, so in the event of being in a non-owned system our traces get shut down
            // only after all of the user-defined actors have terminated.
            var zipkinActor = actorSystem.AsInstanceOf <ExtendedActorSystem>().SystemActorOf(
                Props.Create(() => new HttpReportingActor(options)), $"zipkin-tracing-{NameCounter.GetAndIncrement()}");

            return(new ZipkinHttpSpanReporter(zipkinActor, weOwnActorSystem ? actorSystem : null));
        }
 public void Setup(BenchmarkContext context)
 {
     _system     = ActorSystem.Create($"ClusterMessageSerializerSpec-{Counter.GetAndIncrement()}");
     _serializer = new ClusterMessageSerializer(_system.AsInstanceOf <ExtendedActorSystem>());
     _serializationThroughput = context.GetCounter(SerializerCounterName);
 }
Example #16
0
        protected MultiNodeSpec(
            RoleName myself,
            ActorSystem system,
            ImmutableList<RoleName> roles,
            Func<RoleName, ImmutableList<string>> deployments)
            : base(new XunitAssertions(), system)
        {
            _myself = myself;
            _log = Logging.GetLogger(Sys, this);
            _roles = roles;
            _deployments = deployments;
            var node = new IPEndPoint(Dns.GetHostAddresses(ServerName)[0], ServerPort);
            _controllerAddr = node;

            AttachConductor(new TestConductor(system));

            _replacements = _roles.ToImmutableDictionary(r => r, r => new Replacement("@" + r.Name + "@", r, this));

            InjectDeployments(system, myself);

            _myAddress = system.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;

            Log.Info("Role [{0}] started with address [{1}]", myself.Name, _myAddress);
            MultiNodeSpecBeforeAll();
        }
Example #17
0
 protected void InjectDeployments(ActorSystem system, RoleName role)
 {
     var deployer = system.AsInstanceOf<ExtendedActorSystem>().Provider.Deployer;
     foreach (var str in _deployments(role))
     {
         var deployString = _replacements.Values.Aggregate(str, (@base, r) =>
         {
             var indexOf = @base.IndexOf(r.Tag, StringComparison.Ordinal);
             if (indexOf == -1) return @base;
             string replaceWith;
             try
             {
                 replaceWith = r.Addr;
             }
             catch (Exception e)
             {
                 // might happen if all test cases are ignored (excluded) and
                 // controller node is finished/exited before r.addr is run
                 // on the other nodes
                 var unresolved = "akka://unresolved-replacement-" + r.Role.Name;
                 Log.Warning(unresolved + " due to: {0}", e.ToString());
                 replaceWith = unresolved;
             }
             return @base.Replace(r.Tag, replaceWith);
         });
         foreach (var pair in ConfigurationFactory.ParseString(deployString).AsEnumerable())
         {
             if (pair.Value.IsObject())
             {
                 var deploy =
                     deployer.ParseConfig(pair.Key, new Config(new HoconRoot(pair.Value)));
                 deployer.SetDeploy(deploy);
             }
             else
             {
                 throw new ArgumentException(String.Format("key {0} must map to deployment section, not simple value {1}",
                     pair.Key, pair.Value));
             }
         }
     }
 }
Example #18
0
 static RemoteActorRefProvider RarpFor(ActorSystem system)
 {
     return(system.AsInstanceOf <ExtendedActorSystem>().Provider.AsInstanceOf <RemoteActorRefProvider>());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingRoutingLogic"/> class.
 /// </summary>
 /// <param name="system">The actor system that owns the router with this logic.</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingRoutingLogic(ActorSystem system, int virtualNodesFactor,
     ConsistentHashMapping hashMapping)
 {
     _system = system;
     _log = new Lazy<ILoggingAdapter>(() => Logging.GetLogger(_system, this), true);
     _hashMapping = hashMapping;
     _selfAddress = system.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;
     _vnodes = virtualNodesFactor == 0 ? system.Settings.DefaultVirtualNodesFactor : virtualNodesFactor;
 }
Example #20
0
 public void Setup(BenchmarkContext context)
 {
     System         = ActorSystem.Create("SerializationBenchmarks");
     _serialization = new Serialization.Serialization(System.AsInstanceOf <ExtendedActorSystem>());
     _findSerializerForTypeThroughput = context.GetCounter(CreateThroughputCounter);
 }