Commit bc617eab authored by Andre Freyssinet's avatar Andre Freyssinet

Adds a constructor with ConnectionFactory as parameter.

parent eaf58e42
......@@ -198,16 +198,51 @@ public final class JMSConnectorCheck {
String user, String pass,
String qname,
int timeOut) {
if (cfname == null)
throw new IllegalArgumentException("Shall define ConnectionFactory name");
this.cfname = cfname;
if (ictx == null)
throw new IllegalArgumentException("Shall define JNDI initial context");
this.ictx = ictx;
this.user = user;
this.pass = pass;
if (qname == null)
throw new IllegalArgumentException("Shall define Queue name");
this.qname = qname;
this.timeout = timeOut;
}
/**
* Creates a new component allowing to check a JMS connector.
*
* @param cf ConnectionFactory to use.
* @param user User name for authentication, if no defined uses the ConnectionFactory default.
* @param pass Password for authentication, if no defined uses the ConnectionFactory default.
* @param qname Internal name of JMS destination.
* @param timeout Maximum amount of time to wait connecting and receiving messages, by default 10s.
*/
public JMSConnectorCheck(ConnectionFactory cf,
String user, String pass,
String qname,
int timeOut) {
if (cf == null)
throw new IllegalArgumentException("Shall define ConnectionFactory");
this.cf = cf;
this.user = user;
this.pass = pass;
if (qname == null)
throw new IllegalArgumentException("Shall define Queue name");
this.timeout = timeOut;
}
private void getConnectionFactory() throws NamingException {
if (cf != null) return;
......@@ -239,7 +274,7 @@ public final class JMSConnectorCheck {
*/
public boolean check() {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "JMSConnectorStatus(" + cfname + ").check");
logger.log(BasicLevel.DEBUG, "JMSConnectorStatus(" + ((cfname == null)?"":cfname) + ").check");
nbtry += 1;
try {
......@@ -251,9 +286,9 @@ public final class JMSConnectorCheck {
setLatencyPubSub(-1L);
errorMsg = "Cannot get ConnectionFactory";
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + ")<: Cannot get ConnectionFactory.", exc);
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + ")<: Cannot get ConnectionFactory.", exc);
else
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Cannot get ConnectionFactory.");
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Cannot get ConnectionFactory.");
return false;
}
......@@ -274,9 +309,9 @@ public final class JMSConnectorCheck {
setLatencyPubSub(-1L);
errorMsg = "Cannot connect";
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Cannot connect.", exc);
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Cannot connect.", exc);
else
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Cannot connect.");
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Cannot connect.");
return false;
}
......@@ -312,18 +347,18 @@ public final class JMSConnectorCheck {
setLatencyPubSub(-1L);
errorMsg = "Error during message send/receive.";
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Error during message send/receive.", exc);
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Error during message send/receive.", exc);
else
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Error during message send/receive.");
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Error during message send/receive.");
return false;
} finally {
try {
cnx.close();
} catch (JMSException exc) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Error closing connection.", exc);
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Error closing connection.", exc);
else
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + cfname + "): Error closing connection.");
logger.log(BasicLevel.WARN, "JMSConnectorStatus.check(" + ((cfname == null)?"":cfname) + "): Error closing connection.");
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment