2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.client.lcm.impl.business;
26 import java.util.HashMap;
28 import org.onap.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory;
29 import org.onap.appc.client.lcm.api.ApplicationContext;
30 import org.onap.appc.client.lcm.api.LifeCycleManagerStateful;
31 import org.onap.appc.client.lcm.exceptions.AppcClientException;
33 import java.lang.reflect.Proxy;
34 import java.util.Properties;
36 public class AppcLifeCycleManagerServiceFactoryImpl implements AppcLifeCycleManagerServiceFactory {
38 class AppcLifeCycleManagerServiceFactoryImplData {
40 private LifeCycleManagerStateful _lifeCycleManagerStateful;
41 private LCMRequestProcessor _lcmRequestProcessor;
43 AppcLifeCycleManagerServiceFactoryImplData(LifeCycleManagerStateful lifeCycleManagerStateful,
44 LCMRequestProcessor lcmRequestProcessor) {
46 _lifeCycleManagerStateful = lifeCycleManagerStateful;
47 _lcmRequestProcessor = lcmRequestProcessor;
50 LifeCycleManagerStateful getLifeCycleManagerStateful() {
51 return _lifeCycleManagerStateful;
54 LCMRequestProcessor getLCMRequestProcessor() {
55 return _lcmRequestProcessor;
59 private HashMap<String, AppcLifeCycleManagerServiceFactoryImplData> lcmMap = new HashMap<String, AppcLifeCycleManagerServiceFactoryImplData>();
62 public synchronized LifeCycleManagerStateful createLifeCycleManagerStateful(ApplicationContext context,
63 Properties properties) throws AppcClientException {
64 String cType = properties.getProperty("controllerType");
65 if (cType == null || cType.length() == 0)
68 properties.put("controllerType", cType);
71 AppcLifeCycleManagerServiceFactoryImplData lcmData = lcmMap.get(cType);
72 LifeCycleManagerStateful lifeCycleManagerStateful = null;
73 LCMRequestProcessor lcmRequestProcessor = null;
75 if (lcmData != null) {
76 lifeCycleManagerStateful = lcmData.getLifeCycleManagerStateful();
77 lcmRequestProcessor = lcmData.getLCMRequestProcessor();
80 if (lifeCycleManagerStateful == null) {
81 lcmRequestProcessor = new LCMRequestProcessor(context, properties);
82 lifeCycleManagerStateful = (LifeCycleManagerStateful) Proxy.newProxyInstance(
83 LifeCycleManagerStateful.class.getClassLoader(), new Class<?>[] { LifeCycleManagerStateful.class },
84 new RPCInvocator(lcmRequestProcessor));
86 new AppcLifeCycleManagerServiceFactoryImplData(lifeCycleManagerStateful, lcmRequestProcessor));
88 throw new IllegalStateException("already instansiated LifeCycleManagerStateful instance");
90 return lifeCycleManagerStateful;
93 public LifeCycleManagerStateful createLifeCycleManagerStateful(ApplicationContext context,
94 Properties properties, String controllerType) throws AppcClientException {
95 if (controllerType != null && controllerType.length() != 0)
96 properties.put("controllerType", controllerType.toUpperCase());
97 return createLifeCycleManagerStateful(context, properties);
101 public void shutdownLifeCycleManager(boolean isForceShutdown) {
103 shutdownLifeCycleManager(isForceShutdown, "APPC");
107 public void shutdownLifeCycleManager(boolean isForceShutdown, String controllerType) {
108 if (controllerType == null || controllerType.length() == 0)
109 controllerType = "APPC";
111 controllerType = controllerType.toUpperCase();
113 AppcLifeCycleManagerServiceFactoryImplData lcmData = lcmMap.get(controllerType);
114 LCMRequestProcessor lcmRequestProcessor = null;
116 if (lcmData != null) {
117 lcmRequestProcessor = lcmData.getLCMRequestProcessor();
120 if (lcmRequestProcessor != null) {
121 lcmRequestProcessor.shutdown(isForceShutdown);
123 throw new IllegalStateException(
124 "The life cycle manager library wasn't instantiated properly, therefore the shutdown event will not be handled");