Lines 42-47
Link Here
|
42 |
* made subject to such option by the copyright holder. |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
43 |
*/ |
44 |
package org.netbeans.modules.j2ee.jboss4; |
44 |
package org.netbeans.modules.j2ee.jboss4; |
|
|
45 |
|
45 |
import java.util.Collections; |
46 |
import java.util.Collections; |
46 |
import java.util.Map; |
47 |
import java.util.Map; |
47 |
import java.util.WeakHashMap; |
48 |
import java.util.WeakHashMap; |
Lines 52-60
Link Here
|
52 |
import java.io.File; |
53 |
import java.io.File; |
53 |
import java.io.IOException; |
54 |
import java.io.IOException; |
54 |
import java.io.InputStream; |
55 |
import java.io.InputStream; |
|
|
56 |
import java.net.MalformedURLException; |
55 |
import java.net.URLClassLoader; |
57 |
import java.net.URLClassLoader; |
56 |
import java.util.Locale; |
58 |
import java.util.Locale; |
57 |
import java.util.Properties; |
59 |
import java.util.Properties; |
|
|
60 |
import java.util.concurrent.Callable; |
58 |
import java.util.concurrent.ExecutionException; |
61 |
import java.util.concurrent.ExecutionException; |
59 |
import java.util.logging.Level; |
62 |
import java.util.logging.Level; |
60 |
import java.util.logging.Logger; |
63 |
import java.util.logging.Logger; |
Lines 78-83
Link Here
|
78 |
import javax.naming.NamingException; |
81 |
import javax.naming.NamingException; |
79 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
82 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
80 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; |
83 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; |
|
|
84 |
import org.openide.util.Exceptions; |
81 |
|
85 |
|
82 |
/** |
86 |
/** |
83 |
* |
87 |
* |
Lines 94-107
Link Here
|
94 |
|
98 |
|
95 |
private InstanceProperties instanceProperties; |
99 |
private InstanceProperties instanceProperties; |
96 |
private boolean needsRestart; |
100 |
private boolean needsRestart; |
97 |
|
101 |
private Boolean as7; |
98 |
/** |
102 |
/** |
99 |
* Stores information about running instances. instance is represented by its InstanceProperties, |
103 |
* Stores information about running instances. instance is represented by its InstanceProperties, |
100 |
* running state by Boolean.TRUE, stopped state Boolean.FALSE. |
104 |
* running state by Boolean.TRUE, stopped state Boolean.FALSE. |
101 |
* WeakHashMap should guarantee erasing of an unregistered server instance bcs instance properties are also removed along with instance. |
105 |
* WeakHashMap should guarantee erasing of an unregistered server instance bcs instance properties are also removed along with instance. |
102 |
*/ |
106 |
*/ |
103 |
private static final Map<InstanceProperties, Boolean> propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap()); |
107 |
private static final Map<InstanceProperties, Boolean> propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap()); |
104 |
|
108 |
|
105 |
/** Creates a new instance of JBDeploymentManager */ |
109 |
/** Creates a new instance of JBDeploymentManager */ |
106 |
public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { |
110 |
public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { |
107 |
realUri = uri; |
111 |
realUri = uri; |
Lines 139-144
Link Here
|
139 |
return instanceProperties; |
143 |
return instanceProperties; |
140 |
} |
144 |
} |
141 |
|
145 |
|
|
|
146 |
/** |
147 |
* This is a handy method to execute the any {@code action} within JBoss's class loader. |
148 |
* |
149 |
* @param action the action to be executed |
150 |
* @return T |
151 |
* @throws ExecutionException |
152 |
*/ |
153 |
public <T> T invokeLocalAction(Callable<T> action) throws Exception { |
154 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
155 |
try { |
156 |
InstanceProperties ip = getInstanceProperties(); |
157 |
URLClassLoader loader = JBDeploymentFactory.getJBClassLoader(ip); |
158 |
Thread.currentThread().setContextClassLoader(loader); |
159 |
return action.call(); |
160 |
} finally { |
161 |
Thread.currentThread().setContextClassLoader(oldLoader); |
162 |
} |
163 |
} |
164 |
|
142 |
public <T> T invokeRemoteAction(JBRemoteAction<T> action) throws ExecutionException { |
165 |
public <T> T invokeRemoteAction(JBRemoteAction<T> action) throws ExecutionException { |
143 |
|
166 |
|
144 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
167 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
Lines 177-184
Link Here
|
177 |
System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); // NOI18N |
200 |
System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); // NOI18N |
178 |
} |
201 |
} |
179 |
|
202 |
|
180 |
// Gets naming context |
203 |
if (!props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { |
181 |
ctx = new InitialContext(env); |
204 |
// Gets naming context |
|
|
205 |
ctx = new InitialContext(env); |
206 |
} |
182 |
|
207 |
|
183 |
//restore java.security.auth.login.config system property |
208 |
//restore java.security.auth.login.config system property |
184 |
if (oldAuthConf != null) { |
209 |
if (oldAuthConf != null) { |
Lines 189-218
Link Here
|
189 |
|
214 |
|
190 |
MBeanServerConnection rmiServer = null; |
215 |
MBeanServerConnection rmiServer = null; |
191 |
try { |
216 |
try { |
192 |
conn = JMXConnectorFactory.connect(new JMXServiceURL( |
217 |
JMXServiceURL url; |
193 |
"service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi")); |
218 |
if (props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { |
|
|
219 |
// using management-native port |
220 |
url = new JMXServiceURL( |
221 |
System.getProperty("jmx.service.url", "service:jmx:remoting-jmx://localhost:9999")); // NOI18N |
222 |
} else { |
223 |
url = new JMXServiceURL( |
224 |
"service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"); // NOI18N |
225 |
} |
226 |
conn = JMXConnectorFactory.connect(url); |
194 |
|
227 |
|
195 |
rmiServer = conn.getMBeanServerConnection(); |
228 |
rmiServer = conn.getMBeanServerConnection(); |
196 |
} catch (IOException ex) { |
229 |
} catch (IOException ex) { |
197 |
LOGGER.log(Level.FINE, null, ex); |
230 |
LOGGER.log(Level.FINE, null, ex); |
198 |
} |
231 |
} |
199 |
|
232 |
|
200 |
if (rmiServer == null) { |
233 |
if (rmiServer == null && ctx != null) { |
201 |
// Lookup RMI Adaptor |
234 |
// Lookup RMI Adaptor |
202 |
rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); // NOI18N |
235 |
rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); // NOI18N |
203 |
} |
236 |
} |
204 |
|
237 |
|
205 |
JBoss5ProfileServiceProxy profileService = null; |
238 |
JBoss5ProfileServiceProxy profileService = null; |
206 |
try { |
239 |
try { |
207 |
Object service = ctx.lookup("ProfileService"); // NOI18N |
240 |
if (ctx != null) { |
208 |
if (service != null) { |
241 |
Object service = ctx.lookup("ProfileService"); // NOI18N |
209 |
profileService = new JBoss5ProfileServiceProxy(service); |
242 |
if (service != null) { |
|
|
243 |
profileService = new JBoss5ProfileServiceProxy(service); |
244 |
} |
210 |
} |
245 |
} |
211 |
} catch (NameNotFoundException ex) { |
246 |
} catch (NameNotFoundException ex) { |
212 |
LOGGER.log(Level.FINE, null, ex); |
247 |
LOGGER.log(Level.FINE, null, ex); |
213 |
} |
248 |
} |
214 |
|
249 |
|
215 |
return action.action(rmiServer, profileService); |
250 |
if (rmiServer != null) { |
|
|
251 |
return action.action(rmiServer, profileService); |
252 |
} else { |
253 |
throw new IllegalStateException("No rmi server acquired for " + realUri); |
254 |
} |
216 |
} catch (NameNotFoundException ex) { |
255 |
} catch (NameNotFoundException ex) { |
217 |
LOGGER.log(Level.FINE, null, ex); |
256 |
LOGGER.log(Level.FINE, null, ex); |
218 |
throw new ExecutionException(ex); |
257 |
throw new ExecutionException(ex); |
Lines 261-270
Link Here
|
261 |
propertiesToIsRunning.put(ip, isRunning); |
300 |
propertiesToIsRunning.put(ip, isRunning); |
262 |
} |
301 |
} |
263 |
|
302 |
|
|
|
303 |
boolean isAs7() { |
304 |
if (as7 == null) { |
305 |
as7 = getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); |
306 |
} |
307 |
return as7; |
308 |
} |
264 |
//////////////////////////////////////////////////////////////////////////// |
309 |
//////////////////////////////////////////////////////////////////////////// |
265 |
// DeploymentManager Implementation |
310 |
// DeploymentManager Implementation |
266 |
//////////////////////////////////////////////////////////////////////////// |
311 |
//////////////////////////////////////////////////////////////////////////// |
267 |
public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { |
312 |
public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { |
|
|
313 |
if (isAs7()) { |
314 |
return new JB7Deployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
315 |
} |
268 |
return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
316 |
return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
269 |
} |
317 |
} |
270 |
|
318 |
|
Lines 273-290
Link Here
|
273 |
} |
321 |
} |
274 |
|
322 |
|
275 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2) throws UnsupportedOperationException, IllegalStateException { |
323 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2) throws UnsupportedOperationException, IllegalStateException { |
|
|
324 |
if (isAs7()) { |
325 |
return dm.redeploy(translateForUndeploy(targetModuleID), inputStream, inputStream2); |
326 |
} |
276 |
return dm.redeploy(targetModuleID, inputStream, inputStream2); |
327 |
return dm.redeploy(targetModuleID, inputStream, inputStream2); |
277 |
} |
328 |
} |
278 |
|
329 |
|
279 |
public ProgressObject distribute(Target[] target, InputStream inputStream, InputStream inputStream2) throws IllegalStateException { |
330 |
public ProgressObject distribute(Target[] target, InputStream inputStream, InputStream inputStream2) throws IllegalStateException { |
280 |
return dm.distribute(target, inputStream, inputStream2); |
331 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
281 |
} |
332 |
} |
282 |
|
333 |
|
283 |
public ProgressObject distribute(Target[] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException { |
334 |
public ProgressObject distribute(Target[] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException { |
284 |
return distribute(target, inputStream, inputStream0); |
335 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
285 |
} |
336 |
} |
286 |
|
337 |
|
287 |
public ProgressObject undeploy(TargetModuleID[] targetModuleID) throws IllegalStateException { |
338 |
public ProgressObject undeploy(TargetModuleID[] targetModuleID) throws IllegalStateException { |
|
|
339 |
if (isAs7()) { |
340 |
return dm.undeploy(translateForUndeploy(targetModuleID)); |
341 |
} |
288 |
return dm.undeploy(targetModuleID); |
342 |
return dm.undeploy(targetModuleID); |
289 |
} |
343 |
} |
290 |
|
344 |
|
Lines 292-316
Link Here
|
292 |
return dm.stop(targetModuleID); |
346 |
return dm.stop(targetModuleID); |
293 |
} |
347 |
} |
294 |
|
348 |
|
295 |
public ProgressObject start(TargetModuleID[] targetModuleID) throws IllegalStateException { |
349 |
public ProgressObject start(final TargetModuleID[] targetModuleID) throws IllegalStateException { |
|
|
350 |
if (isAs7()) { |
351 |
try { |
352 |
return invokeLocalAction(new Callable<ProgressObject>() { |
353 |
|
354 |
@Override |
355 |
public ProgressObject call() { |
356 |
return dm.start(unwrap(targetModuleID)); |
357 |
} |
358 |
}); |
359 |
} catch (Exception ex) { |
360 |
LOGGER.log(Level.INFO, null, ex); |
361 |
} |
362 |
} |
363 |
|
296 |
return dm.start(targetModuleID); |
364 |
return dm.start(targetModuleID); |
297 |
} |
365 |
} |
298 |
|
366 |
|
299 |
public void setLocale(Locale locale) throws UnsupportedOperationException { |
|
|
300 |
dm.setLocale(locale); |
301 |
} |
302 |
|
303 |
public boolean isLocaleSupported(Locale locale) { |
304 |
return dm.isLocaleSupported(locale); |
305 |
} |
306 |
|
307 |
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
367 |
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
308 |
//return dm.getAvailableModules(moduleType, target); |
368 |
if (isAs7()) { |
|
|
369 |
TargetModuleID[] ids = dm.getAvailableModules(moduleType, target); |
370 |
if (ids != null) { |
371 |
return ids; |
372 |
} |
373 |
} |
309 |
return new TargetModuleID[]{}; |
374 |
return new TargetModuleID[]{}; |
310 |
} |
375 |
} |
311 |
|
376 |
|
312 |
public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
377 |
public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
313 |
//return dm.getNonRunningModules(moduleType, target); |
378 |
if (isAs7()) { |
|
|
379 |
return dm.getAvailableModules(moduleType, target); |
380 |
} |
314 |
return new TargetModuleID[]{}; |
381 |
return new TargetModuleID[]{}; |
315 |
} |
382 |
} |
316 |
|
383 |
|
Lines 319-335
Link Here
|
319 |
} |
386 |
} |
320 |
|
387 |
|
321 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws UnsupportedOperationException, IllegalStateException { |
388 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws UnsupportedOperationException, IllegalStateException { |
|
|
389 |
if (isAs7()) { |
390 |
return new JB7Deployer(realUri, this).redeploy(targetModuleID, file, file2); |
391 |
} |
322 |
return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); |
392 |
return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); |
323 |
} |
393 |
} |
324 |
|
394 |
|
325 |
public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType) throws DConfigBeanVersionUnsupportedException { |
|
|
326 |
dm.setDConfigBeanVersion(dConfigBeanVersionType); |
327 |
} |
328 |
|
329 |
public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) { |
330 |
return dm.isDConfigBeanVersionSupported(dConfigBeanVersionType); |
331 |
} |
332 |
|
333 |
public void release() { |
395 |
public void release() { |
334 |
if (dm != null) { |
396 |
if (dm != null) { |
335 |
dm.release(); |
397 |
dm.release(); |
Lines 340-359
Link Here
|
340 |
return dm.isRedeploySupported(); |
402 |
return dm.isRedeploySupported(); |
341 |
} |
403 |
} |
342 |
|
404 |
|
|
|
405 |
public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType) throws DConfigBeanVersionUnsupportedException { |
406 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
407 |
} |
408 |
|
409 |
public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) { |
410 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
411 |
} |
412 |
|
413 |
public void setLocale(Locale locale) throws UnsupportedOperationException { |
414 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
415 |
} |
416 |
|
417 |
public boolean isLocaleSupported(Locale locale) { |
418 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
419 |
} |
420 |
|
343 |
public Locale getCurrentLocale() { |
421 |
public Locale getCurrentLocale() { |
344 |
return dm.getCurrentLocale(); |
422 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
345 |
} |
423 |
} |
346 |
|
424 |
|
347 |
public DConfigBeanVersionType getDConfigBeanVersion() { |
425 |
public DConfigBeanVersionType getDConfigBeanVersion() { |
348 |
return dm.getDConfigBeanVersion(); |
426 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
349 |
} |
427 |
} |
350 |
|
428 |
|
351 |
public Locale getDefaultLocale() { |
429 |
public Locale getDefaultLocale() { |
352 |
return dm.getDefaultLocale(); |
430 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
353 |
} |
431 |
} |
354 |
|
432 |
|
355 |
public Locale[] getSupportedLocales() { |
433 |
public Locale[] getSupportedLocales() { |
356 |
return dm.getSupportedLocales(); |
434 |
throw new UnsupportedOperationException("This method should never be called!"); // NOI18N |
357 |
} |
435 |
} |
358 |
|
436 |
|
359 |
public Target[] getTargets() throws IllegalStateException { |
437 |
public Target[] getTargets() throws IllegalStateException { |
Lines 388-391
Link Here
|
388 |
public synchronized boolean getNeedsRestart() { |
466 |
public synchronized boolean getNeedsRestart() { |
389 |
return needsRestart; |
467 |
return needsRestart; |
390 |
} |
468 |
} |
|
|
469 |
|
470 |
// we are doing this because undeployment/redeployment as implemented |
471 |
// in current AS7 expect URL as module ID, though the server seturned IDs |
472 |
// are just filenames |
473 |
private TargetModuleID[] translateForUndeploy(TargetModuleID[] ids) { |
474 |
final String deployDir = getInstanceProperties().getProperty(JBPluginProperties.PROPERTY_DEPLOY_DIR); |
475 |
if (deployDir != null) { |
476 |
TargetModuleID[] ret = new TargetModuleID[ids.length]; |
477 |
for (int i = 0; i < ids.length; i++) { |
478 |
File testFile = new File(deployDir, ids[i].getModuleID()); |
479 |
if (testFile.exists()) { |
480 |
// XXX is this needed ? |
481 |
File markFile = new File(deployDir, ids[i].getModuleID() + ".deployed"); // NOI18N |
482 |
if (markFile.isFile()) { |
483 |
try { |
484 |
ret[i] = new WrappedTargetModuleID(ids[i], null, testFile.toURI().toURL().toString(), null); |
485 |
continue; |
486 |
} catch (MalformedURLException ex) { |
487 |
LOGGER.log(Level.FINE, null, ex); |
488 |
} |
489 |
} |
490 |
} |
491 |
ret[i] = ids[i]; |
492 |
} |
493 |
return ret; |
494 |
} |
495 |
return ids; |
496 |
} |
497 |
|
498 |
private static TargetModuleID[] unwrap(TargetModuleID[] ids) { |
499 |
if (ids == null || ids.length == 0) { |
500 |
return ids; |
501 |
} |
502 |
TargetModuleID[] ret = new TargetModuleID[ids.length]; |
503 |
for (int i = 0; i < ids.length; i++) { |
504 |
if (ids[i] instanceof WrappedTargetModuleID) { |
505 |
ret[i] = ((WrappedTargetModuleID) ids[i]).getOriginal(); |
506 |
} else { |
507 |
ret[i] = ids[i]; |
508 |
} |
509 |
} |
510 |
return ret; |
511 |
} |
391 |
} |
512 |
} |