Java Code Examples for java.util.Map.wait()

The following are Jave code examples for showing how to use wait() of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BaseClient   File: HttpPipeline.java   View Source Code Vote up 4 votes
public static HttpResponse executeRequest(HttpRequest p_executeRequest_0_) throws IOException
{
    final Map<String, Object> map = new HashMap();
    String s = "Response";
    String s1 = "Exception";
    HttpListener httplistener = new HttpListener()
    {
        public void finished(HttpRequest p_finished_1_, HttpResponse p_finished_2_)
        {
            synchronized (map)
            {
                map.put("Response", p_finished_2_);
                map.notifyAll();
            }
        }
        public void failed(HttpRequest p_failed_1_, Exception p_failed_2_)
        {
            synchronized (map)
            {
                map.put("Exception", p_failed_2_);
                map.notifyAll();
            }
        }
    };

    synchronized (map)
    {
        HttpPipelineRequest httppipelinerequest = new HttpPipelineRequest(p_executeRequest_0_, httplistener);
        addRequest(httppipelinerequest);

        try
        {
            map.wait();
        }
        catch (InterruptedException var10)
        {
            throw new InterruptedIOException("Interrupted");
        }

        Exception exception = (Exception)map.get("Exception");

        if (exception != null)
        {
            if (exception instanceof IOException)
            {
                throw(IOException)exception;
            }
            else if (exception instanceof RuntimeException)
            {
                throw(RuntimeException)exception;
            }
            else
            {
                throw new RuntimeException(exception.getMessage(), exception);
            }
        }
        else
        {
            HttpResponse httpresponse = (HttpResponse)map.get("Response");

            if (httpresponse == null)
            {
                throw new IOException("Response is null");
            }
            else
            {
                return httpresponse;
            }
        }
    }
}
 
Example 2
Project: Backmemed   File: HttpPipeline.java   View Source Code Vote up 4 votes
public static HttpResponse executeRequest(HttpRequest p_executeRequest_0_) throws IOException
{
    final Map<String, Object> map = new HashMap();
    String s = "Response";
    String s1 = "Exception";
    HttpListener httplistener = new HttpListener()
    {
        public void finished(HttpRequest p_finished_1_, HttpResponse p_finished_2_)
        {
            synchronized (map)
            {
                map.put("Response", p_finished_2_);
                map.notifyAll();
            }
        }
        public void failed(HttpRequest p_failed_1_, Exception p_failed_2_)
        {
            synchronized (map)
            {
                map.put("Exception", p_failed_2_);
                map.notifyAll();
            }
        }
    };

    synchronized (map)
    {
        HttpPipelineRequest httppipelinerequest = new HttpPipelineRequest(p_executeRequest_0_, httplistener);
        addRequest(httppipelinerequest);

        try
        {
            map.wait();
        }
        catch (InterruptedException var10)
        {
            throw new InterruptedIOException("Interrupted");
        }

        Exception exception = (Exception)map.get("Exception");

        if (exception != null)
        {
            if (exception instanceof IOException)
            {
                throw(IOException)exception;
            }
            else if (exception instanceof RuntimeException)
            {
                throw(RuntimeException)exception;
            }
            else
            {
                throw new RuntimeException(exception.getMessage(), exception);
            }
        }
        else
        {
            HttpResponse httpresponse = (HttpResponse)map.get("Response");

            if (httpresponse == null)
            {
                throw new IOException("Response is null");
            }
            else
            {
                return httpresponse;
            }
        }
    }
}