2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdnc.sli.resource.dblib.factory;
24 import java.sql.SQLException;
26 import java.util.concurrent.Callable;
28 import org.openecomp.sdnc.sli.resource.dblib.CachedDataSource;
29 import org.openecomp.sdnc.sli.resource.dblib.CachedDataSourceFactory;
30 import org.openecomp.sdnc.sli.resource.dblib.DBConfigException;
31 import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager;
32 import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
33 import org.openecomp.sdnc.sli.resource.dblib.config.DbConfigPool;
34 import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * @version $Revision: 1.6 $
41 * Author Date Comments
42 * ============== ======== ====================================================
45 public abstract class AbstractResourceManagerFactory {
46 private static Logger LOGGER = LoggerFactory.getLogger(AbstractResourceManagerFactory.class);
48 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) throws Exception;
49 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager dbResourceManager, String sourceName) throws SQLException ;
52 public static AbstractResourceManagerFactory createIntstance() throws FactoryNotDefinedException {
53 throw new FactoryNotDefinedException("Factory method 'createIntstance' needs to be overriden in DBResourceManagerFactory");
56 public class DBInitTask implements Callable<CachedDataSource>
58 private BaseDBConfiguration config = null;
59 private Set<DBInitTask> activeTasks;
61 public DBInitTask(JDBCConfiguration jdbcconfig, Set<DBInitTask> tasks) {
62 this.config = jdbcconfig;
63 this.activeTasks = tasks;
66 public CachedDataSource call() throws Exception {
67 CachedDataSource ds = null;
69 ds = CachedDataSourceFactory.createDataSource(config);
72 synchronized(activeTasks) {
73 activeTasks.remove(this);
74 if (activeTasks.isEmpty()) {
75 final Runnable closure = new Runnable() {
80 } catch (Exception e) {
82 synchronized(activeTasks) {
83 activeTasks.notifyAll();
87 if (LOGGER.isDebugEnabled()) {
88 LOGGER.debug("Completed CachedDataSource.Call and notifyAll from " + ds.getDbConnectionName());
90 Thread worker = new Thread(closure);
91 worker.setDaemon(true);
94 if (LOGGER.isDebugEnabled()) {
96 LOGGER.debug("Completed CachedDataSource.Call from " + ds.getDbConnectionName());