KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConfigException;
34 import com.caucho.config.types.InitProgram;
35 import com.caucho.util.L10N;
36
37 import java.util.ArrayList JavaDoc;
38
39 public class ClusterConfig {
40   private static final L10N L = new L10N(ClusterConfig.class);
41   
42   private ResinConfig _resin;
43
44   private ArrayList JavaDoc<InitProgram> _serverDefaultList
45     = new ArrayList JavaDoc<InitProgram>();
46
47   private ArrayList JavaDoc<ResinWatchdog> _serverList
48     = new ArrayList JavaDoc<ResinWatchdog>();
49   
50   private String JavaDoc _id = "";
51
52   ClusterConfig(ResinConfig resin)
53   {
54     _resin = resin;
55   }
56
57   public void setId(String JavaDoc id)
58   {
59     _id = id;
60   }
61
62   public String JavaDoc getId()
63   {
64     return _id;
65   }
66
67   public ResinConfig getResin()
68   {
69     return _resin;
70   }
71
72   /**
73    * Adds a new server to the cluster.
74    */

75   public void addServerDefault(InitProgram program)
76     throws Throwable JavaDoc
77   {
78     _serverDefaultList.add(program);
79   }
80
81   public ResinWatchdog createServer()
82   {
83     ResinWatchdog watchdog = new ResinWatchdog(this);
84
85     for (int i = 0; i < _serverDefaultList.size(); i++)
86       _serverDefaultList.get(i).configure(watchdog);
87
88     return watchdog;
89   }
90
91   public void addServer(ResinWatchdog server)
92     throws ConfigException
93   {
94     if (_resin.findServer(server.getId()) != null)
95       throw new ConfigException(L.l("<server id='{0}'> is a duplicate server. servers must have unique ids.",
96                     server.getId()));
97       
98     _serverList.add(server);
99   }
100   
101   /**
102    * Ignore items we can't understand.
103    */

104   public void addBuilderProgram(BuilderProgram program)
105   {
106   }
107
108   /**
109    * Finds a server.
110    */

111   public ResinWatchdog findServer(String JavaDoc id)
112   {
113     for (int i = 0; i < _serverList.size(); i++) {
114       ResinWatchdog server = _serverList.get(i);
115
116       if (id.equals(server.getId()))
117     return server;
118     }
119
120     return null;
121   }
122
123   public String JavaDoc toString()
124   {
125     return "ClusterConfig[" + _id + "]";
126   }
127 }
128
Popular Tags