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 java.util.ArrayList;
020import java.util.List;
021import javax.resource.ResourceException;
022
023import org.apache.geronimo.connector.outbound.ConnectionInfo;
024import org.apache.geronimo.connector.outbound.ConnectionReturnAction;
025import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
026import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
027
028public class NuxeoConnectionTrackingCoordinator implements ConnectionTracker {
029
030    private final List<ConnectionTracker> trackers = new ArrayList<>();
031
032    public void addTracker(ConnectionTracker tracker) {
033        trackers.add(tracker);
034    }
035
036    public void removeTracker(ConnectionTracker tracker) {
037        trackers.remove(tracker);
038    }
039
040    @Override
041    public void handleObtained(ConnectionTrackingInterceptor connectionTrackingInterceptor,
042            ConnectionInfo connectionInfo, boolean reassociate) throws ResourceException {
043        for (ConnectionTracker tracker : trackers) {
044            tracker.handleObtained(connectionTrackingInterceptor, connectionInfo, reassociate);
045        }
046    }
047
048    @Override
049    public void handleReleased(ConnectionTrackingInterceptor connectionTrackingInterceptor,
050            ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
051        for (ConnectionTracker tracker : trackers) {
052            tracker.handleReleased(connectionTrackingInterceptor, connectionInfo, connectionReturnAction);
053        }
054    }
055
056    @Override
057    public void setEnvironment(ConnectionInfo connectionInfo, String key) {
058        for (ConnectionTracker tracker : trackers) {
059            tracker.setEnvironment(connectionInfo, key);
060        }
061    }
062
063}