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.impl.core;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 /** Abstract request response handler class, responsible for common functionality of
30 * @{@link AsyncRequestResponseHandler} and @{@link SyncRequestResponseHandler}
32 abstract class AbstractRequestResponseHandler implements RequestResponseHandler {
34 private final EELFLogger LOG = EELFManager.getInstance().getLogger(AbstractRequestResponseHandler.class);
35 ICoreResponseHandler businessCallback;
36 protected String corrID;
37 CoreManager coreManager;
40 AbstractRequestResponseHandler(String corrID,
41 ICoreResponseHandler businessCallback,
42 CoreManager coreManager)
44 this.businessCallback = businessCallback;
46 this.coreManager = coreManager;
49 public synchronized void handleResponse(final MessageContext ctx, final String response) {
51 coreManager.submitTask(ctx.getCorrelationID(), new Runnable() {
54 LOG.info("handling response of corrID <" + corrID + ">" + "response " + response);
55 if(coreManager.isExistHandler(corrID)) {
56 runTask(response, ctx.getType());
61 } catch (InterruptedException e) {
62 LOG.error("could not handle response <" + response + "> of corrID <" + corrID + ">", e);
68 * @param response - Response
69 * @param type - Type of Response
71 abstract void runTask(String response, String type);
74 public void sendRequest(String request, String corrId, String rpcName) throws CoreException {
75 if(!coreManager.isShutdownInProgress()) {
76 coreManager.registerHandler(corrId, this);
77 coreManager.sendRequest(request, corrId, rpcName);
78 coreManager.startTimer(corrId);
80 throw new CoreException("Shutdown is in progress. Request will not be handled");