Provides a wrapper for the creation of new Edges via ECB and EdgeEvent.
Пример #1
0
        ///<summary>This is called when one of our edges closes.  This handles
        ///removing the state from the EdgeListener as necessary.</summary>
        protected void EdgeClose(object o, EventArgs ea)
        {
            Edge e = o as Edge;

            if (e == null)
            {
                throw new Exception("Needs to be an Edge");
            }

            EdgeCreationWrapper ecw = null;
            WrapperEdge         we  = null;

            lock (_sync) {
                if (_edge_to_ecw.ContainsKey(e))
                {
                    ecw = _edge_to_ecw[e];
                    _edge_to_ecw.Remove(e);
                }
                else if (_edge_to_wrapper_edge.ContainsKey(e))
                {
                    we = _edge_to_wrapper_edge[e];
                    _edge_to_wrapper_edge.Remove(e);
                }
            }

            if (ecw != null)
            {
                ecw.CreationCallback(false, null, new EdgeException("Close on unwrapped edge!"));
            }
            else if (we != null)
            {
                we.Close();
            }
        }
Пример #2
0
        ///<summary>When the edge is finally wrapped, this is called to finalize
        ///the adding of the edge to the edgelistner.</summary>
        protected void Finalize(WrapperEdge wedge)
        {
            EdgeCreationWrapper ecw = null;

            lock (_sync) {
                if (_edge_to_ecw.ContainsKey(wedge.WrappedEdge))
                {
                    ecw = _edge_to_ecw[wedge.WrappedEdge];
                    _edge_to_ecw.Remove(wedge.WrappedEdge);
                    _edge_to_wrapper_edge[wedge.WrappedEdge] = wedge;
                }
                else
                {
                    throw new Exception("No record of edge");
                }
            }

            // if ecw is null, that means someone else failed before we announced
            // furthermore, we now have a wedge that needs to be manually closed!
            if (ecw != null)
            {
                ecw.CreationCallback(true, wedge, null);
            }
            else
            {
                wedge.Close();
            }
        }
Пример #3
0
        ///<summary>A new edge has been created!  This comes from the underlying
        ///EL's SendEdgeEvent.</summary>
        protected void HandleEdgeEvent(object edge, EventArgs ea)
        {
            Edge e = edge as Edge;

            if (e == null)
            {
                throw new Exception("Not an Edge!");
            }
            EdgeCreationWrapper ecw = new EdgeCreationWrapper(null, SendEdgeEventHelper, e, this);

            AddEdge(ecw);
        }
Пример #4
0
        ///<summary>A new underlying edge has been created, this is used to add the
        ///edge to the EdgeListener for handling and to wrap the edge.</summary>
        public void AddEdge(EdgeCreationWrapper ecw)
        {
            Edge e = ecw.Edge;

            lock (_sync) {
                _edge_to_ecw[e] = ecw;
            }

            try {
                e.CloseEvent += EdgeClose;
            } catch {
                EdgeClose(e, null);
            }

            if (!e.IsClosed)
            {
                WrapEdge(ecw.Edge);
            }
        }
Пример #5
0
        ///<summary>This handles the RequestClose of the underlying edge.</summary>
        ///<remarks>
        /// The convoluted model for handling edge closes is this...
        /// I) UEL calls RequestClose
        ///  1) Triggers HandleEdgeCloseRequestEvent
        ///  2) If there is a wrapper edge, call RequestClose on it
        ///  3) If there isn't a wrapper edge, we are forced to simply close the edge and send a failed ecw
        /// II) A wrapper edge is responsible for calling edge close on the wrapped edge on edge close
        /// III) if an wrapped edge calls close, we are notified via an event, that will send a failed ecw or close the wrapper edge
        /// </remarks>
        protected void HandleEdgeCloseRequestEvent(object el, EventArgs ea)
        {
            EdgeCloseRequestArgs ecra = ea as EdgeCloseRequestArgs;

            if (ecra == null)
            {
                throw new Exception("Not an EdgeCloseRequestArgs!");
            }
            EdgeCreationWrapper ecw = null;
            Edge e = null;

            lock (_sync) {
                if (_edge_to_ecw.ContainsKey(ecra.Edge))
                {
                    ecw = _edge_to_ecw[ecra.Edge];
                    _edge_to_ecw.Remove(ecra.Edge);
                }
                else if (_edge_to_wrapper_edge.ContainsKey(ecra.Edge))
                {
                    e = _edge_to_wrapper_edge[ecra.Edge];
                    _edge_to_wrapper_edge.Remove(ecra.Edge);
                }
            }

            if (e != null)
            {
                RequestClose(e);
            }
            else
            {
                ecra.Edge.Close();
                if (ecw != null)
                {
                    ecw.CreationCallback(false, null, new EdgeException("Requested close on an unwrapped edge."));
                }
            }
        }
Пример #6
0
        ///<summary>This wraps the underlying CreateEdgeTo using EdgeCreationWrappers</summary>
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            EdgeCreationWrapper ecw = new EdgeCreationWrapper(ta, ecb, null, this);

            _el.CreateEdgeTo(ta, ecw.Callback);
        }