Second part of onap rename
[appc.git] / appc-client / client-lib / src / main / java / org / openecomp / appc / client / impl / core / AsyncRequestResponseHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.client.impl.core;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29
30 import java.util.concurrent.TimeoutException;
31
32 /** Handles async responses
33  */
34 class AsyncRequestResponseHandler extends AbstractRequestResponseHandler {
35
36     private final EELFLogger LOG = EELFManager.getInstance().getLogger(AsyncRequestResponseHandler.class);
37
38     AsyncRequestResponseHandler(String corrID,
39                                 ICoreResponseHandler businessCallback,
40                                 CoreManager coreManager)
41     {
42         super(corrID, businessCallback, coreManager);
43     }
44
45     /**
46      *  Calls API callback for sending response to consumer's listener. in case of complete response cleans timer and
47      *  unregisters the handler.
48      * @param response - Response
49      * @param type - Type of Response
50      */
51     public void runTask(String response, String type) {
52         boolean finalTask = false;
53         try {
54             finalTask = ((ICoreAsyncResponseHandler) businessCallback).onResponse(response, type);
55         } catch (Exception e){
56             LOG.error("Error on API layer, for request with correlation-id " + corrID,  e);
57         }
58         if (finalTask){
59             coreManager.cancelTimer(corrID);
60             coreManager.unregisterHandler(corrID);
61         }
62         else{
63             response = null;
64             type = null;
65         }
66     }
67
68     /**
69      * Calls to API layer for sending timeout exception.
70      */
71     @Override
72     public void onTimeOut() {
73         LOG.info("timeout for request with correlation-id " + corrID);
74         ((ICoreAsyncResponseHandler)businessCallback).onException(new TimeoutException("timeout for request with correlation-id " + corrID));
75     }
76 }