/// <summary> /// Creates a new in-proc node. /// </summary> private bool InstantiateNode(INodePacketFactory factory) { ErrorUtilities.VerifyThrow(null == _inProcNode, "In Proc node already instantiated."); ErrorUtilities.VerifyThrow(null == _inProcNodeEndpoint, "In Proc node endpoint already instantiated."); NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints(NodeEndpointInProc.EndpointMode.Synchronous, _componentHost); _inProcNodeEndpoint = endpoints.ManagerEndpoint; _inProcNodeEndpoint.OnLinkStatusChanged += new LinkStatusChangedDelegate(InProcNodeEndpoint_OnLinkStatusChanged); _packetFactory = factory; _inProcNode = new InProcNode(_componentHost, endpoints.NodeEndpoint); _inProcNodeThread = new Thread(InProcNodeThreadProc, BuildParameters.ThreadStackSize); _inProcNodeThread.Name = String.Format(CultureInfo.CurrentCulture, "In-proc Node ({0})", _componentHost.Name); _inProcNodeThread.IsBackground = true; _inProcNodeThread.CurrentCulture = _componentHost.BuildParameters.Culture; _inProcNodeThread.CurrentUICulture = _componentHost.BuildParameters.UICulture; _inProcNodeThread.Start(); _inProcNodeEndpoint.Connect(this); int connectionTimeout = CommunicationsUtilities.NodeConnectionTimeout; bool connected = _endpointConnectedEvent.WaitOne(connectionTimeout, false); ErrorUtilities.VerifyThrow(connected, "In-proc node failed to start up within {0}ms", connectionTimeout); return(true); }
private void LinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { lock (_linkStatusTable) { _linkStatusTable[endpoint] = new LinkStatusContext(Thread.CurrentThread, status); } }
public Request(TracerBroadcaster tracerBroadcaster, INodeEndpoint endpoint, INodeEndpointProtocolRequest request, Guid guid, string method, XElement body) { this.tracerBroadcaster = tracerBroadcaster; this.endpoint = endpoint; this.request = request; this.guid = guid; this.method = method; this.body = body; }
/// <summary> /// Callback invoked when the link status of the endpoint has changed. /// </summary> /// <param name="endpoint">The endpoint whose status has changed.</param> /// <param name="status">The new link status.</param> private void InProcNodeEndpoint_OnLinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { if (status == LinkStatus.Active) { // We don't verify this outside of the 'if' because we don't care about the link going down, which will occur // after we have cleared the inProcNodeEndpoint due to shutting down the node. ErrorUtilities.VerifyThrow(endpoint == _inProcNodeEndpoint, "Received link status event for a node other than our peer."); _endpointConnectedEvent.Set(); } }
/// <summary> /// Event handler for the node endpoint's LinkStatusChanged event. /// </summary> private void OnLinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { switch (status) { case LinkStatus.ConnectionFailed: case LinkStatus.Failed: _shutdownReason = NodeEngineShutdownReason.ConnectionFailed; _shutdownEvent.Set(); break; case LinkStatus.Inactive: break; } }
/// <summary> /// Constructor. /// </summary> public InProcNode(IBuildComponentHost componentHost, INodeEndpoint inProcNodeEndpoint) { _componentHost = componentHost; _nodeEndpoint = inProcNodeEndpoint; _receivedPackets = new ConcurrentQueue <INodePacket>(); _packetReceivedEvent = new AutoResetEvent(false); _shutdownEvent = new AutoResetEvent(false); _buildRequestEngine = componentHost.GetComponent(BuildComponentType.RequestEngine) as IBuildRequestEngine; _engineExceptionEventHandler = OnEngineException; _newConfigurationRequestEventHandler = OnNewConfigurationRequest; _requestBlockedEventHandler = OnNewRequest; _requestCompleteEventHandler = OnRequestComplete; }
public static INodeEndpointProtocolServer WaitForServer( this INodeEndpointProtocolServerListener serverListener, string address, INodeEndpoint endpoint, int timeout = DefaultTimeout ) { INodeEndpointProtocolServer server = WaitForServerBase(serverListener, address, endpoint, timeout); if (server != null) { server.BeginListen(); } return(server); }
/// <summary> /// Constructor. /// </summary> public InProcNode(IBuildComponentHost componentHost, INodeEndpoint inProcNodeEndpoint) { _componentHost = componentHost; _nodeEndpoint = inProcNodeEndpoint; _receivedPackets = new Queue <INodePacket>(); _packetReceivedEvent = new AutoResetEvent(false); _shutdownEvent = new AutoResetEvent(false); _configurationProjectsLoaded = new HashSet <NGen <int> >(); _buildRequestEngine = componentHost.GetComponent(BuildComponentType.RequestEngine) as IBuildRequestEngine; _engineExceptionEventHandler = new EngineExceptionDelegate(OnEngineException); _newConfigurationRequestEventHandler = new NewConfigurationRequestDelegate(OnNewConfigurationRequest); _requestBlockedEventHandler = new RequestBlockedDelegate(OnNewRequest); _requestCompleteEventHandler = new RequestCompleteDelegate(OnRequestComplete); }
private static INodeEndpointProtocolServer WaitForServerBase( this INodeEndpointProtocolServerListener serverListener, string address, INodeEndpoint endpoint, int timeout ) { if (!serverListener.Connected) { serverListener.Connect(address, endpoint.EndpointName); } INodeEndpointProtocolServer server = serverListener.Listen(timeout); if (server != null) { INodeEndpointProtocolRequestListener endpointListener = new ProtocolEnabledRequestListener(endpoint); server.AddListener(endpointListener); } return(server); }
/// <summary> /// Routes a packet. /// </summary> /// <param name="nodeId">The id of the node from which the packet is being routed.</param> /// <param name="packet">The packet to route.</param> public void RoutePacket(int nodeId, INodePacket packet) { INodePacketFactory factory = _packetFactory; if (_inProcNodeId != InvalidInProcNodeId) { // If this was a shutdown packet, we are done with the node. Release all context associated with it. Do this here, rather // than after we route the packet, because otherwise callbacks to the NodeManager to determine if we have available nodes // will report that the in-proc node is still in use when it has actually shut down. int savedInProcNodeId = _inProcNodeId; if (packet.Type == NodePacketType.NodeShutdown) { _inProcNodeId = InvalidInProcNodeId; // Release the operating environment semaphore if we were holding it. if ((_componentHost.BuildParameters.SaveOperatingEnvironment) && (_inProcNodeOwningOperatingEnvironment != null)) { _inProcNodeOwningOperatingEnvironment.Release(); _inProcNodeOwningOperatingEnvironment.Close(); _inProcNodeOwningOperatingEnvironment = null; } if (!_componentHost.BuildParameters.EnableNodeReuse) { _inProcNode = null; _inProcNodeEndpoint = null; _inProcNodeThread = null; _packetFactory = null; } } // Route the packet back to the NodeManager. factory.RoutePacket(savedInProcNodeId, packet); } }
private void LinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { lock (_linkStatusTable) { _linkStatusTable[endpoint] = new LinkStatusContext(Thread.CurrentThread, status); } }
/// <summary> /// Event handler for the node endpoint's LinkStatusChanged event. /// </summary> private void OnLinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { switch (status) { case LinkStatus.ConnectionFailed: case LinkStatus.Failed: _shutdownReason = NodeEngineShutdownReason.ConnectionFailed; _shutdownEvent.Set(); break; case LinkStatus.Inactive: break; default: break; } }
/// <summary> /// Callback invoked when the link status of the endpoint has changed. /// </summary> /// <param name="endpoint">The endpoint whose status has changed.</param> /// <param name="status">The new link status.</param> private void InProcNodeEndpoint_OnLinkStatusChanged(INodeEndpoint endpoint, LinkStatus status) { if (status == LinkStatus.Active) { // We don't verify this outside of the 'if' because we don't care about the link going down, which will occur // after we have cleared the inProcNodeEndpoint due to shutting down the node. ErrorUtilities.VerifyThrow(endpoint == _inProcNodeEndpoint, "Received link status event for a node other than our peer."); _endpointConnectedEvent.Set(); } }
/// <summary> /// Creates a new in-proc node. /// </summary> private bool InstantiateNode(INodePacketFactory factory) { ErrorUtilities.VerifyThrow(null == _inProcNode, "In Proc node already instantiated."); ErrorUtilities.VerifyThrow(null == _inProcNodeEndpoint, "In Proc node endpoint already instantiated."); NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints(NodeEndpointInProc.EndpointMode.Synchronous, _componentHost); _inProcNodeEndpoint = endpoints.ManagerEndpoint; _inProcNodeEndpoint.OnLinkStatusChanged += new LinkStatusChangedDelegate(InProcNodeEndpoint_OnLinkStatusChanged); _packetFactory = factory; _inProcNode = new InProcNode(_componentHost, endpoints.NodeEndpoint); _inProcNodeThread = new Thread(InProcNodeThreadProc, BuildParameters.ThreadStackSize); _inProcNodeThread.Name = String.Format(CultureInfo.CurrentCulture, "In-proc Node ({0})", _componentHost.Name); _inProcNodeThread.IsBackground = true; _inProcNodeThread.CurrentCulture = _componentHost.BuildParameters.Culture; _inProcNodeThread.CurrentUICulture = _componentHost.BuildParameters.UICulture; _inProcNodeThread.Start(); _inProcNodeEndpoint.Connect(this); int connectionTimeout = CommunicationsUtilities.NodeConnectionTimeout; bool connected = _endpointConnectedEvent.WaitOne(connectionTimeout, false); ErrorUtilities.VerifyThrow(connected, "In-proc node failed to start up within {0}ms", connectionTimeout); return true; }
/// <summary> /// Routes a packet. /// </summary> /// <param name="nodeId">The id of the node from which the packet is being routed.</param> /// <param name="packet">The packet to route.</param> public void RoutePacket(int nodeId, INodePacket packet) { INodePacketFactory factory = _packetFactory; if (_inProcNodeId != InvalidInProcNodeId) { // If this was a shutdown packet, we are done with the node. Release all context associated with it. Do this here, rather // than after we route the packet, because otherwise callbacks to the NodeManager to determine if we have available nodes // will report that the in-proc node is still in use when it has actually shut down. int savedInProcNodeId = _inProcNodeId; if (packet.Type == NodePacketType.NodeShutdown) { _inProcNodeId = InvalidInProcNodeId; // Release the operating environment semaphore if we were holding it. if ((_componentHost.BuildParameters.SaveOperatingEnvironment) && (_inProcNodeOwningOperatingEnvironment != null)) { _inProcNodeOwningOperatingEnvironment.Release(); _inProcNodeOwningOperatingEnvironment.Close(); _inProcNodeOwningOperatingEnvironment = null; } if (!_componentHost.BuildParameters.EnableNodeReuse) { _inProcNode = null; _inProcNodeEndpoint = null; _inProcNodeThread = null; _packetFactory = null; } } // Route the packet back to the NodeManager. factory.RoutePacket(savedInProcNodeId, packet); } }
public ProtocolEnabledRequestListener(INodeEndpoint endpoint) { this.endpoint = endpoint; this.tracers = new List <INodeEndpointProtocolRequestListenerTracer>(); this.tracerBroadcaster = new TracerBroadcaster(this.tracers); }
/// <summary> /// Constructor. /// </summary> public InProcNode(IBuildComponentHost componentHost, INodeEndpoint inProcNodeEndpoint) { _componentHost = componentHost; _nodeEndpoint = inProcNodeEndpoint; _receivedPackets = new Queue<INodePacket>(); _packetReceivedEvent = new AutoResetEvent(false); _shutdownEvent = new AutoResetEvent(false); _configurationProjectsLoaded = new HashSet<NGen<int>>(); _buildRequestEngine = componentHost.GetComponent(BuildComponentType.RequestEngine) as IBuildRequestEngine; _engineExceptionEventHandler = new EngineExceptionDelegate(OnEngineException); _newConfigurationRequestEventHandler = new NewConfigurationRequestDelegate(OnNewConfigurationRequest); _requestBlockedEventHandler = new RequestBlockedDelegate(OnNewRequest); _requestCompleteEventHandler = new RequestCompleteDelegate(OnRequestComplete); }