use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class TransactionHandler method calculateStoredRouting.
private boolean calculateStoredRouting(PartitionedStore pstore, TransactionWorkMessage twm) throws BrokerException {
PacketReference ref = twm.getPacketReference();
Destination[] ds = DL.getDestination(pstore, twm.getDestUID());
Destination dest = ds[0];
ConsumerUID[] storedInterests = null;
if (dest == null) {
String msg = "Could not find destination for " + twm.getDestUID() + " refDest= " + ref.getDestinationName();
logger.log(Logger.ERROR, msg);
throw new BrokerException(msg);
}
try {
storedInterests = dest.calculateStoredInterests(ref);
twm.setStoredInterests(storedInterests);
} catch (SelectorFormatException sfe) {
throw new BrokerException("Could not route transacted message on commit", sfe);
}
if (storedInterests == null) {
if (DEBUG_CLUSTER_TXN) {
logger.log(Logger.INFO, Thread.currentThread().getName() + " stored routing = null " + twm + " persist=" + ref.isPersistent());
}
return false;
} else {
if (DEBUG_CLUSTER_TXN) {
for (int i = 0; i < storedInterests.length; i++) {
logger.log(Logger.INFO, Thread.currentThread().getName() + " stored routing " + storedInterests[i] + " " + twm);
}
}
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ChangeClusterMasterBrokerHandler 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 emsg = null;
if (DEBUG) {
logger.log(Logger.INFO, this.getClass().getName() + ": " + cmd_props);
}
boolean notificationOnly = false, fromJMSRA = false;
String oldmb = (String) cmd_props.get(MessageType.JMQ_CLUSTER_OLD_MASTER_BROKER);
String newmb = (String) cmd_props.get(MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER);
Object val = cmd_props.get(MessageType.JMQ_JMSRA_MANAGED_BROKER);
if (val != null && Boolean.parseBoolean(val.toString())) {
fromJMSRA = true;
}
val = cmd_props.get(MessageType.JMQ_JMSRA_NOTIFICATION_ONLY);
if (val != null && Boolean.parseBoolean(val.toString()) && fromJMSRA && Globals.isJMSRAManagedBroker()) {
notificationOnly = true;
}
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_RECEIVED_CMD, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + "[" + MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER + "=" + newmb + ", " + MessageType.JMQ_CLUSTER_OLD_MASTER_BROKER + "=" + oldmb + "]" + (fromJMSRA ? "JMSRA" : "") + (notificationOnly ? "(" + MessageType.JMQ_JMSRA_NOTIFICATION_ONLY + ")" : "")));
if (Globals.getHAEnabled()) {
status = Status.PRECONDITION_FAILED;
emsg = rb.getKString(rb.E_OP_NOT_APPLY_TO_HA_BROKER, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER));
logger.log(Logger.ERROR, emsg);
sendReply(status, emsg, con, cmd_msg);
return true;
}
if (Globals.useSharedConfigRecord()) {
status = Status.PRECONDITION_FAILED;
emsg = rb.getKString(rb.E_OP_NOT_APPLY_NO_MASTER_BROKER_MODE, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER));
logger.log(Logger.ERROR, emsg);
sendReply(status, emsg, con, cmd_msg);
return true;
}
try {
BrokerStateHandler.setExclusiveRequestLock(ExclusiveRequest.CHANGE_MASTER_BROKER);
} catch (Throwable t) {
status = Status.PRECONDITION_FAILED;
if (t instanceof BrokerException) {
status = ((BrokerException) t).getStatusCode();
}
emsg = MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": " + Status.getString(status) + " - " + t.getMessage();
logger.log(Logger.ERROR, emsg);
status = Status.PRECONDITION_FAILED;
sendReply(status, emsg, con, cmd_msg);
return true;
}
try {
if (!Globals.dynamicChangeMasterBrokerEnabled()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_NO_SUPPORT_DYNAMIC_CHANGE_MASTER_BROKER), Status.NOT_ALLOWED);
}
if (newmb == null) {
throw new IllegalArgumentException("null " + MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER);
}
if (!fromJMSRA && Globals.isJMSRAManagedBroker()) {
throw new IllegalAccessException(Globals.getBrokerResources().getKString(BrokerResources.X_ADMIN_CHANGE_MASTER_NOT_FROM_JMSRA));
}
ClusterManager cm = Globals.getClusterManager();
BrokerMQAddress self = (BrokerMQAddress) cm.getMQAddress();
BrokerMQAddress master = (cm.getMasterBroker() == null ? null : (BrokerMQAddress) cm.getMasterBroker().getBrokerURL());
BrokerMQAddress newmba = BrokerMQAddress.createAddress(newmb);
BrokerMQAddress oldmba = null;
if (oldmb != null) {
oldmba = BrokerMQAddress.createAddress(oldmb);
}
if (notificationOnly) {
if (master == null) {
emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": No master broker";
logger.log(logger.ERROR, emsg);
sendReply(Status.ERROR, emsg, con, cmd_msg);
Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
throw new IllegalStateException(emsg);
}
if (newmba.equals(self)) {
if (!master.equals(self)) {
emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": This broker, which has master broker " + master + ", is not the master broker as expected";
logger.log(logger.ERROR, emsg);
sendReply(Status.ERROR, emsg, con, cmd_msg);
Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
return true;
}
}
if (oldmba != null && oldmba.equals(self)) {
if (!master.equals(newmba)) {
emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": This broker, which is the old master broker " + oldmba + ", does not have " + newmba + " as the master broker as expected";
logger.log(logger.ERROR, emsg);
sendReply(Status.ERROR, emsg, con, cmd_msg);
Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
return true;
}
}
sendReply(Status.OK, null, con, cmd_msg);
return true;
}
if (master == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_NO_MASTER_BROKER_REJECT_CHANGE_MASTER), Status.PRECONDITION_FAILED);
}
if (newmba.equals(master)) {
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CLUSTER_CHANGE_MASTER_BROKER_SAME, newmba));
sendReply(Status.OK, null, con, cmd_msg);
return true;
}
if (oldmba == null) {
oldmba = master;
}
if (!oldmba.equals(master)) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CHANGE_MASTER_BROKER_MISMATCH, oldmba.toString(), master), Status.PRECONDITION_FAILED);
}
if (!self.equals(master)) {
if (!Globals.isJMSRAManagedBroker()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_THIS_BROKER_NOT_MASTER_BROKER_REJECT_CHANGE_MASTER, master.toString()), Status.NOT_ALLOWED);
}
sendReply(Status.OK, null, con, cmd_msg);
return true;
}
Globals.getClusterBroadcast().changeMasterBroker(newmba, oldmba);
sendReply(Status.OK, null, con, cmd_msg);
return true;
} catch (Exception e) {
status = Status.ERROR;
emsg = e.getMessage();
if (e instanceof BrokerException) {
status = ((BrokerException) e).getStatusCode();
emsg = emsg + "[" + Status.getString(status) + "]";
}
logger.logStack(Logger.ERROR, emsg, e);
sendReply(status, emsg, con, cmd_msg);
return true;
} finally {
BrokerStateHandler.unsetExclusiveRequestLock(ExclusiveRequest.CHANGE_MASTER_BROKER);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ProtocolImpl method resumeSession.
/**
* Resume a session
* <P>
* Packet:<B>START</b>
* </p>
*
* @param uid session to resume
*/
@Override
public void resumeSession(SessionUID uid) throws BrokerException {
Session ses = Session.getSession(uid);
if (ses == null) {
throw new BrokerException("No session for " + uid);
}
ses.resume("PROTOCOL");
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ProtocolImpl method rollbackTransaction.
/**
* Rollback a transaction
*
* @param id The TransactionUID to rollback
* @param xid The Xid of the transaction to rollback. Required if transaction is an XA transaction. Must be null if it
* is not an XA transaction.
* @param redeliver should messages be redelivered
* @param setRedeliver if the messages are redelivered, should the redeliver flag be set on all messages or not
* @param con Connection client rollback packet came in on (or null if internal)
*/
@Override
public void rollbackTransaction(TransactionUID id, JMQXid xid, IMQConnection con, boolean redeliver, boolean setRedeliver, int maxRollbacks, boolean dmqOnMaxRollbacks) throws BrokerException {
if (maxRollbacks <= 0) {
dmqOnMaxRollbacks = !(Consumer.MSG_MAX_CONSECUTIVE_ROLLBACKS <= 0);
}
if (DEBUG) {
logger.log(Logger.INFO, "ProtocolImpl.ROLLBACK TRANSACTION:TID=" + id + ", XID=" + xid + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "], redeliver=" + redeliver + ", setRedeliver=" + setRedeliver);
}
List conlist = con.getTransactionListThreadSafe();
TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
TransactionList tl = null;
if (0L == id.longValue()) {
if (xid == null) {
throw new BrokerException("Unexpected TransactionUID " + id);
}
Object[] oo = TransactionList.mapXidToTid(xid, con);
if (oo == null) {
id = null;
} else {
tl = (TransactionList) oo[0];
id = (TransactionUID) oo[1];
}
if (id == null) {
throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
}
}
TransactionState ts = null;
if (tl == null) {
Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
if (oo != null) {
tl = (TransactionList) oo[0];
ts = (TransactionState) oo[1];
}
}
if (tl == null) {
throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
}
if (ts == null) {
ts = tl.retrieveState(id);
if (ts == null) {
throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
}
}
if (xid != null) {
if (ts.getXid() == null || !xid.equals(ts.getXid())) {
throw new BrokerException("Transaction XID mismatch " + xid + ", expected " + ts.getXid() + " for transaction " + id);
}
}
handler.preRollback(tl, id, xid, null, /* xaFlags */
ts);
BrokerException bex = null;
if (redeliver) {
try {
handler.redeliverUnacked(tl, id, true, setRedeliver, false, maxRollbacks, dmqOnMaxRollbacks);
} catch (MaxConsecutiveRollbackException e) {
bex = e;
if (!dmqOnMaxRollbacks) {
throw bex;
}
}
}
try {
handler.doRollback(tl, id, xid, null, /* xaFlags */
ts, conlist, con, RollbackReason.APPLICATION);
} catch (BrokerException e) {
if (bex != null) {
throw bex;
}
throw e;
}
if (bex != null) {
throw bex;
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ProtocolImpl method processMessage.
/**
* route, store and forward a message
*/
@Override
public void processMessage(IMQConnection con, Packet msg) throws BrokerException, SelectorFormatException, IOException {
DataHandler handler = (DataHandler) pr.getHandler(PacketType.MESSAGE);
Destination d = null;
PacketReference ref = null;
Set s = null;
boolean route = false;
boolean isadmin = con.isAdminConnection();
List<MessageDeliveryTimeInfo> deliveryDelayReadyList = new ArrayList<>();
try {
Destination[] ds = DL.getDestination(con.getPartitionedStore(), msg.getDestination(), msg.getIsQueue());
d = ds[0];
if (d == null) {
throw new BrokerException("Unknown Destination:" + msg.getDestination());
}
Producer pausedProducer = handler.checkFlow(msg, con);
boolean transacted = (msg.getTransactionID() != 0);
if (DEBUG) {
logger.log(Logger.INFO, "ProtocolImpl.PROCESS MESSAGE[" + msg + "]TID=" + msg.getTransactionID() + " to destination " + d + ", on conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
}
// OK generate a ref. This checks message size and
// will be needed for later operations
ref = handler.createReference(msg, d.getDestinationUID(), con, isadmin);
// dont bother calling route if there are no messages
//
// to improve performance, we route and later forward
route = handler.queueMessage(d, ref, transacted);
s = handler.routeMessage(con.getPartitionedStore(), transacted, ref, route, d, deliveryDelayReadyList);
// handle producer flow control
handler.pauseProducer(d, pausedProducer, con);
} catch (BrokerException ex) {
int status = ex.getStatusCode();
if (status == Status.ERROR && ref != null && d != null) {
handler.cleanupOnError(d, ref);
}
// rethrow
throw ex;
}
if (route && s != null) {
try {
handler.forwardMessage(d, ref, s);
} catch (Exception e) {
Object[] emsg = { ref, d.getDestinationUID(), s };
logger.logStack(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.X_ROUTE_PRODUCED_MSG_FAIL, emsg), e);
}
}
if (deliveryDelayReadyList.size() > 0) {
MessageDeliveryTimeInfo di = null;
Iterator<MessageDeliveryTimeInfo> itr = deliveryDelayReadyList.iterator();
while (itr.hasNext()) {
di = itr.next();
di.setDeliveryReady();
}
}
}
Aggregations