PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/remote/protocol/versionone/XidTransactionManagementTask.java

#
Java | 98 lines | 55 code | 14 blank | 29 comment | 0 complexity | 0f2d688f95671b087f5d9f63e6800e72 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ejb3.remote.protocol.versionone;
  23. import javax.transaction.Transaction;
  24. import javax.transaction.TransactionManager;
  25. import java.io.IOException;
  26. import org.jboss.as.ejb3.remote.EJBRemoteTransactionsRepository;
  27. import org.jboss.ejb.client.XidTransactionID;
  28. import org.jboss.logging.Logger;
  29. import org.jboss.marshalling.MarshallerFactory;
  30. import org.jboss.remoting3.Channel;
  31. import org.xnio.IoUtils;
  32. /**
  33. * @author Jaikiran Pai
  34. */
  35. abstract class XidTransactionManagementTask implements Runnable {
  36. private static final Logger logger = Logger.getLogger(XidTransactionManagementTask.class);
  37. protected final short invocationId;
  38. protected final Channel channel;
  39. protected final EJBRemoteTransactionsRepository transactionsRepository;
  40. protected final XidTransactionID xidTransactionID;
  41. protected final MarshallerFactory marshallerFactory;
  42. protected final TransactionRequestHandler transactionRequestHandler;
  43. XidTransactionManagementTask(final TransactionRequestHandler txRequestHandler, final EJBRemoteTransactionsRepository transactionsRepository,
  44. final MarshallerFactory marshallerFactory, final XidTransactionID xidTransactionID,
  45. final Channel channel, final short invocationId) {
  46. this.transactionRequestHandler = txRequestHandler;
  47. this.channel = channel;
  48. this.marshallerFactory = marshallerFactory;
  49. this.invocationId = invocationId;
  50. this.transactionsRepository = transactionsRepository;
  51. this.xidTransactionID = xidTransactionID;
  52. }
  53. @Override
  54. public void run() {
  55. try {
  56. this.manageTransaction();
  57. } catch (Throwable t) {
  58. try {
  59. logger.error("Error during transaction management of transaction id " + this.xidTransactionID, t);
  60. // write out a failure message to the channel to let the client know that
  61. // the transaction operation failed
  62. transactionRequestHandler.writeException(this.channel, this.marshallerFactory, this.invocationId, t, null);
  63. } catch (IOException e) {
  64. logger.error("Could not write out message to channel due to", e);
  65. // close the channel
  66. IoUtils.safeClose(this.channel);
  67. }
  68. return;
  69. }
  70. try {
  71. // write out invocation success message to the channel
  72. transactionRequestHandler.writeTxInvocationResponseMessage(this.channel, this.invocationId);
  73. } catch (IOException e) {
  74. logger.error("Could not write out invocation success message to channel due to", e);
  75. // close the channel
  76. IoUtils.safeClose(this.channel);
  77. }
  78. }
  79. protected abstract void manageTransaction() throws Throwable;
  80. protected void resumeTransaction(final Transaction transaction) throws Exception {
  81. final TransactionManager transactionManager = this.transactionsRepository.getTransactionManager();
  82. transactionManager.resume(transaction);
  83. }
  84. }