Skip to content

Commit edf76ae

Browse files
authored
Minor fixes, add CSV and JSON options for JMX connection for cache partition stats (#82)
1 parent c4f4879 commit edf76ae

File tree

8 files changed

+98
-21
lines changed

8 files changed

+98
-21
lines changed

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMModel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,16 @@ public void setImmediateRefresh(boolean fRefresh)
12761276
}
12771277
}
12781278

1279+
public void setRequestSender(RequestSender requestSender)
1280+
{
1281+
m_requestSender = requestSender;
1282+
}
1283+
1284+
public RequestSender getRequestSender()
1285+
{
1286+
return m_requestSender;
1287+
}
1288+
12791289
// ----- constants ------------------------------------------------------
12801290

12811291
/**
@@ -1944,4 +1954,9 @@ public String[] getMetadata()
19441954
* selection in a master-detail table.
19451955
*/
19461956
private boolean m_fIsImmediateRefresh;
1957+
1958+
/**
1959+
* {@link RequestSender} for this {@link VisualVMModel}.
1960+
*/
1961+
private RequestSender m_requestSender;
19471962
}

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public VisualVMView(CoherenceClusterDataSource dataSource)
157157
protected DataViewComponent createComponent()
158158
{
159159
final VisualVMModel model = VisualVMModel.getInstance();
160+
model.setRequestSender(m_requestSender);
160161

161162
m_model = model;
162163

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void invokeStorageManagerOperation(String sService, String sCacheName, St
295295
}
296296

297297
@Override
298-
public String invokeReportPartitionsStatsOperation(String sService, String sCacheName)
298+
public String invokeReportPartitionsStatsOperation(String sService, String sCacheName, String sOutputForma)
299299
throws Exception
300300
{
301301
URLBuilder urlBuilder = getBasePath()

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/JMXRequestSender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public void invokeStorageManagerOperation(String sService, String sCacheName, St
127127
}
128128

129129
@Override
130-
public String invokeReportPartitionsStatsOperation(String sService, String sCacheName)
130+
public String invokeReportPartitionsStatsOperation(String sService, String sCacheName, String sOutputFormat)
131131
throws Exception
132132
{
133133
ObjectName objectName = new ObjectName(STORAGE_MANAGER_EQUALS + sService + CACHE_EQUALS + sCacheName + ",*");
134134

135135
Set<ObjectName> setResult = getCompleteObjectName(objectName);
136136
String sFQN = getFirstResult(setResult);
137137

138-
return (String) invoke(new ObjectName(sFQN), PART_STATS, new Object[]{"json"}, new String[]{String.class.getName()});
138+
return (String) invoke(new ObjectName(sFQN), PART_STATS, new Object[]{sOutputFormat}, new String[]{String.class.getName()});
139139
}
140140

141141

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/RequestSender.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ void invokeStorageManagerOperation(String sService, String sCacheName, String sO
107107
*
108108
* @param sService the name of the service
109109
* @param sCacheName the name of the cache
110+
* @param sOutputFormat the output format
110111
*
111112
* @throws Exception in case of errors
112113
*/
113-
String invokeReportPartitionsStatsOperation(String sService, String sCacheName)
114+
String invokeReportPartitionsStatsOperation(String sService, String sCacheName, String sOutputFormat)
114115
throws Exception;
115116

116117
/**

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceCachePanel.java

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.oracle.coherence.plugin.visualvm.helper.DialogHelper;
3030
import com.oracle.coherence.plugin.visualvm.helper.GraphHelper;
3131
import com.oracle.coherence.plugin.visualvm.helper.HttpRequestSender;
32+
import com.oracle.coherence.plugin.visualvm.helper.JMXRequestSender;
3233
import com.oracle.coherence.plugin.visualvm.helper.RenderHelper;
3334
import com.oracle.coherence.plugin.visualvm.helper.RequestSender;
3435
import com.oracle.coherence.plugin.visualvm.panel.util.MenuOption;
@@ -71,13 +72,15 @@
7172

7273
import java.util.Map;
7374
import java.util.Map.Entry;
75+
import java.util.Objects;
7476
import java.util.Set;
7577

7678
import com.oracle.coherence.plugin.visualvm.tablemodel.model.ViewData;
7779
import javax.management.Attribute;
7880
import javax.management.MBeanServerConnection;
7981
import javax.management.ObjectName;
8082

83+
import javax.swing.JMenuItem;
8184
import javax.swing.JOptionPane;
8285
import javax.swing.JPanel;
8386
import javax.swing.JScrollPane;
@@ -233,11 +236,29 @@ public CoherenceCachePanel(VisualVMModel model)
233236
f_tableFrontDetail.setMenuOptions(new MenuOption[] {new ShowDetailMenuOption(model, f_tableFrontDetail, SELECTED_FRONT_CACHE)});
234237

235238
setTablePadding(f_tableStorage);
236-
f_tableStorage.setMenuOptions(new MenuOption[] {
237-
new ShowDetailMenuOption(model, f_tableStorage, SELECTED_STORAGE),
238-
new ShowIndexInfoMenuOption(model, m_requestSender, f_tableStorage),
239-
new ShowPartitionStatsMenuOption(model, m_requestSender, f_tableStorage)
240-
});
239+
240+
MenuOption showDetailMenuOption = new ShowDetailMenuOption(model, f_tableStorage, SELECTED_STORAGE);
241+
MenuOption showIndexInfoMenuOption = new ShowIndexInfoMenuOption(model, m_requestSender, f_tableStorage);
242+
243+
if (model.getRequestSender() instanceof JMXRequestSender)
244+
{
245+
// add json and csv options
246+
f_tableStorage.setMenuOptions(new MenuOption[] {
247+
showDetailMenuOption,
248+
showIndexInfoMenuOption,
249+
new ShowPartitionStatsMenuOption(model, m_requestSender, f_tableStorage, "json"),
250+
new ShowPartitionStatsMenuOption(model, m_requestSender, f_tableStorage, "csv")
251+
});
252+
}
253+
else
254+
{
255+
// generic json option
256+
f_tableStorage.setMenuOptions(new MenuOption[] {
257+
showDetailMenuOption,
258+
showIndexInfoMenuOption,
259+
new ShowPartitionStatsMenuOption(model, m_requestSender, f_tableStorage, "json")
260+
});
261+
}
241262

242263
// Create the scroll pane and add the table to it.
243264
JScrollPane scrollPane = new JScrollPane(table);
@@ -734,12 +755,15 @@ protected class ShowPartitionStatsMenuOption
734755
* @param model the {@link VisualVMModel} to get collected data from
735756
* @param requestSender the {@link MBeanServerConnection} to perform additional queries
736757
* @param jtable the {@link ExportableJTable} that this applies to
758+
* @param sFormat the format of json or csv
737759
*/
738760
public ShowPartitionStatsMenuOption(VisualVMModel model, RequestSender requestSender,
739-
ExportableJTable jtable)
761+
ExportableJTable jtable, String sFormat)
740762
{
741763
super(model, requestSender, jtable);
742-
f_sMenuItem = getLocalizedText("LBL_cache_partition_stats");
764+
f_sFormat = sFormat;
765+
String sLabel = "csv".equals(f_sFormat) ? "LBL_cache_partition_stats_csv" : "LBL_cache_partition_stats_json";
766+
f_sMenuItem = getLocalizedText(sLabel);
743767
}
744768

745769
// ----- AbstractMenuOption methods ---------------------------------
@@ -758,7 +782,7 @@ public void actionPerformed(ActionEvent e)
758782

759783
try
760784
{
761-
sResult = m_requestSender.invokeReportPartitionsStatsOperation(selectedCache.getX(), selectedCache.getY());
785+
sResult = m_requestSender.invokeReportPartitionsStatsOperation(selectedCache.getX(), selectedCache.getY(), f_sFormat);
762786
showMessageDialog(Localization.getLocalText("LBL_cache_partition_stats"),
763787
sResult, JOptionPane.INFORMATION_MESSAGE);
764788
}
@@ -767,15 +791,49 @@ public void actionPerformed(ActionEvent e)
767791
showMessageDialog(Localization.getLocalText("LBL_error"),
768792
ee.getMessage(), JOptionPane.ERROR_MESSAGE);
769793
}
770-
771794
}
772795

773-
// ----- data members ------------------------------------------------
796+
@Override
797+
public boolean equals(Object o)
798+
{
799+
if (this == o)
800+
{
801+
return true;
802+
}
774803

775-
/**
776-
* Menu option description.
777-
*/
778-
private final String f_sMenuItem;
804+
if (o == null || getClass() != o.getClass())
805+
{
806+
return false;
807+
}
808+
809+
ShowPartitionStatsMenuOption that = (ShowPartitionStatsMenuOption) o;
810+
811+
if (!Objects.equals(f_sMenuItem, that.f_sMenuItem))
812+
{
813+
return false;
814+
}
815+
return Objects.equals(f_sFormat, that.f_sFormat);
816+
}
817+
818+
@Override
819+
public int hashCode()
820+
{
821+
int result = f_sMenuItem != null ? f_sMenuItem.hashCode() : 0;
822+
result = 31 * result + (f_sFormat != null ? f_sFormat.hashCode() : 0);
823+
return result;
824+
}
825+
826+
// ----- data members ------------------------------------------------
827+
828+
/**
829+
* Menu option description.
830+
*/
831+
private final String f_sMenuItem;
832+
833+
/**
834+
* output format.
835+
*/
836+
private final String f_sFormat;
779837
}
780838

781839
/**

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cache/SelectedCacheQueryProbe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ private static ProbeItemDescriptor[] createItemDescriptors()
7272
return new ProbeItemDescriptor[]
7373
{
7474
ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(LBL),
75-
getMonitorsString(LBL), new CustomFormatter(1, "ms"),
76-
1, 0, 1),
75+
getMonitorsString(LBL), new CustomFormatter(1000, "ms"),
76+
1000d, 0, 1),
7777
ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(LBL2),
7878
getMonitorsString(LBL2), new CustomFormatter(1000, "ms"),
7979
1000d, 0, 1),

coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ LBL_title_memory_heat_map=Primary Memory Heat Map for All Caches
9696
LBL_no_caches=No caches are defined or all caches have zero size. Unable to create Heat Map.
9797
LBL_no_data=You have selected a new row, please wait for the data to be refreshed and try viewing the heat map again.
9898
LBL_index_info=Index Information
99-
LBL_cache_partition_stats=Cache Partition Stats
99+
LBL_cache_partition_stats_json=Cache partition stats - JSON
100+
LBL_cache_partition_stats_csv= Cache partition stats - CSV
101+
LBL_cache_partition_stats= Cache partition stats
100102
LBL_truncate=Truncate Cache
101103
LBL_clear=Clear Cache
102104
LBL_confirm_cache_operation=WARNING: This operation will remove the cache contents.\nAre you sure you want to perform operation {0} against cache {1}?

0 commit comments

Comments
 (0)