Improved SCGI server's handling of its environment.
[jsvc.git] / src / dolda / jsvc / util / SimpleContext.java
CommitLineData
13e578b1
FT
1package dolda.jsvc.util;
2
3import java.io.*;
4import java.util.*;
13e578b1
FT
5import dolda.jsvc.*;
6
22779185 7public class SimpleContext implements ServerContext {
13e578b1
FT
8 private final long ctime;
9 private final String name;
10 public final ClassLoader loader;
11 protected final Properties sysconfig, libconfig;
12
13e578b1
FT
13 private void loadconfig() {
14 try {
15 InputStream pi = loader.getResourceAsStream("jsvc.properties");
16 if(pi != null) {
17 try {
18 libconfig.load(pi);
19 } finally {
20 pi.close();
21 }
22 }
23 } catch(IOException e) {
24 throw(new Error(e));
25 }
26 }
27
22779185 28 public SimpleContext(ClassLoader cl, String name) {
13e578b1
FT
29 this.ctime = System.currentTimeMillis();
30 this.name = name;
31 this.loader = cl;
32 sysconfig = new Properties();
33 libconfig = new Properties();
34
35 loadconfig();
36 }
37
13e578b1
FT
38 public long starttime() {
39 return(ctime);
40 }
41
42 public String name() {
43 return(name);
44 }
45
46 public String sysconfig(String key, String def) {
47 return(sysconfig.getProperty(key, def));
48 }
49
50 public String libconfig(String key, String def) {
51 return(libconfig.getProperty(key, def));
52 }
53
54 public RequestThread worker(Responder root, Request req, ThreadGroup tg, String name) {
55 return(new RequestThread(root, req, tg, name));
56 }
57}