summaryrefslogtreecommitdiff
path: root/js/src/Ice/RequestHandlerFactory.js
blob: 58c63aa339b936665a58569cde3929d509d8eb15 (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
// **********************************************************************
//
// 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.
//
// **********************************************************************

var Ice = require("../Ice/ModuleRegistry").Ice;
Ice.__M.require(module,
    [
        "../Ice/Class",
        "../Ice/Debug",
        "../Ice/HashMap",
        "../Ice/Reference",
        "../Ice/ConnectRequestHandler"
    ]);

var Debug = Ice.Debug;
var HashMap = Ice.HashMap;
var ConnectRequestHandler = Ice.ConnectRequestHandler;

var RequestHandlerFactory = Ice.Class({
    __init__: function(instance)
    {
        this._instance = instance;
        this._handlers = new HashMap();
        this._handlers.keyComparator = HashMap.compareEquals;
    },
    getRequestHandler: function(ref, proxy)
    {
        if(ref.getCacheConnection())
        {
            var handler = this._handlers.get(ref);
            if(handler)
            {
                return handler;
            }
            handler = new ConnectRequestHandler(ref, proxy);
            this._handlers.set(ref, handler);
            return handler;
        }
        else
        {
            return new ConnectRequestHandler(ref, proxy);
        }
    },
    removeRequestHandler: function(ref, handler)
    {
        if(ref.getCacheConnection())
        {
            var h = this._handlers.delete(ref);
            Debug.assert(h === handler);
        }
    }
});

Ice.RequestHandlerFactory = RequestHandlerFactory;
module.exports.Ice = Ice;