CS 580 Client-Server Programming Fall Semester, 2002 Configuration Files |
||
---|---|---|
© 2002, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 17-Oct-02 |
Application Parameters & Configuration Files
Applications normal have configuration files to store
cvs co assignment2
ls -la ps -aux
Servers
Servers normally use configuration files & command line flags
Environment variables are uses much in servers (why?)
Java
Some systems have libraries to handle config files & command line arguments
JDK does not seem to have such classes
There should be a number of Java libraries that provide such support
sdsu Java library is one such library
sdsu.util.ProgramProperties
Parses
Simple Example
import sdsu.util.ProgramProperties; public class ConfigurationExample { public static void main(String args[]) { try { ProgramProperties flags = new ProgramProperties( args, "configurationFile"); String nameValue = flags.getString( "name" , "No name given"); int size = flags.getInt( "size", 0); boolean switchOn = flags.containsKey( "s"); System.out.println( " nameValue: " + nameValue); System.out.println( " size: " + size); System.out.println( " switchOn: " + switchOn); } catch (java.io.IOException readParseProblem) { System.err.println( "Program aborted on error " + readParseProblem); } } }
File "configurationFile.labeledData" name=Roger; size=12;
Sample Runs
java ConfigurationExample
Output nameValue: Roger
size: 12
switchOn: false
java ConfigurationExample -s -name Pete
Output nameValue: Pete
size: 12
switchOn: true
java ConfigurationExample -conf=otherFile
Output nameValue: Sam
size: 8
switchOn: true
VisualWorks
Command Line Arguments
CEnvironment
Cenvironment class>>commandLine
visual script.im -port 5 -host=rohan.sdsu.edu -xyzCEnvironment commandLine returns
#('visual' 'script.im' '-port' '5' '-host=rohan.sdsu.edu' '-xyz')
CEnvironment class>> userEnvironment
| user | user :=CEnvironment userEnvironment. user at: 'CVSROOT'
Registering for Flags
To avoid parsing the command line array
Classes can register to be informed of individual flags
To register add method to CommanlLineInterest class
In dependencies-pragma protocol
Example
CommanlLineInterest class>>port: aTokenReadStream <triggerAtSystemEvent: #returnFromSnapshot option: '-port'> | port | port := aTokenReadStream next asNumber. SimpleDateServer port: port. “Now make SimpleDateServer>>port: set the port.
aTokenReadStream next returns the value after the flag
CommanlLineInterest class>>port: is called on startup when flag -port exits on command line
Only supports -flag value options
Can have method triggered at
Configuration Files
VisualWorks servers use configuration files
No system wide classes for supporting them
Too easy to create own system?
Copyright ©, All rights reserved.
2002 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 17-Oct-02    Next