1 package org.ozoneDB.adminGui.feature.server; 2 3 import org.ozoneDB.adminGui.main.AdminGui; 4 import org.ozoneDB.adminGui.feature.ActionBar; 5 import org.ozoneDB.adminGui.feature.InfoPanel; 6 import org.ozoneDB.adminGui.res.Images; 7 8 import javax.swing.*; 9 import java.awt.*; 10 import java.awt.event.ActionListener ; 11 import java.awt.event.ActionEvent ; 12 13 16 public class ServerFeatureBar extends ActionBar { 17 private InfoPanel serverInfoPanel; 18 19 public ServerFeatureBar(ServerInfoPanel userInfoPanel) { 20 this.serverInfoPanel = userInfoPanel; 21 addComponents(); 22 } 23 24 protected void addComponents() { 25 26 this.removeAll(); 27 gbc.insets = new Insets(1, 5, 1, 5); 29 gbc.fill = GridBagConstraints.HORIZONTAL; 30 gbc.gridy = 0; 31 32 add(new ActionButton("shutdown", Images.SERVER_SHUTDOWN, new ShutdownListener()), gbc); 36 37 gbc.gridy++; 38 add(new ActionButton("transactions", Images.SERVER_TRANSACTIONS, new TransactionLister()), gbc); 39 40 gbc.gridy++; 41 add(new ActionButton("garbage collector", Images.SERVER_GARBAGE_COLLECTOR, new GarbageCollectorListener(), "start Ozone garbage collector"), gbc); 42 } 43 44 private class ShutdownListener implements ActionListener { 45 public void actionPerformed(ActionEvent event) { 46 System.out.println("shuttting down server"); 47 try { 48 AdminGui.instance().getDb().admin().shutdown(); 49 AdminGui.instance().showDisconnected(); 50 } catch (Exception e) { 51 serverInfoPanel.setDisplay(new JTextArea("Unable to shut down: " + e.getMessage())); 52 } 53 } 54 } 55 56 private class TransactionLister implements ActionListener { 57 public void actionPerformed(ActionEvent event) { 58 System.out.println("list all transactions"); 59 int transactionCount = 0; 60 try { 61 transactionCount = AdminGui.instance().getDb().admin().numberOfTxs(); 62 } catch (Exception e) { 63 System.out.println("Unable to retrieve transaction count: " + e.getMessage()); 64 } 65 JTextArea display = new JTextArea(); 66 67 display.append("Number of transactions: " + transactionCount); 68 serverInfoPanel.setDisplay(display); 69 } 70 } 71 72 private class GarbageCollectorListener implements ActionListener { 73 public void actionPerformed(ActionEvent event) { 74 System.out.println("Strating garbage collection"); 75 try { 76 AdminGui.instance().getDb().admin().startGarbageCollection(); 77 } catch (Exception e) { 78 e.printStackTrace(); 79 } 80 } 81 82 83 } 84 } 85 | Popular Tags |