use of com.sun.messaging.jmq.jmsservice.JMSServiceReply in project openmq by eclipse-ee4j.
the class DirectSession method _createAndAddConsumer.
/**
* Create a consumerId with the jmsservice and return a MessageConsumer object that can be returned by the JMS API
* method.
* <p>
* This method is used by the methods implementing jakarta.jms.Session, jakarta.jms.QueueSession, and
* jakarta.jms.TopicSession<br>
* A successfully created DirectConsumer is added to the table of Consumer objects maintained by this DirectSession.<br>
* A successfully created durable DirectConsumer is added to the table of durable Consumer objects maintained by the
* DirectConnection of this DirectSession.
*
* @param methodName The JMS API method that was called.
* @param destination The JMS Destination object identifying the destination on which the consumer is to be created.
* @param selector The JMS Message selector to be used.
* @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
* @param durable if dest is Topic, if true, this is a durable subscription
* @param share if dest is Topic, if true, this is a shared subscription
* @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
* true, this is a MQ Shared Subscription
*
* MQ Shared Subscription: messages will be shared with other consumers in the same group that have the same
* clientId+DurableName for Shared Durable Subscriptions
* <p>
* OR
* <p>
* clientId+TopicName+Selector for Shared Non-Durable Sunscriptions
*
* @param noLocal If {@code true} then this consumer does not want to messages produced on it'sconnection to be
* delivered to it.
*
* @return The DirectConsumer object to be returned by the JMS API method.
*
* @throws JMSException if any JMS error occurred.
*/
private DirectConsumer _createAndAddConsumer(String methodName, Destination destination, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, boolean noLocal) throws JMSException {
JMSServiceReply reply;
long consumerId = 0L;
com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + this.sessionId + ":" + methodName + ":Destination=" + destination + ":Selector=" + selector + ":subscriptionName=" + subscriptionName + ":durable=" + durable + ":share=" + share + ":jmsshare=" + jmsshare + ":noLocal=" + noLocal);
}
this._checkIfClosed(methodName);
jmsservice_dest = this._checkDestinationForConsumer(destination);
String duraname = (durable ? subscriptionName : null);
DirectConsumer consumer = new DirectConsumer(this, jmsservice, destination, jmsservice_dest, noLocal, selector, duraname);
try {
// adjusted for JMS 2.0
reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, subscriptionName, durable, share, jmsshare, this.getConnection()._getClientID(), noLocal);
/*
* reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, durableName,
* this.getConnection()._getClientID(), noLocal, //XXX:tharakan:using false for shared temporarily false, false);
*/
try {
// Set consumerId right away
consumerId = reply.getJMQConsumerID();
consumer._setConsumerId(consumerId);
} catch (NoSuchFieldException nsfe) {
String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConsumerID";
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(nsfe);
_loggerJS.severe(exerrmsg);
throw jmse;
}
} catch (JMSServiceException jse) {
JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
String failure_cause;
JMSException jmsse = null;
String exerrmsg = "createConsumer on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
switch(status) {
case FORBIDDEN:
failure_cause = "client forbidden to receive messages from this destination.";
exerrmsg = exerrmsg + failure_cause;
jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
break;
case NOT_FOUND:
failure_cause = "destination not found and cannot be auto-created.";
break;
case CONFLICT:
failure_cause = "destination limit for number of consumers exceeded.";
break;
case BAD_REQUEST:
failure_cause = "invalid selector=" + selector;
exerrmsg = exerrmsg + failure_cause;
jmsse = new InvalidSelectorException(exerrmsg);
break;
case PRECONDITION_FAILED:
if (jse.getCause() != null && jse.getCause() instanceof BrokerException) {
failure_cause = jse.getCause().getMessage();
exerrmsg = exerrmsg + failure_cause;
jmsse = new IllegalStateException(exerrmsg, ((BrokerException) jse.getCause()).getErrorCode());
break;
}
default:
failure_cause = "unknown JMSService server error.";
}
_loggerJS.severe(exerrmsg);
if (jmsse == null) {
exerrmsg = exerrmsg + failure_cause;
jmsse = new JMSException(exerrmsg);
}
jmsse.initCause(jse);
throw jmsse;
}
this.addConsumer(consumer);
if (subscriptionName != null && durable) {
this.dc.addDurableConsumer(consumer);
}
if (destination instanceof TemporaryDestination) {
this.dc._incrementTemporaryDestinationUsage((TemporaryDestination) destination);
}
return consumer;
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceReply in project openmq by eclipse-ee4j.
the class DirectXAResource method commit.
/**
* Commit the global transaction specified by xid.
*
* @param foreignXid A global transaction identifier
*
* @param onePhase If true, the resource manager should use a one-phase commit protocol to commit the work done on
* behalf of xid.
*
* @throws XAException An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX,
* XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*
* <P>
* If the resource manager did not commit the transaction and the parameter onePhase is set to true, the resource
* manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work
* and has released all held resources.
*/
@Override
public synchronized void commit(Xid foreignXid, boolean onePhase) throws XAException {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Commit " + printXid(foreignXid) + " (onePhase=" + onePhase + "), connectionId=" + connectionId);
}
// convert to XidImpl
// XidImpl mqxid = new XidImpl(foreignXid);
String methodName = "commit()";
if (_logFINE) {
// +"Xid="+mqxid.toString()
_loggerJX.fine(// +"Xid="+mqxid.toString()
_lgrMID_INF + methodName + ":onePhase=" + onePhase + ":transactionId=" + this.mTransactionId);
}
boolean rbrollback = false;
Exception rbrollbackex = null;
// JMSServiceReply reply = null;
JMSServiceReply.Status status;
try {
// reply = jmsservice.commitTransaction(this.connectionId,
jmsservice.commitTransaction(this.connectionId, this.mTransactionId, foreignXid, (onePhase ? XAResource.TMONEPHASE : XAResource.TMNOFLAGS));
this.setEnlisted(false);
if (_logFINE) {
_loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":committed transactionId=" + this.mTransactionId);
}
} catch (JMSServiceException jse) {
status = jse.getJMSServiceReply().getStatus();
String failure_cause = getFailureCauseAsString(status, jse);
// XXX:tharakan:This message should be in the JMSServiceException
String exerrmsg = "commitTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and onePhase:" + onePhase + // "and Xid:" + mqxid.toString() +
" due to " + failure_cause;
_loggerOC.severe(exerrmsg);
if (onePhase) {
rbrollback = true;
rbrollbackex = jse;
}
if (!rbrollback) {
XAException xae = new XAException(XAException.XAER_RMFAIL);
xae.initCause(jse);
throw xae;
}
} finally {
if (!rbrollback) {
// finish up this resource and any others joined to it in this transaction
boolean throwExceptionIfNotFound = false;
XidImpl savedXid = this.mXid;
DirectXAResource[] resources = DirectXAResourceMap.getXAResources(this.mXid, throwExceptionIfNotFound);
for (int i = 0; i < resources.length; i++) {
DirectXAResource xari = resources[i];
try {
xari.clearTransactionInfo();
} catch (JMSException jmse) {
_loggerJX.log(Level.SEVERE, "MQRA:DXAR:commit:XAException-Exception=" + jmse.getMessage(), jmse);
Debug.printStackTrace(jmse);
XAException xae = new XAException(XAException.XAER_RMFAIL);
xae.initCause(jmse);
throw xae;
}
}
DirectXAResourceMap.unregister(savedXid);
}
}
if (rbrollback) {
XAException xae;
try {
rollback(foreignXid, DirectXAResourceMap.MAXROLLBACKS, DirectXAResourceMap.DMQ_ON_MAXROLLBACKS);
xae = new XAException(XAException.XA_RBROLLBACK);
xae.initCause(rbrollbackex);
} catch (Exception e) {
_loggerJX.log(Level.SEVERE, "Exception on rollback transaction " + foreignXid + "[" + mTransactionId + "] after 1-phase-commit failure", e);
xae = new XAException(XAException.XAER_RMFAIL);
xae.initCause(rbrollbackex);
}
throw xae;
}
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceReply in project openmq by eclipse-ee4j.
the class DirectXAResource method rollback.
private synchronized void rollback(Xid foreignXid, int maxRollbacks, boolean dmqOnMaxRollbacks) throws XAException {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Rollback " + printXid(foreignXid) + "), connectionId=" + connectionId);
}
// convert to XidImpl
// XidImpl mqxid = new XidImpl(foreignXid);
String methodName = "rollback()";
if (_logFINE) {
// +
_loggerJX.fine(// +
_lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
}
// JMSServiceReply reply = null;
JMSServiceReply.Status status;
try {
// reply = jmsservice.rollbackTransaction(this.connectionId,
jmsservice.rollbackTransaction(this.connectionId, this.mTransactionId, foreignXid, true, true, maxRollbacks, dmqOnMaxRollbacks);
this.setEnlisted(false);
if (_logFINE) {
_loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":rolled back transactionId=" + this.mTransactionId);
}
} catch (JMSServiceException jse) {
status = jse.getJMSServiceReply().getStatus();
String failure_cause = getFailureCauseAsString(status, jse);
// XXX:tharakan:This message should be in the JMSServiceException
String exerrmsg = "rollbackTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + ":transactionId=" + this.mTransactionId + // "and Xid:" + mqxid.toString() +
" due to " + failure_cause;
_loggerOC.severe(exerrmsg);
XAException xae = new XAException(XAException.XAER_RMERR);
xae.initCause(jse);
throw xae;
} finally {
// finish up this resource and any others joined to it in this transaction
boolean throwExceptionIfNotFound = false;
DirectXAResource[] resources = DirectXAResourceMap.getXAResources(this.mXid, throwExceptionIfNotFound);
XidImpl savedXid = this.mXid;
for (int i = 0; i < resources.length; i++) {
DirectXAResource xari = resources[i];
try {
xari.clearTransactionInfo();
} catch (JMSException jmse) {
_loggerJX.log(Level.SEVERE, "MQRA:DXAR:rollback:XAException-Exception=" + jmse.getMessage(), jmse);
Debug.printStackTrace(jmse);
XAException xae = new XAException(XAException.XAER_RMFAIL);
xae.initCause(jmse);
throw xae;
}
}
DirectXAResourceMap.unregister(savedXid);
}
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceReply in project openmq by eclipse-ee4j.
the class DirectXAResource method prepare.
/**
* Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
*
* @param foreignXid A global transaction identifier.
*
* @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values are:
* XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an
* appropriate XAException in the prepare method.
*
* @throws XAException If an error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
* XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*/
@Override
public synchronized int prepare(Xid foreignXid) throws XAException {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Prepare " + printXid(foreignXid) + ", connectionId=" + connectionId);
}
// convert to XidImpl
// XidImpl mqxid = new XidImpl(foreignXid);
String methodName = "prepare()";
if (_logFINE) {
// +
_loggerJX.fine(// +
_lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
}
// JMS does not do RDONLY transactions
int result = XA_OK;
// JMSServiceReply reply = null;
JMSServiceReply.Status status;
try {
// reply = jmsservice.prepareTransaction(this.connectionId,
jmsservice.prepareTransaction(this.connectionId, this.mTransactionId, foreignXid);
if (_logFINE) {
_loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":prepared transactionId=" + this.mTransactionId);
}
} catch (JMSServiceException jse) {
status = jse.getJMSServiceReply().getStatus();
String failure_cause = getFailureCauseAsString(status, jse);
// XXX:tharakan:This message should be in the JMSServiceException
String exerrmsg = "prepareTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
" due to " + failure_cause;
_loggerOC.severe(exerrmsg);
XAException xae = new XAException(XAException.XAER_RMERR);
xae.initCause(jse);
throw xae;
}
// update the resource state
resourceState = PREPARED;
return result;
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceReply in project openmq by eclipse-ee4j.
the class DirectConnection method _createSessionId.
// ///////////////////////////////////////////////////////////////////////
// end private support for jakarta.jms.Connection for RA use
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
// MQ methods
// ///////////////////////////////////////////////////////////////////////
/**
* Create a session with the jmsservice and return a sessionId. Used by the methods implementing jakarta.jms.Connection,
* jakarta.jms.QueueConnection, and jakarta.jms.TopicConnection
*
* @param connectionId The connectionId in which the session is being created.
* @param acknowledgeMode The acknowledgment mode being used
*
* @return The sessionId to be used by the DirectSession object that is returned by the JMS API method
*
* @throws JMSException if any JMS server error occurred
*/
private long _createSessionId(long connectionId, boolean isTransacted, int acknowledgeMode) throws JMSException {
JMSServiceReply reply;
long sessionId = 0L;
SessionAckMode ackMode = this._getSessionAckModeFromSessionParams(isTransacted, acknowledgeMode);
try {
reply = jmsservice.createSession(connectionId, ackMode);
try {
sessionId = reply.getJMQSessionID();
} catch (NoSuchFieldException nsfe) {
String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQSessionID";
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(nsfe);
_loggerJC.severe(exerrmsg);
throw jmse;
}
} catch (JMSServiceException jse) {
JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
String failure_cause;
switch(status) {
case BAD_REQUEST:
failure_cause = "invalid acknowledgment mode.";
break;
case NOT_ALLOWED:
failure_cause = "acknowledgmentmode is not allowed.";
break;
default:
failure_cause = "unkown JMSService server error.";
}
String exerrmsg = "createSession on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " due to " + failure_cause;
_loggerJC.severe(exerrmsg);
JMSException jmsse = new JMSException(exerrmsg);
jmsse.initCause(jse);
throw jmsse;
}
return sessionId;
}
Aggregations