summaryrefslogtreecommitdiff
path: root/csharp/src/Ice/DispatchInterceptor.cs
blob: 52685fa6c86034fe81e7d9c95370eb20b5e709e4 (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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

namespace Ice
{
    /// <summary>
    /// Base class that allows a server intercept incoming requests.
    /// The application must derive a concrete class from DispatchInterceptor
    /// that implements the DispatchInterceptor.dispatch operation. An instance of this derived
    /// class can be registered with an object adapter like any other servant.
    /// A dispatch interceptor is useful particularly to automatically retry requests
    /// that have failed due to a recoverable error condition.
    /// </summary>
    public abstract class DispatchInterceptor : ObjectImpl
    {
        /// <summary>
        /// Called by the Ice run time to dispatch an incoming request. The implementation
        /// of <code>dispatch</code> must dispatch the request to the actual servant.
        /// </summary>
        /// <param name="request">The details of the incoming request.</param>
        /// <returns>The task if dispatched asynchronously, null otherwise.</returns>
        public abstract System.Threading.Tasks.Task<OutputStream>
        dispatch(Request request);

        public override System.Threading.Tasks.Task<OutputStream>
        iceDispatch(IceInternal.Incoming inc, Current current)
        {
            try
            {
                return dispatch(inc);
            }
            catch(Exception)
            {
                //
                // If the input parameters weren't read, make sure we skip them here. It's needed to read the
                // encoding version used by the client to eventually marshal the user exception. It's also needed
                // if we dispatch a batch oneway request to read the next batch request.
                //
#pragma warning disable CS8073 // The result of the expression is always 'false'
                if (current.encoding == null || (current.encoding.major == 0 && current.encoding.minor == 0))
#pragma warning restore CS8073 // The result of the expression is always 'false'
                {
                    inc.skipReadParams();
                }
                throw;
            }
        }
    }
}