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.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * @version $Revision: 1.6 $
42 * Author Date Comments
43 * ============== ======== ====================================================
46 public abstract class AbstractResourceManagerFactory {
47 private static Logger LOGGER = LoggerFactory.getLogger(AbstractResourceManagerFactory.class);
49 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) throws Exception;
50 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager dbResourceManager, String sourceName) throws SQLException ;
53 public static AbstractResourceManagerFactory createIntstance() throws FactoryNotDefinedException {
54 throw new FactoryNotDefinedException("Factory method 'createIntstance' needs to be overriden in DBResourceManagerFactory");
57 public class DBInitTask implements Callable<CachedDataSource>
59 private BaseDBConfiguration config = null;
60 private Set<DBInitTask> activeTasks;
62 public DBInitTask(JndiConfiguration jndiConfig, Set<DBInitTask> tasks){
63 this.config = jndiConfig;
64 this.activeTasks = tasks;
67 public DBInitTask(JDBCConfiguration jdbcconfig, Set<DBInitTask> tasks) {
68 this.config = jdbcconfig;
69 this.activeTasks = tasks;
72 public CachedDataSource call() throws Exception {
73 CachedDataSource ds = null;
75 ds = CachedDataSourceFactory.createDataSource(config);
78 synchronized(activeTasks){
79 activeTasks.remove(this);
80 if(activeTasks.isEmpty()){
81 final Runnable closure = new Runnable() {
86 } catch (Exception e) {
88 synchronized(activeTasks){
89 activeTasks.notifyAll();
93 if(LOGGER.isDebugEnabled())
94 LOGGER.debug("Completed CachedDataSource.Call and notifyAll from "+ds.getDbConnectionName());
95 Thread worker = new Thread(closure);
96 worker.setDaemon(true);
99 if(LOGGER.isDebugEnabled())
100 LOGGER.debug("Completed CachedDataSource.Call from "+ds.getDbConnectionName());