summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/CollocatedRequestHandler.h
blob: 7cba2acd5c108834b4760ae688d61cf3891c4dcd (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
// **********************************************************************
//
// 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.
//
// **********************************************************************

#ifndef ICE_COLLOCATED_REQUEST_HANDLER_H
#define ICE_COLLOCATED_REQUEST_HANDLER_H

#include <IceUtil/Mutex.h>
#include <IceUtil/Monitor.h>

#include <Ice/RequestHandler.h>
#include <Ice/ResponseHandler.h>
#include <Ice/BasicStream.h>
#include <Ice/ObjectAdapterF.h>
#include <Ice/LoggerF.h>
#include <Ice/TraceLevelsF.h>

namespace Ice
{

class ObjectAdapterI;
typedef IceUtil::Handle<ObjectAdapterI> ObjectAdapterIPtr;

}

namespace IceInternal
{

class Outgoing;
class BatchOutgoing;
class OutgoingAsync;
class BatchOutgoingAsync;

class CollocatedRequestHandler : public RequestHandler, public ResponseHandler, private IceUtil::Monitor<IceUtil::Mutex>
{
public:

    CollocatedRequestHandler(const ReferencePtr&, const Ice::ObjectAdapterPtr&);

    virtual ~CollocatedRequestHandler();

    virtual void prepareBatchRequest(BasicStream*);
    virtual void finishBatchRequest(BasicStream*);
    virtual void abortBatchRequest();

    virtual bool sendRequest(OutgoingMessageCallback*);
    virtual AsyncStatus sendAsyncRequest(const OutgoingAsyncMessageCallbackPtr&);

    virtual void requestTimedOut(OutgoingMessageCallback*);
    virtual void asyncRequestTimedOut(const OutgoingAsyncMessageCallbackPtr&);

    virtual void sendResponse(Ice::Int, BasicStream*, Ice::Byte);
    virtual void sendNoResponse();
    virtual void invokeException(Ice::Int, const Ice::LocalException&, int);

    const ReferencePtr& getReference() const { return _reference; } // Inlined for performances.

    virtual Ice::ConnectionIPtr getConnection(bool);
    
    void invokeRequest(Outgoing*);
    AsyncStatus invokeAsyncRequest(OutgoingAsync*);
    void invokeBatchRequests(BatchOutgoing*);
    AsyncStatus invokeAsyncBatchRequests(BatchOutgoingAsync*);

    bool sent(OutgoingMessageCallback*);
    bool sentAsync(OutgoingAsyncMessageCallback*);

    void invokeAll(BasicStream*, Ice::Int, Ice::Int, bool);

private:

    void handleException(Ice::Int, const Ice::Exception&);
    
    const Ice::ObjectAdapterIPtr _adapter;
    const bool _dispatcher;
    const Ice::LoggerPtr _logger;
    const TraceLevelsPtr _traceLevels;
    const bool _batchAutoFlush;

    int _requestId;

    std::map<OutgoingMessageCallback*, Ice::Int> _sendRequests;
    std::map<OutgoingAsyncMessageCallbackPtr, Ice::Int> _sendAsyncRequests;

    std::map<Ice::Int, Outgoing*> _requests;
    std::map<Ice::Int, OutgoingAsyncPtr> _asyncRequests;

    bool _batchStreamInUse;
    int _batchRequestNum;
    BasicStream _batchStream;
    size_t _batchMarker;
};
typedef IceUtil::Handle<CollocatedRequestHandler> CollocatedRequestHandlerPtr;

}

#endif