/[projects]/miscJava/thn_mqutils/src/main/java/com/traiana/utils/mq/MQ.java
ViewVC logotype

Contents of /miscJava/thn_mqutils/src/main/java/com/traiana/utils/mq/MQ.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3015 - (show annotations) (download)
Thu Apr 21 09:23:43 2016 UTC (8 years ago) by torben
File size: 2963 byte(s)
better reporting when queue manager creation fails
1 /* */ package com.traiana.utils.mq;
2 /* */
3 /* */ import com.ibm.mq.MQEnvironment;
4 /* */ import com.ibm.mq.MQException;
5 /* */ import com.ibm.mq.MQMessage;
6 /* */ import com.ibm.mq.MQQueue;
7 /* */ import com.ibm.mq.MQQueueManager;
8 /* */ import java.io.IOException;
9 /* */ import java.io.OutputStreamWriter;
10
11 import java.util.Hashtable;
12
13
14 /* */ public class MQ implements AutoCloseable
15 /* */ {
16 /* */ MQQueueManager _qMgr = null;
17 /* */ MQQueue _mQQueue = null;
18 /* */
19 /* */ @SuppressWarnings("unchecked")
20 public MQ(String qmgr, int port, String mqServerName, String channelName, int ccsid, boolean log)
21 /* */ throws Exception
22 /* */ {
23 /* 36 */ MQEnvironment.hostname = mqServerName;
24 /* 37 */ MQEnvironment.port = port;
25 /* 38 */ MQEnvironment.channel = channelName;
26 /* 39 */ MQEnvironment.properties.put("transport", "MQSeries Client");
27
28 /* */
29 /* 41 */ if (log)
30 /* 42 */ MQException.log = new OutputStreamWriter(System.out);
31 /* */ else {
32 /* 44 */ MQException.log = new OutputStreamWriter(new NullOutputStream());
33 /* */ }
34 /* 46 */ if (ccsid > 0)
35 /* 47 */ MQEnvironment.properties.put("CCSID", new Integer(ccsid));
36 /* */ try {
37 /* 49 */ this._qMgr = new MQQueueManager(qmgr);
38 /* */ } catch (MQException e) {
39 throw new Exception("Could not create QueueManager", e);
40 /* */ }
41 /* */ }
42 /* */
43 /* */ public void InitQueue(String queueName) throws MQException {
44 /* 56 */ InitQueue(queueName, false);
45 /* */ }
46 /* */
47 /* */ public void InitQueue(String queueName, boolean depth)
48 /* */ throws MQException
49 /* */ {
50 /* 62 */ int openOptions = depth ? 32 : 16;
51 /* */
52 /* 64 */ if (this._mQQueue != null) {
53 /* 65 */ this._mQQueue.close();
54 /* 66 */ this._mQQueue = null;
55 /* */ }
56 /* 68 */ this._mQQueue = this._qMgr.accessQueue(queueName, openOptions);
57 /* */ }
58 /* */
59 /* */ public int getDepth() throws MQException
60 /* */ {
61 /* 73 */ return this._mQQueue.getCurrentDepth();
62 /* */ }
63 /* */
64 /* */ public void sendToQueue(byte[] message)
65 /* */ throws MQException, IOException
66 /* */ {
67 /* 84 */ MQMessage mQMessage = new MQMessage();
68 /* 85 */ mQMessage.format = new String("MQSTR ");
69 /* 86 */ mQMessage.clearMessage();
70 /* 87 */ mQMessage.write(message);
71 /* 88 */ this._mQQueue.put(mQMessage);
72 /* */ }
73 /* */
74 @Override
75 /* */ public void close() throws MQException {
76 /* 92 */ if (this._mQQueue != null)
77 /* 93 */ this._mQQueue.close();
78 /* 94 */ this._qMgr.disconnect();
79 /* 95 */ this._qMgr.close();
80 /* */ }
81 /* */ }
82
83 /* Location: C:\Users\thn\workspace\mq-utils.jar
84 * Qualified Name: com.traiana.utils.mq.MQ
85 * JD-Core Version: 0.6.2
86 */

  ViewVC Help
Powered by ViewVC 1.1.20