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 55-60
Link Here
|
55 |
import java.net.URLClassLoader; |
56 |
import java.net.URLClassLoader; |
56 |
import java.util.Locale; |
57 |
import java.util.Locale; |
57 |
import java.util.Properties; |
58 |
import java.util.Properties; |
|
|
59 |
import java.util.concurrent.Callable; |
58 |
import java.util.concurrent.ExecutionException; |
60 |
import java.util.concurrent.ExecutionException; |
59 |
import java.util.logging.Level; |
61 |
import java.util.logging.Level; |
60 |
import java.util.logging.Logger; |
62 |
import java.util.logging.Logger; |
Lines 78-83
Link Here
|
78 |
import javax.naming.NamingException; |
80 |
import javax.naming.NamingException; |
79 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
81 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; |
80 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; |
82 |
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; |
|
|
83 |
import org.openide.util.Exceptions; |
81 |
|
84 |
|
82 |
/** |
85 |
/** |
83 |
* |
86 |
* |
Lines 94-107
Link Here
|
94 |
|
97 |
|
95 |
private InstanceProperties instanceProperties; |
98 |
private InstanceProperties instanceProperties; |
96 |
private boolean needsRestart; |
99 |
private boolean needsRestart; |
97 |
|
100 |
private Boolean as7; |
98 |
/** |
101 |
/** |
99 |
* Stores information about running instances. instance is represented by its InstanceProperties, |
102 |
* Stores information about running instances. instance is represented by its InstanceProperties, |
100 |
* running state by Boolean.TRUE, stopped state Boolean.FALSE. |
103 |
* 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. |
104 |
* WeakHashMap should guarantee erasing of an unregistered server instance bcs instance properties are also removed along with instance. |
102 |
*/ |
105 |
*/ |
103 |
private static final Map<InstanceProperties, Boolean> propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap()); |
106 |
private static final Map<InstanceProperties, Boolean> propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap()); |
104 |
|
107 |
|
105 |
/** Creates a new instance of JBDeploymentManager */ |
108 |
/** Creates a new instance of JBDeploymentManager */ |
106 |
public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { |
109 |
public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { |
107 |
realUri = uri; |
110 |
realUri = uri; |
Lines 139-144
Link Here
|
139 |
return instanceProperties; |
142 |
return instanceProperties; |
140 |
} |
143 |
} |
141 |
|
144 |
|
|
|
145 |
/** |
146 |
* This is a handy method to execute the any {@code action} within JBoss's class loader. |
147 |
* |
148 |
* @param action the action to be executed |
149 |
* @return T |
150 |
* @throws ExecutionException |
151 |
*/ |
152 |
public <T> T invokeLocalAction(Callable<T> action) throws Exception { |
153 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
154 |
try { |
155 |
InstanceProperties ip = getInstanceProperties(); |
156 |
URLClassLoader loader = JBDeploymentFactory.getJBClassLoader(ip); |
157 |
Thread.currentThread().setContextClassLoader(loader); |
158 |
return action.call(); |
159 |
} finally { |
160 |
Thread.currentThread().setContextClassLoader(oldLoader); |
161 |
} |
162 |
} |
163 |
|
142 |
public <T> T invokeRemoteAction(JBRemoteAction<T> action) throws ExecutionException { |
164 |
public <T> T invokeRemoteAction(JBRemoteAction<T> action) throws ExecutionException { |
143 |
|
165 |
|
144 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
166 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
Lines 177-184
Link Here
|
177 |
System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); // NOI18N |
199 |
System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); // NOI18N |
178 |
} |
200 |
} |
179 |
|
201 |
|
180 |
// Gets naming context |
202 |
if (!props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { |
181 |
ctx = new InitialContext(env); |
203 |
// Gets naming context |
|
|
204 |
ctx = new InitialContext(env); |
205 |
} |
182 |
|
206 |
|
183 |
//restore java.security.auth.login.config system property |
207 |
//restore java.security.auth.login.config system property |
184 |
if (oldAuthConf != null) { |
208 |
if (oldAuthConf != null) { |
Lines 189-218
Link Here
|
189 |
|
213 |
|
190 |
MBeanServerConnection rmiServer = null; |
214 |
MBeanServerConnection rmiServer = null; |
191 |
try { |
215 |
try { |
192 |
conn = JMXConnectorFactory.connect(new JMXServiceURL( |
216 |
JMXServiceURL url; |
193 |
"service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi")); |
217 |
if (props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { |
|
|
218 |
// using management-native port |
219 |
url = new JMXServiceURL( |
220 |
System.getProperty("jmx.service.url", "service:jmx:remoting-jmx://localhost:9999")); // NOI18N |
221 |
} else { |
222 |
url = new JMXServiceURL( |
223 |
"service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"); // NOI18N |
224 |
} |
225 |
conn = JMXConnectorFactory.connect(url); |
194 |
|
226 |
|
195 |
rmiServer = conn.getMBeanServerConnection(); |
227 |
rmiServer = conn.getMBeanServerConnection(); |
196 |
} catch (IOException ex) { |
228 |
} catch (IOException ex) { |
197 |
LOGGER.log(Level.FINE, null, ex); |
229 |
LOGGER.log(Level.FINE, null, ex); |
198 |
} |
230 |
} |
199 |
|
231 |
|
200 |
if (rmiServer == null) { |
232 |
if (rmiServer == null && ctx != null) { |
201 |
// Lookup RMI Adaptor |
233 |
// Lookup RMI Adaptor |
202 |
rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); // NOI18N |
234 |
rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); // NOI18N |
203 |
} |
235 |
} |
204 |
|
236 |
|
205 |
JBoss5ProfileServiceProxy profileService = null; |
237 |
JBoss5ProfileServiceProxy profileService = null; |
206 |
try { |
238 |
try { |
207 |
Object service = ctx.lookup("ProfileService"); // NOI18N |
239 |
if (ctx != null) { |
208 |
if (service != null) { |
240 |
Object service = ctx.lookup("ProfileService"); // NOI18N |
209 |
profileService = new JBoss5ProfileServiceProxy(service); |
241 |
if (service != null) { |
|
|
242 |
profileService = new JBoss5ProfileServiceProxy(service); |
243 |
} |
210 |
} |
244 |
} |
211 |
} catch (NameNotFoundException ex) { |
245 |
} catch (NameNotFoundException ex) { |
212 |
LOGGER.log(Level.FINE, null, ex); |
246 |
LOGGER.log(Level.FINE, null, ex); |
213 |
} |
247 |
} |
214 |
|
248 |
|
215 |
return action.action(rmiServer, profileService); |
249 |
if (rmiServer != null) { |
|
|
250 |
return action.action(rmiServer, profileService); |
251 |
} else { |
252 |
throw new IllegalStateException("No rmi server acquired for " + realUri); |
253 |
} |
216 |
} catch (NameNotFoundException ex) { |
254 |
} catch (NameNotFoundException ex) { |
217 |
LOGGER.log(Level.FINE, null, ex); |
255 |
LOGGER.log(Level.FINE, null, ex); |
218 |
throw new ExecutionException(ex); |
256 |
throw new ExecutionException(ex); |
Lines 261-273
Link Here
|
261 |
propertiesToIsRunning.put(ip, isRunning); |
299 |
propertiesToIsRunning.put(ip, isRunning); |
262 |
} |
300 |
} |
263 |
|
301 |
|
|
|
302 |
boolean isAs7() { |
303 |
if (as7 == null) { |
304 |
as7 = getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); |
305 |
} |
306 |
return as7; |
307 |
} |
264 |
//////////////////////////////////////////////////////////////////////////// |
308 |
//////////////////////////////////////////////////////////////////////////// |
265 |
// DeploymentManager Implementation |
309 |
// DeploymentManager Implementation |
266 |
//////////////////////////////////////////////////////////////////////////// |
310 |
//////////////////////////////////////////////////////////////////////////// |
267 |
public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { |
311 |
public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { |
|
|
312 |
if (isAs7()) { |
313 |
return new JB7Deployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
314 |
} |
268 |
return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
315 |
return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); |
269 |
} |
316 |
} |
270 |
|
317 |
|
|
|
318 |
public ProgressObject distributeTarget(Target[] target, File file, File file2) throws IllegalStateException { |
319 |
return dm.distribute(target, file, file2); |
320 |
} |
321 |
|
271 |
public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { |
322 |
public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { |
272 |
throw new RuntimeException("This method should never be called."); // NOI18N |
323 |
throw new RuntimeException("This method should never be called."); // NOI18N |
273 |
} |
324 |
} |
Lines 292-298
Link Here
|
292 |
return dm.stop(targetModuleID); |
343 |
return dm.stop(targetModuleID); |
293 |
} |
344 |
} |
294 |
|
345 |
|
295 |
public ProgressObject start(TargetModuleID[] targetModuleID) throws IllegalStateException { |
346 |
public ProgressObject start(final TargetModuleID[] targetModuleID) throws IllegalStateException { |
|
|
347 |
if (isAs7()) { |
348 |
try { |
349 |
return invokeLocalAction(new Callable<ProgressObject>() { |
350 |
|
351 |
@Override |
352 |
public ProgressObject call() { |
353 |
return dm.start(unwrap(targetModuleID)); |
354 |
} |
355 |
}); |
356 |
} catch (Exception ex) { |
357 |
LOGGER.log(Level.INFO, null, ex); |
358 |
} |
359 |
} |
360 |
|
296 |
return dm.start(targetModuleID); |
361 |
return dm.start(targetModuleID); |
297 |
} |
362 |
} |
298 |
|
363 |
|
Lines 305-316
Link Here
|
305 |
} |
370 |
} |
306 |
|
371 |
|
307 |
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
372 |
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
308 |
//return dm.getAvailableModules(moduleType, target); |
373 |
if (isAs7()) { |
|
|
374 |
return dm.getAvailableModules(moduleType, target); |
375 |
} |
309 |
return new TargetModuleID[]{}; |
376 |
return new TargetModuleID[]{}; |
310 |
} |
377 |
} |
311 |
|
378 |
|
312 |
public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
379 |
public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { |
313 |
//return dm.getNonRunningModules(moduleType, target); |
380 |
if (isAs7()) { |
|
|
381 |
return dm.getAvailableModules(moduleType, target); |
382 |
} |
314 |
return new TargetModuleID[]{}; |
383 |
return new TargetModuleID[]{}; |
315 |
} |
384 |
} |
316 |
|
385 |
|
Lines 319-324
Link Here
|
319 |
} |
388 |
} |
320 |
|
389 |
|
321 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws UnsupportedOperationException, IllegalStateException { |
390 |
public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws UnsupportedOperationException, IllegalStateException { |
|
|
391 |
if (isAs7()) { |
392 |
return new JB7Deployer(realUri, this).redeploy(targetModuleID, file, file2); |
393 |
} |
322 |
return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); |
394 |
return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); |
323 |
} |
395 |
} |
324 |
|
396 |
|
Lines 388-391
Link Here
|
388 |
public synchronized boolean getNeedsRestart() { |
460 |
public synchronized boolean getNeedsRestart() { |
389 |
return needsRestart; |
461 |
return needsRestart; |
390 |
} |
462 |
} |
|
|
463 |
|
464 |
private static TargetModuleID[] unwrap(TargetModuleID[] ids) { |
465 |
if (ids == null || ids.length == 0) { |
466 |
return ids; |
467 |
} |
468 |
TargetModuleID[] ret = new TargetModuleID[ids.length]; |
469 |
for (int i = 0; i < ids.length; i++) { |
470 |
if (ids[i] instanceof WrappedTargetModuleID) { |
471 |
ret[i] = ((WrappedTargetModuleID) ids[i]).getOriginal(); |
472 |
} else { |
473 |
ret[i] = ids[i]; |
474 |
} |
475 |
} |
476 |
return ret; |
477 |
} |
391 |
} |
478 |
} |