2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2019 IBM
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.client.impl.core;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
31 /** Abstract request response handler class, responsible for common functionality of
32 * @{@link AsyncRequestResponseHandler} and @{@link SyncRequestResponseHandler}
34 abstract class AbstractRequestResponseHandler implements RequestResponseHandler {
36 private final EELFLogger LOG = EELFManager.getInstance().getLogger(AbstractRequestResponseHandler.class);
37 ICoreResponseHandler businessCallback;
38 protected String corrID;
39 CoreManager coreManager;
42 AbstractRequestResponseHandler(String corrID,
43 ICoreResponseHandler businessCallback,
44 CoreManager coreManager)
46 this.businessCallback = businessCallback;
48 this.coreManager = coreManager;
51 public synchronized void handleResponse(final MessageContext ctx, final String response) {
53 coreManager.submitTask(ctx.getCorrelationID(), new Runnable() {
56 LOG.info("handling response of corrID <" + corrID + ">" + "response " + response);
57 if(coreManager.isExistHandler(corrID)) {
58 runTask(response, ctx.getType());
63 } catch (InterruptedException e) {
64 Thread.currentThread().interrupt();
65 LOG.error("could not handle response <" + response + "> of corrID <" + corrID + ">", e);
71 * @param response - Response
72 * @param type - Type of Response
74 abstract void runTask(String response, String type);
77 public void sendRequest(String request, String corrId, String rpcName) throws CoreException {
78 if(!coreManager.isShutdownInProgress()) {
79 coreManager.registerHandler(corrId, this);
80 coreManager.sendRequest(request, corrId, rpcName);
81 coreManager.startTimer(corrId);
83 throw new CoreException("Shutdown is in progress. Request will not be handled");