use of com.sun.messaging.jmq.util.log.Logger in project openmq by eclipse-ee4j.
the class TransactionHandler method redeliverUnackedNoConsumer.
/**
* @param sendMap consumerUID to PacketReferences map
* @param sToCmap consumerUID to stored ConsumerUID map
* @param redeliver whether set redeliver flag
* @param tid null if not for transaction rollback
* @param translist null if tid is null
*/
public static void redeliverUnackedNoConsumer(HashMap sendMap, HashMap sToCmap, boolean redeliver, TransactionUID tid, TransactionList translist) throws BrokerException {
Logger logger = Globals.getLogger();
Iterator sitr = sendMap.entrySet().iterator();
while (sitr.hasNext()) {
Map.Entry entry = (Map.Entry) sitr.next();
ConsumerUID intid = (ConsumerUID) entry.getKey();
ConsumerUID storedID = (ConsumerUID) sToCmap.get(intid);
SortedSet ss = (SortedSet) entry.getValue();
Iterator itr = ss.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference) itr.next();
SysMessageID sysid = ref.getSysMessageID();
if (!ref.isLocal()) {
if (tid != null && translist != null) {
translist.removeOrphanAck(tid, sysid, storedID, intid);
}
try {
ref.acquireDestroyRemoteReadLock();
try {
if (ref.isLastRemoteConsumerUID(storedID, intid)) {
if (ref.acknowledged(intid, storedID, !(intid.isNoAck() || intid.isDupsOK()), false, tid, translist, null, false)) {
try {
Destination d = ref.getDestination();
if (d != null) {
d.removeRemoteMessage(sysid, RemoveReason.ACKNOWLEDGED, ref);
} else {
if (DEBUG || DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Destination " + ref.getDestinationUID() + " not found on cleanup remote message [" + intid + "," + storedID + "," + ref + "]" + " for rollback transaction " + tid + " for inactive consumer");
}
}
} finally {
ref.postAcknowledgedRemoval();
}
}
}
} finally {
ref.clearDestroyRemoteReadLock();
}
} catch (Exception ex) {
logger.logStack((DEBUG_CLUSTER_TXN ? Logger.WARNING : Logger.DEBUG), "Unable to cleanup remote message " + "[" + intid + "," + storedID + "," + sysid + "]" + " on rollback transaction " + tid + " for inactive consumer.", ex);
}
BrokerAddress addr = null;
if (tid != null && translist != null) {
addr = translist.getAckBrokerAddress(tid, sysid, intid);
} else {
addr = ref.getBrokerAddress();
}
try {
HashMap prop = new HashMap();
if (tid != null) {
prop.put(ClusterBroadcast.RB_RELEASE_MSG_INACTIVE, tid.toString());
} else {
prop.put(ClusterBroadcast.RC_RELEASE_MSG_INACTIVE, "");
}
Globals.getClusterBroadcast().acknowledgeMessage(addr, sysid, intid, ClusterBroadcast.MSG_IGNORED, prop, false);
} catch (BrokerException e) {
Globals.getLogger().log(Logger.WARNING, "Unable to notify " + addr + " for remote message " + "[" + intid + ", " + storedID + ", " + ", " + sysid + "]" + " in " + (tid != null ? ("rollback transaction " + tid) : ("recover")) + " for inactive consumer.");
}
itr.remove();
continue;
}
}
if (storedID == null || intid == storedID) {
// non-durable subscriber, ignore
sitr.remove();
continue;
}
if (ss.isEmpty()) {
if (DEBUG) {
logger.log(Logger.INFO, "redeliverUnackedNoConsuemr: " + "empty local message set for consumer " + intid + "[storedID=" + storedID + "]");
}
continue;
}
// see if we are a queue
if (storedID == PacketReference.getQueueUID()) {
// queue message on
// queues are complex ->
PacketReference ref = (PacketReference) ss.first();
if (ref == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Internal Error: " + " null reterence");
}
continue;
}
if (!redeliver) {
ref.removeDelivered(storedID, false);
}
Destination d = ref.getDestination();
if (d == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Destination " + ref.getDestinationUID() + " not found for reference: " + ref);
}
continue;
}
// this puts it on the pending list
try {
d.forwardOrphanMessages(ss, storedID);
sitr.remove();
} catch (Exception ex) {
logger.log(Logger.INFO, "Internal Error: " + "Unable to re-queue message " + " to queue " + d, ex);
}
} else {
// durable
// ok - requeue the message on the subscription
Consumer cs = Consumer.getConsumer(storedID);
if (cs == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Internal Error: " + " unknown consumer " + storedID);
}
continue;
}
if (!ss.isEmpty() && cs.routeMessages(ss, true)) {
// successful
sitr.remove();
}
}
}
if (DEBUG && sendMap.size() > 0) {
logger.log(Logger.INFO, tid + ":after all processing, " + sendMap.size() + " inactive consumers remaining");
}
}
use of com.sun.messaging.jmq.util.log.Logger in project openmq by eclipse-ee4j.
the class DestinationList method loadTakeoverMsgs.
public static synchronized void loadTakeoverMsgs(PartitionedStore storep, Map<String, String> msgs, List txns, Map txacks) throws BrokerException {
DestinationList dl = destinationListList.get(storep);
Map m = new HashMap();
Logger logger = Globals.getLogger();
Map ackLookup = new HashMap();
// ok create a hashtable for looking up txns
if (txacks != null) {
Iterator itr = txacks.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
TransactionUID tuid = (TransactionUID) entry.getKey();
List l = (List) entry.getValue();
Iterator litr = l.iterator();
while (litr.hasNext()) {
TransactionAcknowledgement ta = (TransactionAcknowledgement) litr.next();
String key = ta.getSysMessageID() + ":" + ta.getStoredConsumerUID();
ackLookup.put(key, tuid);
}
}
}
// Alright ...
// all acks fail once takeover begins
// we expect all transactions to rollback
// here is the logic:
// - load all messages
// - remove any messages in open transactions
// - requeue all messages
// - resort (w/ load comparator)
//
//
// OK, first get msgs and sort by destination
HashMap openMessages = new HashMap();
Iterator itr = msgs.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry me = (Map.Entry) itr.next();
String msgID = (String) me.getKey();
String dst = (String) me.getValue();
DestinationUID dUID = new DestinationUID(dst);
Packet p = null;
try {
p = storep.getMessage(dUID, msgID);
} catch (BrokerException ex) {
Throwable cause = ex.getCause();
if (cause instanceof InvalidPacketException) {
String[] args = { msgID, dst, cause.toString() };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_MSG_CORRUPTED_IN_STORE, args);
logger.logStack(Logger.ERROR, emsg, ex);
handleInvalidPacket(msgID, dst, emsg, (InvalidPacketException) cause, storep);
itr.remove();
continue;
}
// Check if dst even exists!
if (ex.getStatusCode() == Status.NOT_FOUND) {
Destination[] ds = getDestination(storep, dUID);
Destination d = ds[0];
if (d == null) {
String[] args = { msgID, dst, Globals.getBrokerResources().getString(BrokerResources.E_DESTINATION_NOT_FOUND_IN_STORE, dst) };
logger.log(Logger.ERROR, BrokerResources.W_CAN_NOT_LOAD_MSG, args, ex);
}
}
throw ex;
}
dUID = DestinationUID.getUID(p.getDestination(), p.getIsQueue());
PacketReference pr = PacketReference.createReference(storep, p, dUID, null);
// mark already stored and make packet a SoftReference to
// prevent running out of memory if dest has lots of msgs
pr.setLoaded();
logger.log(Logger.DEBUG, "Loading message " + pr.getSysMessageID() + " on " + pr.getDestinationUID());
// check transactions
TransactionUID tid = pr.getTransactionID();
if (tid != null) {
// see if in transaction list
if (txns.contains(tid)) {
// open transaction
TransactionState ts = dl.getTransactionList().retrieveState(pr.getTransactionID());
if (ts != null && ts.getState() != TransactionState.ROLLEDBACK && ts.getState() != TransactionState.COMMITTED) {
// in transaction ...
logger.log(Logger.DEBUG, "Processing open transacted message " + pr.getSysMessageID() + " on " + tid + "[" + TransactionState.toString(ts.getState()) + "]");
openMessages.put(pr.getSysMessageID(), tid);
} else if (ts != null && ts.getState() == TransactionState.ROLLEDBACK) {
pr.destroy();
continue;
} else {
}
}
}
dl.packetlistAdd(pr.getSysMessageID(), pr.getDestinationUID(), null);
Set l = null;
if ((l = (Set) m.get(dUID)) == null) {
l = new TreeSet(new RefCompare());
m.put(dUID, l);
}
l.add(pr);
}
// OK, handle determining how to queue the messages
Map<PacketReference, MessageDeliveryTimeInfo> deliveryDelays = new HashMap<>();
// first add all messages
Iterator dsts = m.entrySet().iterator();
while (dsts.hasNext()) {
Map.Entry entry = (Map.Entry) dsts.next();
DestinationUID dst = (DestinationUID) entry.getKey();
Set l = (Set) entry.getValue();
Destination[] ds = getDestination(storep, dst);
Destination d = ds[0];
if (d == null) {
// create it
String destinationName = dst.getName();
try {
ds = getDestination(storep, destinationName, (dst.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC), true, true);
d = ds[0];
} catch (IOException ex) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CANT_LOAD_DEST, destinationName));
}
} else {
synchronized (d) {
if (d.isLoaded()) {
// Destination has already been loaded so just called
// initialize() to update the size and bytes variables
d.initialize();
}
d.load(l);
}
}
logger.log(Logger.INFO, BrokerResources.I_LOADING_DST, d.getName(), String.valueOf(l.size()));
MessageDeliveryTimeTimer dt = d.deliveryTimeTimer;
if (dt == null && !d.isDMQ()) {
if (!d.isValid()) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_UNABLE_LOAD_TAKEOVER_MSGS_TO_DESTROYED_DST, d.getDestinationUID());
logger.log(Logger.WARNING, emsg);
continue;
}
String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_UNABLE_LOAD_TAKEOVER_MSGS_NO_DST_DELIVERY_TIMER, d.getDestinationUID() + "[" + d.isValid() + "]");
logger.log(Logger.WARNING, emsg);
continue;
}
// now we're sorted, process
Iterator litr = l.iterator();
try {
MessageDeliveryTimeInfo di = null;
while (litr.hasNext()) {
PacketReference pr = (PacketReference) litr.next();
di = pr.getDeliveryTimeInfo();
if (di != null) {
dt.removeMessage(di);
}
try {
// ok allow overrun
boolean el = d.destMessages.getEnforceLimits();
d.destMessages.enforceLimits(false);
if (DEBUG) {
logger.log(logger.INFO, "Put message " + pr + "[" + di + "] to destination " + d);
}
pr.lock();
d.acquireQueueRemoteLock();
try {
d.putMessage(pr, AddReason.LOADED, true);
} finally {
d.clearQueueRemoteLock();
}
// turn off overrun
d.destMessages.enforceLimits(el);
} catch (IllegalStateException | OutOfLimitsException ex) {
// thats ok, we already exists
String[] args = { pr.getSysMessageID().toString(), pr.getDestinationUID().toString(), ex.getMessage() };
logger.logStack(Logger.WARNING, BrokerResources.W_CAN_NOT_LOAD_MSG, args, ex);
continue;
} finally {
if (di != null && !di.isDeliveryDue()) {
dt.addMessage(di);
deliveryDelays.put(pr, di);
}
}
}
// then resort the destination
d.sort(new RefCompare());
} catch (Exception ex) {
}
}
// now route
dsts = m.entrySet().iterator();
while (dsts.hasNext()) {
Map.Entry entry = (Map.Entry) dsts.next();
DestinationUID dst = (DestinationUID) entry.getKey();
Set l = (Set) entry.getValue();
Destination d = dl.getDestination(dst);
// now we're sorted, process
Iterator litr = l.iterator();
try {
while (litr.hasNext()) {
PacketReference pr = (PacketReference) litr.next();
if (DEBUG) {
logger.log(logger.INFO, "Process takeover message " + pr + "[" + pr.getDeliveryTimeInfo() + "] for destination " + d);
}
TransactionUID tuid = (TransactionUID) openMessages.get(pr.getSysMessageID());
if (tuid != null) {
dl.getTransactionList().addMessage(tuid, pr.getSysMessageID(), true);
pr.unlock();
continue;
}
ConsumerUID[] consumers = storep.getConsumerUIDs(dst, pr.getSysMessageID());
if (consumers == null) {
consumers = new ConsumerUID[0];
}
if (consumers.length == 0 && storep.hasMessageBeenAcked(dst, pr.getSysMessageID())) {
logger.log(Logger.INFO, Globals.getBrokerResources().getString(BrokerResources.W_TAKEOVER_MSG_ALREADY_ACKED, pr.getSysMessageID()));
d.unputMessage(pr, RemoveReason.ACKNOWLEDGED);
pr.destroy();
pr.unlock();
continue;
}
if (consumers.length > 0) {
pr.setStoredWithInterest(true);
} else {
pr.setStoredWithInterest(false);
}
int[] states = null;
if (consumers.length == 0 && deliveryDelays.get(pr) == null) {
// message
try {
consumers = d.routeLoadedTransactionMessage(pr);
} catch (Exception ex) {
logger.logStack(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_EXCEPTION_ROUTE_LOADED_MSG, pr.getSysMessageID(), ex.getMessage()), ex);
}
states = new int[consumers.length];
for (int i = 0; i < states.length; i++) {
states[i] = PartitionedStore.INTEREST_STATE_ROUTED;
}
try {
storep.storeInterestStates(d.getDestinationUID(), pr.getSysMessageID(), consumers, states, true, null);
pr.setStoredWithInterest(true);
} catch (Exception ex) {
// message already routed
StringBuilder debuf = new StringBuilder();
for (int i = 0; i < consumers.length; i++) {
if (i > 0) {
debuf.append(", ");
}
debuf.append(consumers[i]);
}
logger.log(logger.WARNING, BrokerResources.W_TAKEOVER_MSG_ALREADY_ROUTED, pr.getSysMessageID(), debuf.toString(), ex);
}
} else if (consumers.length > 0) {
states = new int[consumers.length];
for (int i = 0; i < consumers.length; i++) {
states[i] = storep.getInterestState(dst, pr.getSysMessageID(), consumers[i]);
}
}
pr.update(consumers, states, false);
// OK deal w/ transsactions
// LKS - XXX
ExpirationInfo ei = pr.getExpireInfo();
if (ei != null && d.expireReaper != null) {
d.expireReaper.addExpiringMessage(ei);
}
List<ConsumerUID> consumerList = new ArrayList(Arrays.asList(consumers));
// OK ... see if we are in txn
Iterator citr = consumerList.iterator();
while (citr.hasNext()) {
logger.log(Logger.DEBUG, " Message " + pr.getSysMessageID() + " has " + consumerList.size() + " consumers ");
ConsumerUID cuid = (ConsumerUID) citr.next();
String key = pr.getSysMessageID() + ":" + cuid;
TransactionList tl = dl.getTransactionList();
TransactionUID tid = (TransactionUID) ackLookup.get(key);
if (DEBUG) {
logger.log(logger.INFO, "loadTakeoverMsgs: lookup " + key + " found tid=" + tid);
}
if (tid != null) {
boolean remote = false;
TransactionState ts = tl.retrieveState(tid);
if (ts == null) {
ts = tl.getRemoteTransactionState(tid);
remote = true;
}
if (DEBUG) {
logger.log(logger.INFO, "tid=" + tid + " has state=" + TransactionState.toString(ts.getState()));
}
if (ts != null && ts.getState() != TransactionState.ROLLEDBACK && ts.getState() != TransactionState.COMMITTED) {
// in transaction ...
if (DEBUG) {
logger.log(Logger.INFO, "loadTakeoverMsgs: Open transaction ack [" + key + "]" + (remote ? "remote" : "") + ", TUID=" + tid);
}
if (!remote) {
try {
tl.addAcknowledgement(tid, pr.getSysMessageID(), cuid, cuid, true, false);
} catch (TransactionAckExistException e) {
// can happen if takeover tid's remote txn after restart
// then txn ack would have already been loaded
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_TAKINGOVER_TXN_ACK_ALREADY_EXIST, "[" + pr.getSysMessageID() + "]" + cuid + ":" + cuid, tid + "[" + TransactionState.toString(ts.getState()) + "]"));
}
tl.addOrphanAck(tid, pr.getSysMessageID(), cuid);
}
citr.remove();
logger.log(Logger.INFO, "Processing open ack " + pr.getSysMessageID() + ":" + cuid + " on " + tid);
continue;
} else if (ts != null && ts.getState() == TransactionState.COMMITTED) {
logger.log(Logger.INFO, "Processing committed ack " + pr.getSysMessageID() + ":" + cuid + " on " + tid);
if (pr.acknowledged(cuid, cuid, false, true)) {
d.unputMessage(pr, RemoveReason.ACKNOWLEDGED);
pr.destroy();
continue;
}
citr.remove();
continue;
}
}
}
// route msgs not in transaction
if (DEBUG) {
StringBuilder buf = new StringBuilder();
ConsumerUID cid = null;
for (int j = 0; j < consumerList.size(); j++) {
cid = consumerList.get(j);
buf.append(cid);
buf.append(' ');
}
if (deliveryDelays.get(pr) == null) {
logger.log(Logger.INFO, "non-transacted: Routing Message " + pr.getSysMessageID() + " to " + consumerList.size() + " consumers:" + buf.toString());
} else {
logger.log(Logger.INFO, "non-transacted: deliver time not arrived for message " + pr.getSysMessageID());
}
}
pr.unlock();
if (deliveryDelays.get(pr) == null) {
if (DEBUG) {
logger.log(logger.INFO, "Route takeover message " + pr + "[" + pr.getDeliveryTimeInfo() + "] for destination " + d + " to consumers " + consumerList);
}
if (pr.getDeliveryTimeInfo() != null) {
d.forwardDeliveryDelayedMessage(new HashSet<>(consumerList), pr);
} else {
d.routeLoadedMessage(pr, consumerList);
}
} else {
MessageDeliveryTimeInfo di = pr.getDeliveryTimeInfo();
di.setDeliveryReady();
}
if (d.destReaper != null) {
d.destReaper.cancel();
d.destReaper = null;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of com.sun.messaging.jmq.util.log.Logger in project openmq by eclipse-ee4j.
the class MQAddressUtil method getServiceMQAddress.
/**
* Return connection service MQAddress. Connection service addresses can have 2 forms and the bypassPortmapper parameter
* allows the caller to select which one is desired. The 2 forms depend on whether the client will contact the
* portmapper (mq://host:port) or the connection service directly ({mqtcp,mqssl}://host:port/svcname).
*
* @param svcName Connection service name.
* @param port Portmapper port or connection service port.
* @param bypassPortmapper Boolean to indicate which type of address is desired. If the value for bypassPortmapper is
* false, the address will be of the form mq://host:port/svcName. If the value is true, the scheme will be one of mqtcp
* or mqssl. The address will be of the form scheme://host:svc_port/svc_name. e.g. mqtcp://myhost:87635/jms
* @return Connection service address.
*/
public static MQAddress getServiceMQAddress(String svcName, Integer port, boolean bypassPortmapper) {
MQAddress addr = null;
String scheme = "mq";
Logger logger = Globals.getLogger();
if ((svcName == null) || (svcName.equals("")) || (port == null)) {
if (DEBUG) {
logger.log(Logger.DEBUG, "Null service name and/or port passed in to getServiceMQAddress()");
}
return (null);
}
if (bypassPortmapper) {
scheme = getScheme(svcName);
}
if (scheme == null) {
return (null);
}
if (bypassPortmapper) {
try {
String url = scheme + "://" + Globals.getMQAddress().getHostName() + ":" + port.toString() + "/" + svcName;
addr = MQAddress.getMQAddress(url);
} catch (Exception e) {
if (DEBUG) {
logger.log(Logger.DEBUG, "Failed to create service address", e);
}
}
} else {
try {
String url = Globals.getMQAddress().getHostName() + ":" + port.toString() + "/" + svcName;
addr = PortMapperMQAddress.createAddress(url);
} catch (Exception e) {
if (DEBUG) {
logger.log(Logger.DEBUG, "Failed to create service address", e);
}
}
}
return (addr);
}
use of com.sun.messaging.jmq.util.log.Logger in project openmq by eclipse-ee4j.
the class MQAddressUtil method getPortMapperMQAddress.
/**
* Return portmapper MQAddress. This MQAddress does not include the service name and is of the form mq://host:port
*
* @param port Portmapper port
* @return Portmapper address. This MQAddress does not include the service name. It is of the form mq://host:port.
*/
public static MQAddress getPortMapperMQAddress(Integer port) {
MQAddress addr = null;
if (port == null) {
if (DEBUG) {
Logger logger = Globals.getLogger();
logger.log(Logger.DEBUG, "Null port passed in to getPortMapperMQAddress()");
}
return (null);
}
try {
String url = Globals.getMQAddress().getHostName() + ":" + port.toString();
addr = PortMapperMQAddress.createAddress(url);
} catch (Exception e) {
if (DEBUG) {
Logger logger = Globals.getLogger();
logger.log(Logger.DEBUG, "Failed to create portmapper address", e);
}
}
return (addr);
}
use of com.sun.messaging.jmq.util.log.Logger in project openmq by eclipse-ee4j.
the class ClusterUtil method getConfigCompositeData.
public static CompositeData getConfigCompositeData(ClusteredBroker cb) throws OpenDataException {
Logger logger = Globals.getLogger();
CompositeData cds = null;
Hashtable bkrInfo = GetClusterHandler.getBrokerClusterInfo(cb, logger);
String id = null;
if (Globals.getHAEnabled()) {
id = (String) bkrInfo.get(BrokerClusterInfo.ID);
}
Object[] brokerInfoItemValues = { bkrInfo.get(BrokerClusterInfo.ADDRESS), id };
if (configCompType == null) {
configCompType = new CompositeType("BrokerClusterInfoConfig", "BrokerClusterInfoConfig", configBrokerInfoItemNames, configBrokerInfoItemDesc, configItemTypes);
}
cds = new CompositeDataSupport(configCompType, configBrokerInfoItemNames, brokerInfoItemValues);
return (cds);
}
Aggregations