use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerDAOImpl method checkConsumer.
/**
* Check whether the specified consumer exists.
*
* @param conn database connection
* @param consumer the Consumer
* @return return true if the specified consumer exists
*/
private Consumer checkConsumer(Connection conn, Consumer consumer, boolean byId) throws BrokerException {
ConsumerUID consumerUID = consumer.getConsumerUID();
boolean myConn = false;
String sql = selectExistByIDSQL;
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;
}
if (!byId) {
sql = selectExistSQL;
}
pstmt = dbMgr.createPreparedStatement(conn, sql);
if (byId) {
pstmt.setLong(1, consumerUID.longValue());
} else {
Util.setString(pstmt, 1, ((Subscription) consumer).getDurableName());
Util.setString(pstmt, 2, ((Subscription) consumer).getClientID(), false);
}
rs = pstmt.executeQuery();
if (rs.next()) {
Consumer c = (Consumer) Util.readObject(rs, 1);
return c;
}
return null;
} 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 + "[" + sql + "]", rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + sql + "]", (SQLException) e);
} else if (e instanceof IOException) {
ex = DBManager.wrapIOException("[" + sql + "]", (IOException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_RETRIEVE_INTEREST_FAILED, consumerUID), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerStateDAOImpl method getStates.
/**
* Get all consumers and states associated with the messapge ID.
*
* @param conn database connection
* @return HashMap of containing all consumer's state
*/
@Override
public HashMap getStates(Connection conn, SysMessageID sysMsgID) throws BrokerException {
HashMap map = new HashMap();
String id = sysMsgID.getUniqueName();
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, selectStatesByMsgSQL);
pstmt.setString(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
ConsumerUID cUID = new ConsumerUID(rs.getLong(1));
int state = rs.getInt(2);
map.put(cUID, Integer.valueOf(state));
}
} 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, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + selectStatesByMsgSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_INT_STATES_FOR_MSG_FAILED, id), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return map;
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerStateDAOImpl method getAllTransactionAcks.
/**
* Retrieve all transaction acknowledgements for all transactions.
*
* @param conn database connection
* @return HashMap of containing all acknowledgement
*/
@Override
public HashMap getAllTransactionAcks(Connection conn) throws BrokerException {
HashMap data = new HashMap(100);
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, selectAllTransactionAcksSQL);
rs = pstmt.executeQuery();
while (rs.next()) {
TransactionUID txnUID = new TransactionUID(rs.getLong(1));
ConsumerUID conID = new ConsumerUID(rs.getLong(2));
try {
SysMessageID msgID = SysMessageID.get(rs.getString(3));
List ackList = (List) data.get(txnUID);
if (ackList == null) {
// Create a new list of acks for this txn
ackList = new ArrayList(25);
data.put(txnUID, ackList);
}
// Added ack to the list of acks
ackList.add(new TransactionAcknowledgement(msgID, conID, conID));
} catch (Exception e) {
// fail to parse one object; just log it
logger.logStack(Logger.ERROR, BrokerResources.X_PARSE_TXNACK_FAILED, txnUID, e);
}
}
} 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, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + selectAllTransactionAcksSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TXNACK_FAILED), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
// Transforms HashMap value to TransactionAcknowledgement[] instead of List
Set keySet = data.keySet();
if (!keySet.isEmpty()) {
Iterator itr = keySet.iterator();
while (itr.hasNext()) {
TransactionUID txnUID = (TransactionUID) itr.next();
List ackList = (List) data.get(txnUID);
data.put(txnUID, ackList.toArray(new TransactionAcknowledgement[ackList.size()]));
}
}
return data;
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerStateDAOImpl method getConsumerUIDs.
/**
* Get all consumers associated with the messapge ID and state is not INTEREST_STATE_ACKNOWLEDGED.
*
* @param conn database connection
* @param sysMsgID the system message ID
* @return list of consumer IDs
*/
@Override
public List getConsumerUIDs(Connection conn, SysMessageID sysMsgID) throws BrokerException {
List list = new ArrayList();
String id = sysMsgID.getUniqueName();
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, selectConsumerIDsByMsgSQL);
pstmt.setString(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
ConsumerUID cUID = new ConsumerUID(rs.getLong(1));
list.add(cUID);
}
} 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, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + selectConsumerIDsByMsgSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_INT_STATES_FOR_MSG_FAILED, id), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return list;
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method redeliverMessages.
/**
* Redeliver messages for a Session.
* <p>
* All the messages that are specified by the parameters will be redelivered by the broker.
*
* @param connectionId The Id of the connection in which the messages were received
* @param sessionId The Id of the session in which the messages were received
* @param messageIDs The array of SysMessageID objects for the messages that were received and are to be redelivered
* @param consumerIds The array of consumerId longs for the messages that were received and are to be redelivered
* @param transactionId The Id of the transaction in which the messages were received
* @param setRedelivered Indicates whether to set the Redelivered flag when redelivering the messages.<br>
* If <code>true</code> then the Redelivered flag must be set for the messages when they are redelivered.<br>
* If <code>false</code>, then the Redelivered flag must not be set for the messages when they are redelivered.
*
* @throws JMSServiceException If broker encounters an error.<br>
* {@link JMSServiceException#getJMSServiceReply} should be used to obtain the broker reply in case of an exception.<br>
* The reason for the exception can be obtained from {@link JMSServiceReply.Status}
*/
@Override
public JMSServiceReply redeliverMessages(long connectionId, long sessionId, SysMessageID[] messageIDs, Long[] consumerIds, long transactionId, boolean setRedelivered) throws JMSServiceException {
JMSServiceReply reply;
IMQConnection cxn;
HashMap props = new HashMap();
ConsumerUID[] conUIDs = null;
TransactionUID txnUID = null;
// Session session;
cxn = checkConnectionId(connectionId, "redeliverMessages");
// session = checkSessionId(sessionId, "redeliverMessages");
checkSessionId(sessionId, "redeliverMessages");
if (consumerIds != null) {
conUIDs = new ConsumerUID[consumerIds.length];
for (int i = 0; i < consumerIds.length; ++i) {
conUIDs[i] = new ConsumerUID(consumerIds[i]);
}
}
if (transactionId != -1) {
txnUID = new TransactionUID(transactionId);
}
try {
protocol.redeliver(conUIDs, messageIDs, cxn, txnUID, setRedelivered);
} catch (Exception e) {
String errStr = "redeliverMessages: Redeliver failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", transaction ID: " + transactionId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", getErrorReplyStatus(e));
throw new JMSServiceException(errStr, e, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
reply = new JMSServiceReply(props);
return (reply);
}
Aggregations