PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/remote/EJBRemoteTransactionsRepository.java

#
Java | 97 lines | 52 code | 19 blank | 26 comment | 0 complexity | 2aed1b1d2e8735605645524a67fc0d30 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;
  23. import org.jboss.ejb.client.TransactionID;
  24. import org.jboss.msc.inject.Injector;
  25. import org.jboss.msc.service.Service;
  26. import org.jboss.msc.service.ServiceName;
  27. import org.jboss.msc.service.StartContext;
  28. import org.jboss.msc.service.StartException;
  29. import org.jboss.msc.service.StopContext;
  30. import org.jboss.msc.value.InjectedValue;
  31. import javax.transaction.Transaction;
  32. import javax.transaction.TransactionManager;
  33. import javax.transaction.UserTransaction;
  34. import java.util.Collections;
  35. import java.util.HashMap;
  36. import java.util.Map;
  37. /**
  38. * User: jpai
  39. */
  40. public class EJBRemoteTransactionsRepository implements Service<EJBRemoteTransactionsRepository> {
  41. public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("ejb").append("remote-transactions-repository");
  42. private final InjectedValue<TransactionManager> transactionManagerInjectedValue = new InjectedValue<TransactionManager>();
  43. private final InjectedValue<UserTransaction> userTransactionInjectedValue = new InjectedValue<UserTransaction>();
  44. private final Map<TransactionID, Transaction> transactions = Collections.synchronizedMap(new HashMap<TransactionID, Transaction>());
  45. @Override
  46. public void start(StartContext context) throws StartException {
  47. //To change body of implemented methods use File | Settings | File Templates.
  48. }
  49. @Override
  50. public void stop(StopContext context) {
  51. //To change body of implemented methods use File | Settings | File Templates.
  52. }
  53. @Override
  54. public EJBRemoteTransactionsRepository getValue() throws IllegalStateException, IllegalArgumentException {
  55. return this;
  56. }
  57. public TransactionManager getTransactionManager() {
  58. return this.transactionManagerInjectedValue.getValue();
  59. }
  60. public Transaction getTransaction(final TransactionID transactionID) {
  61. return this.transactions.get(transactionID);
  62. }
  63. public Transaction removeTransaction(final TransactionID transactionID) {
  64. return this.transactions.remove(transactionID);
  65. }
  66. public void addTransaction(final TransactionID transactionID, final Transaction transaction) {
  67. this.transactions.put(transactionID, transaction);
  68. }
  69. public UserTransaction getUserTransaction() {
  70. return this.userTransactionInjectedValue.getValue();
  71. }
  72. public Injector<TransactionManager> getTransactionManagerInjector() {
  73. return this.transactionManagerInjectedValue;
  74. }
  75. public Injector<UserTransaction> getUserTransactionInjector() {
  76. return this.userTransactionInjectedValue;
  77. }
  78. }