You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/11/25 20:40:05 UTC
svn commit: r1771377 [2/2] - in /tomcat/trunk:
java/org/apache/catalina/mbeans/ webapps/docs/
Modified: tomcat/trunk/java/org/apache/catalina/mbeans/ServiceMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/ServiceMBean.java?rev=1771377&r1=1771376&r2=1771377&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/ServiceMBean.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/ServiceMBean.java Fri Nov 25 20:40:04 2016
@@ -14,28 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.catalina.mbeans;
-import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.RuntimeOperationsException;
-import javax.management.modelmbean.InvalidTargetObjectTypeException;
import org.apache.catalina.Executor;
import org.apache.catalina.Service;
import org.apache.catalina.connector.Connector;
-import org.apache.tomcat.util.modeler.BaseModelMBean;
-
-public class ServiceMBean extends BaseModelMBean {
- public ServiceMBean()
- throws MBeanException, RuntimeOperationsException {
+public class ServiceMBean extends BaseCatalinaMBean<Service> {
+ public ServiceMBean() throws MBeanException, RuntimeOperationsException {
super();
-
}
+
/**
* Add a new Connector to the set of defined Connectors, and associate it
* with this Service's Container.
@@ -49,16 +43,7 @@ public class ServiceMBean extends BaseMo
*/
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
- Service service;
- try {
- service = (Service)getManagedResource();
- } catch (InstanceNotFoundException e) {
- throw new MBeanException(e);
- } catch (RuntimeOperationsException e) {
- throw new MBeanException(e);
- } catch (InvalidTargetObjectTypeException e) {
- throw new MBeanException(e);
- }
+ Service service = doGetManagedResource();
String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
Connector connector = new Connector(protocol);
if ((address!=null) && (address.length()>0)) {
@@ -69,42 +54,21 @@ public class ServiceMBean extends BaseMo
connector.setScheme(isSSL ? "https" : "http");
service.addConnector(connector);
-
}
+
/**
* Adds a named executor to the service
* @param type Classname of the Executor to be added
* @throws MBeanException error creating the executor
*/
public void addExecutor(String type) throws MBeanException {
-
- Service service;
- try {
- service = (Service)getManagedResource();
- } catch (InstanceNotFoundException e) {
- throw new MBeanException(e);
- } catch (RuntimeOperationsException e) {
- throw new MBeanException(e);
- } catch (InvalidTargetObjectTypeException e) {
- throw new MBeanException(e);
- }
-
- Executor executor;
- try {
- executor = (Executor)Class.forName(type).newInstance();
- } catch (InstantiationException e) {
- throw new MBeanException(e);
- } catch (IllegalAccessException e) {
- throw new MBeanException(e);
- } catch (ClassNotFoundException e) {
- throw new MBeanException(e);
- }
-
+ Service service = doGetManagedResource();
+ Executor executor = (Executor) newInstance(type);
service.addExecutor(executor);
-
}
+
/**
* Find and return the set of Connectors associated with this Service.
* @return an array of string representations of the connectors
@@ -112,28 +76,19 @@ public class ServiceMBean extends BaseMo
*/
public String[] findConnectors() throws MBeanException {
- Service service;
- try {
- service = (Service)getManagedResource();
- } catch (InstanceNotFoundException e) {
- throw new MBeanException(e);
- } catch (RuntimeOperationsException e) {
- throw new MBeanException(e);
- } catch (InvalidTargetObjectTypeException e) {
- throw new MBeanException(e);
- }
+ Service service = doGetManagedResource();
Connector[] connectors = service.findConnectors();
String[] str = new String[connectors.length];
- for(int i=0; i< connectors.length; i++){
+ for(int i = 0; i < connectors.length; i++) {
str[i] = connectors[i].toString();
}
return str;
-
}
+
/**
* Retrieves all executors.
* @return an array of string representations of the executors
@@ -141,27 +96,19 @@ public class ServiceMBean extends BaseMo
*/
public String[] findExecutors() throws MBeanException {
- Service service;
- try {
- service = (Service)getManagedResource();
- } catch (InstanceNotFoundException e) {
- throw new MBeanException(e);
- } catch (RuntimeOperationsException e) {
- throw new MBeanException(e);
- } catch (InvalidTargetObjectTypeException e) {
- throw new MBeanException(e);
- }
+ Service service = doGetManagedResource();
Executor[] executors = service.findExecutors();
String[] str = new String[executors.length];
- for(int i=0; i< executors.length; i++){
+ for(int i = 0; i < executors.length; i++){
str[i] = executors[i].toString();
}
return str;
}
+
/**
* Retrieves executor by name
* @param name Name of the executor to be retrieved
@@ -169,21 +116,8 @@ public class ServiceMBean extends BaseMo
* @throws MBeanException error accessing the associated service
*/
public String getExecutor(String name) throws MBeanException{
-
- Service service;
- try {
- service = (Service)getManagedResource();
- } catch (InstanceNotFoundException e) {
- throw new MBeanException(e);
- } catch (RuntimeOperationsException e) {
- throw new MBeanException(e);
- } catch (InvalidTargetObjectTypeException e) {
- throw new MBeanException(e);
- }
-
+ Service service = doGetManagedResource();
Executor executor = service.getExecutor(name);
return executor.toString();
-
}
-
}
Modified: tomcat/trunk/java/org/apache/catalina/mbeans/UserMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/UserMBean.java?rev=1771377&r1=1771376&r2=1771377&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/UserMBean.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/UserMBean.java Fri Nov 25 20:40:04 2016
@@ -14,10 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.catalina.mbeans;
-
import java.util.ArrayList;
import java.util.Iterator;
@@ -44,7 +42,6 @@ public class UserMBean extends BaseModel
// ----------------------------------------------------------- Constructors
-
/**
* Construct a <code>ModelMBean</code> with default
* <code>ModelMBeanInfo</code> information.
@@ -54,17 +51,13 @@ public class UserMBean extends BaseModel
* @exception RuntimeOperationsException if an IllegalArgumentException
* occurs
*/
- public UserMBean()
- throws MBeanException, RuntimeOperationsException {
-
+ public UserMBean() throws MBeanException, RuntimeOperationsException {
super();
-
}
// ----------------------------------------------------- Instance Variables
-
/**
* The configuration information registry for our managed beans.
*/
@@ -74,8 +67,7 @@ public class UserMBean extends BaseModel
/**
* The <code>ManagedBean</code> information describing this MBean.
*/
- protected final ManagedBean managed =
- registry.findManagedBean("User");
+ protected final ManagedBean managed = registry.findManagedBean("User");
// ------------------------------------------------------------- Attributes
@@ -104,7 +96,6 @@ public class UserMBean extends BaseModel
}
}
return results.toArray(new String[results.size()]);
-
}
@@ -131,13 +122,11 @@ public class UserMBean extends BaseModel
}
}
return results.toArray(new String[results.size()]);
-
}
// ------------------------------------------------------------- Operations
-
/**
* Add a new {@link Group} to those this user belongs to.
*
@@ -151,11 +140,9 @@ public class UserMBean extends BaseModel
}
Group group = user.getUserDatabase().findGroup(groupname);
if (group == null) {
- throw new IllegalArgumentException
- ("Invalid group name '" + groupname + "'");
+ throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
}
user.addGroup(group);
-
}
@@ -172,11 +159,9 @@ public class UserMBean extends BaseModel
}
Role role = user.getUserDatabase().findRole(rolename);
if (role == null) {
- throw new IllegalArgumentException
- ("Invalid role name '" + rolename + "'");
+ throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
}
user.addRole(role);
-
}
@@ -193,11 +178,9 @@ public class UserMBean extends BaseModel
}
Group group = user.getUserDatabase().findGroup(groupname);
if (group == null) {
- throw new IllegalArgumentException
- ("Invalid group name '" + groupname + "'");
+ throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
}
user.removeGroup(group);
-
}
@@ -214,12 +197,8 @@ public class UserMBean extends BaseModel
}
Role role = user.getUserDatabase().findRole(rolename);
if (role == null) {
- throw new IllegalArgumentException
- ("Invalid role name '" + rolename + "'");
+ throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
}
user.removeRole(role);
-
}
-
-
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1771377&r1=1771376&r2=1771377&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Nov 25 20:40:04 2016
@@ -122,6 +122,10 @@
request body, ensure the read position will be restored to the
original one. (violetagg)
</fix>
+ <scode>
+ Refactor the MBean implementations for the internal Tomcat components
+ to reduce code duplication. (markt)
+ </scode>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org