
org.glassfish.admingui.plugin.jms.JmsHandlers Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admingui.plugin.jms;
import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Server;
import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.connectors.jms.system.JmsProviderLifecycle;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import org.glassfish.admingui.common.util.GuiUtil;
import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.ServerContext;
import org.glassfish.jms.admin.cli.JMSDestination;
import org.glassfish.jms.admin.cli.MQJMXConnectorInfo;
import org.glassfish.resourcebase.resources.api.PoolInfo;
/**
*
* @author jasonlee
*/
public class JmsHandlers {
protected static final String OBJECT_DEST_MGR = "com.sun.messaging.jms.server:type=DestinationManager,subtype=Config";
protected static final String OBJECT_DEST_BASE = "com.sun.messaging.jms.server:type=Destination";
protected static final String SUBTYPE_CONFIG = "Config";
protected static final String SUBTYPE_MONITOR = "Monitor";
protected static final String OP_LIST_DESTINATIONS = "getDestinations";
protected static final String OP_CREATE = "create";
protected static final String OP_DESTROY = "destroy";
protected static final String OP_PURGE = "purge";
// Config attributes
protected static final String ATTR_CONSUMER_FLOW_LIMIT = "ConsumerFlowLimit";
protected static final String ATTR_LIMIT_BEHAVIOR = "LimitBehavior";
protected static final String ATTR_LOCAL_DELIVERY_PREFERRED = "LocalDeliveryPreferred";
protected static final String ATTR_MAX_BYTES_PER_MSG = "MaxBytesPerMsg";
protected static final String ATTR_MAX_NUM_ACTIVE_CONSUMERS = "MaxNumActiveConsumers";
protected static final String ATTR_MAX_NUM_BACKUP_CONSUMERS = "MaxNumBackupConsumers";
protected static final String ATTR_MAX_NUM_PRODUCERS = "MaxNumProducers";
protected static final String ATTR_USE_DMQ = "UseDMQ";
protected static final String ATTR_MAX_NUM_MSGS = "MaxNumMsgs";
protected static final String ATTR_MAX_TOTAL_MSG_BYTES = "MaxTotalMsgBytes";
protected static final String ATTR_VALIDATE_XML_SCHEMA_ENABLED = "ValidateXMLSchemaEnabled";
protected static final String ATTR_XML_SCHEMA_URI_LIST = "XMLSchemaURIList";
// Monitoring attributes
protected static final String ATTR_CREATED_BY_ADMIN = "CreatedByAdmin";
protected static final String ATTR_TEMPORARY = "Temporary";
protected static final String ATTR_CONNECTION_ID = "ConnectionID";
protected static final String ATTR_STATE = "State";
protected static final String ATTR_STATE_LABEL = "StateLabel";
protected static final String ATTR_NUM_PRODUCERS = "NumProducers";
protected static final String ATTR_NUM_CONSUMERS = "NumConsumers";
protected static final String ATTR_NUM_WILDCARD_PRODUCERS = "NumWildcardProducers";
protected static final String ATTR_NUM_WILDCARD_CONSUMERS = "NumWildcardConsumers";
protected static final String ATTR_NUM_WILDCARDS = "NumWildcards";
protected static final String ATTR_PEAK_NUM_CONSUMERS = "PeakNumConsumers";
protected static final String ATTR_AVG_NUM_CONSUMERS = "AvgNumConsumers";
protected static final String ATTR_NUM_ACTIVE_CONSUMERS = "NumActiveConsumers";
protected static final String ATTR_PEAK_NUM_ACTIVE_CONSUMERS = "PeakNumActiveConsumers";
protected static final String ATTR_AVG_NUM_ACTIVE_CONSUMERS = "AvgNumActiveConsumers";
protected static final String ATTR_NUM_BACKUP_CONSUMERS = "NumBackupConsumers";
protected static final String ATTR_PEAK_NUM_BACKUP_CONSUMERS = "PeakNumBackupConsumers";
protected static final String ATTR_AVG_NUM_BACKUP_CONSUMERS = "AvgNumBackupConsumers";
protected static final String ATTR_NUM_MSGS = "NumMsgs";
protected static final String ATTR_NUM_MSGS_REMOTE = "NumMsgsRemote";
protected static final String ATTR_NUM_MSGS_PENDING_ACKS = "NumMsgsPendingAcks";
protected static final String ATTR_NUM_MSGS_HELD_IN_TRANSACTION = "NumMsgsHeldInTransaction";
protected static final String ATTR_NEXT_MESSAGE_ID = "NextMessageID";
protected static final String ATTR_PEAK_NUM_MSGS = "PeakNumMsgs";
protected static final String ATTR_AVG_NUM_MSGS = "AvgNumMsgs";
protected static final String ATTR_NUM_MSGS_IN = "NumMsgsIn";
protected static final String ATTR_NUM_MSGS_OUT = "NumMsgsOut";
protected static final String ATTR_MSG_BYTES_IN = "MsgBytesIn";
protected static final String ATTR_MSG_BYTES_OUT = "MsgBytesOut";
protected static final String ATTR_PEAK_MSG_BYTES = "PeakMsgBytes";
protected static final String ATTR_TOTAL_MSG_BYTES = "TotalMsgBytes";
protected static final String ATTR_TOTAL_MSG_BYTES_REMOTE = "TotalMsgBytesRemote";
protected static final String ATTR_TOTAL_MSG_BYTES_HELD_IN_TRANSACTION = "TotalMsgBytesHeldInTransaction";
protected static final String ATTR_PEAK_TOTAL_MSG_BYTES = "PeakTotalMsgBytes";
protected static final String ATTR_AVG_TOTAL_MSG_BYTES = "AvgTotalMsgBytes";
protected static final String ATTR_DISK_RESERVED = "DiskReserved";
protected static final String ATTR_DISK_USED = "DiskUsed";
protected static final String ATTR_DISK_UTILIZATION_RATIO = "DiskUtilizationRatio";
private static final String[] ATTRS_CONFIG = new String[] { ATTR_MAX_NUM_MSGS, ATTR_MAX_BYTES_PER_MSG, ATTR_MAX_TOTAL_MSG_BYTES, ATTR_LIMIT_BEHAVIOR,
ATTR_MAX_NUM_PRODUCERS, ATTR_MAX_NUM_ACTIVE_CONSUMERS, ATTR_MAX_NUM_BACKUP_CONSUMERS, ATTR_CONSUMER_FLOW_LIMIT,
ATTR_LOCAL_DELIVERY_PREFERRED, ATTR_USE_DMQ, ATTR_VALIDATE_XML_SCHEMA_ENABLED, ATTR_XML_SCHEMA_URI_LIST };
private static final String[] ATTRS_MONITOR = new String[] { ATTR_CREATED_BY_ADMIN, ATTR_TEMPORARY, ATTR_CONNECTION_ID, ATTR_STATE, ATTR_STATE_LABEL,
ATTR_NUM_PRODUCERS, ATTR_NUM_CONSUMERS, ATTR_NUM_WILDCARD_PRODUCERS, ATTR_NUM_WILDCARD_CONSUMERS, ATTR_NUM_WILDCARDS, ATTR_PEAK_NUM_CONSUMERS,
ATTR_AVG_NUM_CONSUMERS, ATTR_NUM_ACTIVE_CONSUMERS, ATTR_PEAK_NUM_ACTIVE_CONSUMERS, ATTR_AVG_NUM_ACTIVE_CONSUMERS,
ATTR_NUM_BACKUP_CONSUMERS, ATTR_PEAK_NUM_BACKUP_CONSUMERS, ATTR_AVG_NUM_BACKUP_CONSUMERS, ATTR_NUM_MSGS, ATTR_NUM_MSGS_REMOTE,
ATTR_NUM_MSGS_PENDING_ACKS, ATTR_NUM_MSGS_HELD_IN_TRANSACTION, ATTR_NEXT_MESSAGE_ID, ATTR_PEAK_NUM_MSGS, ATTR_AVG_NUM_MSGS,
ATTR_NUM_MSGS_IN, ATTR_NUM_MSGS_OUT, ATTR_MSG_BYTES_IN, ATTR_MSG_BYTES_OUT, ATTR_PEAK_MSG_BYTES, ATTR_TOTAL_MSG_BYTES, ATTR_TOTAL_MSG_BYTES_REMOTE,
ATTR_TOTAL_MSG_BYTES_HELD_IN_TRANSACTION, ATTR_PEAK_TOTAL_MSG_BYTES, ATTR_AVG_TOTAL_MSG_BYTES, ATTR_DISK_RESERVED, ATTR_DISK_USED,
ATTR_DISK_UTILIZATION_RATIO };
protected static final String PROP_NAME = "name";
protected static final String PROP_DEST_TYPE = "desttype";
@Handler(id = "getPhysicalDestination",
input = {
@HandlerInput(name = "name", type = String.class, required = true),
@HandlerInput(name = "type", type = String.class, required = true) },
output = {
@HandlerOutput(name = "destData", type = java.util.Map.class) })
public static void getPhysicalDestination(HandlerContext handlerCtx) {
String name = (String) handlerCtx.getInputValue("name");
String type = (String) handlerCtx.getInputValue("type");
Map valueMap = new HashMap();
try {
String objectName = getJmsDestinationObjectName(SUBTYPE_CONFIG, name, type);
AttributeList attributes = JMXUtil.getMBeanServer().getAttributes(new ObjectName(objectName), ATTRS_CONFIG);
for (Attribute attribute : attributes.asList()) {
valueMap.put(attribute.getName(), (attribute.getValue() != null) ? attribute.getValue().toString() : null);
}
handlerCtx.setOutputValue("destData", valueMap);
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
handlerCtx.setOutputValue("destData", valueMap);
}
@Handler(id = "getPhysicalDestinationStats",
input = {
@HandlerInput(name = "name", type = String.class, required = true),
@HandlerInput(name = "type", type = String.class, required = true),
@HandlerInput(name = "target", type = String.class, required = true) },
output = {
@HandlerOutput(name = "statsData", type = java.util.List.class) })
public static void getPhysicalDestinationStats(HandlerContext handlerCtx) {
String name = (String) handlerCtx.getInputValue("name");
String type = (String) handlerCtx.getInputValue("type");
String target = (String) handlerCtx.getInputValue("target");
List statsList = new ArrayList();
try {
insureJmsBrokerIsRunning();
String objectName = getJmsDestinationObjectName(SUBTYPE_MONITOR, name, type);
AttributeList attributes = getMBeanServerConnection(target).getAttributes(new ObjectName(objectName), ATTRS_MONITOR);
ResourceBundle bundle = GuiUtil.getBundle("org.glassfish.jms.admingui.Strings");
statsList.add(createRow("Name", name, ""));
statsList.add(createRow("Type", type.substring(0, 1).toUpperCase(GuiUtil.guiLocale) + type.substring(1), ""));
for (Attribute attribute : attributes.asList()) {
statsList.add(
createRow(
GuiUtil.getMessage(bundle, "jmsPhysDestinations." + attribute.getName()),
attribute.getValue(),
GuiUtil.getMessage(bundle, "jmsPhysDestinations." + attribute.getName() + "Help")));
}
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
handlerCtx.setOutputValue("statsData", statsList);
}
@Handler(id = "getPhysicalDestinations",
input = {
@HandlerInput(name = "selectedRows", type = List.class) },
output = {
@HandlerOutput(name = "result", type = java.util.List.class) })
public static void getPhysicalDestinations(HandlerContext handlerCtx) {
ObjectName[] objectNames = null;
List result = new ArrayList();
try {
insureJmsBrokerIsRunning();
// com.sun.messaging.jms.server:type=Destination,subtype=Config,desttype=q,name="mq.sys.dmq"
objectNames = (ObjectName[]) JMXUtil.invoke(OBJECT_DEST_MGR, OP_LIST_DESTINATIONS);
if (objectNames == null) {
handlerCtx.setOutputValue("result", result);
return; // nothing to load..
}
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy