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