summaryrefslogtreecommitdiff
path: root/java/test/Freeze/evictor/Server.java
blob: c77e273af784a1b4e9cac3d9f9affa50e9b4da15 (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
103
104
// **********************************************************************
//
// Copyright (c) 2003-2010 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.
//
// **********************************************************************

package test.Freeze.evictor;
import test.Freeze.evictor.Test.*;

public class Server extends test.Util.Application
{
    static class AccountFactory implements Ice.ObjectFactory
    {
        public Ice.Object
        create(String type)
        {
            assert(type.equals("::Test::Account"));
            return new AccountI();
        }

        public void
        destroy()
        {
        }
    }

    static class ServantFactory implements Ice.ObjectFactory
    {
        public Ice.Object
        create(String type)
        {
            assert(type.equals("::Test::Servant"));
            _ServantTie tie = new _ServantTie();
            tie.ice_delegate(new ServantI(tie));
            return tie;
        }

        public void
        destroy()
        {
        }
    }

    static class FacetFactory implements Ice.ObjectFactory
    {
        public Ice.Object
        create(String type)
        {
            assert(type.equals("::Test::Facet"));
            _FacetTie tie = new _FacetTie();
            tie.ice_delegate(new FacetI(tie));
            return tie;
        }

        public void
        destroy()
        {
        }
    }

    public int
    run(String[] args)
    {
        Ice.Communicator communicator = communicator();

        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Evictor");

        communicator.addObjectFactory(new AccountFactory(), "::Test::Account");
        communicator.addObjectFactory(new ServantFactory(), "::Test::Servant");
        communicator.addObjectFactory(new FacetFactory(), "::Test::Facet");

        RemoteEvictorFactoryI factory = new RemoteEvictorFactoryI("db");
        adapter.add(factory, communicator.stringToIdentity("factory"));

        adapter.activate();

        communicator.waitForShutdown();

        return 0;
    }

    protected Ice.InitializationData
    getInitData(Ice.StringSeqHolder argsH)
    {
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties(argsH);
        initData.properties.setProperty("Evictor.Endpoints", "default -p 12010");
        initData.properties.setProperty("Ice.Package.Test", "test.Freeze.evictor");
        return initData;
    }

    public static void
    main(String[] args)
    {
        Server c = new Server();
        int status = c.main("Server", args);

        System.gc();
        System.exit(status);
    }
}