001/*
002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 */
017package org.nuxeo.runtime.jtajca;
018
019import javax.resource.ResourceException;
020import javax.resource.spi.ConnectionEventListener;
021
022import org.apache.geronimo.connector.outbound.ConnectionInfo;
023import org.apache.geronimo.connector.outbound.ConnectionInterceptor;
024import org.apache.geronimo.connector.outbound.ConnectionReturnAction;
025import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
026
027/**
028 *
029 *
030 * @since 8.4
031 */
032public class NuxeoPool extends SinglePool {
033
034    ConnectionEventListener listener;
035
036    public NuxeoPool(NuxeoConnectionManagerConfiguration config) {
037        super(config.getMaxPoolSize(), config.getMinPoolSize(), config.getBlockingTimeoutMillis(),
038                config.getIdleTimeoutMinutes(), config.getMatchOne(), config.getMatchAll(),
039                config.getSelectOneNoMatch());
040    }
041
042    private static final long serialVersionUID = 1L;
043
044    void addInterceptor(ConnectionInterceptor interceptor) {
045
046    }
047
048    @Override
049    public ConnectionInterceptor addPoolingInterceptors(ConnectionInterceptor tail) {
050        ConnectionInterceptor stack = super.addPoolingInterceptors(tail);
051        //
052        return new ConnectionInterceptor() {
053
054            @Override
055            public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
056                stack.returnConnection(connectionInfo, connectionReturnAction);
057            }
058
059            @Override
060            public void info(StringBuilder s) {
061                stack.info(s);
062            }
063
064            @Override
065            public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
066                stack.getConnection(connectionInfo);
067                // needed for killing connections
068                connectionInfo.getManagedConnectionInfo().setPoolInterceptor(this);
069            }
070
071            @Override
072            public void destroy() {
073                stack.destroy();
074            }
075        };
076    }
077
078}