1 24 25 package org.objectweb.cjdbc.console.text.module; 26 27 import java.util.Iterator ; 28 29 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 30 import org.objectweb.cjdbc.console.text.Console; 31 import org.objectweb.cjdbc.console.text.commands.monitor.AbstractMonitorCommand; 32 import org.objectweb.cjdbc.console.text.commands.monitor.ChangeTarget; 33 import org.objectweb.cjdbc.console.text.commands.monitor.ShowBackends; 34 import org.objectweb.cjdbc.console.text.commands.monitor.ShowCache; 35 import org.objectweb.cjdbc.console.text.commands.monitor.ShowCacheStats; 36 import org.objectweb.cjdbc.console.text.commands.monitor.ShowController; 37 import org.objectweb.cjdbc.console.text.commands.monitor.ShowDatabases; 38 import org.objectweb.cjdbc.console.text.commands.monitor.ShowRecoveryLog; 39 import org.objectweb.cjdbc.console.text.commands.monitor.ShowScheduler; 40 import org.objectweb.cjdbc.console.text.commands.monitor.ShowStats; 41 42 48 public class MonitorConsole extends AbstractConsoleModule 49 { 50 51 private String currentTarget; 52 53 58 public String getCurrentTarget() 59 { 60 return currentTarget; 61 } 62 63 68 public void setCurrentTarget(String currentTarget) 69 { 70 this.currentTarget = currentTarget; 71 Object o; 72 Iterator it = commands.iterator(); 73 while (it.hasNext()) 74 { 75 o = it.next(); 76 if (o instanceof AbstractMonitorCommand) 77 { 78 ((AbstractMonitorCommand) o).setCurrentTarget(currentTarget); 79 } 80 } 81 } 82 83 88 public MonitorConsole(Console console) 89 { 90 super(console); 91 } 92 93 96 public String getDescriptionString() 97 { 98 return "Monitoring"; 99 } 100 101 104 public String getPromptString() 105 { 106 return "Monitoring:" + currentTarget; 107 } 108 109 112 protected void loadCommands() 113 { 114 commands.add(new ChangeTarget(this)); 115 commands.add(new ShowBackends(this)); 116 commands.add(new ShowCache(this)); 117 commands.add(new ShowCacheStats(this)); 118 commands.add(new ShowController(this)); 119 commands.add(new ShowDatabases(this)); 120 commands.add(new ShowScheduler(this)); 121 commands.add(new ShowStats(this)); 122 commands.add(new ShowRecoveryLog(this)); 123 } 124 125 128 public void login(String [] params) 129 { 130 quit = false; 131 132 String command = (params.length > 0 && params[0] != null) ? params[0] : ""; 133 if (command.equals("")) 134 { 135 console.printError(ConsoleTranslate.get("module.database.invalid", "")); 136 quit = true; 137 } 138 else 139 { 140 try 141 { 142 new ChangeTarget(this).execute(params[0]); 143 console.getConsoleReader().removeCompletor( 144 console.getControllerModule().getCompletor()); 145 console.getConsoleReader().addCompletor(this.getCompletor()); 146 } 147 catch (Exception e) 148 { 149 console.printError(e.getMessage(), e); 150 quit = true; 151 } 152 } 153 } 154 } | Popular Tags |