/// <summary> /// Creates the shared connection for this container. /// </summary> /// <remarks> /// The default implementation creates a standard Connection /// and prepares it through <see cref="PrepareSharedConnection"/> /// </remarks> /// <returns>the prepared Connection</returns> /// <exception cref="EMSException">if the creation failed.</exception> protected virtual IConnection CreateSharedConnection() { IConnection con = CreateConnection(); try { PrepareSharedConnection(con); return(con); } catch (EMSException) { EmsUtils.CloseConnection(con); throw; } }
/// <summary> /// Invoke the specified listener as Spring ISessionAwareMessageListener, /// exposing a new EMS Session (potentially with its own transaction) /// to the listener if demanded. /// </summary> /// <param name="listener">The Spring ISessionAwareMessageListener to invoke.</param> /// <param name="session">The session to operate on.</param> /// <param name="message">The received message.</param> /// <exception cref="EMSException">If thrown by EMS API methods.</exception> /// <see cref="ISessionAwareMessageListener"/> /// <see cref="ExposeListenerSession"/> protected virtual void DoInvokeListener(ISessionAwareMessageListener listener, ISession session, Message message) { IConnection conToClose = null; ISession sessionToClose = null; try { ISession sessionToUse = session; if (!ExposeListenerSession) { //We need to expose a separate Session. conToClose = CreateConnection(); sessionToClose = CreateSession(conToClose); sessionToUse = sessionToClose; } // Actually invoke the message listener if (logger.IsDebugEnabled) { logger.Debug("Invoking listener with message of type [" + message.GetType() + "] and session [" + sessionToUse + "]"); } listener.OnMessage(message, sessionToUse); // Clean up specially exposed Session, if any if (sessionToUse != session) { if (sessionToUse.Transacted && SessionTransacted) { // Transacted session created by this container -> commit. EmsUtils.CommitIfNecessary(sessionToUse); } } } finally { EmsUtils.CloseSession(sessionToClose); EmsUtils.CloseConnection(conToClose); } }