Ejemplo n.º 1
0
        public void TestDynamicInstanceRegister()
        {
            InstanceRepository     repository = new InstanceRepository(Constants.RegistryClientConfig);
            CustomInstanceRegistry registry   = new CustomInstanceRegistry(repository, Constants.RegistryClientConfig);

            Instance[] instances = new Instance[] { Constants.NewInstance(), Constants.NewInstance() };
            repository.Update(instances, RegisterType.register);
            HashSet <Instance> instancesSet = new HashSet <Instance>();

            while (registry.FailedInstances.Count == 0)
            {
                Threads.Sleep(10);
            }
            registry.FailedInstances.ForEach(failedInstance =>
            {
                instancesSet.Add(failedInstance.Instance);
            });
            Assert.AreEqual(instancesSet.Count, instances.Length);
            foreach (Instance instance in instances)
            {
                Assert.IsTrue(instancesSet.Contains(instance));
            }
            while (registry.AcceptHeartbeats < 1 || registry.SendHeartbeats < 1)
            {
                Threads.Sleep(500);
            }
        }
Ejemplo n.º 2
0
        public RegistryClientImpl(string clientId, ArtemisClientManagerConfig managerConfig)
        {
            Preconditions.CheckArgument(!string.IsNullOrWhiteSpace(clientId), "clientId");
            Preconditions.CheckArgument(managerConfig != null, "manager config");
            ArtemisClientConfig clientConfig = new ArtemisClientConfig(clientId, managerConfig,
                                                                       AddressManager.NewRegistryAddressManager(clientId, managerConfig));

            this._instanceRepository = new InstanceRepository(clientConfig);
            this._instanceRegistry   = new InstanceRegistry(_instanceRepository, clientConfig);
        }
Ejemplo n.º 3
0
        public InstanceRegistry(InstanceRepository instanceRepository, ArtemisClientConfig config)
        {
            Preconditions.CheckArgument(instanceRepository != null, "instance repository");
            Preconditions.CheckArgument(config != null, "config");
            _instanceRepository = instanceRepository;
            _ttl      = config.ConfigurationManager.GetProperty(config.Key("instance-registry.instance-ttl"), 20 * 1000, 5 * 1000, 24 * 60 * 60 * 1000);
            _interval = config.ConfigurationManager.GetProperty(config.Key("instance-registry.heartbeat-interval"), 5 * 1000, 500, 5 * 60 * 1000);

            Action <WebSocket> onOpen = (webSocket) => {
            };
            Action <WebSocket, MessageEventArgs> onMessage = (webSocket, message) =>
            {
                AcceptHeartbeat(message);
            };

            _sessionContext = new WebSocketSessionContext(config, onOpen, onMessage);

            var heartbeatStatusMetricConfig = new MetricConfig(new Dictionary <string, string>()
            {
                { "metric_name_distribution", config.Key("heartbeat.event.distribution") }
            });

            _heartbeatStatus         = config.EventMetricManager.GetMetric(config.Key("heartbeat.event"), heartbeatStatusMetricConfig);
            _prepareHeartbeatLatency = config.AuditMetricManager.GetMetric(config.Key("heartbeat.prepare-latency"), new MetricConfig(new Dictionary <string, string>()
            {
                { "metric_name_distribution", config.Key("heartbeat.prepare-latency.distribution") }
            }));
            _sendHeartbeatLatency = config.AuditMetricManager.GetMetric(config.Key("heartbeat.send-latency"), new MetricConfig(new Dictionary <string, string>()
            {
                { "metric_name_distribution", config.Key("heartbeat.send-latency.distribution") }
            }));
            _acceptHeartbeatLatency = config.AuditMetricManager.GetMetric(config.Key("heartbeat.accept-latency"), new MetricConfig(new Dictionary <string, string>()
            {
                { "metric_name_distribution", config.Key("heartbeat.accept-latency.distribution") }
            }));

            _heartbeater = new DynamicTimer(config.ConfigurationManager.GetProperty(config.Key("instances-registry.heartbeat-interval.dynamic-scheduled-thread.run-interval"), 1000, 500, 90 * 1000),
                                            () =>
            {
                CheckHeartbeat();
            });
        }
Ejemplo n.º 4
0
 public CustomInstanceRegistry(InstanceRepository instanceRepository, ArtemisClientConfig config)
     : base(instanceRepository, config)
 {
 }