use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService in project openmq by eclipse-ee4j.
the class CompactDestinationHandler 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) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Compacting: " + cmd_props);
}
logger.log(Logger.INFO, Globals.getBrokerResources().I_COMPACTING, cmd_props);
String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
Integer type = (Integer) cmd_props.get(MessageType.JMQ_DEST_TYPE);
int status = Status.OK;
String errMsg = null;
boolean compactAll = false;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
try {
if (destination != null) {
// compact one destination
Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type.intValue()));
// PART
Destination d = ds[0];
if (d != null) {
if (d.isPaused()) {
d.compact();
} else {
status = Status.ERROR;
String msg = rb.getString(rb.E_DESTINATION_NOT_PAUSED);
errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, msg);
logger.log(Logger.ERROR, errMsg);
}
} else {
status = Status.ERROR;
String subError = rb.getString(rb.E_NO_SUCH_DESTINATION, getDestinationType(type.intValue()), destination);
errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, subError);
logger.log(Logger.ERROR, errMsg);
}
} else {
Iterator[] itrs = DL.getAllDestinations(null);
Iterator itr = itrs[0];
boolean docompact = true;
while (itr.hasNext()) {
// make sure all are paused
Destination d = (Destination) itr.next();
/*
* Skip internal, admin, or temp destinations. Skipping temp destinations may need to be revisited.
*/
if (d.isInternal() || d.isAdmin() || d.isTemporary()) {
continue;
}
if (!d.isPaused()) {
docompact = false;
status = Status.ERROR;
String msg = rb.getString(rb.E_SOME_DESTINATIONS_NOT_PAUSED);
errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, msg);
logger.log(Logger.ERROR, errMsg);
}
}
if (docompact) {
itrs = DL.getAllDestinations(null);
// PART
itr = itrs[0];
while (itr.hasNext()) {
Destination d = (Destination) itr.next();
/*
* Skip internal, admin, or temp destinations. Skipping temp destinations may need to be revisited.
*/
if (d.isInternal() || d.isAdmin() || d.isTemporary()) {
continue;
}
d.compact();
}
}
}
} catch (Exception e) {
status = Status.ERROR;
if (compactAll) {
errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, e.toString());
} else {
errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, e.toString());
}
logger.log(Logger.ERROR, errMsg, e);
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.COMPACT_DESTINATION_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService in project openmq by eclipse-ee4j.
the class CreateDestinationHandler 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
*/
@SuppressWarnings("deprecation")
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
DestinationInfo info;
info = (DestinationInfo) getBodyObject(cmd_msg);
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Creating destination: " + cmd_props + ": " + info.toString());
}
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
int status = Status.OK;
String errMsg = null;
// Default attributes of the destination
int type = DestType.DEST_TYPE_QUEUE | DestType.DEST_FLAVOR_SINGLE;
int maxMessages = -1;
SizeString maxMessageBytes = null;
SizeString maxMessageSize = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else if (MemoryGlobals.getMEM_DISALLOW_CREATE_DEST()) {
status = Status.ERROR;
errMsg = rb.W_LOW_MEM_REJECT_DEST;
} else if (info.isModified(DestinationInfo.NAME)) {
if (info.isModified(DestinationInfo.TYPE)) {
type = info.type;
}
if (info.isModified(DestinationInfo.MAX_MESSAGES)) {
maxMessages = info.maxMessages;
}
if (info.isModified(DestinationInfo.MAX_MESSAGE_BYTES)) {
maxMessageBytes = new SizeString();
maxMessageBytes.setBytes(info.maxMessageBytes);
}
if (info.isModified(DestinationInfo.MAX_MESSAGE_SIZE)) {
maxMessageSize = new SizeString();
maxMessageSize.setBytes(info.maxMessageSize);
}
} else {
status = Status.ERROR;
errMsg = rb.X_NO_DEST_NAME_SET;
}
// XXX create destination
if (status == Status.OK) {
if (DestType.destNameIsInternal(info.name)) {
status = Status.ERROR;
errMsg = rb.getKString(rb.X_CANNOT_CREATE_INTERNAL_DEST, info.name, DestType.INTERNAL_DEST_PREFIX);
} else {
if (isValidDestinationName(info.name)) {
try {
DL.createDestination(null, info.name, type);
} catch (Exception ex) {
status = Status.ERROR;
errMsg = rb.getKString(rb.X_CREATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
if (ex instanceof ConflictException) {
logger.log(Logger.INFO, errMsg, ex);
} else {
logger.logStack(Logger.INFO, errMsg, ex);
}
}
} else {
status = Status.ERROR;
errMsg = rb.getKString(rb.X_DEST_NAME_INVALID, info.name);
}
}
}
if (status == Status.OK) {
try {
Destination[] ds = DL.getDestination(null, info.name, DestType.isQueue(type));
Destination d = ds[0];
d.setCapacity(maxMessages);
d.setByteCapacity(maxMessageBytes);
d.setMaxByteSize(maxMessageSize);
if (info.isModified(info.DEST_SCOPE)) {
int scope = info.destScope;
d.setScope(scope);
}
if (info.isModified(info.DEST_LIMIT)) {
int destlimit = info.destLimitBehavior;
d.setLimitBehavior(destlimit);
}
if (info.isModified(info.DEST_PREFETCH)) {
int prefetch = info.maxPrefetch;
d.setMaxPrefetch(prefetch);
}
if (info.isModified(info.DEST_CDP)) {
int clusterdeliverypolicy = info.destCDP;
d.setClusterDeliveryPolicy(clusterdeliverypolicy);
}
if (info.isModified(info.MAX_ACTIVE_CONSUMERS)) {
int maxcons = info.maxActiveConsumers;
d.setMaxActiveConsumers(maxcons);
}
if (info.isModified(info.MAX_PRODUCERS)) {
int maxp = info.maxProducers;
d.setMaxProducers(maxp);
}
if (info.isModified(info.MAX_FAILOVER_CONSUMERS)) {
int maxcons = info.maxFailoverConsumers;
d.setMaxFailoverConsumers(maxcons);
}
if (info.isModified(info.MAX_SHARED_CONSUMERS)) {
int maxsharedcons = info.maxNumSharedConsumers;
d.setMaxSharedConsumers(maxsharedcons);
}
if (info.isModified(info.SHARE_FLOW_LIMIT)) {
int sflowlimit = info.sharedConsumerFlowLimit;
d.setSharedFlowLimit(sflowlimit);
}
if (info.isModified(info.USE_DMQ)) {
boolean dmq = info.useDMQ;
d.setUseDMQ(dmq);
}
if (info.isModified(info.VALIDATE_XML_SCHEMA_ENABLED)) {
d.setValidateXMLSchemaEnabled(info.validateXMLSchemaEnabled);
}
if (info.isModified(info.XML_SCHEMA_URI_LIST)) {
d.setXMLSchemaUriList(info.XMLSchemaUriList);
}
if (info.isModified(info.RELOAD_XML_SCHEMA_ON_FAILURE)) {
d.setReloadXMLSchemaOnFailure(info.reloadXMLSchemaOnFailure);
}
d.update();
// audit logging for create destination
Globals.getAuditSession().destinationOperation(con.getUserName(), con.remoteHostString(), MQAuditSession.CREATE_DESTINATION, d.isQueue() ? MQAuditSession.QUEUE : MQAuditSession.TOPIC, d.getDestinationName());
} catch (Exception ex) {
// remove the destination
try {
DestinationUID duid = DestinationUID.getUID(info.name, DestType.isQueue(type));
DL.removeDestination(null, duid, false, ex.toString());
} catch (Exception ex1) {
// if we cant destroy .. its ok .. ignore the exception
}
status = Status.ERROR;
errMsg = rb.getString(rb.X_UPDATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
logger.logStack(Logger.WARNING, errMsg, ex);
}
}
// Send reply
setProperties(reply, MessageType.CREATE_DESTINATION_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService in project openmq by eclipse-ee4j.
the class RollbackCommitHandler 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) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Rollback/Commit transaction " + cmd_props);
}
// Get the admin request message type
int requestType = ((Integer) cmd_props.get(MessageType.JMQ_MESSAGE_TYPE)).intValue();
int status = Status.OK;
String errMsg = null;
TransactionUID tid = null;
TransactionState ts = null;
TransactionHandler thandler = null;
// Get the packet handler that handles transaction packets
if (parent.adminPktRtr != null) {
thandler = (TransactionHandler) parent.adminPktRtr.getHandler(PacketType.ROLLBACK_TRANSACTION);
}
Long id = (Long) cmd_props.get(MessageType.JMQ_TRANSACTION_ID);
// only applies to rollback request
Boolean v = (Boolean) cmd_props.get(MessageType.JMQ_PROCESS_ACTIVE_CONSUMERS);
boolean processActiveConsumers = (v != null && v.booleanValue());
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
}
if (id != null) {
tid = new TransactionUID(id.longValue());
} else {
status = Status.BAD_REQUEST;
}
if (status == Status.OK) {
TransactionList[] tls = DL.getTransactionList(null);
TransactionList tl = null;
for (int i = 0; i < tls.length; i++) {
tl = tls[i];
ts = tl.retrieveState(tid);
if (ts == null) {
continue;
}
break;
}
if (ts == null) {
// Specified transaction did not exist
status = Status.NOT_FOUND;
errMsg = rb.getString(rb.E_NO_SUCH_TRANSACTION, tid);
} else if (requestType == MessageType.COMMIT_TRANSACTION && ts.getState() != TransactionState.PREPARED) {
status = Status.PRECONDITION_FAILED;
errMsg = rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid);
} else if (requestType == MessageType.ROLLBACK_TRANSACTION && (ts.getState() < TransactionState.STARTED || ts.getState() > TransactionState.PREPARED)) {
status = Status.PRECONDITION_FAILED;
errMsg = rb.getString(rb.E_INVALID_TXN_STATE_FOR_ROLLBACK, tid);
} else {
JMQXid xid = tl.UIDToXid(tid);
if (xid == null && (!(Globals.getHAEnabled() && ts.getState() == TransactionState.PREPARED))) {
/*
* Need to pick the right error message: If (action is ROLLBACK and state is one of {STARTED, FAILED, INCOMPLETE,
* COMPLETE}) "Rollback of non-XA transaction 123456789 in non-PREPARED state is not supported." else
* "Could not find Xid for 123456789"
*/
if (requestType == MessageType.ROLLBACK_TRANSACTION && (ts.getState() >= TransactionState.STARTED && ts.getState() < TransactionState.PREPARED)) {
errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Rollback of non-XA transaction " + tid + " in non-PREPARED state is not supported.");
} else {
errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not find Xid for " + tid);
}
status = Status.ERROR;
} else if (thandler == null) {
errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate TransactionHandler");
status = Status.ERROR;
} else {
if (requestType == MessageType.ROLLBACK_TRANSACTION) {
if (DEBUG) {
logger.log(Logger.DEBUG, "Rolling back " + tid + " in state " + ts);
}
try {
if (processActiveConsumers) {
logger.log(logger.INFO, rb.getKString(rb.I_ADMIN_REDELIVER_MSGS_ON_TXN_ROLLBACK, tid));
try {
thandler.redeliverUnacked(tl, tid, true, true, true, -1, false);
} catch (Exception e) {
logger.logStack(logger.WARNING, rb.getKString(rb.X_ADMIN_REDELIVER_MSG_ON_TXN_ROLLBACK, tid, e.getMessage()), e);
}
}
thandler.doRollback(tl, tid, xid, null, ts, null, con, RollbackReason.ADMIN);
} catch (BrokerException e) {
status = Status.ERROR;
errMsg = e.getMessage();
}
} else if (requestType == MessageType.COMMIT_TRANSACTION) {
if (DEBUG) {
logger.log(Logger.DEBUG, "Committing " + tid + " in state " + ts);
}
try {
thandler.doCommit(tl, tid, xid, Integer.valueOf(XAResource.TMNOFLAGS), ts, null, false, con, null);
} catch (BrokerException e) {
status = Status.ERROR;
errMsg = e.getMessage();
}
} else {
// Should never happen.
return super.handle(con, cmd_msg, cmd_props);
}
}
}
}
sendReply(con, cmd_msg, requestType + 1, status, errMsg);
return true;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService in project openmq by eclipse-ee4j.
the class QuiesceHandler 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) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Quiescing broker: " + cmd_props);
}
int status = Status.OK;
String errMsg = null;
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
try {
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
bsh.quiesce();
} catch (Exception ex) {
errMsg = ex.toString();
status = Status.ERROR;
}
}
setProperties(reply, MessageType.QUIESCE_BROKER_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService in project openmq by eclipse-ee4j.
the class UpdateServiceHandler 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) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + cmd_props);
}
ServiceInfo info = (ServiceInfo) getBodyObject(cmd_msg);
int status = Status.OK;
String errMsg = null;
ServiceManager sm = Globals.getServiceManager();
Service svc = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
if (info.name == null || ((svc = sm.getService(info.name)) == null)) {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SUCH_SERVICE, (info.name == null ? "<null>" : info.name));
}
}
// OK .. set the service information
if (status == Status.OK) {
if (!(svc instanceof IMQService)) {
status = Status.ERROR;
errMsg = "Internal Error: can updated non-standard Service";
} else {
// to repair this by fcs
try {
IMQService stsvc = (IMQService) svc;
int port = -1;
int min = -1;
int max = -1;
if (info.isModified(info.PORT)) {
port = info.port;
}
if (info.isModified(info.MIN_THREADS)) {
min = info.minThreads;
}
if (info.isModified(info.MAX_THREADS)) {
max = info.maxThreads;
}
if (port != -1 || min != -1 || max != -1) {
stsvc.updateService(port, min, max);
} else {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SERVICE_PROPS_SET, info.name);
}
} catch (Exception ex) {
logger.logStack(Logger.WARNING, rb.W_ERROR_UPDATING_SERVICE, svc.getName(), ex);
status = Status.ERROR;
errMsg = getMessageFromException(ex);
}
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.UPDATE_SERVICE_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
Aggregations