summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/session/ReapThread.h
blob: 7667e8b16dd9eb4c310540ae75d5c898e97bc708 (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
// **********************************************************************
//
// Copyright (c) 2003-2005 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 REAP_THREAD_H
#define REAP_THREAD_H

#include <IceUtil/Thread.h>
#include <IceUtil/StaticMutex.h>
#include <SessionI.h>

class ReapThread;
typedef IceUtil::Handle<ReapThread> ReapThreadPtr;
class ReapThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
{
public:

    static ReapThreadPtr& instance();

    virtual ~ReapThread();

    virtual void run();

    // XXX Rename to destroy().
    //
    // I named it terminate because destroy() methods in Java result
    // in a deprecation warning. If you want to use destroy() in Java
    // then I would have to use a runnable which means the demo isn't
    // the same code. Given the difference is a method name, I didn't
    // think it was worth the cost of different code.
    //
    void terminate();

    // XXX: The alternative here is to make timestamp() a slice
    // method. However, this means that we're adding methods to the
    // slice interface which is only required for the reaping thread,
    // and it obviously couldn't return an IceUtil::Time but instead
    // some other representation...
    //
    void add(const ::Demo::SessionPrx&, const SessionIPtr&);

private:

    ReapThread();

    const IceUtil::Time _timeout;
    bool _terminated;
    std::map< ::Demo::SessionPrx, SessionIPtr> _sessions;

    static ReapThreadPtr _instance;
    static IceUtil::StaticMutex _instanceMutex;
};

#endif