KickJava   Java API By Example, From Geeks To Geeks.

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


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.server.cluster.Cluster;
33 import com.caucho.server.cluster.ClusterPort;
34 import com.caucho.server.cluster.ClusterServer;
35 import com.caucho.util.L10N;
36 import com.caucho.vfs.JsseSSLFactory;
37
38 import javax.annotation.PostConstruct;
39 import java.net.UnknownHostException JavaDoc;
40
41 /**
42  * Compatiblity configuration for Resin 3.0-style configuration.
43  */

44 public class ClusterCompatConfig {
45   private static final L10N L = new L10N(ClusterCompatConfig.class);
46
47   private final Resin _resin;
48   
49   private String JavaDoc _id = "";
50   private Cluster _cluster;
51
52   /**
53    * Creates a new cluster compat
54    */

55   public ClusterCompatConfig(Resin resin)
56   {
57     _resin = resin;
58   }
59
60   public void setId(String JavaDoc id)
61   {
62     _id = id;
63   }
64
65   Cluster getCluster()
66   {
67     if (_cluster != null)
68       return _cluster;
69     
70     _cluster = _resin.findCluster(_id);
71
72     if (_cluster == null) {
73       try {
74     _cluster = _resin.createCluster();
75     _cluster.setId(_id);
76     _resin.addCluster(_cluster);
77       } catch (Throwable JavaDoc e) {
78     throw new RuntimeException JavaDoc(e);
79       }
80     }
81
82     return _cluster;
83   }
84
85   public SrunCompatConfig createSrun()
86   {
87     return new SrunCompatConfig();
88   }
89
90   public class SrunCompatConfig {
91     private String JavaDoc _id = "";
92     private ClusterServer _server;
93
94     SrunCompatConfig()
95     {
96       Cluster cluster = getCluster();
97     }
98
99     public void setId(String JavaDoc id)
100     {
101       _id = id;
102     }
103
104     public void setServerId(String JavaDoc id)
105     {
106       setId(id);
107     }
108
109     public void setHost(String JavaDoc host)
110       throws UnknownHostException JavaDoc
111     {
112       getClusterPort().setAddress(host);
113     }
114
115     public void setPort(int port)
116     {
117       getClusterPort().setPort(port);
118     }
119
120     public void setJsseSsl(JsseSSLFactory ssl)
121     {
122       getClusterPort().setJsseSsl(ssl);
123     }
124
125     public void setIndex(int index)
126     {
127       // getClusterServer().setIndex(index);
128
}
129
130     public void setBackup(boolean backup)
131     {
132       // getClusterServer().setBackup(index);
133
}
134
135     private ClusterPort getClusterPort()
136     {
137       return getClusterServer().getClusterPort();
138     }
139
140     private ClusterServer getClusterServer()
141     {
142       if (_server == null)
143     _server = _cluster.findServer(_id);
144       
145       if (_server == null) {
146     try {
147       _server = _cluster.createServer();
148       _server.setId(_id);
149       _cluster.addServer(_server);
150     } catch (Throwable JavaDoc e) {
151       throw new RuntimeException JavaDoc(e);
152     }
153       }
154
155       return _server;
156     }
157
158     @PostConstruct
159     public void init()
160       throws Exception JavaDoc
161     {
162       _server.init();
163     }
164   }
165 }
166
Popular Tags