summaryrefslogtreecommitdiff
path: root/swift/test/Ice/location/Server.swift
blob: 4bb468638dbea07dec448747c3d558f8b936b6e6 (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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Dispatch
import Ice
import TestCommon

class Server: TestHelperI {
    public override func run(args: [String]) throws {
        //
        // Register the server manager. The server manager creates a new
        // 'server'(a server isn't a different process, it's just a new
        // communicator and object adapter).
        //
        let properties = try createTestProperties(args)
        properties.setProperty(key: "Ice.ThreadPool.Server.Size", value: "2")
        var initData = Ice.InitializationData()
        initData.properties = properties

        let communicator = try initialize(initData)
        defer {
            communicator.destroy()
        }

        communicator.getProperties().setProperty(key: "ServerManagerAdapter.Endpoints", value: getTestEndpoint(num: 0))
        let adapter = try communicator.createObjectAdapter("ServerManagerAdapter")

        //
        // We also register a sample server locator which implements the
        // locator interface, this locator is used by the clients and the
        // 'servers' created with the server manager interface.
        //
        let registry = ServerLocatorRegistry()
        let object = ServerManagerI(registry: registry, helper: self)
        try adapter.add(servant: ServerManagerDisp(object), id: Ice.stringToIdentity("ServerManager"))
        try registry.addObject(adapter.createProxy(Ice.stringToIdentity("ServerManager")))
        let registryPrx = try uncheckedCast(prx: adapter.add(servant: TestLocatorRegistryDisp(registry),
                                                             id: Ice.stringToIdentity("registry")),
                                            type: Ice.LocatorRegistryPrx.self)

        let locator = ServerLocator(registry: registry, registryPrx: registryPrx)
        try adapter.add(servant: TestLocatorDisp(locator), id: Ice.stringToIdentity("locator"))

        try adapter.activate()
        serverReady()
        communicator.waitForShutdown()
    }
}