1- package play ;
2-
3- import static java .util .Arrays .asList ;
4-
5- import java .io .PrintWriter ;
6- import java .io .StringWriter ;
7- import java .text .SimpleDateFormat ;
8- import java .util .ArrayList ;
9- import java .util .Collections ;
10- import java .util .Comparator ;
11- import java .util .Date ;
12- import java .util .List ;
13-
14- import org .apache .commons .lang .StringUtils ;
1+ package play .plugins ;
152
163import com .google .gson .JsonArray ;
174import com .google .gson .JsonObject ;
185import com .google .gson .JsonPrimitive ;
196import com .jamonapi .Monitor ;
207import com .jamonapi .MonitorFactory ;
218import com .jamonapi .utils .Misc ;
22-
9+ import org .apache .commons .lang .StringUtils ;
10+ import play .Invoker ;
11+ import play .Logger ;
12+ import play .Play ;
2313import play .Play .Mode ;
24- import play .classloading .ApplicationClasses .ApplicationClass ;
25- import play .classloading .enhancers .ContinuationEnhancer ;
26- import play .classloading .enhancers .ControllersEnhancer ;
27- import play .classloading .enhancers .Enhancer ;
28- import play .classloading .enhancers .LocalvariablesNamesEnhancer ;
29- import play .classloading .enhancers .MailerEnhancer ;
30- import play .classloading .enhancers .PropertiesEnhancer ;
31- import play .classloading .enhancers .SigEnhancer ;
32- import play .exceptions .UnexpectedException ;
33- import play .libs .Crypto ;
14+ import play .PlayPlugin ;
3415import play .mvc .Http .Header ;
3516import play .mvc .Http .Request ;
3617import play .mvc .Http .Response ;
3718
38- /**
39- * Plugin used for core tasks
40- */
41- public class CorePlugin extends PlayPlugin {
19+ import java .io .PrintWriter ;
20+ import java .io .StringWriter ;
21+ import java .text .SimpleDateFormat ;
22+ import java .util .*;
23+
24+ import static java .util .Arrays .asList ;
25+
26+ public class PlayStatusPlugin extends PlayPlugin {
4227
4328 /**
4429 * Get the application status
@@ -47,7 +32,7 @@ public class CorePlugin extends PlayPlugin {
4732 * true if the status should be return in JSON
4833 * @return application status
4934 */
50- public static String computeApplicationStatus (boolean json ) {
35+ public String computeApplicationStatus (boolean json ) {
5136 if (json ) {
5237 JsonObject o = new JsonObject ();
5338 for (PlayPlugin plugin : Play .pluginCollection .getEnabledPlugins ()) {
@@ -104,8 +89,8 @@ public boolean rawInvocation(Request request, Response response) throws Exceptio
10489 }
10590 response .contentType = request .path .contains (".json" ) ? "application/json" : "text/plain" ;
10691 Header authorization = request .headers .get ("authorization" );
107- if ( authorization != null && ( Crypto . sign ( "@status" ). equals ( authorization . value ())
108- || System . getProperty ( " statusKey" , Play . secretKey ). equals (authorization .value () ))) {
92+ String statusKey = Play . configuration . getProperty ( "application.statusKey" , System . getProperty ( "statusKey" ));
93+ if ( authorization != null && statusKey != null && statusKey . equals (authorization .value ())) {
10994 response .print (computeApplicationStatus (request .path .contains (".json" )));
11095 response .status = 200 ;
11196 return true ;
@@ -184,12 +169,7 @@ public String getStatus() {
184169 out .println ("Monitors:" );
185170 out .println ("~~~~~~~~" );
186171 List <Monitor > monitors = new ArrayList <>(asList (MonitorFactory .getRootMonitor ().getMonitors ()));
187- Collections .sort (monitors , new Comparator <Monitor >() {
188- @ Override
189- public int compare (Monitor m1 , Monitor m2 ) {
190- return Double .compare (m2 .getTotal (), m1 .getTotal ());
191- }
192- });
172+ monitors .sort ((m1 , m2 ) -> Double .compare (m2 .getTotal (), m1 .getTotal ()));
193173 int lm = 10 ;
194174 for (Monitor monitor : monitors ) {
195175 if (monitor .getLabel ().length () > lm ) {
@@ -269,7 +249,7 @@ public JsonObject getJsonStatus() {
269249 /**
270250 * Recursively visit all JVM threads
271251 */
272- static void visit (PrintWriter out , ThreadGroup group , int level ) {
252+ private void visit (PrintWriter out , ThreadGroup group , int level ) {
273253 // Get threads in `group'
274254 int numThreads = group .activeCount ();
275255 Thread [] threads = new Thread [numThreads * 2 ];
@@ -296,32 +276,11 @@ static void visit(PrintWriter out, ThreadGroup group, int level) {
296276 /**
297277 * Retrieve the JVM root thread group.
298278 */
299- static ThreadGroup getRootThread () {
279+ private ThreadGroup getRootThread () {
300280 ThreadGroup root = Thread .currentThread ().getThreadGroup ().getParent ();
301281 while (root .getParent () != null ) {
302282 root = root .getParent ();
303283 }
304284 return root ;
305285 }
306-
307- protected Enhancer [] defaultEnhancers () {
308- return new Enhancer [] { new PropertiesEnhancer (), new ContinuationEnhancer (), new SigEnhancer (), new ControllersEnhancer (),
309- new MailerEnhancer (), new LocalvariablesNamesEnhancer () };
310- }
311-
312- @ Override
313- public void enhance (ApplicationClass applicationClass ) throws Exception {
314- for (Enhancer enhancer : defaultEnhancers ()) {
315- try {
316- long start = System .currentTimeMillis ();
317- enhancer .enhanceThisClass (applicationClass );
318- if (Logger .isTraceEnabled ()) {
319- Logger .trace ("%sms to apply %s to %s" , System .currentTimeMillis () - start , enhancer .getClass ().getSimpleName (),
320- applicationClass .name );
321- }
322- } catch (Exception e ) {
323- throw new UnexpectedException ("While applying " + enhancer + " on " + applicationClass .name , e );
324- }
325- }
326- }
327286}
0 commit comments