KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > f1 > chapter5 > StopServer


1 package com.db4o.f1.chapter5;
2
3 import com.db4o.*;
4 import com.db4o.messaging.*;
5
6 /**
7  * stops the db4o Server started with {@link StartServer}.
8  * <br><br>This is done by opening a client connection
9  * 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 JavaDoc[] 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 JavaDoc 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().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 }
44
Popular Tags