KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > resin > ServerCompatConfig


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.server.resin;
31
32 import com.caucho.config.BuilderProgram;
33 import com.caucho.config.BuilderProgramContainer;
34 import com.caucho.config.SchemaBean;
35 import com.caucho.server.cluster.Cluster;
36 import com.caucho.server.cluster.ClusterServer;
37 import com.caucho.server.port.Port;
38 import com.caucho.util.L10N;
39
40 import javax.annotation.PostConstruct;
41 import java.util.ArrayList JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43
44 /**
45  * Compatiblity configuration for Resin 3.0-style configuration.
46  */

47 public class ServerCompatConfig implements SchemaBean {
48   private static final L10N L = new L10N(ServerCompatConfig.class);
49   private static final Logger JavaDoc log
50     = Logger.getLogger(ServerCompatConfig.class.getName());
51
52   private final Resin _resin;
53
54   private ArrayList JavaDoc<HttpCompatConfig> _httpList
55     = new ArrayList JavaDoc<HttpCompatConfig>();
56
57   private BuilderProgramContainer _program
58     = new BuilderProgramContainer();
59
60   /**
61    * Creates a new resin server.
62    */

63   public ServerCompatConfig(Resin resin)
64   {
65     if (resin == null)
66       throw new NullPointerException JavaDoc();
67     
68     _resin = resin;
69   }
70
71   /**
72    * Returns the relax schema.
73    */

74   public String JavaDoc getSchema()
75   {
76     return "com/caucho/server/resin/server.rnc";
77   }
78
79   public void addBuilderProgram(BuilderProgram program)
80   {
81     _program.addProgram(program);
82   }
83
84   /**
85    * Creates a http compat.
86    */

87   public HttpCompatConfig createHttp()
88   {
89     HttpCompatConfig http = new HttpCompatConfig();
90
91     return http;
92   }
93
94   /**
95    * Creates a cluster compat.
96    */

97   public ClusterCompatConfig createCluster()
98   {
99     return new ClusterCompatConfig(_resin);
100   }
101
102   @PostConstruct
103   public void init()
104   {
105     try {
106       String JavaDoc serverId = _resin.getServerId();
107     
108       ClusterServer clusterServer = _resin.findClusterServer(serverId);
109
110       if (clusterServer != null) {
111       }
112       else {
113     if (_resin.getClusterList().size() > 0 || ! "".equals(serverId)) {
114       log.warning(L.l("-server '{0}' does not match any defined servers",
115               serverId));
116     }
117
118     Cluster cluster = _resin.createCluster();
119     _resin.addCluster(cluster);
120
121     clusterServer = cluster.createServer();
122     
123     clusterServer.setPort(0);
124
125     cluster.addServer(clusterServer);
126       }
127
128       _program.configure(clusterServer.getCluster());
129     } catch (RuntimeException JavaDoc e) {
130       throw e;
131     } catch (Throwable JavaDoc e) {
132       throw new RuntimeException JavaDoc(e);
133     }
134   }
135
136   public class HttpCompatConfig {
137     private String JavaDoc _id = "";
138
139     private BuilderProgramContainer _program
140       = new BuilderProgramContainer();
141
142     HttpCompatConfig()
143     {
144     }
145
146     public void setId(String JavaDoc id)
147     {
148       _id = id;
149     }
150
151     public void setServerId(String JavaDoc id)
152     {
153       setId(id);
154     }
155
156     public void addBuilderProgram(BuilderProgram program)
157     {
158       _program.addProgram(program);
159     }
160
161     @PostConstruct
162     public void init()
163       throws Throwable JavaDoc
164     {
165       ClusterServer server = _resin.findClusterServer(_id);
166
167       if (server == null) {
168     Cluster cluster = _resin.findCluster("");
169
170     if (cluster == null) {
171       cluster = _resin.createCluster();
172       _resin.addCluster(cluster);
173     }
174
175     server = cluster.createServer();
176     server.setId(_id);
177     server.getClusterPort().setPort(0);
178     cluster.addServer(server);
179       }
180
181       Port http = server.createHttp();
182       _program.configure(http);
183     }
184   }
185 }
186
Popular Tags