예제 #1
0
 public TcpConnection(string id, string address, int port, ExponentialDelayPolicy policy, ILogger logger = null)
 {
     this.id      = id;
     this.address = address;
     this.port    = port;
     this.policy  = policy;
     this.logger  = logger;
 }
예제 #2
0
 public SlaveChannel(Slave slave, ILogger logger = null)
 {
     this.slave  = slave;
     this.logger = logger;
     SlaveId     = slave.UnitId;
     mapper      = new MbapMapper(Guid.NewGuid().ToString());
     delayPolicy = new ExponentialDelayPolicy(30000, 2, true);
     retryPolicy = new BasicRetryPolicy(delayPolicy, 5);
     CreateChannelAsync().GetAwaiter();
 }
예제 #3
0
        public async Task RunAsync()
        {
            if (config == null || string.IsNullOrEmpty(config.Hostname))
            {
                return;
            }

            ExponentialDelayPolicy policy = new ExponentialDelayPolicy(180);

            foreach (var slave in config.Slaves)
            {
                string        id         = Guid.NewGuid().ToString();
                TcpConnection connection = new TcpConnection(id, slave.IPAddress, slave.Port, policy, logger);
                connection.OnReceived += Connection_OnReceived;
                connections.Add(slave.UnitId, new Tuple <TcpConnection, byte?>(connection, slave.Alias));
                await connection.OpenAsync();
            }
        }
예제 #4
0
 public BasicRetryPolicy(ExponentialDelayPolicy delayPolicy, int maxRetries)
 {
     this.delayPolicy = delayPolicy;
     max = maxRetries;
 }