1 22 23 package org.continuent.sequoia.console.text.commands.dbadmin; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import org.continuent.sequoia.common.i18n.ConsoleTranslate; 29 import org.continuent.sequoia.common.i18n.Translate; 30 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean; 31 import org.continuent.sequoia.common.jmx.monitoring.backend.BackendStatistics; 32 import org.continuent.sequoia.console.text.formatter.TableFormatter; 33 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin; 34 35 41 public class ShowBackend extends AbstractAdminCommand 42 { 43 44 49 public ShowBackend(VirtualDatabaseAdmin module) 50 { 51 super(module); 52 } 53 54 57 public void parse(String commandText) throws Exception 58 { 59 if (commandText.trim().length() == 0) 60 { 61 console.printError(getUsage()); 62 return; 63 } 64 65 VirtualDatabaseMBean db = jmxClient.getVirtualDatabaseProxy(dbName, user, 66 password); 67 String [] backendNames; 68 if (("*").equals(commandText.trim())) { 70 List backendNamesList = db.getAllBackendNames(); 71 backendNames = (String []) backendNamesList 72 .toArray(new String [backendNamesList.size()]); 73 } 74 else 75 { 76 String backendName = commandText.trim(); 77 backendNames = new String []{backendName}; 78 } 79 80 ArrayList stats = new ArrayList (); 81 if (backendNames.length == 0) 82 { 83 console.printInfo(ConsoleTranslate 84 .get("admin.command.show.backend.no.backends")); return; 86 } 87 for (int i = 0; i < backendNames.length; i++) 88 { 89 String backendName = backendNames[i]; 90 BackendStatistics stat = db.getBackendStatistics(backendName); 91 if (stat == null) 92 { 93 continue; 94 } 95 stats.add(stat); 96 } 97 if (stats.size() == 0) 98 { 99 console.printInfo(ConsoleTranslate.get( 100 "admin.command.show.backend.no.stats", commandText)); return; 102 } 103 String formattedBackends = TableFormatter.format( 104 getBackendStatisticsDescriptions(), 105 getBackendStatisticsAsStrings(stats), false); 106 console.println(formattedBackends); 107 } 108 109 private String [][] getBackendStatisticsAsStrings(ArrayList stats) 110 { 111 String [][] statsStr = new String [stats.size()][15]; 112 for (int i = 0; i < statsStr.length; i++) 113 { 114 BackendStatistics stat = (BackendStatistics) stats.get(i); 115 statsStr[i][0] = stat.getBackendName(); 116 statsStr[i][1] = stat.getDriverClassName(); 117 statsStr[i][2] = stat.getUrl(); 118 statsStr[i][3] = Integer.toString(stat.getNumberOfActiveTransactions()); 119 statsStr[i][4] = Integer.toString(stat.getNumberOfPendingRequests()); 120 statsStr[i][5] = Boolean.toString(stat.isReadEnabled()); 121 statsStr[i][6] = Boolean.toString(stat.isWriteEnabled()); 122 statsStr[i][7] = stat.getInitializationStatus(); 123 statsStr[i][8] = Boolean.toString(false); statsStr[i][9] = Integer.toString(stat.getNumberOfConnectionManagers()); 125 statsStr[i][10] = Long.toString(stat.getNumberOfTotalActiveConnections()); 126 statsStr[i][11] = Integer.toString(stat 127 .getNumberOfPersistentConnections()); 128 statsStr[i][12] = Integer.toString(stat.getNumberOfTotalRequests()); 129 statsStr[i][13] = Integer.toString(stat.getNumberOfTotalTransactions()); 130 statsStr[i][14] = stat.getLastKnownCheckpoint(); 131 } 132 return statsStr; 133 } 134 135 private String [] getBackendStatisticsDescriptions() 136 { 137 String [] descriptions = new String [15]; 138 descriptions[0] = Translate.get("console.infoviewer.backend.name"); descriptions[1] = Translate.get("console.infoviewer.backend.driver"); descriptions[2] = Translate.get("console.infoviewer.backend.url"); descriptions[3] = Translate 142 .get("console.infoviewer.backend.active.transactions"); descriptions[4] = Translate 144 .get("console.infoviewer.backend.pending.requests"); descriptions[5] = Translate.get("console.infoviewer.backend.read.enabled"); descriptions[6] = Translate.get("console.infoviewer.backend.write.enabled"); descriptions[7] = Translate.get("console.infoviewer.backend.init.status"); descriptions[8] = Translate.get("console.infoviewer.backend.static.schema"); descriptions[9] = Translate 150 .get("console.infoviewer.backend.connection.managers"); descriptions[10] = Translate 152 .get("console.infoviewer.backend.total.active.connections"); descriptions[11] = Translate 154 .get("console.infoviewer.backend.persistent.connections"); descriptions[12] = Translate 156 .get("console.infoviewer.backend.total.requests"); descriptions[13] = Translate 158 .get("console.infoviewer.backend.total.transactions"); descriptions[14] = Translate 160 .get("console.infoviewer.backend.lastknown.checkpoint"); return descriptions; 162 } 163 164 167 public String getCommandName() 168 { 169 170 return "show backend"; } 172 173 176 public String getCommandParameters() 177 { 178 return ConsoleTranslate.get("admin.command.show.backend.params"); } 180 181 184 public String getCommandDescription() 185 { 186 return ConsoleTranslate.get("admin.command.show.backend.description"); } 188 189 } 190 | Popular Tags |