KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > outbound > GenericConnectionManager


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
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 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * GenericConnectionManager sets up a connection manager stack according to the
31  * policies described in the attributes.
32  *
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class GenericConnectionManager extends AbstractConnectionManager {
36     protected static final Log log = LogFactory.getLog(AbstractSinglePoolConnectionInterceptor.class.getName());
37
38     //default constructor for use as endpoint
39
public GenericConnectionManager() {
40         super();
41     }
42
43     public GenericConnectionManager(TransactionSupport transactionSupport,
44                                     PoolingSupport pooling,
45                                     boolean containerManagedSecurity,
46                                     ConnectionTracker connectionTracker,
47                                     TransactionManager JavaDoc transactionManager,
48                                     String JavaDoc objectName,
49                                     ClassLoader JavaDoc classLoader) {
50         super(new InterceptorsImpl(transactionSupport, pooling, containerManagedSecurity, objectName, connectionTracker, transactionManager, classLoader));
51     }
52
53     private static class InterceptorsImpl implements AbstractConnectionManager.Interceptors {
54
55         private final ConnectionInterceptor stack;
56         private final ConnectionInterceptor recoveryStack;
57         private final PoolingSupport poolingSupport;
58
59         /**
60          * Order of constructed interceptors:
61          * <p/>
62          * ConnectionTrackingInterceptor (connectionTracker != null)
63          * TCCLInterceptor
64          * ConnectionHandleInterceptor
65          * TransactionCachingInterceptor (useTransactions & useTransactionCaching)
66          * TransactionEnlistingInterceptor (useTransactions)
67          * SubjectInterceptor (realmBridge != null)
68          * SinglePoolConnectionInterceptor or MultiPoolConnectionInterceptor
69          * LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor (useTransactions (&localTransactions))
70          * MCFConnectionInterceptor
71          */

72         public InterceptorsImpl(TransactionSupport transactionSupport,
73                                 PoolingSupport pooling,
74                                 boolean containerManagedSecurity,
75                                 String JavaDoc objectName,
76                                 ConnectionTracker connectionTracker,
77                                 TransactionManager JavaDoc transactionManager,
78                                 ClassLoader JavaDoc classLoader) {
79             //check for consistency between attributes
80
if (!containerManagedSecurity && pooling instanceof PartitionedPool && ((PartitionedPool) pooling).isPartitionBySubject()) {
81                 throw new IllegalStateException JavaDoc("To use Subject in pooling, you need a SecurityDomain");
82             }
83
84             //Set up the interceptor stack
85
MCFConnectionInterceptor tail = new MCFConnectionInterceptor();
86             ConnectionInterceptor stack = tail;
87
88             stack = transactionSupport.addXAResourceInsertionInterceptor(stack, objectName);
89             stack = pooling.addPoolingInterceptors(stack);
90             if (log.isTraceEnabled()) {
91                 log.trace("Connection Manager " + objectName + " installed pool " + stack);
92             }
93
94             this.poolingSupport = pooling;
95             stack = transactionSupport.addTransactionInterceptors(stack, transactionManager);
96
97             if (containerManagedSecurity) {
98                 stack = new SubjectInterceptor(stack);
99             }
100
101             ConnectionInterceptor recoveryStack = stack;
102             this.recoveryStack = new TCCLInterceptor(recoveryStack, classLoader);
103
104
105             stack = new ConnectionHandleInterceptor(stack);
106             stack = new TCCLInterceptor(stack, classLoader);
107             if (connectionTracker != null) {
108                 stack = new ConnectionTrackingInterceptor(stack,
109                         objectName,
110                         connectionTracker);
111             }
112             tail.setStack(stack);
113             this.stack = stack;
114         }
115
116         public ConnectionInterceptor getStack() {
117             return stack;
118         }
119
120         public ConnectionInterceptor getRecoveryStack() {
121             return recoveryStack;
122         }
123
124         public PoolingSupport getPoolingAttributes() {
125             return poolingSupport;
126         }
127     }
128
129 }
130
Popular Tags