From 4dd9cbaf7fdc498a4eb5f2652d88afd20fe5d530 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Fri, 27 Jan 2012 20:15:31 +0000 Subject: NO-JIRA: Encapsulate fields, use private members and accesors (keep checkstyle happy) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1236867 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/example/OptionParser.java | 26 +++---- .../publisher/MonitorMessageDispatcher.java | 2 +- .../qpid/example/publisher/MonitorPublisher.java | 14 ++-- .../apache/qpid/example/publisher/Publisher.java | 87 ++++++++++++++++------ .../qpid/example/publisher/TopicPublisher.java | 5 +- .../org/apache/qpid/example/pubsub/Client.java | 32 +++++++- .../org/apache/qpid/example/pubsub/Publisher.java | 10 +-- .../org/apache/qpid/example/pubsub/Subscriber.java | 12 +-- .../apache/qpid/example/simple/reqresp/Client.java | 12 +-- .../apache/qpid/example/simple/reqresp/Server.java | 12 +-- 10 files changed, 138 insertions(+), 74 deletions(-) (limited to 'java/client/example/src') diff --git a/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java b/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java index 9548eab4c5..6cc6db1974 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java @@ -147,8 +147,8 @@ public class OptionParser for (Option option: optDefs) { - if ((op.startsWith("-") && option.shortForm != null && option.shortForm.equals(key)) || - (op.startsWith("--") && option.longForm != null && option.longForm.equals(key)) ) + if ((op.startsWith("-") && option.getShortForm() != null && option.getShortForm().equals(key)) || + (op.startsWith("--") && option.getLongForm() != null && option.getLongForm().equals(key)) ) { match = true; break; @@ -219,18 +219,18 @@ public class OptionParser protected boolean containsOp(Option op) { - return optMap.containsKey(op.shortForm) || optMap.containsKey(op.longForm); + return optMap.containsKey(op.getShortForm()) || optMap.containsKey(op.getLongForm()); } protected String getOp(Option op) { - if (optMap.containsKey(op.shortForm)) + if (optMap.containsKey(op.getShortForm())) { - return (String)optMap.get(op.shortForm); + return (String)optMap.get(op.getShortForm()); } - else if (optMap.containsKey(op.longForm)) + else if (optMap.containsKey(op.getLongForm())) { - return (String)optMap.get(op.longForm); + return (String)optMap.get(op.getLongForm()); } else { @@ -286,12 +286,12 @@ public class OptionParser static class Option { - private String shortForm; - private String longForm; - private String desc; - private String valueLabel; - private String defaultValue; - private Class type; + private final String shortForm; + private final String longForm; + private final String desc; + private final String valueLabel; + private final String defaultValue; + private final Class type; public Option(String shortForm, String longForm, String desc, String valueLabel, String defaultValue, Class type) diff --git a/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java b/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java index 3d16e01af4..2b1e641689 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java @@ -103,7 +103,7 @@ public class MonitorMessageDispatcher // (FileMessageFactory.createSimpleEventMessage(getMonitorPublisher().getSession(),"monitor:" +System.currentTimeMillis())); getMonitorPublisher().sendMessage - (getMonitorPublisher()._session, + (getMonitorPublisher().getSession(), FileMessageFactory.createSimpleEventMessage(getMonitorPublisher().getSession(), "monitor:" + System.currentTimeMillis()), DeliveryMode.PERSISTENT, false, true); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorPublisher.java b/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorPublisher.java index 750f57d9dc..b2bb0893d8 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorPublisher.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/publisher/MonitorPublisher.java @@ -36,7 +36,7 @@ public class MonitorPublisher extends Publisher private static final Logger _log = LoggerFactory.getLogger(Publisher.class); - BasicMessageProducer _producer; + private BasicMessageProducer _producer; public MonitorPublisher() { @@ -51,14 +51,14 @@ public class MonitorPublisher extends Publisher { try { - _producer = (BasicMessageProducer) session.createProducer(_destination); + _producer = (BasicMessageProducer) session.createProducer(getDestination()); _producer.send(message, deliveryMode, immediate); if (commit) { //commit the message send and close the transaction - _session.commit(); + getSession().commit(); } } @@ -70,7 +70,7 @@ public class MonitorPublisher extends Publisher throw new UndeliveredMessageException("Cannot deliver immediate message", e); } - _log.info(_name + " finished sending message: " + message); + _log.info(getName() + " finished sending message: " + message); return true; } @@ -81,14 +81,14 @@ public class MonitorPublisher extends Publisher { try { - _producer = (BasicMessageProducer) _session.createProducer(_destination); + _producer = (BasicMessageProducer) getSession().createProducer(getDestination()); //Send message via our producer which is not persistent and is immediate //NB: not available via jms interface MessageProducer _producer.send(message, DeliveryMode.NON_PERSISTENT, true); //commit the message send and close the transaction - _session.commit(); + getSession().commit(); } catch (JMSException e) @@ -99,7 +99,7 @@ public class MonitorPublisher extends Publisher throw new UndeliveredMessageException("Cannot deliver immediate message", e); } - _log.info(_name + " finished sending message: " + message); + _log.info(getName() + " finished sending message: " + message); return true; } } diff --git a/java/client/example/src/main/java/org/apache/qpid/example/publisher/Publisher.java b/java/client/example/src/main/java/org/apache/qpid/example/publisher/Publisher.java index b5f44557a4..76531523b9 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/publisher/Publisher.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/publisher/Publisher.java @@ -34,19 +34,19 @@ public class Publisher protected InitialContextHelper _contextHelper; - protected Connection _connection; + private Connection _connection; - protected Session _session; + private Session _session; - protected MessageProducer _producer; + private MessageProducer _producer; - protected String _destinationDir; + private String _destinationDir; - protected String _name = "Publisher"; + private String _name = "Publisher"; - protected Destination _destination; + private Destination _destination; - protected static final String _defaultDestinationDir = "/tmp"; + private static final String _defaultDestinationDir = "/tmp"; /** * Creates a Publisher instance using properties from example.properties @@ -62,9 +62,9 @@ public class Publisher //then create a connection using the AMQConnectionFactory AMQConnectionFactory cf = (AMQConnectionFactory) ctx.lookup("local"); - _connection = cf.createConnection(); + setConnection(cf.createConnection()); - _connection.setExceptionListener(new ExceptionListener() + getConnection().setExceptionListener(new ExceptionListener() { public void onException(JMSException jmse) { @@ -76,19 +76,19 @@ public class Publisher }); //create a transactional session - _session = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE); + setSession(getConnection().createSession(true, Session.AUTO_ACKNOWLEDGE)); //lookup the example queue and use it //Queue is non-exclusive and not deleted when last consumer detaches - _destination = (Queue) ctx.lookup("MyQueue"); + setDestination((Queue) ctx.lookup("MyQueue")); //create a message producer - _producer = _session.createProducer(_destination); + setProducer(getSession().createProducer(getDestination())); //set destination dir for files that have been processed - _destinationDir = _defaultDestinationDir; + setDestinationDir(get_defaultDestinationDir()); - _connection.start(); + getConnection().start(); } catch (Exception e) { @@ -97,6 +97,11 @@ public class Publisher } } + public static String get_defaultDestinationDir() + { + return _defaultDestinationDir; + } + /** * Creates and sends the number of messages specified in the param */ @@ -104,7 +109,7 @@ public class Publisher { try { - TextMessage txtMessage = _session.createTextMessage("msg"); + TextMessage txtMessage = getSession().createTextMessage("msg"); for (int i=0;i