Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="publisher"></param>
        /// <param name="reader"></param>
        /// <param name="streamNumber"></param>
        public BoundedBlockingQueue ConnectNodes(TaskNode publisher, TaskNode reader, int streamNumber, int queueSize)
        {
            if (!reader.InType.IsAssignableFrom(publisher.OutTypes[streamNumber]))
            {
                throw new InvalidOperationException(String.Format("The in-stream of the reader ({1}) cannot be assigned from the publisher of type ({0})", publisher.OutTypes[streamNumber].Name, reader.InType.Name));
            }
            Type bbOfT = typeof(BoundedBlockingQueue <>).MakeGenericType(new Type[] { reader.InType });
            BoundedBlockingQueue stream = (BoundedBlockingQueue)Activator.CreateInstance(bbOfT, queueSize);

            publisher.ConnectOutStream(stream, streamNumber, reader.InType);
            reader.ConnectInStream(stream);
            if (String.IsNullOrEmpty(stream.Name))
            {
                stream.Name = String.Format("from '{0}' to '{1}'", publisher.Name, reader.Name);
            }
            _streams.Add(stream);
            stream.OwningFlow = this;
            return(stream);
        }
Exemplo n.º 2
0
        public void Stop()
        {
            if (Status == RunStatus.Running)
            {
                Status = RunStatus.Stopping;
            }
            Thread.Sleep(200);
            lock (_threads)
            {
                foreach (var t in _threads)
                {
                    if (t.ThreadState != ThreadState.WaitSleepJoin && t.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)
                    {
                        t.Abort();
                    }
                }
            }
            // Clear instream
            BoundedBlockingQueue queueIn = this.StreamIn as BoundedBlockingQueue;

            if (queueIn != null)
            {
                queueIn.CloseEntrance();
                while (queueIn.Count > 0)
                {
                    queueIn.ReceiveInner();
                }
            }
            // this.StreamIn. close entrance
            // clear all items in it
            if (Status == RunStatus.Stopping)
            {
                this.Status = RunStatus.Stopped;
            }
            this._threads.Clear();
            //Thread.CurrentThread.Abort();
            log.InfoFormat("Task '{0}' forcibly stopped", this.Name);
        }
Exemplo n.º 3
0
        internal static void ExtractNodesAndConnections(string art, IDictionary <char, TaskNode> nodes, Flow f)
        {
            char[,] artChars = ExtractMatrix(art);
            f.Art            = artChars;
            List <PositionedTask>       tasks       = GetTasks(artChars, nodes);
            List <PositionedConnection> connections = new List <PositionedConnection>();

            foreach (var task  in tasks)
            {
                f.AddNode(task.task, task.pos);
            }
            int totalUsed = 0;

            foreach (var task in tasks)
            {
                PositionedConnection conn = FindConnectionEnd(task, artChars);
                if (conn != null)
                {
                    while (ExpandConnection(conn, artChars))
                    {
                    }
                    ;
                    Position startPos = conn.track[conn.track.Count - 1];
                    char     start    = artChars[startPos.x, startPos.y];
                    conn.startPoint = new PositionedTask()
                    {
                        task = nodes[start], pos = startPos
                    };
                    int outNr = GetStreamNumber(conn, artChars);
                    BoundedBlockingQueue stream = f.ConnectNodes(conn.startPoint.task, conn.endPoint.task, outNr);
                    stream.InPoint = conn.track[1];
                    connections.Add(conn);
                    totalUsed += conn.track.Count - 1;
                }
            }
            foreach (Position p in GetJoinPosition(artChars))
            {
                PositionedConnection        joinedWith = connections.Where((PositionedConnection c) => c.track.Contains(p)).Single();
                List <PositionedConnection> conns      = FindConnectionJoin(p, artChars);
                foreach (var conn in conns)
                {
                    conn.endPoint = joinedWith.endPoint;
                    while (ExpandConnection(conn, artChars))
                    {
                    }
                    ;
                    Position startPos = conn.track[conn.track.Count - 1];
                    char     start    = artChars[startPos.x, startPos.y];
                    conn.startPoint = new PositionedTask()
                    {
                        task = nodes[start], pos = startPos
                    };
                    int outNr = GetStreamNumber(conn, artChars);
                    f.ConnectNodeByJoin(conn.startPoint.task, conn.endPoint.task, outNr);
                    connections.Add(conn);
                    totalUsed += conn.track.Count - 1; // both the end and begin point are already counted
                }
            }



            // after finding all connections, the total number of +, |, -, digits and letters should sum to the
            // total tracks + nr of tasks
            int usedSpots = art.ToCharArray().Count(c => { return("1234567890abcdefghijklmnopqrstuvwxyz-+#|<>^V".Contains(c)); });

            if (usedSpots != totalUsed + tasks.Count)
            {
                throw new InvalidOperationException("loose ends!");
            }
        }