use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class CmdRunner method runUpdate.
private int runUpdate(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
Properties targetAttrs;
String input = null;
String yes, yesShort, no, noShort;
yes = ar.getString(ar.Q_RESPONSE_YES);
yesShort = ar.getString(ar.Q_RESPONSE_YES_SHORT);
no = ar.getString(ar.Q_RESPONSE_NO);
noShort = ar.getString(ar.Q_RESPONSE_NO_SHORT);
broker = init();
String commandArg = brokerCmdProps.getCommandArg();
boolean force = brokerCmdProps.forceModeSet();
if (CMDARG_BROKER.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR_FAIL));
return (1);
}
if (!force)
broker = promptForAuthentication(broker);
targetAttrs = brokerCmdProps.getTargetAttrs();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR));
Globals.stdOutPrintln("");
printAttrs(targetAttrs);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
if (!force) {
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_UPDATE_BKR_OK), noShort);
Globals.stdOutPrintln("");
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR_NOOP));
return (0);
} else if (!(yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input))) {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR_NOOP));
return (1);
}
}
try {
connectToBroker(broker);
broker.sendUpdateBrokerPropsMessage(targetAttrs);
broker.receiveUpdateBrokerPropsReplyMessage();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_BKR_FAIL));
return (1);
}
} else if (CMDARG_SERVICE.equals(commandArg)) {
ServiceInfo si;
String svcName;
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_FAIL));
return (1);
}
if (!force)
broker = promptForAuthentication(broker);
targetAttrs = brokerCmdProps.getTargetAttrs();
svcName = brokerCmdProps.getTargetName();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC, svcName));
Globals.stdOutPrintln("");
printAttrs(targetAttrs);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
si = getServiceInfoFromAttrs(targetAttrs);
si.setName(svcName);
/*
* Get the svcPort value.
*/
// int svcType = -1;
int svcPort = -1;
Vector svc = null;
try {
connectToBroker(broker);
broker.sendGetServicesMessage(svcName);
svc = broker.receiveGetServicesReplyMessage();
if ((svc != null) && (svc.size() == 1)) {
Enumeration thisEnum = svc.elements();
ServiceInfo sInfo = (ServiceInfo) thisEnum.nextElement();
// svcType = sInfo.type;
svcPort = sInfo.port;
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_FAIL));
return (1);
}
if (!force) {
/*
* Rollback the fix for bug 4432483: jmqcmd, jmqadmin: setting admin max threads = 0 is allowed & hangs. Now this check
* is done by the broker. if ((si.isModified(ServiceInfo.MAX_THREADS)) && (si.maxThreads == 0)) {
* Globals.stdErrPrintln(ar.getString(ar.W_SET_MAX_THREAD_ZERO, svcName)); }
*/
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_UPDATE_SVC_OK), noShort);
Globals.stdOutPrintln("");
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_NOOP));
return (0);
} else if (!(yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input))) {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_NOOP));
return (1);
}
}
// If the port is -1, it is not used, so disallow the update.
if ((si.isModified(ServiceInfo.PORT)) && (svcPort == -1)) {
Globals.stdErrPrintln(ar.getString(ar.E_PORT_NOT_ALLOWED_TO_CHANGE, svcName));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_FAIL));
return (1);
}
try {
broker.sendUpdateServiceMessage(si);
broker.receiveUpdateServiceReplyMessage();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_SVC_FAIL));
return (1);
}
} else if (CMDARG_DESTINATION.equals(commandArg)) {
DestinationInfo di;
String destName;
int destTypeMask;
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_FAIL));
return (1);
}
if (!force)
broker = promptForAuthentication(broker);
targetAttrs = brokerCmdProps.getTargetAttrs();
destTypeMask = getDestTypeMask(brokerCmdProps);
destName = brokerCmdProps.getTargetName();
if (DestType.isQueue(destTypeMask)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_Q, destName));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_T, destName));
}
Globals.stdOutPrintln("");
printAttrs(targetAttrs);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
if (!force) {
if (updatingDestXMLSchema(targetAttrs)) {
Object[] args = new Object[3];
args[0] = PROP_NAME_VALIDATE_XML_SCHEMA_ENABLED;
args[1] = PROP_NAME_XML_SCHEMA_URI_LIST;
args[2] = PROP_NAME_RELOAD_XML_SCHEMA_ON_FAILURE;
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_UPDATE_DEST_XML_SCHEMA_OK, args), noShort);
} else {
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_UPDATE_DEST_OK), noShort);
}
Globals.stdOutPrintln("");
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_NOOP));
return (0);
} else if (!(yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input))) {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_NOOP));
return (1);
}
}
try {
di = getDestinationInfoFromAttrs(targetAttrs);
di.setType(destTypeMask);
di.setName(destName);
connectToBroker(broker);
broker.sendUpdateDestinationMessage(di);
broker.receiveUpdateDestinationReplyMessage();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_UPDATE_DEST_FAIL));
return (1);
}
}
broker.close();
return (0);
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class CmdRunner method getServiceInfoFromAttrs.
private ServiceInfo getServiceInfoFromAttrs(Properties svcAttrs) {
ServiceInfo si = new ServiceInfo();
for (Enumeration e = svcAttrs.propertyNames(); e.hasMoreElements(); ) {
String propName = (String) e.nextElement(), value = svcAttrs.getProperty(propName);
int intValue = 0;
boolean valueOK = true;
if (propName.equals(PROP_NAME_SVC_PORT)) {
try {
intValue = Integer.parseInt(value);
} catch (NumberFormatException nfe) {
valueOK = false;
}
if (valueOK) {
si.setPort(intValue);
}
continue;
}
if (propName.equals(PROP_NAME_SVC_MIN_THREADS)) {
try {
intValue = Integer.parseInt(value);
} catch (NumberFormatException nfe) {
valueOK = false;
}
if (valueOK) {
si.setMinThreads(intValue);
}
continue;
}
if (propName.equals(PROP_NAME_SVC_MAX_THREADS)) {
try {
intValue = Integer.parseInt(value);
} catch (NumberFormatException nfe) {
valueOK = false;
}
if (valueOK) {
si.setMaxThreads(intValue);
}
continue;
}
}
return (si);
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class ServiceMonitor method getNumPktsOut.
public Long getNumPktsOut() {
ServiceInfo si = ServiceUtil.getServiceInfo(service);
MetricCounters metrics = si.metrics;
if (metrics != null) {
return (Long.valueOf(metrics.packetsOut));
} else {
return (Long.valueOf(-1));
}
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class ServiceMonitor method getNumMsgsOut.
public Long getNumMsgsOut() {
ServiceInfo si = ServiceUtil.getServiceInfo(service);
MetricCounters metrics = si.metrics;
if (metrics != null) {
return (Long.valueOf(metrics.messagesOut));
} else {
return (Long.valueOf(-1));
}
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class ServiceMonitor method getNumActiveThreads.
public Integer getNumActiveThreads() {
ServiceInfo si = ServiceUtil.getServiceInfo(service);
MetricCounters metrics = si.metrics;
if (metrics != null) {
return (Integer.valueOf(metrics.threadsActive));
} else {
return (Integer.valueOf(-1));
}
}
Aggregations