2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 ONAP
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.onap.ccsdk.sli.core.dblib.factory;
24 import org.onap.ccsdk.sli.core.dblib.CachedDataSource;
25 import org.onap.ccsdk.sli.core.dblib.CachedDataSourceFactory;
26 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
27 import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
28 import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
29 import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import java.sql.SQLException;
35 import java.util.concurrent.Callable;
38 * @version $Revision: 1.6 $
40 * Author Date Comments
41 * ============== ======== ====================================================
44 public abstract class AbstractResourceManagerFactory {
45 private static Logger LOGGER = LoggerFactory.getLogger(AbstractResourceManagerFactory.class);
47 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) throws Exception;
48 public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager dbResourceManager, String sourceName) throws SQLException ;
51 public static AbstractResourceManagerFactory createIntstance() throws FactoryNotDefinedException {
52 throw new FactoryNotDefinedException("Factory method 'createIntstance' needs to be overriden in DBResourceManagerFactory");
55 public class DBInitTask implements Callable<CachedDataSource>
57 private BaseDBConfiguration config = null;
58 private Set<DBInitTask> activeTasks;
60 public DBInitTask(JDBCConfiguration jdbcconfig, Set<DBInitTask> tasks) {
61 this.config = jdbcconfig;
62 this.activeTasks = tasks;
65 public CachedDataSource call() throws Exception {
66 CachedDataSource ds = null;
68 ds = CachedDataSourceFactory.createDataSource(config);
71 synchronized(activeTasks) {
72 activeTasks.remove(this);
73 if (activeTasks.isEmpty()) {
74 final Runnable closure = new Runnable() {
79 } catch (Exception e) {
81 synchronized(activeTasks) {
82 activeTasks.notifyAll();
86 if (LOGGER.isDebugEnabled()) {
87 LOGGER.debug("Completed CachedDataSource.Call and notifyAll from " + (ds != null ? ds
88 .getDbConnectionName() : null));
90 Thread worker = new Thread(closure);
91 worker.setDaemon(true);
94 if (LOGGER.isDebugEnabled()) {
96 LOGGER.debug("Completed CachedDataSource.Call from " + ds.getDbConnectionName());