2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.client.lcm.impl.business;
27 import java.util.HashMap;
29 import org.onap.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory;
30 import org.onap.appc.client.lcm.api.ApplicationContext;
31 import org.onap.appc.client.lcm.api.LifeCycleManagerStateful;
32 import org.onap.appc.client.lcm.exceptions.AppcClientException;
34 import java.lang.reflect.Proxy;
35 import java.util.Properties;
37 public class AppcLifeCycleManagerServiceFactoryImpl implements AppcLifeCycleManagerServiceFactory {
39 class AppcLifeCycleManagerServiceFactoryImplData {
41 private LifeCycleManagerStateful _lifeCycleManagerStateful;
42 private LCMRequestProcessor _lcmRequestProcessor;
44 AppcLifeCycleManagerServiceFactoryImplData(LifeCycleManagerStateful lifeCycleManagerStateful,
45 LCMRequestProcessor lcmRequestProcessor) {
47 _lifeCycleManagerStateful = lifeCycleManagerStateful;
48 _lcmRequestProcessor = lcmRequestProcessor;
51 LifeCycleManagerStateful getLifeCycleManagerStateful() {
52 return _lifeCycleManagerStateful;
55 LCMRequestProcessor getLCMRequestProcessor() {
56 return _lcmRequestProcessor;
60 private HashMap<String, AppcLifeCycleManagerServiceFactoryImplData> lcmMap = new HashMap<String, AppcLifeCycleManagerServiceFactoryImplData>();
63 public synchronized LifeCycleManagerStateful createLifeCycleManagerStateful(ApplicationContext context,
64 Properties properties) throws AppcClientException {
65 String cType = properties.getProperty("controllerType");
66 if (cType == null || cType.length() == 0)
69 properties.put("controllerType", cType);
72 AppcLifeCycleManagerServiceFactoryImplData lcmData = lcmMap.get(cType);
73 LifeCycleManagerStateful lifeCycleManagerStateful = null;
74 LCMRequestProcessor lcmRequestProcessor = null;
76 if (lcmData != null) {
77 lifeCycleManagerStateful = lcmData.getLifeCycleManagerStateful();
78 lcmRequestProcessor = lcmData.getLCMRequestProcessor();
81 if (lifeCycleManagerStateful == null) {
82 lcmRequestProcessor = new LCMRequestProcessor(context, properties);
83 lifeCycleManagerStateful = (LifeCycleManagerStateful) Proxy.newProxyInstance(
84 LifeCycleManagerStateful.class.getClassLoader(), new Class<?>[] { LifeCycleManagerStateful.class },
85 new RPCInvocator(lcmRequestProcessor));
87 new AppcLifeCycleManagerServiceFactoryImplData(lifeCycleManagerStateful, lcmRequestProcessor));
89 throw new IllegalStateException("already instansiated LifeCycleManagerStateful instance");
91 return lifeCycleManagerStateful;
94 public LifeCycleManagerStateful createLifeCycleManagerStateful(ApplicationContext context,
95 Properties properties, String controllerType) throws AppcClientException {
96 if (controllerType != null && controllerType.length() != 0)
97 properties.put("controllerType", controllerType.toUpperCase());
98 return createLifeCycleManagerStateful(context, properties);
102 public void shutdownLifeCycleManager(boolean isForceShutdown) {
104 shutdownLifeCycleManager(isForceShutdown, "APPC");
108 public void shutdownLifeCycleManager(boolean isForceShutdown, String controllerType) {
109 if (controllerType == null || controllerType.length() == 0)
110 controllerType = "APPC";
112 controllerType = controllerType.toUpperCase();
114 AppcLifeCycleManagerServiceFactoryImplData lcmData = lcmMap.get(controllerType);
115 LCMRequestProcessor lcmRequestProcessor = null;
117 if (lcmData != null) {
118 lcmRequestProcessor = lcmData.getLCMRequestProcessor();
121 if (lcmRequestProcessor != null) {
122 lcmRequestProcessor.shutdown(isForceShutdown);
124 throw new IllegalStateException(
125 "The life cycle manager library wasn't instantiated properly, therefore the shutdown event will not be handled");