public VivaldiTargetSelector(Node n, NCService service) {
_sync = new object();
_channel_to_state = new Hashtable();
_node = n;
_nc_service = service;
_num_requests = 0;
#if VTS_DEBUG
lock(_sync) {
_node.StateChangeEvent += delegate(Node node, Node.ConnectionState s) {
if( s == Node.ConnectionState.Joining ) {
lock(_class_lock) {
_vts_nodes[node] = null;
if (_vts_nodes.Keys.Count == 1) { //first node
Console.Error.WriteLine("Starting the VTS checkpoint thread. ");
_checkpoint_thread = new Thread(CheckpointThread);
_checkpoint_thread_finished = 0;
_checkpoint_thread.Start();
}
}
}
};
_node.StateChangeEvent += delegate(Node node, Node.ConnectionState s) {
if( s == Node.ConnectionState.Disconnected ) {
lock(_class_lock) {
_vts_nodes.Remove(node);
if (_vts_nodes.Keys.Count == 0) { //last node to leave
Console.Error.WriteLine("Interrupting the VTS checkpoint thread. ");
Interlocked.Exchange(ref _checkpoint_thread_finished, 1);
_checkpoint_thread.Interrupt();
_checkpoint_thread.Join();
Console.Error.WriteLine("Join with the VTS checkpoint thread (finished).");
}
}
}
};
}
#endif
}