use of com.sun.messaging.jmq.jmsserver.core.Producer in project openmq by eclipse-ee4j.
the class GetDestinationsHandler method getDestinationInfo.
private static DestinationInfo getDestinationInfo(Destination d, DestinationInfo dinfo, boolean showpartition) {
DestinationInfo di = dinfo;
if (di == null || showpartition) {
di = new DestinationInfo();
}
d.getSizeInfo(di);
if (dinfo == null || showpartition) {
di.nConsumers = d.getConsumerCount();
di.nfConsumers = d.getFailoverConsumerCount();
di.naConsumers = d.getActiveConsumerCount();
}
di.nProducers += d.getProducerCount();
if (dinfo == null || showpartition) {
di.autocreated = (d.isAutoCreated() || d.isInternal() || d.isDMQ() || d.isAdmin());
}
if (dinfo == null || showpartition) {
di.destState = d.getState();
}
if (d.isAdmin() || !showpartition) {
di.name = d.getDestinationName();
} else {
PartitionedStore pstore = d.getPartitionedStore();
di.name = d.getDestinationName() + "[" + pstore.getPartitionID() + (pstore.isPrimaryPartition() ? "*]" : "]");
}
if (dinfo == null || showpartition) {
di.type = d.getType() & ~(DestType.DEST_INTERNAL | DestType.DEST_AUTO | DestType.DEST_ADMIN);
di.fulltype = d.getType();
}
di.maxMessages += d.getCapacity();
if (di.maxMessages < 0) {
di.maxMessages = 0;
}
SizeString bc = d.getByteCapacity();
di.maxMessageBytes += (bc == null ? 0 : bc.getBytes());
if (di.maxMessageBytes < 0) {
di.maxMessageBytes = 0;
}
bc = d.getMaxByteSize();
di.maxMessageSize += (bc == null ? 0 : bc.getBytes());
if (di.maxMessageSize < 0) {
di.maxMessageSize = 0;
}
if (dinfo == null || showpartition) {
di.destScope = d.getScope();
di.destLimitBehavior = d.getLimitBehavior();
di.maxPrefetch = d.getMaxPrefetch();
di.destCDP = d.getClusterDeliveryPolicy();
di.maxActiveConsumers = d.getMaxActiveConsumers();
di.maxFailoverConsumers = d.getMaxFailoverConsumers();
di.maxProducers = d.getMaxProducers();
di.maxNumSharedConsumers = d.getMaxNumSharedConsumers();
di.sharedConsumerFlowLimit = d.getSharedConsumerFlowLimit();
di.useDMQ = d.getUseDMQ();
di.validateXMLSchemaEnabled = d.validateXMLSchemaEnabled();
di.XMLSchemaUriList = d.getXMLSchemaUriList();
di.reloadXMLSchemaOnFailure = d.reloadXMLSchemaOnFailure();
}
if (!d.isQueue()) {
Hashtable<String, Integer> h = new Hashtable<>();
if (dinfo == null || showpartition) {
if (di.nConsumers > 0) {
Iterator consumers = d.getConsumers();
while (consumers.hasNext()) {
Consumer oneCon = (Consumer) consumers.next();
if (oneCon.isWildcard()) {
DestinationUID id = oneCon.getDestinationUID();
String wildcard = id.getName();
Integer count = h.get(wildcard), newCount;
if (count == null) {
newCount = Integer.valueOf(1);
} else {
newCount = Integer.valueOf(count.intValue() + 1);
}
h.put(wildcard, newCount);
}
}
}
if (h.size() > 0) {
di.consumerWildcards = h;
}
}
h = di.producerWildcards;
if (h == null) {
h = new Hashtable<>();
}
if (di.nProducers > 0) {
Iterator producers = d.getProducers();
while (producers.hasNext()) {
Producer oneProd = (Producer) producers.next();
if (oneProd.isWildcard()) {
DestinationUID id = oneProd.getDestinationUID();
String wildcard = id.getName();
Integer count = h.get(wildcard), newCount;
if (count == null) {
newCount = Integer.valueOf(1);
} else {
newCount = Integer.valueOf(count.intValue() + 1);
}
h.put(wildcard, newCount);
}
}
}
if (h.size() > 0) {
di.producerWildcards = h;
}
}
return di;
}
use of com.sun.messaging.jmq.jmsserver.core.Producer in project openmq by eclipse-ee4j.
the class AdminDataHandler method handle.
/**
* Method to handle administration messages
*/
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
if (DEBUG) {
logger.log(Logger.DEBUGMED, "AdminDataHandler: handle() [ Received JMS Admin Message] {0} ", msg.toString());
if (logger.level >= Logger.DEBUGHIGH) {
msg.dump(System.out);
}
}
String dest = msg.getDestination();
// administration Queue
if (!msg.getIsQueue() || (!dest.equals(MessageType.JMQ_ADMIN_DEST) && !dest.equals(MessageType.JMQ_BRIDGE_ADMIN_DEST))) {
// Normal message. Let standard JMS data handler deal with it.
return super.handle(con, msg);
}
boolean bridgeAdmin = false;
if (dest.equals(MessageType.JMQ_BRIDGE_ADMIN_DEST)) {
if (DEBUG) {
logger.log(Logger.INFO, "Received bridge admin message");
}
bridgeAdmin = true;
}
Hashtable props = null;
Integer msgType = null;
try {
props = msg.getProperties();
msgType = (Integer) props.get(MessageType.JMQ_MESSAGE_TYPE);
} catch (Exception e) {
// Programming error. No need to I18N
String emsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Admin: Could not extract properties from pkt");
logger.logStack(Logger.WARNING, emsg, e);
throw new BrokerException(emsg, e);
}
if (msgType == null) {
// Programming error. No need to I18N
String emsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Message received on administration destination " + dest + " has no " + MessageType.JMQ_MESSAGE_TYPE + " property ignoring it.");
logger.log(Logger.WARNING, emsg);
throw new BrokerException(emsg);
}
/**
*/
if (bridgeAdmin) {
if (msgType.intValue() != MessageType.HELLO) {
return super.handle(con, msg);
}
}
// send the reply (if necessary)
if (msg.getSendAcknowledge()) {
Packet pkt = new Packet(con.useDirectBuffers());
pkt.setPacketType(PacketType.SEND_REPLY);
pkt.setConsumerID(msg.getConsumerID());
Hashtable hash = new Hashtable();
hash.put("JMQStatus", Integer.valueOf(Status.OK));
pkt.setProperties(hash);
con.sendControlMessage(pkt);
}
Producer pausedProducer = checkFlow(msg, con);
if (pausedProducer != null) {
DestinationUID duid = DestinationUID.getUID(msg.getDestination(), msg.getIsQueue());
Destination[] ds = DL.findDestination(DL.getAdminPartition(), duid);
Destination d = ds[0];
pauseProducer(d, duid, pausedProducer, con);
}
// Administrative message. Process it.
// Get message type property
// Get AdminCmdHandler for this message type
int t = msgType.intValue();
AdminCmdHandler ach = null;
/*
* If the connection is authenticated using admin key authentication then it is considered "restricted" and can only
* perform minimal operations. Anything else is forbidden.
*/
if (con.getAccessController().isRestrictedAdmin() && t != MessageType.SHUTDOWN && t != MessageType.HELLO && t != MessageType.RESTART) {
logger.log(Logger.WARNING, BrokerResources.W_FORBIDDEN_ADMIN_OP, MessageType.getString(t));
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
// By convention reply message is the message type + 1
AdminCmdHandler.setProperties(reply, t + 1, Status.FORBIDDEN, null);
sendReply(con, msg, reply);
// done
return true;
}
// if we arent shutdown .. track our handler cnt
if (t != MessageType.SHUTDOWN && t != MessageType.MIGRATESTORE_BROKER) {
incrementActiveHandlers();
}
try {
if (BrokerStateHandler.isShuttingDown()) {
String message = Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_BKR_SHUTTINGDOWN, MessageType.getString(t));
logger.log(Logger.WARNING, message);
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
// By convention reply message is the message type + 1
AdminCmdHandler.setProperties(reply, t + 1, Status.UNAVAILABLE, message);
sendReply(con, msg, reply);
// done
return true;
}
if (!Broker.getBroker().startupComplete) {
String message = Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_BKR_NOT_READY, MessageType.getString(t));
logger.log(Logger.WARNING, message);
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
// By convention reply message is the message type + 1
AdminCmdHandler.setProperties(reply, t + 1, Status.UNAVAILABLE, message);
sendReply(con, msg, reply);
// done
return true;
}
try {
ach = handlers[t];
} catch (IndexOutOfBoundsException e) {
logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Bad " + MessageType.JMQ_MESSAGE_TYPE + ": " + t, e);
return true;
}
if (ach == null) {
logger.log(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "No administration handler found for message type " + msgType + ". Ignoring.");
return true;
} else {
// Call command handler to handle message
try {
return ach.handle(con, msg, props);
} catch (Exception e) {
// Excepion before sendReply
int estatus = Status.ERROR;
String emsg = e.getMessage();
if (e instanceof BrokerException) {
estatus = ((BrokerException) e).getStatusCode();
} else {
emsg = Globals.getBrokerResources().getKString(BrokerResources.X_INTERNAL_EXCEPTION, e.toString());
}
logger.logStack(Logger.ERROR, emsg, e);
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
AdminCmdHandler.setProperties(reply, t + 1, estatus, emsg);
sendReply(con, msg, reply);
// done
return true;
}
}
} finally {
if (t != MessageType.SHUTDOWN && t != MessageType.MIGRATESTORE_BROKER) {
decrementActiveHandlers();
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.Producer in project openmq by eclipse-ee4j.
the class DebugHandler method handle.
/**
* Handle the incomming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
int status = Status.OK;
String msg = null;
boolean logOnly = false;
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + cmd_props);
}
String cmd = (String) cmd_props.get(MessageType.JMQ_CMD), cmdarg = (String) cmd_props.get(MessageType.JMQ_CMDARG), target = (String) cmd_props.get(MessageType.JMQ_TARGET), targetType = (String) cmd_props.get(MessageType.JMQ_TARGET_TYPE);
// Get properties we are to update from message body
Properties p = (Properties) getBodyObject(cmd_msg);
/*
* To always see output (when debugging/developing this handler) change: if (DEBUG) to if (true)
*
* and Logger.DEBUG to Logger.INFO
*/
if (DEBUG) {
logger.log(Logger.DEBUG, "DEBUG message received:");
logger.log(Logger.DEBUG, "\t" + MessageType.JMQ_CMD + ": " + cmd);
logger.log(Logger.DEBUG, "\t" + MessageType.JMQ_CMDARG + ": " + cmdarg);
logger.log(Logger.DEBUG, "\t" + MessageType.JMQ_TARGET + ": " + target);
logger.log(Logger.DEBUG, "\tOptional Properties: " + p);
}
/*
* CHECK: Should make sure relevant values above are non null (e.g. cmd).
*/
Hashtable debugHash = null;
String fileStr = p.getProperty("file");
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
if ((cmd == null) || (cmdarg == null)) {
status = Status.BAD_REQUEST;
msg = "Null/Missing values for " + MessageType.JMQ_CMD + " and/or " + MessageType.JMQ_CMDARG + " properties.";
setProperties(reply, MessageType.DEBUG_REPLY, status, msg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
if (cmd.equals("update") && cmdarg.equals("bkr")) {
// Get properties we are to update from message body
// Update the broker configuration
BrokerConfig bcfg = Globals.getConfig();
try {
bcfg.updateProperties(p, true);
} catch (PropertyUpdateException e) {
status = Status.BAD_REQUEST;
msg = e.getMessage();
logger.log(Logger.WARNING, msg);
} catch (IOException e) {
status = Status.ERROR;
msg = e.toString();
logger.log(Logger.WARNING, msg);
}
// Send reply
setProperties(reply, MessageType.DEBUG_REPLY, status, msg);
parent.sendReply(con, cmd_msg, reply);
return true;
} else if (cmd.equals("dump") || cmd.equals("query")) {
if (cmd.equals("dump")) {
logOnly = true;
if (fileStr == null) {
fileStr = "dumpOutput";
}
}
try {
debugHash = getDebugInfo(cmdarg, target, targetType, p);
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error " + cmd + "ing " + cmdarg + " because " + ex.getMessage();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (cmd.equals("list")) {
debugHash = new Hashtable();
if (cmdarg.equals("dst")) {
Iterator[] itrs = DL.getAllDestinations(null);
Iterator itr = itrs[0];
while (itr.hasNext()) {
Destination d = (Destination) itr.next();
debugHash.put(d.getDestinationUID().toString(), DestType.toString(d.getType()) + ":" + (d.isStored() ? "stored" : "not stored"));
}
} else if (cmdarg.equals("con")) {
debugHash = new Hashtable();
if (target == null) {
// all
Iterator itr = Consumer.getAllConsumers();
if (!itr.hasNext()) {
status = Status.ERROR;
msg = "No consumers on the broker";
}
while (itr.hasNext()) {
Consumer c = (Consumer) itr.next();
if (c == null) {
continue;
}
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(c.getConnectionUID());
ConsumerUID cuid = c.getConsumerUID();
ConnectionUID cxuid = c.getConnectionUID();
debugHash.put(String.valueOf((cuid == null ? 0 : cuid.longValue())), (cxn == null ? "none" : cxn.getRemoteConnectionString()) + " [" + (cxuid == null ? 0 : cxuid.longValue()) + "]");
}
} else if (targetType == null) {
msg = "Please supply targetType if you are supplying a target ";
status = Status.ERROR;
} else if (targetType.equals("t") || targetType.equals("q")) {
try {
boolean isQueue = false;
if (targetType.equals("q")) {
isQueue = true;
}
DestinationUID uid = null;
Destination d = null;
if (status != Status.ERROR) {
uid = DestinationUID.getUID(target, isQueue);
Destination[] ds = DL.getDestination(null, uid);
d = ds[0];
}
if (status != Status.ERROR && d == null) {
status = Status.ERROR;
msg = "Error listing consumers on destination " + target + " unknown destination";
} else if (status != Status.ERROR) {
Iterator itr = d.getConsumers();
if (!itr.hasNext()) {
status = Status.ERROR;
msg = "No consumers on destination " + target;
}
while (itr.hasNext()) {
Consumer c = (Consumer) itr.next();
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(c.getConnectionUID());
debugHash.put(String.valueOf(c.getConsumerUID().longValue()), (cxn == null ? "" : cxn.getRemoteConnectionString()) + " [" + (c.getConnectionUID() == null ? "none" : c.getConnectionUID().longValue()) + "]");
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error listing consumers on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (targetType.equals("ses")) {
try {
SessionUID uid = new SessionUID(Long.parseLong(target));
Session ses = Session.getSession(uid);
if (ses == null) {
status = Status.ERROR;
msg = "Error listing consumers on session " + target + " unknown sessionUID";
} else {
Iterator itr = ses.getConsumers();
if (!itr.hasNext()) {
status = Status.ERROR;
msg = "No consumers on session " + target;
}
while (itr.hasNext()) {
ConsumerSpi c = (ConsumerSpi) itr.next();
if (uid.equals(c.getConnectionUID())) {
debugHash.put(String.valueOf(c.getConsumerUID().longValue()), c.getDestinationUID().toString());
}
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error listing consumers on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (targetType.equals("cxn")) {
try {
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
if (cxn == null) {
status = Status.ERROR;
msg = "Error listing consumers on connection " + target + " unknown connectionUID";
} else {
Iterator itr = Consumer.getAllConsumers();
while (itr.hasNext()) {
Consumer c = (Consumer) itr.next();
if (uid.equals(c.getConnectionUID())) {
debugHash.put(String.valueOf(c.getConsumerUID().longValue()), c.getDestinationUID().toString());
}
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error listing consumers on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown targetType (-t) " + target + "\n Valid formats are of the form: " + "[q|t|ses|cxn]";
}
} else if (cmdarg.equals("prd")) {
debugHash = new Hashtable();
if (target == null) {
// all
Iterator itr = Producer.getAllProducers();
while (itr.hasNext()) {
Producer c = (Producer) itr.next();
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(c.getConnectionUID());
debugHash.put(String.valueOf(c.getProducerUID().longValue()), cxn.getRemoteConnectionString() + " [" + c.getConnectionUID().longValue() + "]");
}
} else if (targetType == null) {
msg = "Please supply targetType if you are supplying a target ";
status = Status.ERROR;
} else if (targetType.equals("t") || targetType.equals("q")) {
// destination
boolean isQueue = false;
if (targetType.equals("q")) {
isQueue = true;
}
try {
DestinationUID uid = DestinationUID.getUID(target, isQueue);
Destination[] ds = DL.getDestination(null, uid);
Destination d = ds[0];
if (d == null) {
status = Status.ERROR;
msg = "Error listing producers on destination " + target + " unknown destination";
} else {
Iterator itr = d.getProducers();
while (itr.hasNext()) {
Producer c = (Producer) itr.next();
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(c.getConnectionUID());
debugHash.put(String.valueOf(c.getProducerUID().longValue()), cxn.getRemoteConnectionString() + " [" + c.getConnectionUID().longValue() + "]");
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error listing producers on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (targetType.equals("cxn")) {
try {
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
if (cxn == null) {
status = Status.ERROR;
msg = "Error listing producers on connection " + target + " unknown connectionUID";
} else {
Iterator itr = Producer.getAllProducers();
while (itr.hasNext()) {
Producer c = (Producer) itr.next();
if (uid.equals(c.getConnectionUID())) {
debugHash.put(String.valueOf(c.getProducerUID().longValue()), c.getDestinationUID().toString());
}
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error listing producers on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown targetType (-t) " + targetType + "\n Valid formats are of the form: " + "[t|q|cxn]";
}
} else {
status = Status.ERROR;
msg = "Unknown argument " + cmdarg;
}
} else if (cmd.equals("debug")) {
String debugStr = (String) p.get("enable");
if (debugStr != null && !debugStr.equalsIgnoreCase("true") && !debugStr.equalsIgnoreCase("false")) {
status = Status.ERROR;
msg = "bad enable flag setting " + debugStr + " defauling to false";
}
boolean debugOn = debugStr == null || Boolean.parseBoolean(debugStr);
if (cmdarg.equals("reset")) {
if (targetType == null) {
msg = "Please supply targetType (-t)\n Valid formats are of the form: [metrics|jdbcconnpool]";
status = Status.ERROR;
} else if (targetType.equalsIgnoreCase("jdbcconnpool")) {
try {
if (Globals.getStore().isJDBCStore()) {
Globals.getStore().resetConnectionPool();
} else {
status = Status.ERROR;
msg = "Operation is not applicable for a file-based data store.";
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error resetting JDBC connection pool because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (targetType.equalsIgnoreCase("metrics")) {
com.sun.messaging.jmq.jmsserver.data.handlers.admin.ResetMetricsHandler.resetAllMetrics();
}
} else if (cmdarg.equals("fault")) {
// handle fault injection
String faultName = (String) p.get("name");
if (faultName == null) {
faultName = target;
}
String faultSelector = (String) p.get("selector");
FaultInjection fi = FaultInjection.getInjection();
// ok only turn off fault injection if no name pair
if (debugStr != null && debugStr.equalsIgnoreCase("false")) {
if (faultName == null) {
fi.setFaultInjection(false);
} else {
fi.unsetFault(faultName);
}
} else {
fi.setFaultInjection(true);
if (faultName != null) {
try {
fi.setFault(faultName, faultSelector, p);
} catch (Exception ex) {
status = Status.ERROR;
msg = "Bad Selector " + faultSelector;
}
}
}
} else if (cmdarg.equals("gc")) {
logger.log(Logger.INFO, "GC'ing the system");
System.gc();
long usedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
msg = "Used memory is " + (usedMem / 1024l) + "k, " + " this is " + (usedMem * 100 / Runtime.getRuntime().maxMemory()) + "% of " + (Runtime.getRuntime().maxMemory() / 1024l) + "k";
logger.log(Logger.INFO, msg);
debugHash = new Hashtable();
debugHash.put("Memory", msg);
debugHash.put("Used", (usedMem / 1024l) + "k");
debugHash.put("Total", ((Runtime.getRuntime().totalMemory() / 1024l) + "k"));
debugHash.put("Free", ((Runtime.getRuntime().freeMemory() / 1024l) + "k"));
debugHash.put("Max", ((Runtime.getRuntime().maxMemory() / 1024l) + "k"));
} else if (cmdarg.equals("threads")) {
// log
try {
debugHash = new Hashtable();
debugHash.put("threads", "dumped to log");
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error " + cmd + "ing " + cmdarg + " because " + ex.getMessage() + "";
logger.logStack(Logger.INFO, msg, ex);
}
logger.log(Logger.INFO, "Dumping threads:\n" + SupportUtil.getAllStackTraces("\t"));
} else if (cmdarg.equals("pkt")) {
IMQBasicConnection.dumpPacket(debugOn);
} else if (cmdarg.equals("pktin")) {
IMQBasicConnection.dumpInPacket(debugOn);
} else if (cmdarg.equals("pktout")) {
IMQBasicConnection.dumpOutPacket(debugOn);
} else if (cmdarg.equals("class")) {
try {
Class cl = Class.forName(target);
Field[] fields = cl.getDeclaredFields();
boolean found = false;
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(Debug.debugFieldName)) {
logger.log(Logger.INFO, "Turn " + (debugOn ? "on" : "off") + " debug for class " + target);
final Field f = fields[i];
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {
@Override
public Object run() {
f.setAccessible(true);
return null;
}
});
fields[i].setBoolean(null, debugOn);
found = true;
break;
}
}
if (!found) {
throw new NoSuchFieldException(Debug.debugFieldName);
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Unable to set DEBUG on class " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown debug argument " + cmdarg;
}
} else if (cmd.equals("resume")) {
// session, connection, consumerUID, producer
if (cmdarg.equals("prd")) {
try {
ProducerUID pid = new ProducerUID(Long.parseLong(target));
Producer pr = (Producer) Producer.getProducer(pid);
Destination[] ds = DL.getDestination(null, pr.getDestinationUID());
Destination d = ds[0];
logger.log(Logger.INFO, "Resuming " + pr);
d.forceResumeFlow(pr);
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error resuming flow from producer " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (cmdarg.equals("cxn")) {
try {
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
cxn.resumeFlow(-1);
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error resuming flow on connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (cmdarg.equals("con")) {
try {
ConsumerUID cid = new ConsumerUID(Long.parseLong(target));
Consumer cxn = Consumer.getConsumer(cid);
cxn.resume("admin debug");
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error resuming flow to consumer " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (cmdarg.equals("ses")) {
try {
SessionUID sid = new SessionUID(Long.parseLong(target));
Session session = Session.getSession(sid);
session.resume("admin debug");
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error resuming flow to session " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown resume argument " + cmdarg;
}
} else if (cmd.equals("send")) {
if (cmdarg.equals("cxn")) {
try {
if (target == null) {
status = Status.ERROR;
msg = "Missing connectionUID ";
} else {
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
if (cxn == null) {
status = Status.ERROR;
msg = "Unknown connectionUID " + uid;
} else {
sendClientDEBUG(cxn, cmd_props, p);
}
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error notifying consumer " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else if (cmdarg.equals("bkr") || cmdarg.equals("svc")) {
Service s = null;
if (target != null) {
s = Globals.getServiceManager().getService(target);
if (s == null) {
msg = "Unknown service " + target;
status = Status.ERROR;
}
}
Iterator itr = Globals.getConnectionManager().getConnectionList(s).iterator();
try {
while (itr.hasNext()) {
IMQConnection cxn = (IMQConnection) itr.next();
Packet pkt = new Packet(false);
pkt.setPacketType(PacketType.DEBUG);
Hashtable hash = new Hashtable(cmd_props);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(p);
oos.flush();
bos.flush();
pkt.setMessageBody(bos.toByteArray());
pkt.setProperties(hash);
cxn.sendControlMessage(pkt);
}
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error notifying consumer " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown send argument " + cmdarg;
}
} else if (cmd.equals("kill")) {
if (cmdarg.equals("cxn")) {
try {
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
cxn.destroyConnection(true, GoodbyeReason.ADMIN_KILLED_CON, "kill cnx");
} catch (Exception ex) {
status = Status.ERROR;
msg = "Error killing connection " + target + " because " + ex.toString();
logger.logStack(Logger.INFO, msg, ex);
}
} else {
status = Status.ERROR;
msg = "Unknown kill argument " + cmdarg;
}
}
if (fileStr != null && debugHash != null) {
DebugPrinter dbp = new DebugPrinter(2);
dbp.setHashtable(debugHash);
dbp.setFile(fileStr);
dbp.println();
dbp.close();
if (status == Status.OK) {
msg = "Data logged at file " + fileStr;
}
if (logOnly) {
debugHash = new Hashtable();
debugHash.put("logfile", fileStr);
}
}
if (msg != null) {
logger.log(Logger.INFO, msg);
}
setProperties(reply, MessageType.DEBUG_REPLY, status, msg);
if (debugHash != null) {
setBodyObject(reply, debugHash);
}
parent.sendReply(con, cmd_msg, reply);
return true;
}
Aggregations