Exemple #1
0
 internal void DoAfterFlush(DocumentsWriterPerThread dwpt)
 {
     lock (this)
     {
         Debug.Assert(flushingWriters.ContainsKey(dwpt));
         try
         {
             long?bytes = flushingWriters[dwpt];
             flushingWriters.Remove(dwpt);
             flushBytes -= (long)bytes;
             perThreadPool.Recycle(dwpt);
             Debug.Assert(AssertMemory());
         }
         finally
         {
             try
             {
                 UpdateStallState();
             }
             finally
             {
                 Monitor.PulseAll(this);
             }
         }
     }
 }
        /* Add a new shutdown hook.  Checks the shutdown state and the hook itself,
         * but does not do any security checks.
         */
        internal static void Add(Thread hook)
        {
            lock (typeof(ApplicationShutdownHooks))
            {
                if (Hooks == null)
                {
                    throw new IllegalStateException("Shutdown in progress");
                }

                if (hook.Alive)
                {
                    throw new IllegalArgumentException("Hook already running");
                }

                if (Hooks.ContainsKey(hook))
                {
                    throw new IllegalArgumentException("Hook previously registered");
                }

                Hooks.Put(hook, hook);
            }
        }
        private static String ToDotString(PredictionContext context)
        {
            StringBuilder nodes = new StringBuilder();
            StringBuilder edges = new StringBuilder();
            IDictionary <PredictionContext, PredictionContext> visited = new IdentityHashMap <PredictionContext, PredictionContext>();
            IDictionary <PredictionContext, int> contextIds            = new IdentityHashMap <PredictionContext, int>();
            Stack <PredictionContext>            workList = new Stack <PredictionContext>();

            visited[context]    = context;
            contextIds[context] = contextIds.Count;
            workList.Push(context);
            while (workList.Count > 0)
            {
                PredictionContext current = workList.Pop();
                nodes.Append("  s").Append(contextIds[current]).Append('[');

                if (current.Size > 1)
                {
                    nodes.Append("shape=record, ");
                }

                nodes.Append("label=\"");

                if (current.IsEmpty)
                {
                    nodes.Append(PredictionContext.IsEmptyLocal(current) ? '*' : '$');
                }
                else if (current.Size > 1)
                {
                    for (int i = 0; i < current.Size; i++)
                    {
                        if (i > 0)
                        {
                            nodes.Append('|');
                        }

                        nodes.Append("<p").Append(i).Append('>');
                        if (current.GetReturnState(i) == PredictionContext.EmptyFullStateKey)
                        {
                            nodes.Append('$');
                        }
                        else if (current.GetReturnState(i) == PredictionContext.EmptyLocalStateKey)
                        {
                            nodes.Append('*');
                        }
                    }
                }
                else
                {
                    nodes.Append(contextIds[current]);
                }

                nodes.AppendLine("\"];");

                for (int i = 0; i < current.Size; i++)
                {
                    if (current.GetReturnState(i) == PredictionContext.EmptyFullStateKey ||
                        current.GetReturnState(i) == PredictionContext.EmptyLocalStateKey)
                    {
                        continue;
                    }

                    if (!visited.ContainsKey(current.GetParent(i)))
                    {
                        visited[current.GetParent(i)]    = current.GetParent(i);
                        contextIds[current.GetParent(i)] = contextIds.Count;
                        workList.Push(current.GetParent(i));
                    }

                    edges.Append("  s").Append(contextIds[current]);
                    if (current.Size > 1)
                    {
                        edges.Append(":p").Append(i);
                    }

                    edges.Append("->");
                    edges.Append('s').Append(contextIds[current.GetParent(i)]);
                    edges.Append("[label=\"").Append(current.GetReturnState(i)).Append("\"]");
                    edges.AppendLine(";");
                }
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("digraph G {");
            builder.AppendLine("rankdir=LR;");
            builder.Append(nodes);
            builder.Append(edges);
            builder.AppendLine("}");
            return(builder.ToString());
        }