use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerDAOImpl method delete.
/**
* Delete an existing entry.
*
* @param conn database connection
* @param consumer the Consumer
* @throws BrokerException if entry does not exists in the store
*/
@Override
public void delete(Connection conn, Consumer consumer) throws BrokerException {
ConsumerUID consumerUID = consumer.getConsumerUID();
boolean deleted = false;
boolean myConn = false;
PreparedStatement pstmt = 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, deleteSQL);
pstmt.setLong(1, consumerUID.longValue());
if (pstmt.executeUpdate() > 0) {
deleted = 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, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + deleteSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_REMOVE_INTEREST_FAILED, consumerUID), ex);
} finally {
if (myConn) {
Util.close(null, pstmt, conn, myex);
} else {
Util.close(null, pstmt, null, myex);
}
}
if (!deleted) {
DestinationUID destinationUID = consumer.getDestinationUID();
throw new BrokerException(br.getKString(BrokerResources.E_INTEREST_NOT_FOUND_IN_STORE, consumerUID, destinationUID), Status.NOT_FOUND);
}
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerStateDAOImpl method insert.
/**
* Insert a new entry.
*
* @param conn database connection
* @param dstID the destination ID
* @param sysMsgID the system message ID
* @param conUIDs an array of consumer ids
* @param states an array of states
*/
@Override
public void insert(Connection conn, String dstID, SysMessageID sysMsgID, ConsumerUID[] conUIDs, int[] states, boolean checkMsgExist, boolean replaycheck) throws BrokerException {
String msgID = sysMsgID.getUniqueName();
int count = 0;
boolean myConn = false;
PreparedStatement pstmt = null;
Exception myex = null;
try {
// Get a connection
DBManager dbMgr = DBManager.getDBManager();
if (conn == null) {
conn = dbMgr.getConnection(false);
myConn = true;
}
// No need to check for message existence
if (checkMsgExist) {
int cnt = -1;
try {
cnt = getConsumerCount(conn, msgID);
} catch (BrokerException e) {
e.setSQLRecoverable(true);
e.setSQLReplayCheck(replaycheck);
throw e;
}
if (cnt > 0 && replaycheck) {
if (conUIDs != null) {
HashMap map = null;
try {
map = getStates(conn, sysMsgID);
} catch (BrokerException e) {
e.setSQLRecoverable(true);
e.setSQLReplayCheck(replaycheck);
throw e;
}
List cids = Arrays.asList(conUIDs);
Iterator itr = map.entrySet().iterator();
Map.Entry pair = null;
ConsumerUID cid = null;
while (itr.hasNext()) {
pair = (Map.Entry) itr.next();
cid = (ConsumerUID) pair.getKey();
int st = ((Integer) pair.getValue()).intValue();
for (int i = 0; i < conUIDs.length; i++) {
if (conUIDs[i].equals(cid)) {
if (states[i] == st) {
cids.remove(conUIDs[i]);
}
}
}
}
if (cids.size() == 0) {
logger.log(Logger.INFO, BrokerResources.I_CANCEL_SQL_REPLAY, msgID + "[" + dstID + "]" + cids);
return;
}
}
}
if (cnt > 0) {
// the message has a list already
throw new BrokerException(br.getKString(BrokerResources.E_MSG_INTEREST_LIST_EXISTS, msgID));
}
try {
dbMgr.getDAOFactory().getMessageDAO().checkMessage(conn, dstID, msgID);
} catch (BrokerException e) {
if (e.getStatusCode() != Status.NOT_FOUND) {
e.setSQLRecoverable(true);
}
throw e;
}
}
boolean dobatch = dbMgr.supportsBatchUpdates();
pstmt = dbMgr.createPreparedStatement(conn, insertSQL);
for (int len = conUIDs.length; count < len; count++) {
pstmt.setString(1, msgID);
pstmt.setLong(2, conUIDs[count].longValue());
pstmt.setInt(3, states[count]);
pstmt.setLong(4, System.currentTimeMillis());
if (dobatch) {
pstmt.addBatch();
} else {
pstmt.executeUpdate();
}
}
if (dobatch) {
pstmt.executeBatch();
}
if (myConn) {
conn.commit();
}
} catch (Exception e) {
myex = e;
if (DEBUG && count < conUIDs.length) {
logger.log(Logger.INFO, "Failed to persist interest: " + conUIDs[count].toString() + "(" + conUIDs[count].getUniqueName() + ")");
}
boolean replayck = false;
try {
if ((conn != null) && !conn.getAutoCommit()) {
conn.rollback();
}
} catch (SQLException rbe) {
replayck = true;
logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof IOException) {
ex = DBManager.wrapIOException("[" + insertSQL + "]", (IOException) e);
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + insertSQL + "]", (SQLException) e);
} else {
ex = e;
}
BrokerException be = new BrokerException(br.getKString(BrokerResources.X_PERSIST_INTEREST_LIST_FAILED, msgID), ex);
be.setSQLRecoverable(true);
if (replayck) {
be.setSQLReplayCheck(true);
}
throw be;
} finally {
if (myConn) {
Util.close(null, pstmt, conn, myex);
} else {
Util.close(null, pstmt, null, myex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerStateDAOImpl method getTransactionAcks.
/**
* Retrieve all transaction acknowledgements for the specified transaction ID.
*
* @param conn database connection
* @param txnUID the transaction ID
* @return List of transaction acks
*/
@Override
public List getTransactionAcks(Connection conn, TransactionUID txnUID) throws BrokerException {
List data = new ArrayList();
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, selectTransactionAcksSQL);
pstmt.setLong(1, txnUID.longValue());
rs = pstmt.executeQuery();
while (rs.next()) {
ConsumerUID conID = new ConsumerUID(rs.getLong(1));
try {
SysMessageID msgID = SysMessageID.get(rs.getString(2));
data.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("[" + selectTransactionAcksSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_ACKS_FOR_TXN_FAILED, txnUID), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return data;
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ConsumerUtil method getConsumerInfo.
public static CompositeData getConsumerInfo(String consumerID) throws BrokerException, OpenDataException {
CompositeData cd = null;
ConsumerUID tmpcid, cid = null;
BrokerResources rb = Globals.getBrokerResources();
if (consumerID == null) {
throw new IllegalArgumentException(rb.getString(rb.X_JMX_NULL_CONSUMER_ID_SPEC));
}
long longCid = 0;
try {
longCid = Long.parseLong(consumerID);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(rb.getString(rb.X_JMX_INVALID_CONSUMER_ID_SPEC, consumerID));
}
tmpcid = new ConsumerUID(longCid);
Consumer con = Consumer.getConsumer(tmpcid);
if (con == null) {
throw new BrokerException(rb.getString(rb.X_JMX_CONSUMER_NOT_FOUND, consumerID));
}
// triggers the broker to load messages if necessary
con.load();
cid = con.getConsumerUID();
if (cid == null) {
throw new BrokerException(rb.getString(rb.X_JMX_CONSUMER_NOT_FOUND, consumerID));
}
cd = getConsumerInfo(cid);
return (cd);
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method deleteBrowser.
@Override
public JMSServiceReply deleteBrowser(long connectionId, long sessionId, long consumerId) throws JMSServiceException {
JMSServiceReply reply;
// IMQConnection cxn;
HashMap props = new HashMap();
ConsumerUID uid;
// Session session;
// cxn = checkConnectionId(connectionId, "deleteBrowser");
checkConnectionId(connectionId, "deleteBrowser");
// session = checkSessionId(sessionId, "deleteBrowser");
checkSessionId(sessionId, "deleteBrowser");
uid = new ConsumerUID(consumerId);
if (queueBrowseList.containsKey(uid)) {
queueBrowseList.remove(uid);
} else {
String errStr = "deleteBrowser: consumer ID not found. Connection ID:" + connectionId + ", Session ID: " + sessionId + ", Consumer ID: " + consumerId;
logger.log(Logger.ERROR, errStr);
props.put("JMQStatus", JMSServiceReply.Status.NOT_FOUND);
throw new JMSServiceException(errStr, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
props.put("JMQConsumerID", uid.longValue());
reply = new JMSServiceReply(props);
return (reply);
}
Aggregations