001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.sql;
031:
032: import javax.management.*;
033:
034: import com.caucho.management.server.AbstractManagedObject;
035: import com.caucho.management.server.JdbcDriverMXBean;
036:
037: import java.util.Date;
038: import java.util.Map;
039:
040: public class DriverAdmin extends AbstractManagedObject implements
041: JdbcDriverMXBean {
042: private DriverConfig _driver;
043:
044: public DriverAdmin(DriverConfig driver) {
045: _driver = driver;
046: }
047:
048: @Override
049: public String getName() {
050: return _driver.getDBPool().getName();
051: }
052:
053: public String getClassName() {
054: return _driver.getType();
055: }
056:
057: public String getUrl() {
058: return _driver.getURL();
059: }
060:
061: protected void addObjectNameProperties(Map<String, String> props)
062: throws MalformedObjectNameException {
063: String url = getUrl();
064:
065: if (url != null) {
066: if (url.indexOf(':') >= 0)
067: url = ObjectName.quote(url);
068:
069: props.put("url", url);
070: }
071: }
072:
073: //
074: // state
075: //
076:
077: public String getState() {
078: return _driver.getLifecycle().getStateName();
079: }
080:
081: //
082: // statistics
083: //
084:
085: public long getConnectionCountTotal() {
086: return _driver.getConnectionCountTotal();
087: }
088:
089: public long getConnectionFailCountTotal() {
090: return _driver.getConnectionFailCountTotal();
091: }
092:
093: public Date getLastFailTime() {
094: return new Date(_driver.getLastFailTime());
095: }
096:
097: //
098: // Operations
099: //
100:
101: /**
102: * Enable the port, letting it listening to new requests.
103: */
104: public boolean start() {
105: return _driver.start();
106: }
107:
108: /**
109: * Disable the port, stopping it from listening to new requests.
110: */
111: public boolean stop() {
112: return _driver.stop();
113: }
114:
115: void register() {
116: registerSelf();
117: }
118:
119: public String toString() {
120: return "JdbcDriverAdmin[" + getObjectName() + "]";
121: }
122:
123: }
|