1 /**********************************************************************
2 * EJServerConfig.java
3 * created on 25.03.2006 by netseeker
4 * $Source$
5 * $Date$
6 * $Revision$
7 *
8 * ====================================================================
9 *
10 * Copyright 2006 netseeker aka Michael Manske
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 * ====================================================================
24 *
25 * This file is part of the EJOE framework.
26 * For more information on the author, please see
27 * <http://www.manskes.de/>.
28 *
29 *********************************************************************/
30
31 package de.netseeker.ejoe.jmx;
32
33 import java.io.IOException;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36
37 import javax.management.AttributeChangeNotification;
38 import javax.management.MBeanNotificationInfo;
39 import javax.management.Notification;
40 import javax.management.NotificationBroadcasterSupport;
41
42 import de.netseeker.ejoe.EJServer;
43 import de.netseeker.ejoe.handler.ServerHandler;
44
45 /***
46 * Simlpe MBean interface implementation to support runtime configuration via JMX
47 *
48 * @author netseeker
49 * @since 0.3.9.1
50 */
51 public final class EJServerConfig extends NotificationBroadcasterSupport implements EJServerConfigMBean
52 {
53 private static final Logger logger = Logger.getLogger( EJServerConfig.class.getName() );
54
55 private EJServer _ejServer;
56
57 private long _sequenceNumber = 1;
58
59 /***
60 *
61 */
62 public EJServerConfig()
63 {
64 super();
65 ServerHandler handler = null;
66 this._ejServer = new EJServer( handler );
67 this._ejServer.setMaxReadProcessors( 1 );
68 this._ejServer.setMaxWriteProcessors( 1 );
69 startEJServer();
70 }
71
72 /***
73 * @param ejServer
74 */
75 public EJServerConfig(EJServer ejServer)
76 {
77 super();
78 this._ejServer = ejServer;
79 }
80
81
82
83
84
85
86 public MBeanNotificationInfo[] getNotificationInfo()
87 {
88 String[] types = new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE };
89 String name = AttributeChangeNotification.class.getName();
90 String description = "An attribute of the monitored EJServer has changed";
91 MBeanNotificationInfo info = new MBeanNotificationInfo( types, name, description );
92 return new MBeanNotificationInfo[] { info };
93 }
94
95
96
97
98
99
100 public boolean isNonBlockingIO()
101 {
102 return this._ejServer.hasNonBlockingIO();
103 }
104
105
106
107
108
109
110 public void setNonBlockingIO( boolean isNonBlockingIO )
111 {
112 this._ejServer.enableNonBlockingIO( isNonBlockingIO );
113 }
114
115
116
117
118
119
120 public boolean isPersistentConnections()
121 {
122 return this._ejServer.hasPersistentConnections();
123 }
124
125
126
127
128
129
130 public void setPersistentConnections( boolean isPersistentConnections )
131 {
132 this._ejServer.enablePersistentConnections( isPersistentConnections );
133 }
134
135
136
137
138
139
140 public boolean isHttpPackaging()
141 {
142 return this._ejServer.hasHttPackaging();
143 }
144
145
146
147
148
149
150 public void setHttpPackaging( boolean enable )
151 {
152 this._ejServer.enableHttpPackaging( enable );
153 }
154
155
156
157
158
159
160 public boolean isCompression()
161 {
162 return this._ejServer.hasCommpression();
163 }
164
165
166
167
168
169
170 public void setCompression( boolean compression )
171 {
172 this._ejServer.enableCompression( compression );
173 }
174
175
176
177
178
179
180 public boolean isRunning()
181 {
182 return this._ejServer.isRunning();
183 }
184
185
186
187
188
189
190 public int getMaxReadProcessors()
191 {
192 return this._ejServer.getMaxReadProcessors();
193 }
194
195
196
197
198
199
200 public void setMaxReadProcessors( int maxReadProcessors )
201 {
202 this._ejServer.stop();
203 this._ejServer.setMaxReadProcessors( maxReadProcessors );
204 startEJServer();
205 }
206
207
208
209
210
211
212 public int getMaxWriteProcessors()
213 {
214 return this._ejServer.getMaxWriteProcessors();
215 }
216
217
218
219
220
221
222 public void setMaxWriteProcessors( int maxWriteProcessors )
223 {
224 this._ejServer.stop();
225 this._ejServer.setMaxWriteProcessors( maxWriteProcessors );
226 startEJServer();
227 }
228
229
230
231
232
233
234 public void stopEJServer()
235 {
236 this._ejServer.stop();
237 Notification n = new AttributeChangeNotification( this, _sequenceNumber++, System.currentTimeMillis(),
238 "Running state changed", "Running", "boolean", Boolean.TRUE,
239 Boolean.FALSE );
240 sendNotification( n );
241 }
242
243
244
245
246
247
248 public void startEJServer()
249 {
250 try
251 {
252 this._ejServer.start();
253 Notification n = new AttributeChangeNotification( this, _sequenceNumber++, System.currentTimeMillis(),
254 "Running state changed", "Running", "boolean",
255 Boolean.FALSE, Boolean.TRUE );
256 sendNotification( n );
257 }
258 catch ( IOException e )
259 {
260 logger.log( Level.SEVERE, e.getMessage(), e );
261 }
262 }
263
264
265
266
267
268
269 public void restartEJServer()
270 {
271 stopEJServer();
272 startEJServer();
273 }
274 }