svn commit: r930988 - /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java
Author: sebb Date: Tue Apr 6 00:23:16 2010 New Revision: 930988 URL: http://svn.apache.org/viewvc?rev=930988view=rev Log: Javadoc; no need for lookupTopic() to be synch. Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java?rev=930988r1=930987r2=930988view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java Tue Apr 6 00:23:16 2010 @@ -41,16 +41,27 @@ public class InitialContextFactory { private static final Logger log = LoggingManager.getLoggerForClass(); -public static synchronized Context lookupContext(String jndi, String url, boolean useAuth, String user, String pwd) { -Context ctx = MAP.get(jndi + url); +/** + * Look up the context from the local cache, creating it if necessary. + * + * @param initialContextFactory used to set the property {...@link Context#INITIAL_CONTEXT_FACTORY} + * @param providerUrl used to set the property {...@link Context#PROVIDER_URL} + * @param useAuth set true if security is to be used. + * @param securityPrincipal used to set the property {...@link Context#SECURITY_PRINCIPAL} + * @param securityCredentials used to set the property {...@link Context#SECURITY_CREDENTIALS} + * @return the context, may be null + */ +public static synchronized Context lookupContext(String initialContextFactory, +String providerUrl, boolean useAuth, String securityPrincipal, String securityCredentials) { +Context ctx = MAP.get(initialContextFactory + providerUrl); if (ctx == null) { Properties props = new Properties(); -props.setProperty(Context.INITIAL_CONTEXT_FACTORY, jndi); -props.setProperty(Context.PROVIDER_URL, url); -if (useAuth user != null pwd != null - user.length() 0 pwd.length() 0) { -props.setProperty(Context.SECURITY_PRINCIPAL, user); -props.setProperty(Context.SECURITY_CREDENTIALS, pwd); +props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); +props.setProperty(Context.PROVIDER_URL, providerUrl); +if (useAuth securityPrincipal != null securityCredentials != null + securityPrincipal.length() 0 securityCredentials.length() 0) { +props.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal); +props.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials); log.info(authentication properties set); } try { @@ -60,7 +71,7 @@ public class InitialContextFactory { log.error(lookupContext:: + e.getMessage()); } if (ctx != null) { -MAP.put(jndi + url, ctx); +MAP.put(initialContextFactory + providerUrl, ctx); } } return ctx; @@ -73,7 +84,9 @@ public class InitialContextFactory { * @param name * @return the topic or null */ -public static synchronized Topic lookupTopic(Context ctx, String name) { +// TODO this method probably belongs in a separate utility class. +// Also, why allow null input? Better to throw NPE or IAE +public static Topic lookupTopic(Context ctx, String name) { Topic t = null; if (name != null ctx != null) { try { - To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org
svn commit: r930993 - /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java
Author: sebb Date: Tue Apr 6 01:07:29 2010 New Revision: 930993 URL: http://svn.apache.org/viewvc?rev=930993view=rev Log: Clarify log message Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java?rev=930993r1=930992r2=930993view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/InitialContextFactory.java Tue Apr 6 01:07:29 2010 @@ -66,7 +66,7 @@ public class InitialContextFactory { } try { ctx = new InitialContext(props); -log.info(created the JNDI initial context factory); +log.info(created the JNDI initial context for the factory); } catch (NamingException e) { log.error(lookupContext:: + e.getMessage()); } - To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org
svn commit: r930994 - /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java
Author: sebb Date: Tue Apr 6 01:44:08 2010 New Revision: 930994 URL: http://svn.apache.org/viewvc?rev=930994view=rev Log: Javadoc; general tidyup Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java?rev=930994r1=930993r2=930994view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ConnectionFactory.java Tue Apr 6 01:44:08 2010 @@ -98,19 +98,29 @@ public class ConnectionFactory implement public void testIterationStart(LoopIterationEvent event) { } -public static synchronized TopicConnectionFactory getTopicConnectionFactory(Context ctx, String fac) { +/** + * Get the cached TopicConnectionFactory. + * + * @param ctx the context to use + * @param factoryName the name of the factory + * @return the factory, or null if it could not be found + */ +public static synchronized TopicConnectionFactory getTopicConnectionFactory(Context ctx, String factoryName) { int counter = MAX_RETRY; while (factory == null counter 0) { try { - Object objfac = ctx.lookup(fac); + Object objfac = ctx.lookup(factoryName); if (objfac instanceof TopicConnectionFactory) { factory = (TopicConnectionFactory) objfac; + } else { + log.error(Expected TopicConnectionFactory, found +objfac.getClass().getName()); + break; } } catch (NamingException e) { if (counter == MAX_RETRY) { -log.error(Unable to find connection factory + fac + , will retry. Error: + e.toString()); +log.error(Unable to find topic connection factory + factoryName + , will retry. Error: + e.toString()); } else if (counter == 1) { -log.error(Unable to find connection factory + fac + , giving up. Error: + e.toString()); +log.error(Unable to find topic connection factory + factoryName + , giving up. Error: + e.toString()); } counter--; try { @@ -123,19 +133,29 @@ public class ConnectionFactory implement return factory; } -public static synchronized QueueConnectionFactory getQueueConnectionFactory(Context ctx, String fac) { +/** + * Get the cached QueueConnectionFactory. + * + * @param ctx the context to use + * @param factoryName the queue factory name + * @return the factory, or null if the factory could not be found + */ +public static synchronized QueueConnectionFactory getQueueConnectionFactory(Context ctx, String factoryName) { int counter = MAX_RETRY; while (qfactory == null counter 0) { try { - Object objfac = ctx.lookup(fac); + Object objfac = ctx.lookup(factoryName); if (objfac instanceof QueueConnectionFactory) { qfactory = (QueueConnectionFactory) objfac; + } else { + log.error(Expected QueueConnectionFactory, found +objfac.getClass().getName()); + break; } } catch (NamingException e) { if (counter == MAX_RETRY) { -log.error(Unable to find connection factory + fac + , will retry. Error: + e.toString()); +log.error(Unable to find queue connection factory + factoryName + , will retry. Error: + e.toString()); } else if (counter == 1) { -log.error(Unable to find connection factory + fac + , giving up. Error: + e.toString()); +log.error(Unable to find queue connection factory + factoryName + , giving up. Error: + e.toString()); } counter--; try { - To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org
svn commit: r930995 - /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
Author: sebb Date: Tue Apr 6 01:44:54 2010 New Revision: 930995 URL: http://svn.apache.org/viewvc?rev=930995view=rev Log: Prevent NPEs General tidyup Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=930995r1=930994r2=930995view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Tue Apr 6 01:44:54 2010 @@ -37,25 +37,31 @@ public class Publisher { private static final Logger log = LoggingManager.getLoggerForClass(); -private TopicConnection CONN = null; +private TopicConnection connection = null; -private TopicSession SESSION = null; +private TopicSession session = null; -private Topic TOPIC = null; +private Topic topic = null; -private TopicPublisher PUBLISHER = null; - -//private byte[] RESULT = null; - -//private Object OBJ_RESULT = null; +private TopicPublisher publisher = null; /** - * + * Create a publisher using either the jndi.properties file or the provided parameters + * @param useProps true if a jndi.properties file is to be used + * @param initialContextFactory the (ignored if useProps is true) + * @param providerUrl (ignored if useProps is true) + * @param connfactory + * @param topic + * @param useAuth (ignored if useProps is true) + * @param securityPrincipal (ignored if useProps is true) + * @param securityCredentials (ignored if useProps is true) */ -public Publisher(boolean useProps, String jndi, String url, String connfactory, String topic, boolean useAuth, -String user, String pwd) { +public Publisher(boolean useProps, String initialContextFactory, String providerUrl, +String connfactory, String topic, boolean useAuth, +String securityPrincipal, String securityCredentials) { super(); -Context ctx = initJNDI(useProps, jndi, url, useAuth, user, pwd); +Context ctx = initJNDI(useProps, initialContextFactory, +providerUrl, useAuth, securityPrincipal, securityCredentials); if (ctx != null) { initConnection(ctx, connfactory, topic); } else { @@ -63,7 +69,8 @@ public class Publisher { } } -private Context initJNDI(boolean useProps, String jndi, String url, boolean useAuth, String user, String pwd) { +private Context initJNDI(boolean useProps, String initialContextFactory, +String providerUrl, boolean useAuth, String securityPrincipal, String securityCredentials) { if (useProps) { try { return new InitialContext(); @@ -72,17 +79,18 @@ public class Publisher { return null; } } else { -return InitialContextFactory.lookupContext(jndi, url, useAuth, user, pwd); +return InitialContextFactory.lookupContext(initialContextFactory, +providerUrl, useAuth, securityPrincipal, securityCredentials); } } -private void initConnection(Context ctx, String connfactory, String topic) { +private void initConnection(Context ctx, String connfactory, String topicName) { try { ConnectionFactory.getTopicConnectionFactory(ctx,connfactory); -this.CONN = ConnectionFactory.getTopicConnection(); -this.TOPIC = InitialContextFactory.lookupTopic(ctx, topic); -this.SESSION = this.CONN.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); -this.PUBLISHER = this.SESSION.createPublisher(this.TOPIC); +connection = ConnectionFactory.getTopicConnection(); +topic = InitialContextFactory.lookupTopic(ctx, topicName); +session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); +publisher = session.createPublisher(topic); log.info(created the topic connection successfully); } catch (JMSException e) { log.error(Connection error: + e.getMessage()); @@ -91,8 +99,8 @@ public class Publisher { public void publish(String text) { try { -TextMessage msg = this.SESSION.createTextMessage(text); -this.PUBLISHER.publish(msg); +TextMessage msg = session.createTextMessage(text); +publisher.publish(msg); } catch (JMSException e) { log.error(e.getMessage()); } @@ -100,25 +108,31 @@ public class Publisher { public void publish(Serializable contents)
svn commit: r930998 - in /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms: client/Publisher.java sampler/PublisherSampler.java
Author: sebb Date: Tue Apr 6 02:06:16 2010 New Revision: 930998 URL: http://svn.apache.org/viewvc?rev=930998view=rev Log: Basic check to ensure that Publisher failures are better reported in test results Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=930998r1=930997r2=930998view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Tue Apr 6 02:06:16 2010 @@ -45,6 +45,8 @@ public class Publisher { private TopicPublisher publisher = null; +public final boolean isValid; + /** * Create a publisher using either the jndi.properties file or the provided parameters * @param useProps true if a jndi.properties file is to be used @@ -56,6 +58,8 @@ public class Publisher { * @param securityPrincipal (ignored if useProps is true) * @param securityCredentials (ignored if useProps is true) */ +// TODO - does it make sense to return a Publisher that has not been created successfully? +// Might be simpler just to return JMSException public Publisher(boolean useProps, String initialContextFactory, String providerUrl, String connfactory, String topic, boolean useAuth, String securityPrincipal, String securityCredentials) { @@ -67,6 +71,7 @@ public class Publisher { } else { log.error(Could not initialize JNDI Initial Context Factory); } +isValid = publisher != null; // This is the last item set up by initConnection } private Context initJNDI(boolean useProps, String initialContextFactory, Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java?rev=930998r1=930997r2=930998view=diff == --- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java (original) +++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java Tue Apr 6 02:06:16 2010 @@ -128,12 +128,15 @@ public class PublisherSampler extends Ba public SampleResult sample() { SampleResult result = new SampleResult(); result.setSampleLabel(getName()); +result.setSuccessful(false); // Assume it will fail +result.setResponseCode(000); // ditto $NON-NLS-1$ +result.setResponseMessage(See log file for details); // ditto if (publisher == null) { initClient(); } StringBuilder buffer = new StringBuilder(); int loop = getIterationCount(); -if (publisher != null) { +if (publisher != null publisher.isValid) { result.sampleStart(); for (int idx = 0; idx loop; idx++) { String tmsg = getMessageContent(); - To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org
Graham Little is out of the office.
I will be out of the office starting 06/04/2010 and will not return until 12/04/2010. Please email OTG_Components alias for urgent support requests ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmas...@scee.net This footnote also confirms that this email message has been checked for all known viruses. Sony Computer Entertainment Europe Limited Registered Office: 10 Great Marlborough Street, London W1F 7LP, United Kingdom Registered in England: 3277793 ** - To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org