[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New server class with useful options



Hi all,
  I've attached a modification of the main server entrypoint class with
some useful options added.  There are two additions:

  i) The "-c" option will cause the server to create a new database (just
like the install tool) if it doesn't find a config.properties file in the
specified directory.

  ii) the "-u<name>" option adds user <name> to the database with the first
available id above 1024 (if that user is not already in the database).

  The net effect of these two additions is to speed up debugging.  You no
longer have to run install before starting the server if you just wiped
your database; a fresh database will be installed if needed.  You no longer
have to run the admin-tool before using a new database to add yourself as a
user.

  (This also means that the following code can be removed from line 149 of
Env.java:

            try {
                userManager.newUser ("daniela", (short)1);
                userManager.newUser ("gerd", (short)2);
                userManager.newUser ("lars", (short)3);
                }
            catch (Exception e) {
                }
  and added to bin/ozone and bin/ozone.bat where it is more obvious.
)

Later,

\x/ill              :-}


// Copyright 1997-1999 by softwarebuero m&b (SMB). All rights reserved.
//
// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by softwarebuero m&b (SMB).
//
// $Id: Server.java,v 1.28 2000/02/02 17:40:15 daniela Exp $

package org.ozoneDB.core;

import org.ozoneDB.*;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.tools.*;
import java.io.*;
import java.util.*;


/** Main class to start the stand-alone server.
*/
public class Server extends Object {
    /** */
    public static Env env;
     
    /** */
    public static void main (String[] args) throws Exception {
        String dir = File.separator + "tmp" + File.separator + "db";
        int debugLevel = 0;
        boolean help = false;
        boolean verbose = false;
        boolean createDB = false;
        Vector users = new Vector();
        
        System.out.println ("ozone server - version " + Env.VERSION);
  
        //kommandozeilen argumente auswerten; vor default file lesen,
        //damit das db-dir bekannt ist
        for (int i=0; i<args.length; i++) {
            if (args[i].equals ("-debug") || args[i].equals ("-debug1")) {
                debugLevel = LogWriter.DEBUG;
                }
            else  if (args[i].equals ("-debug2")) {
                debugLevel = LogWriter.DEBUG | LogWriter.DEBUG2;
                }
            else  if (args[i].equals ("-debug3")) {
                debugLevel = LogWriter.DEBUG | LogWriter.DEBUG2 |
LogWriter.DEBUG3;
                }
            else if (args[i].startsWith ("-d")) {
                dir = args[i].substring (2);
                }
            else  if (args[i].startsWith ("-h")) {
                help = true;
                }
            else if (args[i].startsWith ("-c")) {
            	createDB = true;
            	}
            else if (args[i].startsWith ("-u")) {
                String name = args[i].substring (2);
                users.addElement(name);
            	}
            else {
                System.out.println ("illegal option: " + args[i]);
                help = true;
                }
            }
        
        if (args.length==0 || help) {
            System.out.println ("usage: ozone -d<dir> [-h] [-debug] [-v]");
            System.out.println ("   -d<directory>         database
directory");
            System.out.println ("   -debug<level>         enable debug
messages");
            System.out.println ("   -v                    starts the
ozonometer");
            System.out.println ("   -h                    shows this help");
            System.out.println ("   -c                    create a database
if neccessary");
            System.out.println ("   -u<name>              add user <name>");
            System.exit (0);
            }
  
        try {
            System.out.println ("initializing...");
            if (createDB) {
	            // check to see if we have a config file in the database
directory
	            // if not, assume we need to make a new database, and do so.
	            File testFile = new File(dir, Env.CONFIG_FILE);
	            if (!testFile.exists()) {
			        System.out.println ("Installing new database in " + dir + "
..");

			        Setup defaults = new Setup();
			        defaults.addProperties (System.getProperties(), "ozoneDB.");
			        Install.createDB (dir, defaults, new PrintWriter(System.out,
true));

			        System.out.println ("Edit the file " + dir + "ozone.properties to
change settings.");
	            }
            }
            env = new Env (dir, debugLevel, verbose, false);
            
            short freeSlot = 1024;
            for (int i=0; i<users.size(); i++) {
            	String name = (String)users.elementAt(i);
            	// don't insert a name twice
            	if (env.userManager.userForName(name) != null) {
            		System.out.println ("User " + name + " already exists.");
            		continue;
            	}
            	// find a free id
          		while (env.userManager.userForID(new UserID(freeSlot)) != null)
          			freeSlot++;
          		// add the user
            	System.out.println ("Adding user " + name + " with ID: " +
freeSlot + ".");
            	env.userManager.newUser (name, freeSlot);
            }
            
            env.startExternalEventProcessing();
            env.startDeadlockRecognition();
      
            System.out.println ("('q' to shutdown without admin tool)");
   
            InputStreamReader is = new InputStreamReader (System.in);
            Thread.currentThread().setPriority (Env.SERVER_THREAD_PRIORITY);
            int c = 0;
   
            // regt gleichzeitig task-wechsel an
            for (;;) {
               while (!is.ready() && !env.shuttingdown) {
                  Thread.currentThread().sleep (1000);
 //                 if (env.storageFrame != null)
 //                    env.storageFrame.updateView();
                  }
               
               // MEN 6/25/1999 - added a way to exit when the AdminTool
               // shuts us down
               if (env.shuttingdown) {
                  break;
                  }
   
               c = is.read();
               if (c == 'q') {
                  env.shutdown();
                  break;
                  }
               }
           }
        catch (Exception e) {
          // env.logWriter.newEntry (null, "", e, LogWriter.ERROR);
           System.exit (1);
           }   
        }
    }