Author |
Message
|
tczielke |
Posted: Fri Jun 05, 2015 11:55 am Post subject: Java PCF code to return string constant of integer |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
Does anyone know if the MQ Java PCF code has functionality to return the equivalent string constant value for a PCF integer field? For example, if I made a PCF call to get the queue attributes of Q1 that had a DEFPRESP(SYNC), then I would get returned to me the string "SYNC" instead of the integer 1 (1 is the numeric value for SYNC) for the DEFPRESP for Q1. I looked through the PCFMessage class documentation for Java, and I could not find any method that could do that. But just curious if that functionality is out there and I am missing it. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jun 05, 2015 12:08 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
perhaps markt has something to say on this. |
|
Back to top |
|
 |
RogerLacroix |
Posted: Fri Jun 05, 2015 12:22 pm Post subject: Re: Java PCF code to return string constant of integer |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
tczielke wrote: |
if I made a PCF call to get the queue attributes of Q1 that had a DEFPRESP(SYNC), then I would get returned to me the string "SYNC" instead of the integer 1 (1 is the numeric value for SYNC) for the DEFPRESP for Q1. |
I don't believe so. If the field is an integer field (MQIACF_* vs MQCACF_*) then that is what you get. I haven't played with anything from MQ V8 but it would be interesting if it did.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
markt |
Posted: Sat Jun 06, 2015 4:01 am Post subject: |
|
|
 Knight
Joined: 14 May 2002 Posts: 508
|
MQConstants.lookup(value,filter)
But you need to know which filter to apply. For example,
if the parameter is for MQIA_PM_DELIVERY, then you would have to know to use the filter "MQDLV_.*". |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Jun 06, 2015 7:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
markt wrote: |
MQConstants.lookup(value,filter)
But you need to know which filter to apply. For example,
if the parameter is for MQIA_PM_DELIVERY, then you would have to know to use the filter "MQDLV_.*". |
Agreed. MQV8 is much better at this. Not all versions of MQ can handle this right. And then there is the case when the integer represents different options like for MQOO_ or MQGMO_ etc... I believe MQV8 has a function for this either in the PCFConstants or in the MQConstants. For earlier versions you will have to roll your own...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
tczielke |
Posted: Sat Jun 06, 2015 12:53 pm Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
Thanks all for the information. I was asking because I recently wrote a C PCF client program to get information like queue attributes, channel attributes, etc. I wanted to be able to see the actual constant values that are returned(i.e. DEFPRESP(SYNC) instead of DEFPRESP(1) ) so I ended up writing some code to do that conversion for the PCF queue attributes, channel attributes, queue manager attributes and cluster queue manager attributes. However, it was very tedious to do. So I was hoping there might be an easier way to do it in Java. It sounds like there is a little more help with Java PCF programming, but not what I was hoping for. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Jun 06, 2015 7:20 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Don't know how you'd do it in C but java reflection makes it quite easy.
The way it works:
Field name is being checked against the regular expression and the Field value is then being checked against the value passed (or the mask for options (bit check)).
The field name is being returned...
Hope this helps some.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
tczielke |
Posted: Sun Jun 07, 2015 5:28 am Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
fjb_saper wrote: |
Don't know how you'd do it in C but java reflection makes it quite easy.
The way it works:
Field name is being checked against the regular expression and the Field value is then being checked against the value passed (or the mask for options (bit check)).
The field name is being returned...
Hope this helps some.  |
I am new to Java, so I need to do some more research to better understand what you said there. If you already had a code snippet that you would not mind sharing, that would be helpful .
Looking at my C code, I did not state exactly what I was looking for correctly. What I was really hoping for was some way in Java where you could just start with a MQCFIN instance (let's say an instance that holds the equivalent of a DEFPRESP of SYNC), and then with some method calls you would get returned to you that the MQCFIN.Parameter is a "DEFPRESP" and the MQCFIN.Value is "SYNC". I have written some C code that can do that for the PCF inquire queue, channel, etc. attributes, but it was very tedious to write. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
markt |
Posted: Sun Jun 07, 2015 7:11 am Post subject: |
|
|
 Knight
Joined: 14 May 2002 Posts: 508
|
Quote: |
java reflection makes it quite easy. |
Not really. Or at least, it doesn't really solve the problem Tim is asking about. The MQConstants.lookup() method is actually using reflection to generate the strings that get returned, so that bit is easy, but the fundamental point is that there is no inbuilt way to find which enumerated sets of constants are used by which object attributes. So if I want to get the possible strings associated with the DEFPSIST attribute of an object then MQConstants.lookup will help only if I also know that that associated enumerated set begin with "MQPER_". Otherwise I might be just doing a lookup of the number "1" - and you can see from cmq*.h just how many definitions have that value if there is no filter on the strings.
Code: |
#define MQPER_PERSISTENCE_AS_PARENT (-1)
#define MQPER_NOT_PERSISTENT 0
#define MQPER_PERSISTENT 1
#define MQPER_PERSISTENCE_AS_Q_DEF 2
#define MQPER_PERSISTENCE_AS_TOPIC_DEF 2
|
And in the DEFPSIST example, there's a further wrinkle in that the most appropriate string may depend on whether it's a queue or topic object...
In MS0P SupportPac I have the mqidecode program which is just a wrapper around the MQConstants.lookup method - you can play with that to see just how many definitions and duplicate/overlapping values that might apply. Simple example of a problem - what happens when you try to get the "platform" attribute.
Code: |
C:\MS0P\mqidecode>mqidecode -p MQPL -v 1 -e
MQPL_MVS/MQPL_OS390/MQPL_ZOS
|
Several possibilities returned. Which may be equivalent in this case, but what should you print?
I am hoping that in "a future update to MQ" (to use a standard RFE response) there may be some example C code to help with this problem. Even though it will still may not solve it completely. But I'm not promising what might finally get from my personal directory into shipped product.
Formatting this stuff is very similar in Java and C; the benefit of Java is that you get the lookup function builtin. In C I had to write something comparable myself - which started as an awk script to generate tables out of cmq*.h. But in both my new C code and the older Java in MS0P that formats object attributes (eg configuration events) end up having blocks of switch statements to select the appropriate filter for each attribute.
I've also been writing up some of this to go into one of the presentations I'm doing at MQTC in September ... Try to give some of my experiences working with PCF. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Jun 07, 2015 8:49 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Hope this snippet helps...
Code: |
StringBuffer sb = new StringBuffer();
//make this part of a class definition
Field[] mqcfields = MQConstants.class.getFields();
// lookup method starts here...
String fieldname;
// might have to unbox from Integer to int
Object fieldvalue
for (int i = 0; i < mqcfields.length; i++){
//check if fieldname matches
fieldname = mqcfields[i].getName();
// input name is a regex like "MQPER_.*"
if (fieldname.matches(inputname){
fieldvalue = mqcfields[i].get(null);
classname = fieldvalue.getClass().getSimpleName();
if (classname.equals("Integer")){
fieldvalue = ((Integer)fieldvalue).intValue();
// gets more complex here if you need to check for options
// as you'd have to match byte per byte
// like (((value & inputvalue) == value ) && value != 0)
if (fieldvalue == inputvalue) {
sb.append(fieldname);
sb.append(" ");
}
}
}
}
return sb.toString(); |
_________________ MQ & Broker admin |
|
Back to top |
|
 |
tczielke |
Posted: Mon Jun 08, 2015 4:19 am Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
fjb_saper - Thanks for the code snippet.
markt - Thanks for the extra information. Also, looking forward to your PCF Programming session at MQTC. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
vsathyan |
Posted: Fri Feb 12, 2016 10:56 pm Post subject: |
|
|
Centurion
Joined: 10 Mar 2014 Posts: 121
|
Hi tczielke,
If you want the MQSC output of the attributes, why dont you use the PCF 'ESCAPE' method?
Hope this helps.
Thanks,
vsathyan _________________ Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004
Last edited by vsathyan on Sat Feb 13, 2016 5:51 am; edited 2 times in total |
|
Back to top |
|
 |
vsathyan |
Posted: Fri Feb 12, 2016 11:12 pm Post subject: |
|
|
Centurion
Joined: 10 Mar 2014 Posts: 121
|
Sample code to dump queue manager data using my library
Code: |
using CT.WMQ;
main()
{
try
{
MQAgent mqa = new MQAgent(qmgrName, serverName, portNumber, channelName);
if (mqa.IsConnected)
{
mqa.DumpAllObjectData("C:\\Queue_Manager_Data.txt");
}
mqa.DisconnectFromQueueManager();
MessageBox.Show("Dumping queue manager data complete");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
|
_________________ Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004 |
|
Back to top |
|
 |
tczielke |
Posted: Sat Feb 13, 2016 4:42 am Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
Hi vsathyan,
Thanks for the information. Yes, the PCF ESCAPE approach would be a good way to go. My PCF inquiry program is currently written in C. I originally did this post as I was thinking of changing to a Java approach. Also, I didn't think the PCF ESCAPE approach was supported on z/OS, but I have found out later that it is but with a slightly different approach of doing it. Anyway, at this point, I will probably just stick with the C program and change it to use PCF ESCAPE for distributed and the z/OS way of doing the equivalent.
Thanks,
Tim _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
vsathyan |
Posted: Sat Feb 13, 2016 5:53 am Post subject: |
|
|
Centurion
Joined: 10 Mar 2014 Posts: 121
|
Hi tczielke,
Ok, thats nice.
Also i've updated / edited my previous post and removed the API download link. Thanks,
Regards,
vsathyan _________________ Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004 |
|
Back to top |
|
 |
|