/// <summary> /// 创建一个双机热备的 malock 服务器 /// </summary> public MalockServer(MalockConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration it cannot be considered a null"); } this.configuration = configuration; this.malockEngine = new MalockEngine(configuration); this.malockListener = new MalockSocketListener(configuration.Port); do { this.onAboredHandler = this.ProcessAborted; this.onReceivedHandler = this.ProcessReceived; this.malockListener.Accept += (sender, e) => { MalockSocket socket = (MalockSocket)e; lock (socket) { socket.Received += this.onReceivedHandler; socket.Aborted += this.onAboredHandler; socket.Connected += this.onConnectedHandler; socket.Run(); } }; } while (false); this.onConnectedHandler = (sender, e) => this.ProcessAccept(sender, (MalockSocket)sender); }
protected virtual string GetAddress(MalockConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } return(configuration.StandbyNode); }
public MalockEngine(MalockConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } this.configuration = configuration; this.malockTable = new MalockTable(); this.malockTaskPoll = new MalockTaskPoll(this); this.malockNnsClient = new MalockNnsClient(configuration); this.malockStandbyClient = new MalockStandbyClient(this, configuration); }
public MalockStandbyClient(MalockEngine engine, MalockConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (engine == null) { throw new ArgumentNullException("engine"); } this.configuration = configuration; this.engine = engine; do { this.Identity = configuration.Identity; this.Address = this.GetAddress(configuration); this.listenport = configuration.Port; } while (false); this.socket = new MalockInnetSocket(this.Identity, this.Address, this.GetListenPort(), MalockMessage.LINK_MODE_SERVER); this.socket.Received += this.OnReceived; this.socket.Connected += this.OnConnected; this.socket.Aborted += this.OnAborted; this.socket.Run(); }
protected override int GetListenPort() { MalockConfiguration configuration = (MalockConfiguration)this.GetStateObject(); return(configuration.Port); }
internal MalockNnsClient(MalockConfiguration configuration) : base(configuration.NnsId, configuration.NnsNode, configuration.NnsStandbyNode, configuration) { this.configuration = configuration; base.Run(); }