001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Emic Networks.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Jeff Mesnil.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.controller.management;
021:
022: import java.io.IOException;
023: import java.rmi.RemoteException;
024: import java.util.List;
025:
026: import javax.management.NotCompliantMBeanException;
027:
028: import org.continuent.sequoia.common.exceptions.ControllerException;
029: import org.continuent.sequoia.common.i18n.Translate;
030: import org.continuent.sequoia.common.jmx.mbeans.ControllerMBean;
031: import org.continuent.sequoia.common.log.Trace;
032: import org.continuent.sequoia.controller.core.ControllerConstants;
033: import org.continuent.sequoia.controller.jmx.AbstractStandardMBean;
034:
035: /**
036: * This class defines the management interface of a Controller
037: *
038: * @author <a href="mailto:jeff@emicnetworks.com">Jeff Mesnil</a>
039: * @version 1.0
040: */
041: public class Controller extends AbstractStandardMBean implements
042: ControllerMBean {
043:
044: private org.continuent.sequoia.controller.core.Controller controller;
045: static Trace endUserLogger = Trace
046: .getLogger("org.continuent.sequoia.enduser");
047:
048: /**
049: * Creates a new <code>Controller</code> object based on a
050: * <code>managedController</code>
051: *
052: * @param managedController the controller to manage
053: * @throws NotCompliantMBeanException if this instance is not a compliant
054: * MBean
055: */
056: public Controller(
057: org.continuent.sequoia.controller.core.Controller managedController)
058: throws NotCompliantMBeanException {
059: super (ControllerMBean.class);
060: this .controller = managedController;
061: }
062:
063: /**
064: * @see org.continuent.sequoia.controller.jmx.AbstractStandardMBean#getAssociatedString()
065: */
066: public String getAssociatedString() {
067: return "controller"; //$NON-NLS-1$
068: }
069:
070: /**
071: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#addVirtualDatabases(java.lang.String)
072: */
073: public void addVirtualDatabases(String xml)
074: throws ControllerException {
075: try {
076: endUserLogger.info(Translate
077: .get("controller.add.virtualdatabases"));
078: controller.addVirtualDatabases(xml);
079: endUserLogger.info(Translate
080: .get("controller.virtualdatabases.added"));
081: } catch (ControllerException ex) {
082: endUserLogger.error(ex.getMessage());
083: throw ex;
084: }
085: }
086:
087: /**
088: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#initializeVirtualDatabases(java.lang.String, boolean)
089: */
090: public void addVirtualDatabases(String vdbXmlSpec, boolean force)
091: throws ControllerException {
092: if (!force) {
093: addVirtualDatabases(vdbXmlSpec);
094: return;
095: }
096:
097: try {
098: endUserLogger.info(Translate
099: .get("controller.add.virtualdatabases")
100: + " (force)");
101: controller.addVirtualDatabases(vdbXmlSpec, null,
102: ControllerConstants.AUTO_ENABLE_FORCE_LOAD, null);
103: endUserLogger.info(Translate
104: .get("controller.virtualdatabases.added")
105: + " (force)");
106: } catch (ControllerException ex) {
107: endUserLogger.error(ex.getMessage());
108: throw ex;
109: }
110: }
111:
112: /**
113: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#initializeVirtualDatabases(java.lang.String)
114: */
115: public void initializeVirtualDatabases(String vdbXmlSpec)
116: throws ControllerException {
117: try {
118: endUserLogger.info(Translate
119: .get("controller.add.virtualdatabases")
120: + " (init)");
121: controller.addVirtualDatabases(vdbXmlSpec, null,
122: ControllerConstants.AUTO_ENABLE_INIT, null);
123: endUserLogger.info(Translate
124: .get("controller.virtualdatabases.added")
125: + " (init)");
126: } catch (ControllerException ex) {
127: endUserLogger.error(ex.getMessage());
128: throw ex;
129: }
130: }
131:
132: /**
133: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getVirtualDatabaseNames()
134: */
135: public List getVirtualDatabaseNames() {
136: return controller.getVirtualDatabaseNames();
137: }
138:
139: /**
140: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#addDriver(byte[])
141: */
142: public void addDriver(byte[] bytes) throws Exception {
143: try {
144: controller.addDriver(bytes);
145: } catch (ControllerException e) {
146: throw e;
147: }
148: }
149:
150: /**
151: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#saveConfiguration()
152: */
153: public String saveConfiguration() throws Exception {
154: String msg = controller.saveConfiguration();
155: endUserLogger.info(msg);
156: return msg;
157: }
158:
159: /**
160: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#shutdown()
161: */
162: public void shutdown() throws ControllerException {
163: try {
164: endUserLogger.info(Translate.get("controller.shutdown",
165: this .getControllerName()));
166: controller.shutdown();
167: endUserLogger.info(Translate.get(
168: "controller.shutdown.completed", this
169: .getControllerName()));
170: } catch (ControllerException ex) {
171: endUserLogger.error(ex.getMessage());
172: throw ex;
173: }
174: }
175:
176: /**
177: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getBacklogSize()
178: */
179: public int getBacklogSize() {
180: return controller.getBacklogSize();
181: }
182:
183: /**
184: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getControllerName()
185: */
186: public String getControllerName() {
187: return controller.getControllerName();
188: }
189:
190: /**
191: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getJmxName()
192: */
193: public String getJmxName() {
194: return controller.getJmxName();
195: }
196:
197: /**
198: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getPortNumber()
199: */
200: public int getPortNumber() {
201: return controller.getPortNumber();
202: }
203:
204: /**
205: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getVersionNumber()
206: */
207: public String getVersionNumber() throws RemoteException {
208: return controller.getVersionNumber();
209: }
210:
211: /**
212: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#getXml()
213: */
214: public String getXml() {
215: return controller.getXml();
216: }
217:
218: /**
219: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#isShuttingDown()
220: */
221: public boolean isShuttingDown() {
222: return controller.isShuttingDown();
223: }
224:
225: /**
226: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#setBacklogSize(int)
227: */
228: public void setBacklogSize(int size) {
229: controller.setBacklogSize(size);
230: }
231:
232: /**
233: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#refreshLogConfiguration()
234: */
235: public void refreshLogConfiguration() throws ControllerException {
236: try {
237: controller.refreshLogConfiguration();
238: endUserLogger.info(Translate
239: .get("controller.refresh.log.success"));
240: } catch (ControllerException ex) {
241: endUserLogger.error(ex.getMessage());
242: throw ex;
243: }
244: }
245:
246: /**
247: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#updateLogConfigurationFile(java.lang.String)
248: */
249: public void updateLogConfigurationFile(String newConfiguration)
250: throws IOException, ControllerException {
251: try {
252: controller.updateLogConfigurationFile(newConfiguration);
253: endUserLogger.info(Translate
254: .get("controller.update.log.success"));
255: } catch (ControllerException ex) {
256: endUserLogger.error(ex.getMessage());
257: throw ex;
258: } catch (IOException ioex) {
259: endUserLogger.error(ioex.getMessage());
260: throw ioex;
261: }
262: }
263:
264: /**
265: * @see org.continuent.sequoia.common.jmx.mbeans.ControllerMBean#viewLogConfigurationFile()
266: */
267: public String viewLogConfigurationFile() throws IOException {
268: return controller.viewLogConfigurationFile();
269: }
270:
271: }
|