-
Notifications
You must be signed in to change notification settings - Fork 178
Add base java samples #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add base java samples #316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
800 lines of code, mostly repeated that can be condensed down to no more than 200 lines of code.
The feedback for BasicGet
equally applies to the rest of the modules.
@@ -0,0 +1,142 @@ | |||
# IBM MQ Base Java Samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like base-java as a name. Lead with Java eg. Java-MQ
@@ -0,0 +1,55 @@ | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file is missing copyright
@@ -0,0 +1,133 @@ | |||
package com.ibm.mq.samples.java; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing copyright
|
||
public class BasicGet { | ||
|
||
private static class MQDetails { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is repeated in all these samples, best to have a separate .java
file for it.
Or to create a base class that BasicGet
etc inherit from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at https://github.com/ibm-messaging/mq-dev-patterns/blob/master/amqp-qpid/qpid-standard/src/main/java/com/ibm/mq/samples/jms/qpid/BaseJMS20.java and
https://github.com/ibm-messaging/mq-dev-patterns/blob/master/amqp-qpid/qpid-standard/src/main/java/com/ibm/mq/samples/jms/qpid/GetJMS20.java
for inspiration.
private static JSONArray endpoints; | ||
|
||
public static void main(String[] args) { | ||
loadEnv("env.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadEnv
, everything to do with env.json is common to all these files - needs to be in a separate file - used by the base class.
This main should
BasicGet bg = new BasicGet()
which in turn would new BasicBase()
which should load the endpoints as a class instance, and provide getter methods to read and manipulate them.
|
||
try { | ||
Hashtable<String, Object> props = new Hashtable<>(); | ||
String ccdtUrl = System.getenv("MQCCDTURL"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common shared check - should be a public method in the base class which all subclasses can invoke.
System.setProperty("MQCCDTURL", ccdtPath); | ||
System.out.println("Using CCDT at: " + ccdtPath); | ||
} else { | ||
props.put(MQConstants.HOST_NAME_PROPERTY, details.HOST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shared code - pubic method in shared base class.
System.setProperty("com.ibm.mq.ssl.keyStorePassword", ""); | ||
} | ||
|
||
qMgr = new MQQueueManager(details.QMGR, props); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shared code - paramatized pubic method in base class.
queue = qMgr.accessQueue(details.QUEUE_NAME, openOptions); | ||
|
||
boolean keepReading = true; | ||
while (keepReading) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally code that belongs in the BasicGet
} | ||
} | ||
|
||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best to have a common method - in base class - to handle the displaying of exceptions, so can show nested exceptions.
No description provided.