use of com.sun.messaging.jmq.io.InvalidPacketException 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.io.InvalidPacketException in project openmq by eclipse-ee4j.
the class DestinationList method remoteCheckTakeoverMsgs.
public static void remoteCheckTakeoverMsgs(Map<String, String> msgs, String brokerid, PartitionedStore ps) throws BrokerException {
Set destroyConns = new HashSet();
Map<String, String> badsysids = null;
Iterator<Map.Entry<String, String>> itr = msgs.entrySet().iterator();
Map.Entry<String, String> me = null;
String sysidstr = null, duidstr = null;
SysMessageID sysid = null;
DestinationUID duid = null;
while (itr.hasNext()) {
me = itr.next();
sysidstr = me.getKey();
duidstr = me.getValue();
try {
sysid = SysMessageID.get(sysidstr);
} catch (InvalidSysMessageIDException e) {
Globals.getLogger().logStack(Logger.ERROR, e.getMessage(), e);
if (!Globals.getStore().getStoreType().equals(Store.JDBC_STORE_TYPE)) {
throw e;
}
duid = new DestinationUID(duidstr);
Globals.getLogger().log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.X_TAKEOVER_MSGID_CORRUPT_TRY_REPAIR, sysidstr, duidstr));
try {
Packet p = null;
try {
p = ps.getMessage(duid, sysidstr);
} catch (BrokerException ee) {
Throwable cause = ee.getCause();
String[] args = { sysidstr, "[?]", duidstr, cause.toString() };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_REPAIR_CORRUPTED_MSGID_IN_STORE, args);
Globals.getLogger().logStack(Logger.ERROR, emsg, ee);
if (cause instanceof InvalidPacketException) {
handleInvalidPacket(sysidstr, duidstr, emsg, (InvalidPacketException) cause, ps);
itr.remove();
continue;
} else {
throw ee;
}
}
sysid = p.getSysMessageID();
String realsysidstr = sysid.getUniqueName();
String[] args3 = { sysidstr, realsysidstr, duidstr };
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.X_REPAIR_CORRUPTED_MSGID_TO, args3));
ps.repairCorruptedSysMessageID(sysid, sysidstr, duidstr, true);
if (badsysids == null) {
badsysids = new HashMap<>();
}
badsysids.put(sysidstr, realsysidstr);
} catch (BrokerException ee) {
Globals.getLogger().logStack(Logger.ERROR, e.getMessage(), ee);
throw e;
}
}
PacketReference ref = get(null, sysid);
if (ref == null) {
continue;
}
Iterator cnitr = ref.getRemoteConsumerUIDs().values().iterator();
while (cnitr.hasNext()) {
destroyConns.add(cnitr.next());
}
}
if (badsysids != null) {
itr = badsysids.entrySet().iterator();
String v = null;
while (itr.hasNext()) {
me = itr.next();
v = msgs.remove(me.getKey());
msgs.put(me.getValue(), v);
}
}
destroyConnections(destroyConns, GoodbyeReason.BKR_IN_TAKEOVER, GoodbyeReason.toString(GoodbyeReason.BKR_IN_TAKEOVER) + ":" + brokerid);
}
use of com.sun.messaging.jmq.io.InvalidPacketException in project openmq by eclipse-ee4j.
the class DestinationList method handleInvalidPacket.
private static void handleInvalidPacket(String sysidstr, String duidstr, String comment, InvalidPacketException ipex, PartitionedStore ps) throws BrokerException {
Properties props = new Properties();
props.put(DMQ.UNDELIVERED_REASON, RemoveReason.ERROR.toString());
props.put(DMQ.UNDELIVERED_TIMESTAMP, Long.valueOf(System.currentTimeMillis()));
props.put(DMQ.UNDELIVERED_COMMENT, comment);
String cstr = SupportUtil.getStackTraceString(ipex);
props.put(DMQ.UNDELIVERED_EXCEPTION, cstr);
props.put(DMQ.BROKER, Globals.getMyAddress().toString());
props.put(DMQ.DEAD_BROKER, Globals.getMyAddress().toString());
byte[] data = ipex.getBytes();
Queue[] dmqs = DL.getDMQ(ps);
Queue dmq = dmqs[0];
Packet pkt = new Packet();
pkt.setPacketType(PacketType.BYTES_MESSAGE);
pkt.setProperties(props);
pkt.setDestination(dmq.getDestinationName());
pkt.setIsQueue(true);
pkt.setPersistent(true);
pkt.setIP(Globals.getBrokerInetAddress().getAddress());
pkt.setPort(Globals.getPortMapper().getPort());
pkt.updateSequenceNumber();
pkt.updateTimestamp();
pkt.generateSequenceNumber(false);
pkt.generateTimestamp(false);
pkt.setSendAcknowledge(false);
pkt.setMessageBody(data);
PacketReference ref = PacketReference.createReference(dmq.getPartitionedStore(), pkt, null);
String[] args1 = { sysidstr, duidstr, ref.getSysMessageID().toString() + "[" + PacketType.getString(PacketType.BYTES_MESSAGE) + "]" };
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_PLACING_CORRUPTED_MSG_TO_DMQ, args1));
dmq.queueMessage(ref, false);
Set s = dmq.routeNewMessage(ref);
String[] args2 = { sysidstr, duidstr, ref.getSysMessageID().toString() + "[" + PacketType.getString(PacketType.BYTES_MESSAGE) + "]" };
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_PLACED_CORRUPTED_MSG_TO_DMQ, args2));
dmq.forwardMessage(s, ref);
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_REMOVE_CORRUPTED_MSG_IN_STORE, sysidstr, duidstr));
try {
ps.removeMessage((new DestinationUID(duidstr)), sysidstr, true);
} catch (Exception e) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_PERSIST_MESSAGE_REMOVE_FAILED, sysidstr);
Globals.getLogger().logStack(Logger.ERROR, emsg, e);
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
throw new BrokerException(emsg, e);
}
}
use of com.sun.messaging.jmq.io.InvalidPacketException in project openmq by eclipse-ee4j.
the class MessageDAOImpl method getMessage.
/**
* Get a Message.
*
* @param conn database connection
* @param dstUID the destination
* @param id the system message id of the message
* @return Packet the message
*/
@Override
public Packet getMessage(Connection conn, DestinationUID dstUID, String id) throws BrokerException {
Packet msg = null;
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
try {
// Get a connection
DBManager dbMgr = DBManager.getDBManager();
if (conn == null) {
conn = dbMgr.getConnection(true);
myConn = true;
}
pstmt = dbMgr.createPreparedStatement(conn, selectSQL);
pstmt.setString(1, id);
rs = pstmt.executeQuery();
msg = (Packet) loadData(rs, true);
} catch (Exception e) {
myex = e;
try {
if ((conn != null) && !conn.getAutoCommit()) {
conn.rollback();
}
} catch (SQLException rbe) {
logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED + "[" + selectSQL + "]", rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof InvalidPacketException) {
InvalidPacketException ipe = (InvalidPacketException) e;
ipe.appendMessage("[" + id + ", " + dstUID + "][" + selectSQL + "]");
ex = ipe;
} else if (e instanceof PacketReadEOFException) {
PacketReadEOFException pre = (PacketReadEOFException) e;
pre.appendMessage("[" + id + ", " + dstUID + "][" + selectSQL + "]");
ex = pre;
} else if (e instanceof IOException) {
ex = DBManager.wrapIOException("[" + selectSQL + "]", (IOException) e);
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + selectSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_MESSAGE_FAILED, id), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
if (msg == null) {
throw new BrokerException(br.getKString(BrokerResources.E_MSG_NOT_FOUND_IN_STORE, id, dstUID), Status.NOT_FOUND);
}
return msg;
}
use of com.sun.messaging.jmq.io.InvalidPacketException in project openmq by eclipse-ee4j.
the class MessageDAOImpl method loadData.
/**
* Load a single message or messages from a ResultSet.
*
* @param rs the ResultSet
* @param isSingleRow specify interesed in only the 1st row of the ResultSet
* @return a message or a List of messages
*/
protected Object loadData(ResultSet rs, boolean isSingleRow) throws IOException, SQLException {
ArrayList list = null;
if (!isSingleRow) {
list = new ArrayList(100);
}
while (rs.next()) {
Packet msg = new Packet(false);
msg.generateTimestamp(false);
msg.generateSequenceNumber(false);
InputStream is = null;
InvalidPacketException ipex = null;
IOException origex = null;
Blob blob = null;
long bloblen = -1;
try {
if (getMsgColumnType(rs, 1) == Types.BLOB) {
blob = rs.getBlob(1);
is = blob.getBinaryStream();
bloblen = blob.length();
} else {
is = rs.getBinaryStream(1);
}
try {
if (fi.FAULT_INJECTION) {
if (fi.checkFault(FaultInjection.FAULT_HA_BADPKT_EXCEPTION, null)) {
fi.unsetFault(FaultInjection.FAULT_HA_BADPKT_EXCEPTION);
throw new StreamCorruptedException(FaultInjection.FAULT_HA_BADPKT_EXCEPTION);
}
if (fi.checkFault(FaultInjection.FAULT_HA_PKTREADEOF_RECONNECT_EXCEPTION, null)) {
fi.unsetFault(FaultInjection.FAULT_HA_PKTREADEOF_RECONNECT_EXCEPTION);
PacketReadEOFException e = new PacketReadEOFException(FaultInjection.FAULT_HA_PKTREADEOF_RECONNECT_EXCEPTION);
e.setBytesRead(0);
throw e;
}
}
msg.readPacket(is);
if (fi.FAULT_INJECTION) {
if (fi.checkFault(FaultInjection.FAULT_HA_PKTREADEOF_EXCEPTION, null)) {
fi.unsetFault(FaultInjection.FAULT_HA_PKTREADEOF_EXCEPTION);
PacketReadEOFException e = new PacketReadEOFException(FaultInjection.FAULT_HA_PKTREADEOF_EXCEPTION + ":pktsize=" + msg.getPacketSize() + ", blobsize=" + (blob != null ? bloblen : rs.getBytes(1).length));
e.setBytesRead(msg.getPacketSize());
throw e;
}
}
} catch (StreamCorruptedException e) {
origex = e;
ipex = new InvalidPacketException(e.getMessage(), e);
} catch (IllegalArgumentException e) {
origex = new IOException(e.getMessage(), e);
ipex = new InvalidPacketException(e.getMessage(), e);
} catch (PacketReadEOFException e) {
origex = e;
if (blob != null && e.getBytesRead() < bloblen) {
// for auto-reconnect
throw e;
}
ipex = new InvalidPacketException(e.getMessage(), e);
}
if (ipex != null) {
try {
is.close();
} catch (Exception e) {
/* ignore */
}
is = null;
byte[] bytes = null;
if (blob != null) {
try {
bytes = blob.getBytes(1L, (int) bloblen);
} catch (Exception e) {
String es = SupportUtil.getStackTraceString(e);
bytes = es.getBytes("UTF-8");
}
} else {
bytes = rs.getBytes(1);
if (bytes != null && (origex instanceof PacketReadEOFException)) {
if (((PacketReadEOFException) origex).getBytesRead() < bytes.length) {
throw origex;
}
}
}
if (bytes == null) {
throw origex;
}
ipex.setBytes(bytes);
throw ipex;
}
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
/* ignore */
}
}
}
if (DEBUG) {
logger.log(Logger.INFO, "MessageDAOImpl.loadData(isSingleRow=" + isSingleRow + "):" + "Loaded message from database for " + msg.getMessageID());
}
if (isSingleRow) {
return msg;
} else {
list.add(msg);
}
}
if (DEBUG && list != null) {
logger.log(Logger.INFO, "MessageDAOImpl.loadData(): ResultSet[size=" + list.size() + "]");
}
return list;
}
Aggregations