KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > boot > ResinConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.boot;
31
32 import com.caucho.config.BuilderProgram;
33 import com.caucho.config.types.InitProgram;
34 import com.caucho.loader.EnvironmentBean;
35 import com.caucho.loader.EnvironmentClassLoader;
36 import com.caucho.vfs.Path;
37
38 import javax.annotation.PostConstruct;
39 import java.util.ArrayList JavaDoc;
40
41 public class ResinConfig implements EnvironmentBean {
42   private ArrayList JavaDoc<InitProgram> _clusterDefaultList
43     = new ArrayList JavaDoc<InitProgram>();
44   
45   private ArrayList JavaDoc<ClusterConfig> _clusterList
46     = new ArrayList JavaDoc<ClusterConfig>();
47
48   private ClassLoader JavaDoc _classLoader;
49
50   private Path _resinHome;
51   private Path _rootDirectory;
52
53   ResinConfig(Path resinHome, Path serverRoot)
54   {
55     _resinHome = resinHome;
56     _rootDirectory = serverRoot;
57
58     _classLoader = new EnvironmentClassLoader();
59   }
60
61   public Path getResinHome()
62   {
63     return _resinHome;
64   }
65
66   public Path getRootDirectory()
67   {
68     return _rootDirectory;
69   }
70
71   public void setRootDirectory(Path rootDirectory)
72   {
73     _rootDirectory = rootDirectory;
74   }
75
76   public ClassLoader JavaDoc getClassLoader()
77   {
78     return _classLoader;
79   }
80
81   /**
82    * Adds a new default to the cluster.
83    */

84   public void addClusterDefault(InitProgram program)
85     throws Throwable JavaDoc
86   {
87     _clusterDefaultList.add(program);
88   }
89
90   public ClusterConfig createCluster()
91   {
92     ClusterConfig cluster = new ClusterConfig(this);
93
94     for (int i = 0; i < _clusterDefaultList.size(); i++)
95       _clusterDefaultList.get(i).configure(cluster);
96     
97     _clusterList.add(cluster);
98
99     return cluster;
100   }
101
102   public ServerCompatConfig createServer()
103   {
104     return new ServerCompatConfig();
105   }
106   
107   /**
108    * Ignore items we can't understand.
109    */

110   public void addThreadPool(BuilderProgram program)
111   {
112   }
113   
114   public void setGroupName(BuilderProgram program)
115   {
116   }
117   
118   public void setUserName(BuilderProgram program)
119   {
120   }
121
122   public void setMinFreeMemory(BuilderProgram program)
123   {
124   }
125     
126     /**
127      * Ignore items we can't understand.
128      */

129     public void setSecurityManager(BuilderProgram program)
130     {
131     }
132
133   /**
134    * Finds a server.
135    */

136   public ClusterConfig findCluster(String JavaDoc id)
137   {
138     for (int i = 0; i < _clusterList.size(); i++) {
139       ClusterConfig cluster = _clusterList.get(i);
140
141       if (id.equals(cluster.getId()))
142     return cluster;
143     }
144
145     return null;
146   }
147
148   /**
149    * Finds a server.
150    */

151   public ResinWatchdog findServer(String JavaDoc id)
152   {
153     for (int i = 0; i < _clusterList.size(); i++) {
154       ClusterConfig cluster = _clusterList.get(i);
155
156       ResinWatchdog server = cluster.findServer(id);
157
158       if (server != null)
159     return server;
160     }
161
162     return null;
163   }
164
165   public class ServerCompatConfig {
166     public ClusterCompatConfig createCluster()
167     {
168       return new ClusterCompatConfig();
169     }
170     
171     public SrunCompatConfig createHttp()
172     {
173       return new SrunCompatConfig();
174     }
175     
176     /**
177      * Ignore items we can't understand.
178      */

179     public void addBuilderProgram(BuilderProgram program)
180     {
181     }
182   }
183
184   public class ClusterCompatConfig {
185     public SrunCompatConfig createSrun()
186     {
187       return new SrunCompatConfig();
188     }
189     
190     /**
191      * Ignore items we can't understand.
192      */

193     public void addBuilderProgram(BuilderProgram program)
194     {
195     }
196   }
197
198   public class SrunCompatConfig {
199     private String JavaDoc _id = "";
200
201     public void setId(String JavaDoc id)
202     {
203       _id = id;
204     }
205
206     public void setServerId(String JavaDoc id)
207     {
208       _id = id;
209     }
210     
211     /**
212      * Ignore items we can't understand.
213      */

214     public void addBuilderProgram(BuilderProgram program)
215     {
216     }
217
218     @PostConstruct
219       public void init()
220     {
221       ResinWatchdog server = findServer(_id);
222
223       if (server != null)
224     return;
225
226       ClusterConfig cluster = findCluster("");
227
228       if (cluster == null)
229     cluster = createCluster();
230
231       server = cluster.createServer();
232       server.setId(_id);
233       cluster.addServer(server);
234     }
235   }
236 }
237
Popular Tags