/** * <summary>This is called whenever there is a disconnect or a connect, the * idea is to determine if there is a new left or right node, if there is and * here is a pre-existing transfer, we must interupt it, and start a new * transfer.</summary> * <remarks>The possible scenarios where this would be active: * - no change on left * - new left node with no previous node (from disc or new node) * - left disconnect and new left ready * - left disconnect and no one ready * - no change on right * - new right node with no previous node (from disc or new node) * - right disconnect and new right ready * - right disconnect and no one ready * </remarks> * <param name="o">Unimportant</param> * <param name="eargs">Contains the ConnectionEventArgs, which lets us know * if this was a Structured Connection change and if it is, we should check * the state of the system to see if we have a new left or right neighbor. * </param> */ protected void ConnectionHandler(object o, EventArgs eargs) { if (!_online) { return; } ConnectionEventArgs cargs = eargs as ConnectionEventArgs; Connection old_con = cargs.Connection; //first make sure that it is a new StructuredConnection if (old_con.MainType != ConnectionType.Structured) { return; } lock (_transfer_sync) { if (!_online) { return; } ConnectionTable tab = _node.ConnectionTable; Connection lc = null, rc = null; try { lc = tab.GetLeftStructuredNeighborOf((AHAddress)_node.Address); } catch (Exception) {} try { rc = tab.GetRightStructuredNeighborOf((AHAddress)_node.Address); } catch (Exception) {} if (lc != null) { if (lc.Address != _left_addr) { if (_left_transfer_state != null) { _left_transfer_state.Interrupt(); _left_transfer_state = null; } _left_addr = lc.Address; if (Count > 0) { _left_transfer_state = new TransferState(lc, this); } } } else if (_left_addr != null) { if (_left_transfer_state != null) { _left_transfer_state.Interrupt(); _left_transfer_state = null; } _left_addr = null; } if (rc != null) { if (rc.Address != _right_addr) { if (_right_transfer_state != null) { _right_transfer_state.Interrupt(); _right_transfer_state = null; } _right_addr = rc.Address; if (Count > 0) { _right_transfer_state = new TransferState(rc, this); } } } else if (_right_addr != null) { if (_right_transfer_state != null) { _right_transfer_state.Interrupt(); _right_transfer_state = null; } _right_addr = null; } } }