/// <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> /// This method is used to create a matched pair of endpoints used by the Node Provider and /// the Node. The inputs and outputs for each node are automatically configured. /// </summary> /// <param name="mode">The communications mode for the endpoints.</param> /// <param name="host">The component host.</param> /// <returns>A matched pair of endpoints.</returns> internal static EndpointPair CreateInProcEndpoints(EndpointMode mode, IBuildComponentHost host) { NodeEndpointInProc node = new NodeEndpointInProc(mode, host); NodeEndpointInProc manager = new NodeEndpointInProc(mode, host); // NOTE: This creates a circular reference which must be explicitly broken before these // objects can be reclaimed by the garbage collector. node._peerEndpoint = manager; manager._peerEndpoint = node; return(new EndpointPair(node, manager)); }
private NodeEndpointInProc.EndpointPair SetupConnection(NodeEndpointInProc.EndpointMode mode) { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints(mode, _host); endpoints.ManagerEndpoint.OnLinkStatusChanged += LinkStatusChanged; endpoints.NodeEndpoint.OnLinkStatusChanged += LinkStatusChanged; // Call listen. This shouldn't have any effect on the link statuses. endpoints.ManagerEndpoint.Listen(_host); endpoints.NodeEndpoint.Connect(_host); return endpoints; }
private void VerifyLinksAndCallbacksInactive(NodeEndpointInProc.EndpointPair endpoints) { CallOpOnEndpoints(endpoints, VerifyLinkInactive); Assert.IsTrue(_linkStatusTable[endpoints.NodeEndpoint].status == LinkStatus.Inactive); Assert.IsTrue(_linkStatusTable[endpoints.ManagerEndpoint].status == LinkStatus.Inactive); }
private void DisconnectionTestHelper(NodeEndpointInProc.EndpointMode mode) { NodeEndpointInProc.EndpointPair endpoints = SetupConnection(mode); endpoints.ManagerEndpoint.Disconnect(); VerifyLinksAndCallbacksInactive(endpoints); endpoints = SetupConnection(mode); endpoints.NodeEndpoint.Disconnect(); VerifyLinksAndCallbacksInactive(endpoints); }
private void VerifyConnectCallSuccess(NodeEndpointInProc endpoint) { endpoint.Connect(_host); Assert.IsTrue(endpoint.LinkStatus == LinkStatus.Active); }
private void VerifyListenCallSuccess(NodeEndpointInProc endpoint) { endpoint.Listen(_host); }
private void VerifyDisconnectInvalidOperation(NodeEndpointInProc endpoint) { bool caught = false; try { endpoint.Disconnect(); } catch (InternalErrorException) { caught = true; } Assert.IsTrue(caught, "Did not receive InternalErrorException."); }
private void VerifySendDataInvalidOperation(NodeEndpointInProc endpoint) { bool caught = false; try { endpoint.SendData(new TestPacket()); } catch (InternalErrorException) { caught = true; } Assert.IsTrue(caught, "Did not receive InternalErrorException."); }
private void VerifyLinkActive(NodeEndpointInProc endpoint) { Assert.IsTrue(endpoint.LinkStatus == LinkStatus.Active, "Expected LinkStatus to be Active"); }
private void CallOpOnEndpoints(NodeEndpointInProc.EndpointPair pair, EndpointOperationDelegate opDelegate) { opDelegate(pair.NodeEndpoint); opDelegate(pair.ManagerEndpoint); }
/// <summary> /// Creates an endpoint pair /// </summary> /// <param name="node">The node-side endpoint.</param> /// <param name="manager">The manager-side endpoint.</param> internal EndpointPair(NodeEndpointInProc node, NodeEndpointInProc manager) { NodeEndpoint = node; ManagerEndpoint = manager; }
private void VerifyLinkActive(NodeEndpointInProc endpoint) { Assert.Equal(endpoint.LinkStatus, LinkStatus.Active); // "Expected LinkStatus to be Active" }
/// <summary> /// This method is used to create a matched pair of endpoints used by the Node Provider and /// the Node. The inputs and outputs for each node are automatically configured. /// </summary> /// <param name="mode">The communications mode for the endpoints.</param> /// <param name="host">The component host.</param> /// <returns>A matched pair of endpoints.</returns> internal static EndpointPair CreateInProcEndpoints(EndpointMode mode, IBuildComponentHost host) { NodeEndpointInProc node = new NodeEndpointInProc(mode, host); NodeEndpointInProc manager = new NodeEndpointInProc(mode, host); // NOTE: This creates a circular reference which must be explicitly broken before these // objects can be reclaimed by the garbage collector. node._peerEndpoint = manager; manager._peerEndpoint = node; return new EndpointPair(node, manager); }