1 24 25 package org.objectweb.cjdbc.console.text.commands.dbadmin; 26 27 import java.util.ArrayList ; 28 import java.util.StringTokenizer ; 29 30 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 31 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean; 32 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin; 33 34 40 public class ShowBackendState extends AbstractAdminCommand 41 { 42 43 48 public ShowBackendState(VirtualDatabaseAdmin module) 49 { 50 super(module); 51 } 52 53 56 public void parse(String commandText) throws Exception 57 { 58 if (commandText == null || commandText.trim().equals("")) 59 { 60 console.printError(ConsoleTranslate 61 .get("admin.command.showbackend.state.no.input")); 62 return; 63 } 64 StringTokenizer st = new StringTokenizer (commandText); 65 66 String backendName = st.nextToken(); 67 68 if (!jmxClient.getVirtualDatabaseProxy(dbName, user, password) 69 .getAllBackendNames().contains(backendName)) 70 { 71 console.printError(ConsoleTranslate.get( 72 "admin.command.showbackend.state.invalid.backend", backendName)); 73 return; 74 } 75 76 int count = 0; 77 if (st.hasMoreTokens()) 78 { 79 try 80 { 81 count = Integer.parseInt(st.nextToken()); 82 } 83 catch (NumberFormatException e) 84 { 85 } 86 } 87 boolean fromFirst = true; 88 if (st.hasMoreTokens()) 89 fromFirst = Boolean.valueOf(st.nextToken()).booleanValue(); 90 boolean clone = false; 91 if (st.hasMoreTokens()) 92 clone = Boolean.valueOf(st.nextToken()).booleanValue(); 93 94 console.println(ConsoleTranslate.get( 96 "admin.command.showbackend.state.echo", new Object []{backendName, 97 String.valueOf(count), String.valueOf(fromFirst), 98 String.valueOf(clone)})); 99 DatabaseBackendMBean db = jmxClient.getDatabaseBackendProxy(dbName, 100 backendName, user, password); 101 102 ArrayList list = db.getActiveTransactions(); 103 console.printInfo(ConsoleTranslate 104 .get("admin.command.showbackend.state.state")); 105 console.println(db.getState()); 106 console.printInfo(ConsoleTranslate 107 .get("admin.command.showbackend.state.active.transactions")); 108 for (int i = 0; i < list.size(); i++) 109 { 110 if (i != 0) 111 console.print(","); 112 console.print(list.get(i).toString()); 113 } 114 console.println(); 115 console.printInfo(ConsoleTranslate 116 .get("admin.command.showbackend.state.pending.requests")); 117 try 118 { 119 list = db.getPendingRequestsDescription(count, fromFirst, clone); 120 for (int i = 0; i < list.size(); i++) 121 console.println((String ) list.get(i)); 122 } 123 catch (Exception e) 124 { 125 e.printStackTrace(); 126 } 127 } 128 129 132 public String getCommandName() 133 { 134 return "showbackend"; 135 } 136 137 140 public String getCommandDescription() 141 { 142 return ConsoleTranslate.get("admin.command.showbackend.state"); 143 } 144 145 148 public String getCommandParameters() 149 { 150 return "<backendName> [<count>] [<fromFirst>] [<clone>]"; 151 } 152 } | Popular Tags |