Skip to content

Instantly share code, notes, and snippets.

@clebertsuconic
Created July 9, 2014 14:34
Show Gist options
  • Save clebertsuconic/76f050b30f2b6147d4dd to your computer and use it in GitHub Desktop.
Save clebertsuconic/76f050b30f2b6147d4dd to your computer and use it in GitHub Desktop.
protected HornetQRASession allocateConnection(boolean transacted, int acknowledgeMode, final int sessionType) throws JMSException
{
if (HornetQRASessionFactoryImpl.trace)
{
HornetQRALogger.LOGGER.trace("allocateConnection(" + transacted +
", " +
acknowledgeMode +
", " +
sessionType +
")");
}
try
{
synchronized (sessions)
{
if (sessions.isEmpty() == false)
{
throw new IllegalStateException("Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
}
//from createSession
// In a Java EE web or EJB container, when there is an active JTA transaction in progress:
//Both arguments {@code transacted} and {@code acknowledgeMode} are ignored.
if (inJtaTransaction())
{
transacted = true;
//from getAcknowledgeMode
// If the session is not transacted, returns the
// current acknowledgement mode for the session.
// If the session
// is transacted, returns SESSION_TRANSACTED.
acknowledgeMode = Session.SESSION_TRANSACTED;
}
//In the Java EE web or EJB container, when there is no active JTA transaction in progress
// The argument {@code transacted} is ignored.
else
{
//The session will always be non-transacted,
transacted = false;
switch (acknowledgeMode)
{
//using one of the two acknowledgement modes AUTO_ACKNOWLEDGE and DUPS_OK_ACKNOWLEDGE.
case Session.AUTO_ACKNOWLEDGE:
case Session.DUPS_OK_ACKNOWLEDGE:
//plus our own
case HornetQJMSConstants.INDIVIDUAL_ACKNOWLEDGE:
case HornetQJMSConstants.PRE_ACKNOWLEDGE:
break;
//The value {@code Session.CLIENT_ACKNOWLEDGE} may not be used.
case Session.CLIENT_ACKNOWLEDGE:
throw HornetQRABundle.BUNDLE.invalidSessionTransactedModeRuntime();
//same with this although the spec doesn't explicitly say
case Session.SESSION_TRANSACTED:
throw HornetQRABundle.BUNDLE.invalidClientAcknowledgeModeRuntime();
default:
throw HornetQRABundle.BUNDLE.invalidAcknowledgeMode(acknowledgeMode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment