01: package com.db4o.f1.chapter5;
02:
03: import com.db4o.*;
04: import com.db4o.messaging.*;
05:
06: /**
07: * stops the db4o Server started with {@link StartServer}.
08: * <br><br>This is done by opening a client connection
09: * to the server and by sending a StopServer object as
10: * a message. {@link StartServer} will react in it's
11: * processMessage method.
12: */
13: public class StopServer implements ServerConfiguration {
14:
15: /**
16: * stops a db4o Server started with StartServer.
17: * @throws Exception
18: */
19: public static void main(String[] args) {
20: ObjectContainer objectContainer = null;
21: try {
22:
23: // connect to the server
24: objectContainer = Db4o.openClient(HOST, PORT, USER, PASS);
25:
26: } catch (Exception e) {
27: e.printStackTrace();
28: }
29:
30: if (objectContainer != null) {
31:
32: // get the messageSender for the ObjectContainer
33: MessageSender messageSender = objectContainer.ext()
34: .configure().clientServer().getMessageSender();
35:
36: // send an instance of a StopServer object
37: messageSender.send(new StopServer());
38:
39: // close the ObjectContainer
40: objectContainer.close();
41: }
42: }
43: }
|