Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.server;
 
 
 
 import java.util.List;
 
 import static com.facebook.presto.server.ThreadResource.Info.byName;
 import static com.google.common.io.Resources.getResource;
 
 @Path("/")
 public class ThreadResource
 {
     @GET
     @Path("/ui/thread")
     public String getUi()
             throws IOException
     {
         return Resources.toString(getResource(getClass(), "thread.html"), .);
     }
 
     @GET
     @Path("/v1/thread")
     public List<InfogetThreadInfo()
     {
         ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
 
         ImmutableList.Builder<Infobuilder = ImmutableList.builder();
         for (ThreadInfo info : mbean.getThreadInfo(mbean.getAllThreadIds(), .)) {
             builder.add(new Info(
                     info.getThreadId(),
                     info.getThreadName(),
                     info.getThreadState().name(),
                     info.getLockOwnerId() == -1 ? null : info.getLockOwnerId(),
                     toStackTrace(info.getStackTrace())));
         }
         return Ordering.from(byName()).sortedCopy(builder.build());
     }
 
     private static List<StackLinetoStackTrace(StackTraceElement[] stackTrace)
     {
         ImmutableList.Builder<StackLinebuilder = ImmutableList.builder();
 
         for (StackTraceElement item : stackTrace) {
             builder.add(new StackLine(
                     item.getFileName(),
                     item.getLineNumber(),
                     item.getClassName(),
                     item.getMethodName()));
         }
 
         return builder.build();
     }
 
     public static class Info
     {
         private final long id;
         private final String name;
         private final String state;
         private final Long lockOwnerId;
         private final List<StackLinestackTrace;
 
         @JsonCreator
         public Info(
                 @JsonProperty("id"long id,
                 @JsonProperty("name"String name,
                 @JsonProperty("state"String state,
                 @JsonProperty("lockOwner"Long lockOwnerId,
                 @JsonProperty("stackTrace"List<StackLinestackTrace)
         {
            this. = id;
            this. = name;
            this. = state;
            this. = lockOwnerId;
            this. = stackTrace;
        }
        @JsonProperty
        public long getId()
        {
            return ;
        }
        @JsonProperty
        public String getName()
        {
            return ;
        }
        @JsonProperty
        public String getState()
        {
            return ;
        }
        @JsonProperty
        public Long getLockOwnerId()
        {
            return ;
        }
        @JsonProperty
        public List<StackLinegetStackTrace()
        {
            return ;
        }
        public static Comparator<InfobyName()
        {
            return new Comparator<Info>()
            {
                @Override
                public int compare(Info infoInfo info2)
                {
                    return info.getName().compareTo(info2.getName());
                }
            };
        }
    }
    public static class StackLine
    {
        private final String file;
        private final int line;
        private final String className;
        private final String method;
        @JsonCreator
        public StackLine(
                @JsonProperty("file"String file,
                @JsonProperty("line"int line,
                @JsonProperty("class"String className,
                @JsonProperty("method"String method)
        {
            this. = file;
            this. = line;
            this. = className;
            this. = method;
        }
        @JsonProperty
        public String getFile()
        {
            return ;
        }
        @JsonProperty
        public int getLine()
        {
            return ;
        }
        @JsonProperty
        public String getClassName()
        {
            return ;
        }
        @JsonProperty
        public String getMethod()
        {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X