| 1 package com.db4o.f1.chapter5; 2 3 import com.db4o.*; 4 import com.db4o.messaging.*; 5 6 16 public class StartServer 17 implements ServerConfiguration, MessageRecipient { 18 19 22 private boolean stop = false; 23 24 28 public static void main(String [] arguments) { 29 new StartServer().runServer(); 30 } 31 32 36 public void runServer(){ 37 synchronized(this){ 38 ObjectServer db4oServer = Db4o.openServer(FILE, PORT); 39 db4oServer.grantAccess(USER, PASS); 40 41 db4oServer.ext().configure().setMessageRecipient(this); 44 45 Thread.currentThread().setName(this.getClass().getName()); 47 48 Thread.currentThread().setPriority(Thread.MIN_PRIORITY); 51 try { 52 if(! stop){ 53 this.wait(Long.MAX_VALUE); 55 } 56 } catch (Exception e) { 57 e.printStackTrace(); 58 } 59 db4oServer.close(); 60 } 61 } 62 63 67 public void processMessage(ObjectContainer con, Object message) { 68 if(message instanceof StopServer){ 69 close(); 70 } 71 } 72 73 76 public void close(){ 77 synchronized(this){ 78 stop = true; 79 this.notify(); 80 } 81 } 82 } 83 | Popular Tags |