internal GatewayConnection(Uri address, ClientMessageCenter mc, MessageFactory messageFactory, ExecutorService executorService, ILoggerFactory loggerFactory, TimeSpan openConnectionTimeout) : base("GatewayClientSender_" + address, mc.SerializationManager, executorService, loggerFactory) { this.messageFactory = messageFactory; this.openConnectionTimeout = openConnectionTimeout; Address = address; MsgCenter = mc; receiver = new GatewayClientReceiver(this, mc.SerializationManager, executorService, loggerFactory); lastConnect = new DateTime(); IsLive = true; }
public GatewayManager( ClientMessageCenter messageCenter, GatewayOptions gatewayOptions, IGatewayListProvider gatewayListProvider, ILoggerFactory loggerFactory) { this.messageCenter = messageCenter; this.gatewayOptions = gatewayOptions; knownDead = new Dictionary <Uri, DateTime>(); rand = new SafeRandom(); logger = loggerFactory.CreateLogger <GatewayManager>(); this.loggerFactory = loggerFactory; lockable = new object(); gatewayRefreshCallInitiated = false; ListProvider = gatewayListProvider; var knownGateways = ListProvider.GetGateways().GetResult(); if (knownGateways.Count == 0) { string gatewayProviderType = gatewayListProvider.GetType().FullName; string err = $"Could not find any gateway in {gatewayProviderType}. Orleans client cannot initialize."; logger.Error(ErrorCode.GatewayManager_NoGateways, err); throw new OrleansException(err); } logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways)); if (ListProvider is IGatewayListObservable) { ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this); } roundRobinCounter = this.gatewayOptions.PreferedGatewayIndex >= 0 ? this.gatewayOptions.PreferedGatewayIndex : rand.Next(knownGateways.Count); cachedLiveGateways = knownGateways; lastRefreshTime = DateTime.UtcNow; if (ListProvider.IsUpdatable) { gatewayRefreshTimer = new SafeTimer(this.loggerFactory.CreateLogger <SafeTimer>(), RefreshSnapshotLiveGateways_TimerCallback, null, this.gatewayOptions.GatewayListRefreshPeriod, this.gatewayOptions.GatewayListRefreshPeriod); } }