diff --git a/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaExtension.java b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaExtension.java index c2a8080..01b99a1 100644 --- a/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaExtension.java +++ b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaExtension.java @@ -34,6 +34,7 @@ import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.OperationEntry; +import org.jboss.as.controller.registry.OperationEntry.Flag; import org.jboss.as.threads.BoundedQueueThreadPoolResourceDefinition; import org.jboss.as.threads.ThreadsParser; import org.jboss.as.threads.ThreadsServices; @@ -85,6 +86,8 @@ public class JcaExtension implements Extension { private static final int MANAGEMENT_API_MINOR_VERSION = 1; private static final int MANAGEMENT_API_MICRO_VERSION = 0; + private static final EnumSet RUNTIME_ONLY_FLAG = EnumSet.of(Flag.RUNTIME_ONLY); + @Override public void initialize(final ExtensionContext context) { ROOT_LOGGER.debugf("Initializing Connector Extension"); @@ -123,6 +126,9 @@ public class JcaExtension implements Extension { cachedConnectionManager.registerOperationHandler(ADD, CachedConnectionManagerAdd.INSTANCE, JcaSubsystemProviders.ADD_CACHED_CONNECTION_MANAGER_DESC, false); cachedConnectionManager.registerOperationHandler(REMOVE, ReloadRequiredRemoveStepHandler.INSTANCE, JcaSubsystemProviders.REMOVE_CACHED_CONNECTION_MANAGER_DESC, false); + if (registerRuntimeOnly) + cachedConnectionManager.registerOperationHandler("listInUseConnections", ListInUseConnectionsOperationHandler.INSTANCE, JcaSubsystemProviders.LIST_IN_USE_CONN_CACHED_CONNECTION_MANAGER_DESC, RUNTIME_ONLY_FLAG); + for (final CachedConnectionManagerAdd.CcmParameters parameter : CachedConnectionManagerAdd.CcmParameters.values()) { if (parameter != CachedConnectionManagerAdd.CcmParameters.INSTALL) { cachedConnectionManager.registerReadWriteAttribute(parameter.getAttribute().getName(), null, JcaAttributeWriteHandler.INSTANCE, AttributeAccess.Storage.CONFIGURATION); diff --git a/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemProviders.java b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemProviders.java index 66fc213..d9789fc 100644 --- a/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemProviders.java +++ b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemProviders.java @@ -34,17 +34,21 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHI import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HEAD_COMMENT_ALLOWED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACE; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NILLABLE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REPLY_PROPERTIES; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TAIL_COMMENT_ALLOWED; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE; import java.util.Locale; import java.util.ResourceBundle; import org.jboss.as.controller.descriptions.DescriptionProvider; import org.jboss.dmr.ModelNode; +import org.jboss.dmr.ModelType; /** * @author Kabir Khan @@ -249,6 +253,38 @@ class JcaSubsystemProviders { } }; + static DescriptionProvider LIST_IN_USE_CONN_CACHED_CONNECTION_MANAGER_DESC = new DescriptionProvider() { + + + @Override + public ModelNode getModelDescription(final Locale locale) { + // final ResourceBundle bundle = getResourceBundle(locale); + final ModelNode operation = new ModelNode(); + + operation.get(OPERATION_NAME).set("list-in-use-connections"); + operation.get(DESCRIPTION).set("jca.cached-connection-manager.list-in-use-connections"); + operation.get(REQUEST_PROPERTIES).setEmptyObject(); + + final ModelNode reply = operation.get(REPLY_PROPERTIES); + + reply.get(DESCRIPTION).set("connections"); + reply.get(TYPE).set(ModelType.LIST); + reply.get(NILLABLE).set(false); + ModelNode valueNode = reply.get(VALUE_TYPE); + + valueNode.get("count", DESCRIPTION).set("used-conn..count"); + valueNode.get("count", TYPE).set(ModelType.STRING); + valueNode.get("count", NILLABLE).set(true); + + valueNode.get("listing", DESCRIPTION).set("used-conn.listing"); + valueNode.get("listing", TYPE).set(ModelType.STRING); + + return operation; + } + + + }; + static DescriptionProvider WORKMANAGER_DESC = new DescriptionProvider() { @Override public ModelNode getModelDescription(Locale locale) { diff --git a/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ListInUseConnectionsOperationHandler.java b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ListInUseConnectionsOperationHandler.java new file mode 100644 index 0000000..be71be9 --- /dev/null +++ b/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ListInUseConnectionsOperationHandler.java @@ -0,0 +1,57 @@ +package org.jboss.as.connector.subsystems.jca; + +import java.util.Map; + +import org.jboss.as.connector.util.ConnectorServices; +import org.jboss.as.controller.OperationContext; +import org.jboss.as.controller.OperationFailedException; +import org.jboss.as.controller.OperationStepHandler; +import org.jboss.dmr.ModelNode; +import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; +import org.jboss.msc.service.ServiceController; + +/** + * Reads the "connections in use from ccm" attribute. + * + */ +public class ListInUseConnectionsOperationHandler implements OperationStepHandler { + + public static final ListInUseConnectionsOperationHandler INSTANCE = new ListInUseConnectionsOperationHandler(); + + private ListInUseConnectionsOperationHandler() { + } + + @Override + public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { + + context.addStep(new OperationStepHandler() { + + @Override + public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { + ServiceController sc = context.getServiceRegistry(false).getRequiredService(ConnectorServices.CCM_SERVICE); + CachedConnectionManager ccm = CachedConnectionManager.class.cast(sc.getValue()); + + int inUseConnections = ccm.getInUseConnections(); + + ModelNode result = context.getResult(); + ModelNode sizeNode = new ModelNode(); + sizeNode.get("count").set(inUseConnections); + result.add(sizeNode); + + if (inUseConnections > 0) { + Map listInUseConnections = ccm.listInUseConnections(); + listInUseConnections.keySet(); + for (String key : listInUseConnections.keySet()) { + ModelNode driverNode = new ModelNode(); + driverNode.get("listing").set(key + "\n\n" + listInUseConnections.get(key)); + result.add(driverNode); + } + } + + context.completeStep(); + } + }, OperationContext.Stage.RUNTIME); + + context.completeStep(); + } +}