studio.ui.action.ConnectionStats Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kdbStudio Show documentation
Show all versions of kdbStudio Show documentation
Studio for kdb+ is a rapid development environment for the ultra-fast database kdb+ from Kx Systems: http://www.kx.com.
package studio.ui.action;
import kx.KConnectionStats;
import studio.kdb.K;
import studio.kdb.Session;
import studio.ui.StudioWindow;
import java.util.HashMap;
import java.util.Map;
public class ConnectionStats {
public static void getStats(StudioWindow studioWindow) {
studioWindow.addResultTab(new QueryResult(getTable()), "Connection statistics");
}
private static K.Flip getTable() {
Map sessionsCount = new HashMap<>();
StudioWindow.executeAll(editor -> {
Session session = editor.getSession();
if (session == null) return true;
Integer count = sessionsCount.get(session);
if (count == null) {
sessionsCount.put(session, 1);
} else {
sessionsCount.put(session, count + 1);
}
return true;
});
final int DELTA = 4;
String[] statsHeaders = KConnectionStats.getStatsHeaders();
String[] names = new String[DELTA + statsHeaders.length];
names[0] = "name";
names[1] = "server";
names[2] = "status";
names[3] = "numberOfTabs";
System.arraycopy(statsHeaders, 0, names, DELTA, statsHeaders.length);
int count = sessionsCount.size();
Object[] cols = new Object[names.length];
Class extends K.KBase>[] types = (Class extends K.KBase>[]) new Class[names.length];
String[] serverNames = new String[count];
String[] servers = new String[count];
String[] statuses = new String[count];
int[] numbers = new int[count];
cols[0] = serverNames;
cols[1] = servers;
cols[2] = statuses;
cols[3] = numbers;
types[0] = K.KSymbol.class;
types[1] = K.KSymbol.class;
types[2] = K.KSymbol.class;
types[3] = K.KInteger.class;
int index = 0;
for (Session session: sessionsCount.keySet()) {
serverNames[index] = session.getServer().getFullName();
servers[index] = session.getServer().getConnectionString().substring(1);
statuses[index] = session.isClosed() ? "Disconnected" : "Connected";
numbers[index] = sessionsCount.get(session);
K.KBase[] values = session.getConnectionStats().getValues();
if (index == 0) {
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy