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