Lines 45-50
Link Here
|
45 |
|
45 |
|
46 |
import java.net.URISyntaxException; |
46 |
import java.net.URISyntaxException; |
47 |
import java.util.Collections; |
47 |
import java.util.Collections; |
|
|
48 |
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; |
48 |
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; |
49 |
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; |
49 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
50 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
50 |
import java.io.IOException; |
51 |
import java.io.IOException; |
Lines 71-76
Link Here
|
71 |
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; |
72 |
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; |
72 |
import javax.enterprise.deploy.spi.status.ClientConfiguration; |
73 |
import javax.enterprise.deploy.spi.status.ClientConfiguration; |
73 |
import javax.enterprise.deploy.spi.status.DeploymentStatus; |
74 |
import javax.enterprise.deploy.spi.status.DeploymentStatus; |
|
|
75 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils.Version; |
74 |
import org.openide.util.NbBundle; |
76 |
import org.openide.util.NbBundle; |
75 |
import org.netbeans.modules.j2ee.jboss4.nodes.Util; |
77 |
import org.netbeans.modules.j2ee.jboss4.nodes.Util; |
76 |
|
78 |
|
Lines 78-126
Link Here
|
78 |
* |
80 |
* |
79 |
* @author Kirill Sorokin |
81 |
* @author Kirill Sorokin |
80 |
*/ |
82 |
*/ |
81 |
public class JBStartServer extends StartServer implements ProgressObject{ |
83 |
public class JBStartServer extends StartServer implements ProgressObject { |
82 |
|
84 |
|
83 |
static enum MODE { RUN, DEBUG, PROFILE }; |
85 |
static enum MODE { |
84 |
|
86 |
|
85 |
static enum ACTION_STATUS { SUCCESS, FAILURE, UNKNOWN }; |
87 |
RUN, DEBUG, PROFILE |
86 |
|
88 |
}; |
|
|
89 |
|
90 |
static enum ACTION_STATUS { |
91 |
|
92 |
SUCCESS, FAILURE, UNKNOWN |
93 |
}; |
87 |
private static final int AVERAGE_SERVER_INSTANCES = 2; |
94 |
private static final int AVERAGE_SERVER_INSTANCES = 2; |
88 |
|
|
|
89 |
private MODE mode; |
95 |
private MODE mode; |
90 |
|
|
|
91 |
private final JBDeploymentManager dm; |
96 |
private final JBDeploymentManager dm; |
92 |
|
|
|
93 |
private static Set<String> isDebugModeUri = Collections.synchronizedSet( |
97 |
private static Set<String> isDebugModeUri = Collections.synchronizedSet( |
94 |
new HashSet<String>(AVERAGE_SERVER_INSTANCES)); |
98 |
new HashSet<String>(AVERAGE_SERVER_INSTANCES)); |
95 |
|
99 |
|
96 |
public JBStartServer(DeploymentManager dm) { |
100 |
public JBStartServer(DeploymentManager dm) { |
97 |
if (!(dm instanceof JBDeploymentManager)) { |
101 |
if (!(dm instanceof JBDeploymentManager)) { |
98 |
throw new IllegalArgumentException("Not an instance of JBDeploymentManager"); // NOI18N |
102 |
throw new IllegalArgumentException("Not an instance of JBDeploymentManager"); // NOI18N |
99 |
} |
103 |
} |
100 |
this.dm = (JBDeploymentManager) dm; |
104 |
this.dm = (JBDeploymentManager) dm; |
101 |
} |
105 |
} |
102 |
|
106 |
|
103 |
private void addDebugModeUri() { |
107 |
private void addDebugModeUri() { |
104 |
isDebugModeUri.add(dm.getUrl()); |
108 |
isDebugModeUri.add(dm.getUrl()); |
105 |
} |
109 |
} |
106 |
|
110 |
|
107 |
private void removeDebugModeUri() { |
111 |
private void removeDebugModeUri() { |
108 |
isDebugModeUri.remove(dm.getUrl()); |
112 |
isDebugModeUri.remove(dm.getUrl()); |
109 |
} |
113 |
} |
110 |
|
114 |
|
111 |
private boolean existsDebugModeUri() { |
115 |
private boolean existsDebugModeUri() { |
112 |
return isDebugModeUri.contains(dm.getUrl()); |
116 |
return isDebugModeUri.contains(dm.getUrl()); |
113 |
} |
117 |
} |
114 |
|
118 |
|
115 |
public ProgressObject startDebugging(Target target) { |
119 |
public ProgressObject startDebugging(Target target) { |
116 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
120 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
117 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName))); //NOI18N |
121 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName))); //NOI18N |
118 |
mode = MODE.DEBUG; |
122 |
mode = MODE.DEBUG; |
119 |
RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); |
123 |
RequestProcessor.getDefault().post(new JBStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY); |
120 |
addDebugModeUri(); |
124 |
addDebugModeUri(); |
121 |
return this; |
125 |
return this; |
122 |
} |
126 |
} |
123 |
|
127 |
|
124 |
public boolean isDebuggable(Target target) { |
128 |
public boolean isDebuggable(Target target) { |
125 |
if (!existsDebugModeUri()) { |
129 |
if (!existsDebugModeUri()) { |
126 |
return false; |
130 |
return false; |
Lines 130-165
Link Here
|
130 |
} |
134 |
} |
131 |
return true; |
135 |
return true; |
132 |
} |
136 |
} |
133 |
|
137 |
|
134 |
public boolean supportsStartDebugging(Target target) { |
138 |
public boolean supportsStartDebugging(Target target) { |
135 |
return true; |
139 |
return true; |
136 |
} |
140 |
} |
137 |
|
141 |
|
138 |
public boolean supportsStartProfiling(Target target) { |
142 |
public boolean supportsStartProfiling(Target target) { |
139 |
return true; |
143 |
return true; |
140 |
} |
144 |
} |
141 |
|
145 |
|
142 |
public boolean isAlsoTargetServer(Target target) { |
146 |
public boolean isAlsoTargetServer(Target target) { |
143 |
return true; |
147 |
return true; |
144 |
} |
148 |
} |
145 |
|
149 |
|
146 |
public ServerDebugInfo getDebugInfo(Target target) { |
150 |
public ServerDebugInfo getDebugInfo(Target target) { |
147 |
return new ServerDebugInfo("localhost", dm.getDebuggingPort()); |
151 |
return new ServerDebugInfo("localhost", dm.getDebuggingPort()); |
148 |
} |
152 |
} |
149 |
|
153 |
|
150 |
/** |
154 |
/** |
151 |
* Starts the server in profiling mode. |
155 |
* Starts the server in profiling mode. |
152 |
*/ |
156 |
*/ |
153 |
public ProgressObject startProfiling(Target target) { |
157 |
public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) { |
154 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
158 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
155 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_PROFILED_SERVER_IN_PROGRESS", serverName))); //NOI18N |
159 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_PROFILED_SERVER_IN_PROGRESS", serverName))); //NOI18N |
156 |
mode = MODE.PROFILE; |
160 |
mode = MODE.PROFILE; |
157 |
RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); |
161 |
RequestProcessor.getDefault().post(new JBStartRunnable(settings, dm, this), 0, Thread.NORM_PRIORITY); |
158 |
removeDebugModeUri(); |
162 |
removeDebugModeUri(); |
159 |
return this; |
163 |
return this; |
160 |
} |
164 |
} |
161 |
|
165 |
|
162 |
|
|
|
163 |
/** |
166 |
/** |
164 |
* Indicates whether this server supports start/stop. |
167 |
* Indicates whether this server supports start/stop. |
165 |
* |
168 |
* |
Lines 168-174
Link Here
|
168 |
public boolean supportsStartDeploymentManager() { |
171 |
public boolean supportsStartDeploymentManager() { |
169 |
return true; |
172 |
return true; |
170 |
} |
173 |
} |
171 |
|
174 |
|
172 |
/** |
175 |
/** |
173 |
* Stops the server. |
176 |
* Stops the server. |
174 |
*/ |
177 |
*/ |
Lines 179-185
Link Here
|
179 |
removeDebugModeUri(); |
182 |
removeDebugModeUri(); |
180 |
return this; |
183 |
return this; |
181 |
} |
184 |
} |
182 |
|
185 |
|
183 |
/** |
186 |
/** |
184 |
* Starts the server |
187 |
* Starts the server |
185 |
*/ |
188 |
*/ |
Lines 187-210
Link Here
|
187 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
190 |
String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); |
188 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)));//NOI18N |
191 |
fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)));//NOI18N |
189 |
mode = MODE.RUN; |
192 |
mode = MODE.RUN; |
190 |
RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); |
193 |
RequestProcessor.getDefault().post(new JBStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY); |
191 |
removeDebugModeUri(); |
194 |
removeDebugModeUri(); |
192 |
return this; |
195 |
return this; |
193 |
} |
196 |
} |
194 |
|
197 |
|
195 |
|
|
|
196 |
public boolean needsStartForTargetList() { |
198 |
public boolean needsStartForTargetList() { |
197 |
return false; |
199 |
return false; |
198 |
} |
200 |
} |
199 |
|
201 |
|
200 |
public boolean needsStartForConfigure() { |
202 |
public boolean needsStartForConfigure() { |
201 |
return false; |
203 |
return false; |
202 |
} |
204 |
} |
203 |
|
205 |
|
204 |
public boolean needsStartForAdminConfig() { |
206 |
public boolean needsStartForAdminConfig() { |
205 |
return false; |
207 |
return false; |
206 |
} |
208 |
} |
207 |
|
209 |
|
208 |
private boolean isReallyRunning() { |
210 |
private boolean isReallyRunning() { |
209 |
final InstanceProperties ip = dm.getInstanceProperties(); |
211 |
final InstanceProperties ip = dm.getInstanceProperties(); |
210 |
if (ip == null) { |
212 |
if (ip == null) { |
Lines 237-285
Link Here
|
237 |
result = false; |
239 |
result = false; |
238 |
} |
240 |
} |
239 |
|
241 |
|
240 |
Object serverName = Util.getMBeanParameter(dm, "ServerName", "jboss.system:type=ServerConfig"); //NOI18N |
242 |
Object serverName; |
241 |
Object serverHome = Util.getMBeanParameter(dm, "ServerHomeLocation", "jboss.system:type=ServerConfig"); //NOI18N |
243 |
Object serverHome; |
242 |
boolean isJBoss6 = serverHome != null; |
244 |
Version version = dm.getProperties().getServerVersion(); |
243 |
if (!isJBoss6) { |
245 |
if(version != null && "7".equals(version.getMajorNumber())) { |
244 |
serverHome = Util.getMBeanParameter(dm, "ServerHomeDir", "jboss.system:type=ServerConfig"); //NOI18N |
246 |
serverHome = Util.getMBeanParameter(dm, "baseDir", "jboss.as:core-service=server-environment"); //NOI18N |
|
|
247 |
serverName = Util.getMBeanParameter(dm, "launchType", "jboss.as:core-service=server-environment"); //NOI18N |
248 |
if (serverName != null) { |
249 |
serverName = serverName.toString().toLowerCase(); |
250 |
} |
251 |
}else { |
252 |
serverName = Util.getMBeanParameter(dm, "ServerName", "jboss.system:type=ServerConfig"); //NOI18N |
253 |
serverHome = Util.getMBeanParameter(dm, "ServerHomeLocation", "jboss.system:type=ServerConfig"); //NOI18N |
254 |
boolean isJBoss6 = serverHome != null; |
255 |
if (!isJBoss6) { |
256 |
serverHome = Util.getMBeanParameter(dm, "ServerHomeDir", "jboss.system:type=ServerConfig"); //NOI18N |
257 |
} |
258 |
try { |
259 |
if (serverHome != null) { |
260 |
if (isJBoss6) { |
261 |
serverHome = new File(((URL) serverHome).toURI()).getAbsolutePath(); |
262 |
} else { |
263 |
serverHome = ((File) serverHome).getAbsolutePath(); |
264 |
} |
265 |
} |
266 |
} catch (URISyntaxException use) { |
267 |
Logger.getLogger(JBStartServer.class.getName()).log(Level.WARNING, "error getting file from URI: " + serverHome, use); //NOI18N |
268 |
} |
245 |
} |
269 |
} |
246 |
try { |
|
|
247 |
if (serverHome != null) { |
248 |
if (isJBoss6) { |
249 |
serverHome = new File(((URL) serverHome).toURI()).getAbsolutePath(); |
250 |
} else { |
251 |
serverHome = ((File) serverHome).getAbsolutePath(); |
252 |
} |
253 |
} |
254 |
} catch (URISyntaxException use) { |
255 |
Logger.getLogger(JBStartServer.class.getName()).log(Level.WARNING, "error getting file from URI: " + serverHome, use); //NOI18N |
256 |
} |
257 |
|
258 |
if (serverName == null || serverHome == null) { |
270 |
if (serverName == null || serverHome == null) { |
259 |
result = false; |
271 |
result = false; |
260 |
return; |
272 |
return; |
261 |
} |
273 |
} |
262 |
if (checkingConfigName.equals(serverName) && checkingServerDir.equals(serverHome)) { |
274 |
if (checkingConfigName.equals(serverName) && checkingServerDir.equals(serverHome)) { |
263 |
result = true; |
275 |
result = true; |
264 |
} |
276 |
} |
265 |
} |
277 |
} |
266 |
}; |
278 |
}; |
267 |
|
279 |
|
268 |
return safeTrueTest(test, 10000); |
280 |
return safeTrueTest(test, 10000); |
269 |
} |
281 |
} |
270 |
|
282 |
|
271 |
/** Safe true/false test useful. */ |
283 |
/** |
|
|
284 |
* Safe true/false test useful. |
285 |
*/ |
272 |
private abstract static class SafeTrueTest implements Runnable { |
286 |
private abstract static class SafeTrueTest implements Runnable { |
|
|
287 |
|
273 |
protected boolean result = false; |
288 |
protected boolean result = false; |
274 |
|
289 |
|
275 |
public abstract void run(); |
290 |
public abstract void run(); |
276 |
|
291 |
|
277 |
public final boolean result() { |
292 |
public final boolean result() { |
278 |
return result; |
293 |
return result; |
279 |
} |
294 |
} |
280 |
}; |
295 |
}; |
281 |
|
296 |
|
282 |
/** Return the result of the test or false if the given time-out ran out. */ |
297 |
/** |
|
|
298 |
* Return the result of the test or false if the given time-out ran out. |
299 |
*/ |
283 |
private boolean safeTrueTest(SafeTrueTest test, int timeout) { |
300 |
private boolean safeTrueTest(SafeTrueTest test, int timeout) { |
284 |
try { |
301 |
try { |
285 |
new RequestProcessor().post(test).waitFinished(timeout); |
302 |
new RequestProcessor().post(test).waitFinished(timeout); |
Lines 288-366
Link Here
|
288 |
} |
305 |
} |
289 |
return test.result(); |
306 |
return test.result(); |
290 |
} |
307 |
} |
291 |
|
308 |
|
292 |
public boolean isRunning() { |
309 |
public boolean isRunning() { |
293 |
|
310 |
|
294 |
InstanceProperties ip = dm.getInstanceProperties(); |
311 |
InstanceProperties ip = dm.getInstanceProperties(); |
295 |
if (ip == null) { |
312 |
if (ip == null) { |
296 |
return false; // finish, it looks like this server instance has been unregistered |
313 |
return false; // finish, it looks like this server instance has been unregistered |
297 |
} |
314 |
} |
298 |
|
315 |
|
299 |
if (!isReallyRunning()){ |
316 |
if (!isReallyRunning()) { |
300 |
dm.setRunningLastCheck(ip, Boolean.FALSE); |
317 |
dm.setRunningLastCheck(ip, Boolean.FALSE); |
301 |
return false; |
318 |
return false; |
302 |
} |
319 |
} |
303 |
|
320 |
|
304 |
dm.setRunningLastCheck(ip, Boolean.TRUE); |
321 |
dm.setRunningLastCheck(ip, Boolean.TRUE); |
305 |
return true; |
322 |
return true; |
306 |
} |
323 |
} |
307 |
|
|
|
308 |
// ---------- Implementation of ProgressObject interface |
324 |
// ---------- Implementation of ProgressObject interface |
309 |
private Vector listeners = new Vector(); |
325 |
private Vector listeners = new Vector(); |
310 |
private DeploymentStatus deploymentStatus; |
326 |
private DeploymentStatus deploymentStatus; |
311 |
|
327 |
|
312 |
public void addProgressListener(ProgressListener pl) { |
328 |
public void addProgressListener(ProgressListener pl) { |
313 |
listeners.add(pl); |
329 |
listeners.add(pl); |
314 |
} |
330 |
} |
315 |
|
331 |
|
316 |
public void removeProgressListener(ProgressListener pl) { |
332 |
public void removeProgressListener(ProgressListener pl) { |
317 |
listeners.remove(pl); |
333 |
listeners.remove(pl); |
318 |
} |
334 |
} |
319 |
|
335 |
|
320 |
public void stop() throws OperationUnsupportedException { |
336 |
public void stop() throws OperationUnsupportedException { |
321 |
throw new OperationUnsupportedException(""); |
337 |
throw new OperationUnsupportedException(""); |
322 |
} |
338 |
} |
323 |
|
339 |
|
324 |
public boolean isStopSupported() { |
340 |
public boolean isStopSupported() { |
325 |
return false; |
341 |
return false; |
326 |
} |
342 |
} |
327 |
|
343 |
|
328 |
public void cancel() throws OperationUnsupportedException { |
344 |
public void cancel() throws OperationUnsupportedException { |
329 |
throw new OperationUnsupportedException(""); |
345 |
throw new OperationUnsupportedException(""); |
330 |
} |
346 |
} |
331 |
|
347 |
|
332 |
public boolean isCancelSupported() { |
348 |
public boolean isCancelSupported() { |
333 |
return false; |
349 |
return false; |
334 |
} |
350 |
} |
335 |
|
351 |
|
336 |
public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { |
352 |
public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { |
337 |
return null; |
353 |
return null; |
338 |
} |
354 |
} |
339 |
|
355 |
|
340 |
public TargetModuleID[] getResultTargetModuleIDs() { |
356 |
public TargetModuleID[] getResultTargetModuleIDs() { |
341 |
return new TargetModuleID[]{}; |
357 |
return new TargetModuleID[]{}; |
342 |
} |
358 |
} |
343 |
|
359 |
|
344 |
public DeploymentStatus getDeploymentStatus() { |
360 |
public DeploymentStatus getDeploymentStatus() { |
345 |
return deploymentStatus; |
361 |
return deploymentStatus; |
346 |
} |
362 |
} |
347 |
|
363 |
|
348 |
/** Report event to any registered listeners. */ |
364 |
/** |
|
|
365 |
* Report event to any registered listeners. |
366 |
*/ |
349 |
public void fireHandleProgressEvent(TargetModuleID targetModuleID, DeploymentStatus deploymentStatus) { |
367 |
public void fireHandleProgressEvent(TargetModuleID targetModuleID, DeploymentStatus deploymentStatus) { |
350 |
ProgressEvent evt = new ProgressEvent(this, targetModuleID, deploymentStatus); |
368 |
ProgressEvent evt = new ProgressEvent(this, targetModuleID, deploymentStatus); |
351 |
|
369 |
|
352 |
this.deploymentStatus = deploymentStatus; |
370 |
this.deploymentStatus = deploymentStatus; |
353 |
|
371 |
|
354 |
java.util.Vector targets = null; |
372 |
java.util.Vector targets = null; |
355 |
synchronized (this) { |
373 |
synchronized (this) { |
356 |
if (listeners != null) { |
374 |
if (listeners != null) { |
357 |
targets = (java.util.Vector) listeners.clone(); |
375 |
targets = (java.util.Vector) listeners.clone(); |
358 |
} |
376 |
} |
359 |
} |
377 |
} |
360 |
|
378 |
|
361 |
if (targets != null) { |
379 |
if (targets != null) { |
362 |
for (int i = 0; i < targets.size(); i++) { |
380 |
for (int i = 0; i < targets.size(); i++) { |
363 |
ProgressListener target = (ProgressListener)targets.elementAt(i); |
381 |
ProgressListener target = (ProgressListener) targets.elementAt(i); |
364 |
target.handleProgressEvent(evt); |
382 |
target.handleProgressEvent(evt); |
365 |
} |
383 |
} |
366 |
} |
384 |
} |
Lines 369-374
Link Here
|
369 |
MODE getMode() { |
387 |
MODE getMode() { |
370 |
return mode; |
388 |
return mode; |
371 |
} |
389 |
} |
372 |
|
|
|
373 |
|
374 |
} |
390 |
} |