Skip to content

Commit 2e479b4

Browse files
committed
Finalize
1 parent ec5e0db commit 2e479b4

File tree

10 files changed

+497
-26
lines changed

10 files changed

+497
-26
lines changed

src/org/cyberpwn/react/ReactClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.apache.commons.lang3.StringUtils;
2727
import org.cyberpwn.react.network.Network;
28+
import org.cyberpwn.react.network.NetworkScheduler;
2829
import org.cyberpwn.react.network.NetworkedServer;
2930
import org.cyberpwn.react.ui.AbstractTabRenderer;
3031
import org.cyberpwn.react.ui.JXTabbedPane;
@@ -34,7 +35,7 @@
3435
public class ReactClient
3536
{
3637
private final Network network;
37-
38+
private NetworkScheduler ns;
3839
private JFrame frmReactClient;
3940
private static ReactClient instance;
4041
public JXTabbedPane tabbedPane;
@@ -66,6 +67,8 @@ public ReactClient()
6667

6768
this.network = new Network();
6869
initialize();
70+
ns = new NetworkScheduler(network.getServers(), 500);
71+
ns.start();
6972
}
7073

7174
private void initialize()
@@ -190,6 +193,7 @@ public void showTutorial()
190193

191194
public static void restart()
192195
{
196+
instance.ns.interrupt();
193197
Dimension d = instance.frmReactClient.getSize();
194198
Point p = instance.frmReactClient.getLocationOnScreen();
195199
instance.frmReactClient.setVisible(false);
@@ -207,6 +211,7 @@ public void addTab(String name)
207211

208212
public void exit()
209213
{
214+
ns.interrupt();
210215
System.exit(0);
211216
}
212217

src/org/cyberpwn/react/ServerTab.java

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,34 @@
1818
import javax.swing.border.SoftBevelBorder;
1919

2020
import org.cyberpwn.react.network.NetworkedServer;
21+
import org.cyberpwn.react.ui.Grapher;
2122
import org.cyberpwn.react.ui.JXTabbedPane;
23+
import org.cyberpwn.react.util.F;
24+
import org.cyberpwn.react.util.GList;
25+
import org.cyberpwn.react.util.GMap;
2226

2327
import net.miginfocom.swing.MigLayout;
2428

2529
public class ServerTab
2630
{
2731
private NetworkedServer ns;
2832

33+
private JLabel lblTps;
34+
private JLabel lblMbUsed;
35+
private JLabel lblGcminute;
36+
private JLabel lblMahs;
37+
private JLabel lblUsingSpigot;
38+
private JLabel lblOnline;
39+
private JLabel lblmsPing;
40+
41+
private JPanel TPS;
42+
private Grapher GTPS;
43+
private GList<Double> DTPS;
44+
2945
public ServerTab(JFrame frame, NetworkedServer server, JXTabbedPane tabbedPane)
3046
{
3147
this.ns = server;
48+
this.DTPS = new GList<Double>().qadd(20.0);
3249

3350
JPanel panel = new JPanel();
3451
tabbedPane.addTab(ns.getName(), new ImageIcon(ReactClient.class.getResource("/org/cyberpwn/react/ui/server-mini.png")), panel, null);
@@ -52,21 +69,17 @@ public ServerTab(JFrame frame, NetworkedServer server, JXTabbedPane tabbedPane)
5269
lblServerName.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
5370
panel_5.add(lblServerName, "cell 0 0");
5471

55-
JLabel lblUsingSpigot = new JLabel("Using Spigot 1.8.8");
72+
lblUsingSpigot = new JLabel("Using Spigot 1.8.8");
5673
lblUsingSpigot.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
5774
panel_5.add(lblUsingSpigot, "cell 0 1");
5875

59-
JLabel lblOnline = new JLabel("146 Players Online");
76+
lblOnline = new JLabel("146 Players Online");
6077
lblOnline.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
6178
panel_5.add(lblOnline, "cell 0 2");
6279

63-
JLabel lblHours = new JLabel("7 Hours Uptime");
64-
lblHours.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
65-
panel_5.add(lblHours, "cell 0 3");
66-
67-
JLabel lblmsPing = new JLabel("43 Plugins");
80+
lblmsPing = new JLabel("43 Plugins");
6881
lblmsPing.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
69-
panel_5.add(lblmsPing, "cell 0 4");
82+
panel_5.add(lblmsPing, "cell 0 3");
7083

7184
JPanel panel_8 = new JPanel();
7285
panel_8.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
@@ -120,14 +133,16 @@ public void mouseReleased(MouseEvent e)
120133
lblCpuLoad.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
121134
panel_7.add(lblCpuLoad, "flowx,cell 0 0");
122135

123-
JLabel lblTps = new JLabel("20 TPS (99% Stable)");
136+
lblTps = new JLabel("20 TPS (99% Stable)");
124137
lblTps.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
125138
panel_7.add(lblTps, "cell 1 0");
126139

127-
JPanel panel_10 = new JPanel();
128-
panel_10.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
129-
panel_10.setBackground(Color.DARK_GRAY);
130-
panel_7.add(panel_10, "cell 0 1 2 2,grow");
140+
TPS = new JPanel();
141+
TPS.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
142+
TPS.setBackground(Color.DARK_GRAY);
143+
panel_7.add(TPS, "cell 0 1 2 2,grow");
144+
GTPS = new Grapher(TPS.getWidth(), TPS.getHeight(), 20, Color.CYAN, new GList<Double>().qadd(1.0));
145+
TPS.add(GTPS);
131146

132147
JPanel panel_13 = new JPanel();
133148
tabbedPane_2.addTab("Memory", null, panel_13, null);
@@ -143,7 +158,7 @@ public void mouseReleased(MouseEvent e)
143158
lblMemory.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
144159
panel_14.add(lblMemory, "cell 0 0");
145160

146-
JLabel lblMbUsed = new JLabel("683 MB Used");
161+
lblMbUsed = new JLabel("683 MB Used");
147162
lblMbUsed.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
148163
panel_14.add(lblMbUsed, "cell 1 0");
149164

@@ -162,7 +177,7 @@ public void mouseReleased(MouseEvent e)
162177
lblGarbage.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
163178
panel_16.add(lblGarbage, "cell 0 0");
164179

165-
JLabel lblGcminute = new JLabel("9 GC/Minute");
180+
lblGcminute = new JLabel("9 GC/Minute");
166181
lblGcminute.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
167182
panel_16.add(lblGcminute, "cell 1 0");
168183

@@ -181,7 +196,7 @@ public void mouseReleased(MouseEvent e)
181196
lblState.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
182197
panel_15.add(lblState, "cell 0 0");
183198

184-
JLabel lblMahs = new JLabel("264 MAH/s");
199+
lblMahs = new JLabel("264 MAH/s");
185200
lblMahs.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
186201
panel_15.add(lblMahs, "cell 1 0");
187202

@@ -210,7 +225,7 @@ public void mouseReleased(MouseEvent e)
210225
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
211226
panel_12.add(list, "cell 0 1 2 1,grow");
212227

213-
JLabel lblNewLabel = new JLabel("Executing \"Purge Chunks\" (33%)");
228+
JLabel lblNewLabel = new JLabel("Not Yet Implemented");
214229
lblNewLabel.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
215230
panel_12.add(lblNewLabel, "cell 0 2");
216231

@@ -228,13 +243,51 @@ public void mouseReleased(MouseEvent e)
228243
panel_3.add(panel_18, "cell 0 0 2 2,grow");
229244
panel_18.setLayout(new MigLayout("", "[]", "[][]"));
230245

231-
JLabel lblNoIssuesFound = new JLabel("No Issues Found");
246+
JLabel lblNoIssuesFound = new JLabel("No Issues Found (NOT YET IMPLEMENTED)");
232247
lblNoIssuesFound.setFont(new Font("Segoe UI Light", Font.PLAIN, 35));
233248
panel_18.add(lblNoIssuesFound, "cell 0 0");
234249

235250
JLabel lblNewLabel_1 = new JLabel("Looks Like this server is doing fine for the moment!");
236251
lblNewLabel_1.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
237252
panel_18.add(lblNewLabel_1, "cell 0 1");
253+
}
254+
255+
public void push(GMap<String, Double> sample)
256+
{
257+
lblUsingSpigot.setText("Using " + ns.getVersionBukkit());
258+
lblTps.setText(F.f(sample.get("tps"), 2) + " TPS (" + F.pc(sample.get("stability"), 0) + " Stable)");
259+
lblGcminute.setText(F.f(sample.get("spms")) + " GC/Minute");
260+
lblMahs.setText(F.f(sample.get("mah/s")) + " MAH/s");
261+
lblMbUsed.setText(F.mem(sample.get("mem").longValue()) + " Used");
262+
lblOnline.setText(F.f(sample.get("plr")) + " Players Online");
263+
lblmsPing.setText(F.f(sample.get("plg")) + " Loaded Plugins");
264+
265+
DTPS.add(sample.get("tps"));
238266

267+
if(DTPS.size() > 64)
268+
{
269+
DTPS.remove(0);
270+
}
271+
272+
GTPS.setWidth(TPS.getWidth());
273+
GTPS.setHeight(TPS.getHeight());
274+
GTPS.setData(DTPS);
275+
GTPS.repaint();
276+
TPS.repaint();
239277
}
278+
279+
/*
280+
>> liq/s : 0.0
281+
>> tnt/s : 0.0
282+
>> drops : 31.0
283+
>> hist : 1.0
284+
>> chk/s : 10.6
285+
>> rct : 501220.2773345846
286+
>> red/s : 0.0
287+
>> chunks : 0.0
288+
>> mb/p : 29.857142857142858
289+
>> ents : 190.0
290+
>> cgen/s : 2.0
291+
>> chunkmem : 0.0
292+
*/
240293
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.cyberpwn.react.network;
2+
3+
import org.cyberpwn.react.util.GList;
4+
5+
public class NetworkScheduler extends Thread
6+
{
7+
private GList<NetworkedServer> ns;
8+
private long ms;
9+
10+
public NetworkScheduler(GList<NetworkedServer> ns, long ms)
11+
{
12+
this.ns = ns;
13+
this.ms = ms;
14+
}
15+
16+
public void run()
17+
{
18+
while(!interrupted())
19+
{
20+
for(NetworkedServer i : ns)
21+
{
22+
i.requestSample();
23+
}
24+
25+
try
26+
{
27+
Thread.sleep(ms);
28+
}
29+
30+
catch(InterruptedException e)
31+
{
32+
break;
33+
}
34+
}
35+
}
36+
}

src/org/cyberpwn/react/network/NetworkedServer.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class NetworkedServer
1414
private Integer port;
1515
private GMap<String, Double> sample;
1616
private ServerTab tab;
17+
private Request rx;
18+
private String version;
19+
private String versionBukkit;
1720

1821
public NetworkedServer(String name, String username, String password, String address, Integer port)
1922
{
@@ -24,6 +27,9 @@ public NetworkedServer(String name, String username, String password, String add
2427
this.tab = null;
2528
this.port = port;
2629
this.sample = new GMap<String, Double>();
30+
this.rx = null;
31+
this.version = null;
32+
this.versionBukkit = null;
2733
}
2834

2935
public NetworkedServer(JSONObject js)
@@ -52,16 +58,39 @@ public void toJson(JSONArray parent)
5258

5359
public void requestSample()
5460
{
55-
new Request(this, new RequestCallback()
61+
if(version == null || versionBukkit == null)
62+
{
63+
new RequestBasic(this, new RequestCallbackBasic()
64+
{
65+
public void run()
66+
{
67+
if(isOk())
68+
{
69+
version = getData().get("version");
70+
versionBukkit = getData().get("version-bukkit");
71+
}
72+
}
73+
}).start();
74+
}
75+
76+
if(rx != null && rx.isAlive())
77+
{
78+
return;
79+
}
80+
81+
rx = new Request(this, new RequestCallback()
5682
{
5783
public void run()
5884
{
5985
if(isOk())
6086
{
6187
sample = getData();
88+
tab.push(sample);
6289
}
6390
}
6491
});
92+
93+
rx.start();
6594
}
6695

6796
public String getName()
@@ -123,14 +152,29 @@ public void setSample(GMap<String, Double> sample)
123152
{
124153
this.sample = sample;
125154
}
126-
155+
127156
public ServerTab getTab()
128157
{
129158
return tab;
130159
}
131-
160+
132161
public void setTab(ServerTab tab)
133162
{
134163
this.tab = tab;
135164
}
165+
166+
public Request getRx()
167+
{
168+
return rx;
169+
}
170+
171+
public String getVersion()
172+
{
173+
return version;
174+
}
175+
176+
public String getVersionBukkit()
177+
{
178+
return versionBukkit;
179+
}
136180
}

src/org/cyberpwn/react/network/PacketRequestType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
public enum PacketRequestType
44
{
5-
GET_ACTIONS, GET_SAMPLES;
5+
GET_ACTIONS, GET_SAMPLES, GET_BASIC;
66
}

src/org/cyberpwn/react/network/Request.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.DataOutputStream;
55
import java.io.IOException;
66
import java.net.Socket;
7+
import java.net.SocketTimeoutException;
78
import java.net.UnknownHostException;
89

910
import org.cyberpwn.react.util.GMap;
@@ -26,11 +27,14 @@ public void run()
2627
try
2728
{
2829
s = new Socket(ns.getAddress(), ns.getPort());
30+
s.setSoTimeout(500);
2931
DataInputStream i = new DataInputStream(s.getInputStream());
3032
DataOutputStream o = new DataOutputStream(s.getOutputStream());
3133
PacketRequest pr = new PacketRequest(ns.getUsername(), ns.getPassword(), PacketRequestType.GET_SAMPLES.toString());
3234
o.writeUTF(pr.toString());
33-
PacketResponse ps = new PacketResponse(new JSONObject(i.readUTF()));
35+
o.flush();
36+
String response = i.readUTF();
37+
PacketResponse ps = new PacketResponse(new JSONObject(response));
3438
GMap<String, Double> data = new GMap<String, Double>();
3539

3640
if(ps.getString("type").equals("OK"))
@@ -49,7 +53,7 @@ public void run()
4953

5054
catch(Exception e)
5155
{
52-
56+
e.printStackTrace();
5357
}
5458
}
5559

@@ -62,7 +66,12 @@ public void run()
6266
catch(UnknownHostException e)
6367
{
6468
e.printStackTrace();
65-
}
69+
}
70+
71+
catch(SocketTimeoutException e)
72+
{
73+
e.printStackTrace();
74+
}
6675

6776
catch(IOException e)
6877
{

0 commit comments

Comments
 (0)