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
|
// **********************************************************************
//
// Copyright (c) 2001
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
class PhoneBookServer extends Freeze.Application
{
public int
runFreeze(String[] args, Freeze.DBEnvironment dbEnv)
{
Ice.Properties properties = communicator().getProperties();
Freeze.DB dbPhoneBook = dbEnv.openDB("phonebook", true);
Freeze.DB dbContacts = dbEnv.openDB("contacts", true);
//
// Create an Evictor for contacts.
//
Freeze.Evictor evictor;
if(properties.getPropertyAsInt("PhoneBook.SaveAfterMutatingOperation") > 0)
{
evictor = dbContacts.createEvictor(Freeze.EvictorPersistenceMode.SaveAfterMutatingOperation);
}
else
{
evictor = dbContacts.createEvictor(Freeze.EvictorPersistenceMode.SaveUponEviction);
}
int evictorSize = properties.getPropertyAsInt("PhoneBook.EvictorSize");
if(evictorSize > 0)
{
evictor.setSize(evictorSize);
}
//
// Create an Object Adapter, use the Evictor as Servant
// Locator.
//
Ice.ObjectAdapter adapter = communicator().createObjectAdapter("PhoneBook");
adapter.addServantLocator(evictor, "contact");
//
// Create the phonebook, and add it to the Object Adapter.
//
PhoneBookI phoneBook = new PhoneBookI(adapter, dbPhoneBook, evictor);
adapter.add(phoneBook, Ice.Util.stringToIdentity("phonebook"));
//
// Create and install a factory and initializer for contacts.
//
Ice.ObjectFactory contactFactory = new ContactFactory(phoneBook, evictor);
Freeze.ServantInitializer contactInitializer = (Freeze.ServantInitializer)contactFactory;
communicator().addObjectFactory(contactFactory, "::Contact");
evictor.installServantInitializer(contactInitializer);
//
// Everything ok, let's go.
//
adapter.activate();
shutdownOnInterrupt();
communicator().waitForShutdown();
ignoreInterrupt();
return 0;
}
PhoneBookServer(String dbEnvName)
{
super(dbEnvName);
}
}
public class Server
{
static public void
main(String[] args)
{
PhoneBookServer app = new PhoneBookServer("db");
app.main("test.Freeze.phonebook.Server", args, "config");
}
}
|