use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.
the class MQAddressList method getDefaultJmsHost.
public JmsHost getDefaultJmsHost(JmsService jmsService) {
String defaultJmsHost = jmsService.getDefaultJmsHost();
List<JmsHost> jmsHosts = jmsService.getJmsHost();
JmsHost jmsHost = null;
if (defaultJmsHost != null && !defaultJmsHost.equals("") && jmsHosts != null && jmsHosts.size() > 0) {
for (int i = 0; i < jmsHosts.size(); i++) if (defaultJmsHost.equals((jmsHosts.get(i)).getName()))
return (JmsHost) jmsHosts.get(i);
}
if (jmsHosts != null && jmsHosts.size() > 0)
jmsHost = jmsHosts.get(0);
else
jmsHost = Globals.get(JmsHost.class);
return jmsHost;
}
use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.
the class ActiveJmsResourceAdapter method initializeLazyListener.
/**
* Start Grizzly based JMS lazy listener, which is going to initialize
* JMS container on first request.
* @param jmsService
* @throws com.sun.enterprise.connectors.jms.system.JmsInitialisationException
*/
public void initializeLazyListener(JmsService jmsService) throws JmsInitialisationException {
if (jmsService != null && jmsService.getType().equals("DISABLED")) {
return;
}
if (jmsService != null) {
if (EMBEDDED.equalsIgnoreCase(jmsService.getType()) && !grizzlyListenerInit) {
GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
if (grizzlyService != null) {
List<JmsHost> jmsHosts = jmsService.getJmsHost();
for (JmsHost oneHost : jmsHosts) {
if (Boolean.valueOf(oneHost.getLazyInit()) && !doBind) {
String jmsHost = null;
if (oneHost.getHost() != null && "localhost".equals(oneHost.getHost())) {
jmsHost = "0.0.0.0";
} else {
jmsHost = oneHost.getHost();
}
NetworkListener dummy = new DummyNetworkListener();
dummy.setPort(oneHost.getPort());
dummy.setAddress(jmsHost);
dummy.setType("proxy");
dummy.setProtocol(JMS_SERVICE);
dummy.setTransport("tcp");
String name = GRIZZLY_PROXY_PREFIX + oneHost.getName();
dummy.setName(name);
synchronized (grizzlyListeners) {
Future<Result<Thread>> createNetworkProxy = grizzlyService.createNetworkProxy(dummy);
try {
Result<Thread> result = createNetworkProxy.get();
if (result.exception() != null) {
throw new JmsInitialisationException(MessageFormat.format("Cannot initialise JMS broker listener on {0}:{1}", oneHost.getHost(), oneHost.getPort()), result.exception());
}
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
}
grizzlyListeners.add(name);
}
grizzlyListenerInit = true;
}
}
}
}
}
}
use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.
the class JMSDestination method _getMQJMXConnectorInfo.
protected MQJMXConnectorInfo _getMQJMXConnectorInfo(String targetName, JmsService jmsService, Class mqRAClassName, ServerContext serverContext, Config config, Domain domain) throws ConnectorRuntimeException {
try {
// If DAS, use the default address list, else obtain
String connectionURL = null;
MQAddressList mqadList = new MQAddressList();
if (getTypeForTarget(targetName) == CommandTarget.DAS) {
connectionURL = getDefaultAddressList(jmsService).toString();
} else {
// Standalone server instance
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "not in DAS");
logger.log(Level.FINE, " _getMQJMXConnectorInfo - NOT in DAS");
}
JmsService serverJmsService = getJmsServiceOfStandaloneServerInstance(targetName, config, domain);
// MQAddressList mqadList = new MQAddressList(serverJmsService, targetName);
mqadList.setJmsService(serverJmsService);
mqadList.setTargetName(targetName);
mqadList.setup(false);
connectionURL = mqadList.toString();
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, " _getMQJMXConnectorInfo - connection URL " + connectionURL);
}
String adminUserName = null;
String adminPassword = null;
JmsHost jmsHost = mqadList.getDefaultJmsHost(jmsService);
if (jmsHost != null) {
// && jmsHost.isEnabled()) {
adminUserName = jmsHost.getAdminUserName();
adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
} else {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, " _getMQJMXConnectorInfo, using default jms admin user and password ");
}
}
ResourceAdapter raInstance = getConfiguredRA(mqRAClassName, connectionURL, adminUserName, adminPassword);
String jmxServiceURL = null, jmxServiceURLList = null;
Map<String, ?> jmxConnectorEnv = null;
Method[] methds = raInstance.getClass().getMethods();
for (int i = 0; i < methds.length; i++) {
Method m = methds[i];
if (m.getName().equalsIgnoreCase("get" + JMXSERVICEURLLIST)) {
jmxServiceURLList = (String) m.invoke(raInstance, new Object[] {});
} else if (m.getName().equalsIgnoreCase("get" + JMXCONNECTORENV)) {
jmxConnectorEnv = (Map<String, ?>) m.invoke(raInstance, new Object[] {});
}
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, " _getMQJMXConnectorInfo - jmxServiceURLList " + jmxServiceURLList);
logger.log(Level.FINE, " _getMQJMXConnectorInfo - jmxConnectorEnv " + jmxConnectorEnv);
}
jmxServiceURL = getFirstJMXServiceURL(jmxServiceURLList);
MQJMXConnectorInfo mqInfo = new MQJMXConnectorInfo(targetName, ActiveJmsResourceAdapter.getBrokerInstanceName(jmsService), jmsService.getType(), jmxServiceURL, jmxConnectorEnv);
return mqInfo;
} catch (Exception e) {
e.printStackTrace();
ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
cre.initCause(e);
throw cre;
}
}
use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.
the class ListJMSHosts method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Config targetConfig = domain.getConfigNamed(target);
if (targetConfig != null)
config = targetConfig;
Server targetServer = domain.getServerNamed(target);
// String configRef = targetServer.getConfigRef();
if (targetServer != null) {
config = domain.getConfigNamed(targetServer.getConfigRef());
}
com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
config = domain.getConfigNamed(cluster.getConfigRef());
}
JmsService jmsService = config.getExtensionByType(JmsService.class);
if (jmsService == null) {
report.setMessage(localStrings.getLocalString("list.jms.host.invalidTarget", "Invalid Target specified."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ArrayList<String> list = new ArrayList();
for (JmsHost r : jmsService.getJmsHost()) {
list.add(r.getName());
}
for (String jmsName : list) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jmsName);
}
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.jms.host.fail", "Unable to list JMS Hosts") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.
the class CreateJMSHost method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Config targetConfig = domain.getConfigNamed(target);
if (targetConfig != null)
config = targetConfig;
Server targetServer = domain.getServerNamed(target);
// String configRef = targetServer.getConfigRef();
if (targetServer != null) {
config = domain.getConfigNamed(targetServer.getConfigRef());
}
com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
config = domain.getConfigNamed(cluster.getConfigRef());
}
if (jmsHostName == null) {
report.setMessage(localStrings.getLocalString("create.jms.host.noJmsHost", "No JMS Host name specified."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
JmsService jmsservice = config.getExtensionByType(JmsService.class);
// ensure we don't already have one of this name before creating it.
for (JmsHost jmsHost : jmsservice.getJmsHost()) {
if (jmsHostName.equals(jmsHost.getName())) {
if (force) {
ActionReport deleteReport = report.addSubActionsReport();
ParameterMap parameters = new ParameterMap();
parameters.set("DEFAULT", jmsHostName);
parameters.set("target", target);
commandRunner.getCommandInvocation("delete-jms-host", deleteReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
break;
} else {
report.setMessage(localStrings.getLocalString("create.jms.host.duplicate", "A JMS Host named {0} already exists.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
// TODO: need a way to create a JmsHost instance
JmsHost jmsHost = param.createChild(JmsHost.class);
jmsHost.setAdminPassword(mqpassword);
jmsHost.setAdminUserName(mquser);
jmsHost.setName(jmsHostName);
jmsHost.setHost(mqhost);
jmsHost.setPort(mqport);
if (props != null) {
for (Map.Entry e : props.entrySet()) {
Property prop = jmsHost.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
jmsHost.getProperty().add(prop);
}
}
param.getJmsHost().add(jmsHost);
return jmsHost;
}
}, jmsservice);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("create.jms.host.fail", "Unable to create jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("create.jms.host.success", "Jms Host {0} created.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations