summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/GetConnectionOutgoingAsync.java
blob: 95878b90709a4b10ecca8613b2ac6933726396cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

package IceInternal;

public class GetConnectionOutgoingAsync extends IceInternal.OutgoingAsync
{
    public GetConnectionOutgoingAsync(Ice.ObjectPrxHelperBase prx, String operation, CallbackBase callback)
    {
        super(prx, operation, callback);
        _observer = ObserverHelper.get(prx, operation);
    }

    public void __invoke()
    {
        while(true)
        {
            try
            {
                _handler = _proxy.__getRequestHandler();
                _handler.sendAsyncRequest(this);
            }
            catch(RetryException ex)
            {
                _proxy.__setRequestHandler(_handler, null);
            }
            catch(Ice.Exception ex)
            {
                handleException(ex);
            }
            break;
        }
    }

    @Override
    public int send(Ice.ConnectionI conection, boolean compress, boolean response)
        throws RetryException
    {
        sent();
        return 0;
    }

    @Override
    public int invokeCollocated(CollocatedRequestHandler handler)
    {
        sent();
        return 0;
    }

    @Override
    public boolean sent()
    {
        synchronized(_monitor)
        {
            _state |= StateDone;
            _monitor.notifyAll();
        }
        invokeCompleted();
        return false;
    }

    @Override
    public void invokeSent()
    {
        // No sent callback
    }

    @Override
    public void finished(Ice.Exception exc)
    {
        try
        {
            handleException(exc);
        }
        catch(Ice.Exception ex)
        {
            invokeExceptionAsync(ex);
        }
    }

    private void handleException(Ice.Exception exc)
    {
       try
        {
            Ice.Holder<Integer> interval = new Ice.Holder<Integer>();
            _cnt = _proxy.__handleException(exc, _handler, Ice.OperationMode.Idempotent, false, interval, _cnt);
            if(_observer != null)
            {
                _observer.retried(); // Invocation is being retried
            }
            _instance.retryQueue().add(this, interval.value);
        }
        catch(Ice.Exception ex)
        {
            if(_observer != null)
            {
                _observer.failed(ex.ice_name());
            }
            throw ex;
        }
    }
}