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