View Javadoc

1   /**
2    *
3    * Copyright 2003-2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.geronimo.connector.outbound;
19  
20  import javax.transaction.TransactionManager;
21  
22  import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool;
23  import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
24  import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
25  import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
26  
27  /**
28   * GenericConnectionManager sets up a connection manager stack according to the
29   * policies described in the attributes.
30   *
31   * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
32   */
33  public class GenericConnectionManager extends AbstractConnectionManager {
34  
35      //default constructor for use as endpoint
36      public GenericConnectionManager() {
37          super();
38      }
39  
40      public GenericConnectionManager(TransactionSupport transactionSupport,
41                                      PoolingSupport pooling,
42                                      boolean containerManagedSecurity,
43                                      ConnectionTracker connectionTracker,
44                                      TransactionManager transactionManager,
45                                      String objectName,
46                                      ClassLoader classLoader) {
47          super(new InterceptorsImpl(transactionSupport, pooling, containerManagedSecurity, objectName, connectionTracker, transactionManager, classLoader));
48      }
49  
50      private static class InterceptorsImpl implements AbstractConnectionManager.Interceptors {
51  
52          private final ConnectionInterceptor stack;
53          private final ConnectionInterceptor recoveryStack;
54          private final PoolingSupport poolingSupport;
55  
56          /**
57           * Order of constructed interceptors:
58           * <p/>
59           * ConnectionTrackingInterceptor (connectionTracker != null)
60           * TCCLInterceptor
61           * ConnectionHandleInterceptor
62           * TransactionCachingInterceptor (useTransactions & useTransactionCaching)
63           * TransactionEnlistingInterceptor (useTransactions)
64           * SubjectInterceptor (realmBridge != null)
65           * SinglePoolConnectionInterceptor or MultiPoolConnectionInterceptor
66           * LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor (useTransactions (&localTransactions))
67           * MCFConnectionInterceptor
68           */
69          public InterceptorsImpl(TransactionSupport transactionSupport,
70                                  PoolingSupport pooling,
71                                  boolean containerManagedSecurity,
72                                  String objectName,
73                                  ConnectionTracker connectionTracker,
74                                  TransactionManager transactionManager,
75                                  ClassLoader classLoader) {
76              //check for consistency between attributes
77              if (!containerManagedSecurity && pooling instanceof PartitionedPool && ((PartitionedPool) pooling).isPartitionBySubject()) {
78                  throw new IllegalStateException("To use Subject in pooling, you need a SecurityDomain");
79              }
80  
81              //Set up the interceptor stack
82              MCFConnectionInterceptor tail = new MCFConnectionInterceptor();
83              ConnectionInterceptor stack = tail;
84  
85              stack = transactionSupport.addXAResourceInsertionInterceptor(stack, objectName);
86              stack = pooling.addPoolingInterceptors(stack);
87              this.poolingSupport = pooling;
88              stack = transactionSupport.addTransactionInterceptors(stack, transactionManager);
89  
90              if (containerManagedSecurity) {
91                  stack = new SubjectInterceptor(stack);
92              }
93  
94              ConnectionInterceptor recoveryStack = stack;
95              this.recoveryStack = new TCCLInterceptor(recoveryStack, classLoader);
96  
97  
98              stack = new ConnectionHandleInterceptor(stack);
99              stack = new TCCLInterceptor(stack, classLoader);
100             if (connectionTracker != null) {
101                 stack = new ConnectionTrackingInterceptor(stack,
102                         objectName,
103                         connectionTracker);
104             }
105             tail.setStack(stack);
106             this.stack = stack;
107         }
108 
109         public ConnectionInterceptor getStack() {
110             return stack;
111         }
112 
113         public ConnectionInterceptor getRecoveryStack() {
114             return recoveryStack;
115         }
116 
117         public PoolingSupport getPoolingAttributes() {
118             return poolingSupport;
119         }
120     }
121 
122 }