void markDead(PacketReference pr, Reason reason,
Hashtable props)
throws BrokerException
{
Packet p = pr.getPacket();
if (p == null) {
logger.log(Logger.DEBUG,"Internal Error: null packet for DMQ");
return;
}
Hashtable packetProps = null;
try {
packetProps = p.getProperties();
if (packetProps == null)
packetProps = new Hashtable();
} catch (Exception ex) {
logger.logStack(Logger.DEBUG,"could not get props ", ex);
packetProps = new Hashtable();
}
boolean useVerbose = false;
Object o = packetProps.get(DMQ.VERBOSE);
if (o != null) {
if (o instanceof Boolean) {
useVerbose = ((Boolean)o).booleanValue();
} else if (o instanceof String) {
useVerbose = Boolean.valueOf((String)o).booleanValue();
} else {
logger.log(Logger.WARNING,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"Unknown type for verbose " + o.getClass());
useVerbose=verbose;
}
} else {
useVerbose = verbose;
}
if (isDMQ) {
if (DEBUG || useVerbose) {
logger.log(Logger.INFO, BrokerResources.I_DMQ_REMOVING_DMQ_MSG,
pr.getSysMessageID(),
DestinationUID.getUID(p.getDestination(),
p.getIsQueue()).toString());
}
return;
}
// OK deal with various flags
boolean useDMQforMsg = false;
o = packetProps.get(DMQ.PRESERVE_UNDELIVERED);
if (o != null) {
if (o instanceof Boolean) {
useDMQforMsg = ((Boolean)o).booleanValue();
} else if (o instanceof String) {
useDMQforMsg = Boolean.valueOf((String)o).booleanValue();
} else {
logger.log(Logger.WARNING,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"Unknown type for preserve undelivered " +
o.getClass());
useDMQforMsg=useDMQ;
}
} else {
useDMQforMsg = useDMQ;
}
long receivedTime = pr.getTime();
long senderTime = pr.getTimestamp();
long expiredTime = pr.getExpireTime();
if (!useDMQforMsg) {
if (DEBUG || useVerbose) {
String args[] = { pr.getSysMessageID().toString(),
pr.getDestinationUID().toString(),
lookupReasonString(reason, receivedTime,
expiredTime, senderTime) };
logger.log(Logger.INFO, BrokerResources.I_DMQ_REMOVING_MSG, args);
}
if (!pr.isLocal()) {
Globals.getClusterBroadcast().acknowledgeMessage(
pr.getAddress(),
pr.getSysMessageID(),
pr.getQueueUID(),
ClusterBroadcast.MSG_DEAD,
props, true /*wait for ack*/);
}
return;
}
boolean truncateBody = false;
o = packetProps.get(DMQ.TRUNCATE_BODY);
if (o != null) {
if (o instanceof Boolean) {
truncateBody = ((Boolean)o).booleanValue();
} else if (o instanceof String) {
truncateBody = Boolean.valueOf((String)o).booleanValue();
} else {
logger.log(Logger.WARNING,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"Unknown type for preserve undelivered " +
o.getClass());
truncateBody=!storeBodyWithDMQ;
}
} else {
truncateBody = !storeBodyWithDMQ;
}
if (props == null) {
props = new Hashtable();
}
Integer cnt = (Integer)props.remove(TEMP_CNT);
if (cnt != null) {
// set as a header property
props.put("JMSXDeliveryCount", cnt);
} else { // total deliver cnt ?
}
if (pr.isLocal()) {
props.putAll(packetProps);
} else {
// reason for the other side
props.put("REASON", new Integer(reason.intValue()));
}
if (props.get(DMQ.UNDELIVERED_COMMENT) == null) {
props.put(DMQ.UNDELIVERED_COMMENT, lookupReasonString(reason,
receivedTime, expiredTime, senderTime));
}
props.put(DMQ.UNDELIVERED_TIMESTAMP,
new Long(System.currentTimeMillis()));
props.put(DMQ.BODY_TRUNCATED,
Boolean.valueOf(truncateBody));
String reasonstr = null;
if (reason == RemoveReason.EXPIRED ||
reason == RemoveReason.EXPIRED_BY_CLIENT ||
reason == RemoveReason.EXPIRED_ON_DELIVERY) {
props.put(DMQ.UNDELIVERED_REASON,
DMQ.REASON_EXPIRED);
} else if (reason == RemoveReason.REMOVED_LOW_PRIORITY) {
props.put(DMQ.UNDELIVERED_REASON,
DMQ.REASON_LOW_PRIORITY);
} else if (reason == RemoveReason.REMOVED_OLDEST) {
props.put(DMQ.UNDELIVERED_REASON,
DMQ.REASON_OLDEST);
} else if (reason == RemoveReason.UNDELIVERABLE) {
props.put(DMQ.UNDELIVERED_REASON,
DMQ.REASON_UNDELIVERABLE);
} else {
props.put(DMQ.UNDELIVERED_REASON,
DMQ.REASON_ERROR);
}
if (pr.getAddress() != null)
props.put(DMQ.BROKER, pr.getAddress().toString());
else
props.put(DMQ.BROKER, Globals.getMyAddress().toString());
String deadbkr = (String)packetProps.get(DMQ.DEAD_BROKER);
if (deadbkr != null)
props.put(DMQ.DEAD_BROKER, deadbkr);
else
props.put(DMQ.DEAD_BROKER, Globals.getMyAddress().toString());
if (!pr.isLocal()) {
Globals.getClusterBroadcast().
acknowledgeMessage(pr.getAddress(),
pr.getSysMessageID(), pr.getQueueUID(),
ClusterBroadcast.MSG_DEAD, props, true /*wait for ack*/);
return; // done
}
// OK ... now create the packet
Packet newp = new Packet();
// first make sure we have the room to put it on the
// queue ... if we dont, an exception will be thrown
// from queue Message
boolean route = false;
PacketReference ref = null;
try {
newp.generateSequenceNumber(false);
newp.generateTimestamp(false);
newp.fill(p);
newp.setProperties(props);
if (truncateBody) {
newp.setMessageBody(new byte[0]);
}
ref = PacketReference.createReference(
newp, deadMessageQueue.getDestinationUID(), null);
ref.overrideExpireTime(0);