use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class TransactionList method updateStateCommitWithWork.
public TransactionState updateStateCommitWithWork(TransactionUID tid, int state, boolean persist) throws BrokerException {
if (state != TransactionState.COMMITTED) {
throw new BrokerException("Unexpected call TransactionList.updateStateCommitWithWork(tid=" + tid + ", " + TransactionState.toString(state) + ", " + persist + ")");
}
TransactionWork[] txnworks = getTransactionWork(tid);
TransactionState ts = updateState(tid, state, TransactionState.NULL, false, TransactionState.NULL, persist, txnworks[0]);
Iterator<TransactionWorkMessage> itr = txnworks[0].getSentMessages().iterator();
while (itr.hasNext()) {
PacketReference ref = itr.next().getPacketReference();
ref.setIsStored();
}
return ts;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class TransactionListLoader method handleSentMessages.
static void handleSentMessages(TransactionList transactionList, TransactionWork txnWork) throws BrokerException {
for (int i = 0; i < txnWork.numSentMessages(); i++) {
TransactionWorkMessage msg = txnWork.getSentMessages().get(i);
Packet packet = msg.getMessage();
DestinationUID duid = msg.getDestUID();
logger.log(Logger.DEBUG, " handleSentMessages: duid= " + duid);
PacketReference pr = PacketReference.createReference(transactionList.getPartitionedStore(), packet, duid, null);
Destination[] ds = Globals.getDestinationList().getDestination(transactionList.getPartitionedStore(), duid);
Destination d = ds[0];
if (d == null) {
// Lets recreate it here.
try {
int type = (duid.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
ds = Globals.getDestinationList().getDestination(transactionList.getPartitionedStore(), duid.getName(), type, true, true);
d = ds[0];
} catch (IOException e) {
throw new BrokerException("Could not recreate destination " + duid, e);
}
}
// check it is loaded
d.load();
logger.log(Logger.DEBUG, " loadTransactions: processing prepared sent message " + packet.getMessageID());
// queue message
d.queueMessage(pr, true);
// store (should not really be persisted as we are using txnLog)
// pr.store();
// add message to transaction
transactionList.addMessage(pr.getTransactionID(), pr.getSysMessageID(), true);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class GetBrokerPropsHandler 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.DEBUG, this.getClass().getName() + ": " + cmd_props);
}
/*
* We need to create a copy of the broker configuration because the protocol requires we send a serialized
* java.util.Properties object. If we just serialize (or clone the serialize) BrokerConfig it will end up being a
* serialized BrokerConfig object, not a serialized Properties object (even if we cast). So we do this rather expensive
* operation.
*/
Properties brokerProps = Globals.getConfig().toProperties();
/* Add the version properties */
Version version = Globals.getVersion();
brokerProps.putAll(version.getProps());
brokerProps.put(Globals.IMQ + ".system.current_count", String.valueOf(DL.totalCount()));
brokerProps.put(Globals.IMQ + ".system.current_size", String.valueOf(DL.totalBytes()));
Queue[] qs = DL.getDMQ(null);
// PART
Queue dmq = qs[0];
brokerProps.put(Globals.IMQ + ".dmq.current_count", String.valueOf(dmq.size()));
brokerProps.put(Globals.IMQ + ".dmq.current_size", String.valueOf(dmq.byteSize()));
String val = brokerProps.getProperty(DL.USE_DMQ_STR);
if (val == null || val.trim().equals("")) {
brokerProps.put(DL.USE_DMQ_STR, String.valueOf(DL.defaultUseDMQ));
}
if (Globals.getBrokerID() != null) {
brokerProps.put(Globals.IMQ + ".brokerid", Globals.getBrokerID());
}
if (Globals.getClusterID() != null) {
brokerProps.put(Globals.IMQ + ".cluster.clusterid", Globals.getClusterID());
}
if (DL.isPartitionMode() && DL.isPartitionMigratable()) {
brokerProps.put(Globals.IMQ + ".partitionmigratable", "true");
}
brokerProps.put(Globals.IMQ + ".embedded", Boolean.toString(Broker.isInProcess()));
if (Globals.getHAEnabled()) {
brokerProps.put(ClusterManager.CONFIG_SERVER, "");
} else if (Globals.useSharedConfigRecord()) {
String shareccVendor = null;
try {
shareccVendor = Globals.getStore().getShareConfigChangeStore().getVendorPropertySetting();
} catch (BrokerException e) {
logger.logStack(Logger.WARNING, e.getMessage(), e);
}
brokerProps.put(ClusterManager.CONFIG_SERVER, "[" + Globals.NO_MASTERBROKER_PROP + "=" + brokerProps.get(Globals.NO_MASTERBROKER_PROP) + ", " + shareccVendor + "]");
}
/**
* OK, use the cluster object to get active and normal brokers
*/
ClusterManager cfg = Globals.getClusterManager();
// calculate url
String list = null;
Iterator itr = cfg.getConfigBrokers();
// OK we want to remove any duplicates
Set s = new HashSet();
while (itr.hasNext()) {
ClusteredBroker cb = (ClusteredBroker) itr.next();
s.add(cb.getBrokerURL().toString());
}
itr = s.iterator();
while (itr.hasNext()) {
if (list == null) {
list = itr.next().toString();
} else {
list += "," + itr.next().toString();
}
}
if (list == null) {
list = "";
}
brokerProps.put("imq.cluster.brokerlist", list);
list = null;
s = new HashSet();
itr = cfg.getActiveBrokers();
while (itr.hasNext()) {
ClusteredBroker cb = (ClusteredBroker) itr.next();
s.add(cb.getBrokerURL().toString());
}
itr = s.iterator();
while (itr.hasNext()) {
if (list == null) {
list = itr.next().toString();
} else {
list += "," + itr.next().toString();
}
}
if (list == null) {
list = "";
}
brokerProps.put("imq.cluster.brokerlist.active", list);
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.GET_BROKER_PROPS_REPLY, status, emsg);
setBodyObject(reply, brokerProps);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class AckHandler method validateMessages.
public boolean validateMessages(TransactionList translist, TransactionUID tid, SysMessageID[] ids, ConsumerUID[] cids) throws BrokerException {
// LKS - XXX need to revisit this
// I'm not 100% sure if we still need this or not (since its really
// targeted at supporting the NEVER rollback option
// putting in a mimimal support for the feature
// OK, get a status on the transaction
boolean openTransaction = false;
try {
translist.getTransactionMap(tid, false);
openTransaction = true;
} catch (BrokerException ex) {
}
// if transaction exists we need to check its information
if (openTransaction) {
for (int i = 0; i < ids.length; i++) {
Consumer c = Consumer.getConsumer(cids[i]);
if (c == null) {
// unknown consumer
throw new BrokerException("Internal Error, " + "unknown consumer " + cids[i], Status.BAD_REQUEST);
}
if (!translist.checkAcknowledgement(tid, ids[i], c.getConsumerUID())) {
return false;
}
}
} else {
// check packet reference
for (int i = 0; i < ids.length; i++) {
Consumer c = Consumer.getConsumer(cids[i]);
if (c == null) {
// unknown consumer
throw new BrokerException("Internal Error, " + "unknown consumer " + cids[i], Status.BAD_REQUEST);
}
PacketReference ref = DL.get(null, ids[i]);
if (ref == null) {
if (DEBUG) {
logger.log(Logger.INFO, "AckHandler.validateMessages(): message reference Could not find " + ids[i] + "[" + cids[i] + "]");
}
continue;
}
if (!ref.hasConsumerAcked(c.getStoredConsumerUID())) {
return false;
}
}
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class AckHandler method handleAcks.
public void handleAcks(IMQConnection con, SysMessageID[] ids, ConsumerUID[] cids, boolean ackack, List cleanList) throws BrokerException, IOException {
// we could eliminate on of the lookups
for (int i = 0; i < ids.length; i++) {
if (DEBUG) {
logger.log(logger.INFO, "handleAcks[" + i + ", " + ids.length + "]:sysid=" + ids[i] + ", cid=" + cids[i] + ", on connection " + con);
}
Session s = Session.getSession(cids[i]);
if (s == null) {
// consumer does not have session
Consumer c = Consumer.getConsumer(cids[i]);
if (c == null) {
if (!con.isValid() || con.isBeingDestroyed()) {
if (DEBUG) {
logger.log(logger.INFO, "Received ack for consumer " + cids[i] + " on closing connection " + con);
}
continue;
}
if (BrokerStateHandler.isShutdownStarted()) {
throw new BrokerException(br.I_ACK_FAILED_BROKER_SHUTDOWN);
}
throw new BrokerException(br.getKString(br.I_ACK_FAILED_NO_CONSUMER, cids[i]), Status.NOT_FOUND);
} else if (c.getConsumerUID().getBrokerAddress() != Globals.getClusterBroadcast().getMyAddress()) {
// remote consumer
PacketReference ref = DL.get(null, ids[i]);
if (ref == null) {
BrokerException bex = new BrokerException(br.getKString(br.I_ACK_FAILED_MESSAGE_REF_GONE, ids[i]) + "[" + cids[i] + "]", Status.GONE);
bex.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
bex.setRemote(true);
throw bex;
}
ConsumerUID cuid = c.getConsumerUID();
// but who knows if that will change
if (ref.acknowledged(cuid, c.getStoredConsumerUID(), !cuid.isDupsOK(), true, ackack)) {
cleanList.add(ref);
}
} else {
String emsg = br.getKString(br.I_LOCAL_CONSUMER_ACK_FAILED_NO_SESSION, "[" + ids[i] + ", " + cids[i] + "]", cids[i]);
logger.log(Logger.WARNING, emsg);
throw new BrokerException(emsg);
}
} else {
if (fi.FAULT_INJECTION) {
PacketReference ref = DL.get(null, ids[i]);
if (ref != null && !ref.getDestination().isAdmin() && !ref.getDestination().isInternal()) {
if (fi.checkFault(fi.FAULT_ACK_MSG_1_5, null)) {
fi.unsetFault(fi.FAULT_ACK_MSG_1_5);
BrokerException bex = new BrokerException("FAULT:" + fi.FAULT_ACK_MSG_1_5, Status.GONE);
bex.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
bex.setRemote(true);
throw bex;
}
}
}
PacketReference ref = (PacketReference) s.ackMessage(cids[i], ids[i], ackack);
try {
s.postAckMessage(cids[i], ids[i], ackack);
} finally {
if (ref != null) {
cleanList.add(ref);
}
}
}
}
}
Aggregations