1 package com.db4odoc.f1.clientserver; 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 33 37 public void runServer(){ 38 synchronized(this){ 39 ObjectServer db4oServer = Db4o.openServer(FILE, PORT); 40 db4oServer.grantAccess(USER, PASS); 41 42 db4oServer.ext().configure().setMessageRecipient(this); 45 46 Thread.currentThread().setName(this.getClass().getName()); 48 49 Thread.currentThread().setPriority(Thread.MIN_PRIORITY); 52 try { 53 if(! stop){ 54 this.wait(Long.MAX_VALUE); 56 } 57 } catch (Exception e) { 58 e.printStackTrace(); 59 } 60 db4oServer.close(); 61 } 62 } 63 65 69 public void processMessage(ObjectContainer con, Object message) { 70 if(message instanceof StopServer){ 71 close(); 72 } 73 } 74 76 79 public void close(){ 80 synchronized(this){ 81 stop = true; 82 this.notify(); 83 } 84 } 85 } 87 | Popular Tags |