1
1
/*
2
- * Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2020, 2024 Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
46
46
import java .awt .event .ActionEvent ;
47
47
48
48
import java .awt .event .ActionListener ;
49
+ import java .io .File ;
50
+ import java .io .IOException ;
51
+ import java .io .PrintWriter ;
52
+
49
53
import java .util .ArrayList ;
50
54
import java .util .Date ;
51
55
import java .util .List ;
52
56
import java .util .Map ;
53
57
import java .util .Map .Entry ;
54
58
55
59
import java .util .logging .Logger ;
60
+ import com .oracle .coherence .plugin .visualvm .threaddump .ThreadDumpImpl ;
56
61
import javax .swing .*;
57
62
import javax .swing .border .CompoundBorder ;
58
63
import javax .swing .border .EmptyBorder ;
59
64
import javax .swing .border .TitledBorder ;
60
65
61
66
import javax .swing .event .ChangeListener ;
62
67
import org .graalvm .visualvm .charts .SimpleXYChartSupport ;
68
+ import org .graalvm .visualvm .core .datasource .DataSource ;
69
+ import org .graalvm .visualvm .core .ui .DataSourceWindowManager ;
63
70
import org .openide .awt .StatusDisplayer ;
64
71
65
72
import static com .oracle .coherence .plugin .visualvm .Localization .getLocalText ;
@@ -267,7 +274,6 @@ public void updateGUI()
267
274
{
268
275
GraphHelper .addValuesToClusterMemoryGraph (f_memoryGraph , cTotalMemory , cTotalMemoryUsed );
269
276
}
270
-
271
277
}
272
278
273
279
@ Override
@@ -515,7 +521,7 @@ public void actionPerformed(ActionEvent e)
515
521
516
522
DialogHelper .showInfoDialog (getLocalText ("LBL_thread_dump_confirmation" ));
517
523
518
- StringBuilder sb = new StringBuilder (sMessage ). append ( " \n " ). append ( generateHeader ( nNode )) ;
524
+ StringBuilder sb = new StringBuilder (sMessage );
519
525
520
526
Timer timer = new Timer (nDelay * 1000 , null );
521
527
@@ -542,7 +548,7 @@ public void actionPerformed(ActionEvent e)
542
548
timer .stop ();
543
549
status [0 ] = StatusDisplayer .getDefault ().setStatusText (getLocalText ("LBL_thread_dump_completed" ),5 );
544
550
status [0 ].clear (5000 );
545
- showThreadDumpResult (nNode , sb .toString ());
551
+ showThreadDumpInVisualVM (nNode , sb .toString ());
546
552
}
547
553
}
548
554
@@ -555,7 +561,7 @@ public void actionPerformed(ActionEvent e)
555
561
}
556
562
else
557
563
{
558
- showThreadDumpResult (nNodeId , generateHeader ( nNodeId ) + " " + m_requestSender .getNodeState (nNodeId ));
564
+ showThreadDumpInVisualVM (nNodeId , m_requestSender .getNodeState (nNodeId ));
559
565
}
560
566
}
561
567
catch (Exception ee )
@@ -568,17 +574,48 @@ public void actionPerformed(ActionEvent e)
568
574
// ------ helpers -----------------------------------------------
569
575
570
576
/**
571
- * Display the thread dump result.
572
- *
573
- * @param nNode node id
574
- * @param sThreadDump the result
577
+ * Show the therad dump result in VisualVM thread dump viewer.
578
+ * @param nNode node id
579
+ * @param sThreadDump thread dump content
575
580
*/
576
- private void showThreadDumpResult (int nNode , String sThreadDump )
581
+ private void showThreadDumpInVisualVM (int nNode , String sThreadDump )
577
582
{
578
- showMessageDialog (getLocalizedText ("LBL_state_for_node" ) + " " + nNode ,
579
- sThreadDump , JOptionPane .INFORMATION_MESSAGE , 500 , 400 , true );
583
+ // create a temp file
584
+ try
585
+ {
586
+ String sPrefix = "node-" + nNode + "-" ;
587
+ File fileTempDir = new File (System .getProperty ("java.io.tmpdir" ));
588
+ File fileTemp = File .createTempFile (sPrefix , null , fileTempDir );
589
+ boolean fResult1 = fileTemp .setReadable (false );
590
+ boolean fResult2 = fileTemp .setWritable (false );
591
+ boolean fResult3 = fileTemp .setExecutable (false );
592
+ boolean fResult4 = fileTemp .setReadable (true , true );
593
+ boolean fResult5 = fileTemp .setWritable (true , true );
594
+ boolean fResult6 = fileTemp .setExecutable (true , true );
595
+
596
+ if (!fResult1 || !fResult2 || !fResult3 || !fResult4 || !fResult5 || !fResult6 )
597
+ {
598
+ throw new RuntimeException ("unable to set file permissions for " + fileTemp .getAbsolutePath ());
599
+ }
600
+
601
+ try (PrintWriter pw = new PrintWriter (fileTemp , "UTF-8" ))
602
+ {
603
+ pw .write (sThreadDump );
604
+ }
605
+
606
+ final ThreadDumpImpl threadDump = new ThreadDumpImpl (fileTemp , null );
607
+
608
+ DataSource .EVENT_QUEUE .post (new Runnable ()
609
+ {
610
+ public void run () { DataSourceWindowManager .sharedInstance ().openDataSource (threadDump ); }
611
+ });
612
+ }
613
+ catch (IOException e )
614
+ {
615
+ LOGGER .warning (e .getMessage ());
616
+ }
580
617
}
581
- }
618
+ }
582
619
583
620
/**
584
621
* Generate a thread dump and save the output in the {@link StringBuilder}.
0 commit comments