summaryrefslogtreecommitdiff
path: root/swift/test/Ice/timeout/TestI.swift
blob: bd98e8296eec15e09ea28259fb58e8064ecd15db (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
//
import Foundation
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Ice

class TimeoutI: Timeout {
    func op(current _: Current) throws {}

    func sendData(seq _: ByteSeq, current _: Current) throws {}

    func sleep(to: Int32, current _: Current) throws {
        Thread.sleep(forTimeInterval: TimeInterval(to) / 1000)
    }
}

class ControllerI: Controller {
    var _adapter: Ice.ObjectAdapter

    init(_ adapter: Ice.ObjectAdapter) {
        _adapter = adapter
    }

    func holdAdapter(to: Int32, current: Ice.Current) throws {
        _adapter.hold()
        if to >= 0 {
            let queue = try current.adapter!.getDispatchQueue()
            queue.async {
                self._adapter.waitForHold()
                queue.asyncAfter(deadline: .now() + .milliseconds(Int(to))) {
                    do {
                        try self._adapter.activate()
                    } catch {
                        precondition(false)
                    }
                }
            }
        }
    }

    func resumeAdapter(current _: Ice.Current) throws {
        try _adapter.activate()
    }

    func shutdown(current: Ice.Current) {
        current.adapter!.getCommunicator().shutdown()
    }
}