/*
 *  Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  WSO2 Inc. licenses this file to you under the Apache License,
 *  Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */

package org.wso2.carbon.transport.http.netty.contractimpl;

import org.wso2.carbon.transport.http.netty.contract.HttpConnectorListener;
import org.wso2.carbon.transport.http.netty.contract.HttpResponseFuture;
import org.wso2.carbon.transport.http.netty.message.HTTPCarbonMessage;

import java.util.concurrent.Semaphore;

/**
 * Implementation of the response status future.
 */
public class HttpResponseStatusFuture implements HttpResponseFuture {

    private HTTPCarbonMessage httpCarbonMessage;
    private Throwable throwable, status;
    private Semaphore executionWaitSem;

    @Override
    public void setHttpConnectorListener(HttpConnectorListener connectorListener) {
    }

    @Override
    public void removeHttpListener() {
    }

    @Override
    public void notifyHttpListener(HTTPCarbonMessage httpCarbonMessage) {
        this.httpCarbonMessage = httpCarbonMessage;
        if (executionWaitSem != null) {
            executionWaitSem.release();
        }
    }

    @Override
    public void notifyHttpListener(Throwable throwable) {
        this.throwable = throwable;
        if (executionWaitSem != null) {
            executionWaitSem.release();
        }
    }

    public Throwable sync() throws InterruptedException {
        executionWaitSem = new Semaphore(0);
        if (this.httpCarbonMessage == null && this.throwable == null) {
            executionWaitSem.acquire();
        }
        if (httpCarbonMessage != null) {
            status = null;
            httpCarbonMessage = null;
        }
        if (throwable != null) {
            status = throwable;
            throwable = null;
        }
        return status;
    }
}

@@ -1264,173 +1264,8 @@
 m;%0A%0A
-    @Override%0A    public void setHttpConnectorListener(HttpConnectorListener connectorListener) %7B%0A    %7D%0A%0A    @Override%0A    public void removeHttpListener() %7B%0A    %7D%0A%0A
     
@@ -1344,24 +1344,24 @@
 nMessage) %7B%0A
+
         this
@@ -1713,24 +1713,39 @@
  public 
-Throwabl
+HttpResponseStatusFutur
 e sync()
@@ -2178,23 +2178,251 @@
  return 
-status;
+this;%0A    %7D%0A%0A    public Throwable getStatus() %7B%0A        return status;%0A    %7D%0A%0A    @Override%0A    public void setHttpConnectorListener(HttpConnectorListener connectorListener) %7B%0A    %7D%0A%0A    @Override%0A    public void removeHttpListener() %7B
 %0A    %7D%0A%7D

Refactor HttpResponseStatusFuture sync method