KickJava   Java API By Example, From Geeks To Geeks.

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


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.resource.ResourceException JavaDoc;
21 import javax.resource.spi.ConnectionManager JavaDoc;
22 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
23 import javax.resource.spi.LazyAssociatableConnectionManager JavaDoc;
24 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
25
26 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
27 import org.apache.geronimo.transaction.manager.NamedXAResource;
28
29 /**
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public abstract class AbstractConnectionManager implements ConnectionManagerContainer, ConnectionManager JavaDoc, LazyAssociatableConnectionManager JavaDoc, PoolingAttributes {
33     protected final Interceptors interceptors;
34
35     //default constructor for use as endpoint
36
public AbstractConnectionManager() {
37         interceptors = null;
38     }
39
40     public AbstractConnectionManager(Interceptors interceptors) {
41         this.interceptors = interceptors;
42     }
43
44     public Object JavaDoc createConnectionFactory(ManagedConnectionFactory JavaDoc mcf) throws ResourceException JavaDoc {
45         return mcf.createConnectionFactory(this);
46     }
47
48     public ConnectionManager JavaDoc getConnectionManager() {
49         return this;
50     }
51     
52     /**
53      * in: mcf != null, is a deployed mcf
54      * out: useable connection object.
55      */

56     public Object JavaDoc allocateConnection(ManagedConnectionFactory JavaDoc managedConnectionFactory,
57                                      ConnectionRequestInfo JavaDoc connectionRequestInfo)
58             throws ResourceException JavaDoc {
59         ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo);
60         ConnectionInfo ci = new ConnectionInfo(mci);
61         getStack().getConnection(ci);
62         return ci.getConnectionHandle();
63     }
64
65     /**
66      * in: non-null connection object, from non-null mcf.
67      * connection object is not associated with a managed connection
68      * out: supplied connection object is assiciated with a non-null ManagedConnection from mcf.
69      */

70     public void associateConnection(Object JavaDoc connection,
71                                     ManagedConnectionFactory JavaDoc managedConnectionFactory,
72                                     ConnectionRequestInfo JavaDoc connectionRequestInfo)
73             throws ResourceException JavaDoc {
74         ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo);
75         ConnectionInfo ci = new ConnectionInfo(mci);
76         ci.setConnectionHandle(connection);
77         getStack().getConnection(ci);
78     }
79
80     ConnectionInterceptor getConnectionInterceptor() {
81         return getStack();
82     }
83
84
85     public ConnectionManagerContainer.ReturnableXAResource getRecoveryXAResource(ManagedConnectionFactory JavaDoc managedConnectionFactory) throws ResourceException JavaDoc {
86         ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, null);
87         NamedXAResource namedXAResource = (NamedXAResource) mci.getXAResource();
88         if (namedXAResource == null) {
89             //obviously, we can't do recovery.
90
return null;
91         }
92         ConnectionInfo recoveryConnectionInfo = new ConnectionInfo(mci);
93         getRecoveryStack().getConnection(recoveryConnectionInfo);
94         return new ConnectionManagerContainer.ReturnableXAResource(namedXAResource, getRecoveryStack(), recoveryConnectionInfo);
95     }
96
97     //statistics
98

99     public int getPartitionCount() {
100         return getPooling().getPartitionCount();
101     }
102
103     public int getPartitionMaxSize() {
104         return getPooling().getPartitionMaxSize();
105     }
106
107     public void setPartitionMaxSize(int maxSize) throws InterruptedException JavaDoc {
108         getPooling().setPartitionMaxSize(maxSize);
109     }
110
111     public int getPartitionMinSize() {
112         return getPooling().getPartitionMinSize();
113     }
114
115     public void setPartitionMinSize(int minSize) {
116         getPooling().setPartitionMinSize(minSize);
117     }
118
119     public int getIdleConnectionCount() {
120         return getPooling().getIdleConnectionCount();
121     }
122
123     public int getConnectionCount() {
124         return getPooling().getConnectionCount();
125     }
126
127     public int getBlockingTimeoutMilliseconds() {
128         return getPooling().getBlockingTimeoutMilliseconds();
129     }
130
131     public void setBlockingTimeoutMilliseconds(int timeoutMilliseconds) {
132         getPooling().setBlockingTimeoutMilliseconds(timeoutMilliseconds);
133     }
134
135     public int getIdleTimeoutMinutes() {
136         return getPooling().getIdleTimeoutMinutes();
137     }
138
139     public void setIdleTimeoutMinutes(int idleTimeoutMinutes) {
140         getPooling().setIdleTimeoutMinutes(idleTimeoutMinutes);
141     }
142
143     private ConnectionInterceptor getStack() {
144         return interceptors.getStack();
145     }
146
147     private ConnectionInterceptor getRecoveryStack() {
148         return interceptors.getRecoveryStack();
149     }
150
151     //public for persistence of pooling attributes (max, min size, blocking/idle timeouts)
152
public PoolingSupport getPooling() {
153         return interceptors.getPoolingAttributes();
154     }
155
156     public interface Interceptors {
157         ConnectionInterceptor getStack();
158
159         ConnectionInterceptor getRecoveryStack();
160
161         PoolingSupport getPoolingAttributes();
162     }
163
164     public void doStart() throws Exception JavaDoc {
165
166     }
167
168     public void doStop() throws Exception JavaDoc {
169         interceptors.getStack().destroy();
170     }
171
172     public void doFail() {
173         interceptors.getStack().destroy();
174     }
175 }
176
Popular Tags