summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2007-06-15 16:28:46 +0000
committerMartin Ritchie <ritchiem@apache.org>2007-06-15 16:28:46 +0000
commitf92c24912aafd5fd5a0c279fddb9c51123b89df0 (patch)
treeac7368d22bd2265861bb79072b5fa7d3056b5445
parentb12c2969adee98ba7ee68349c051b59a549b2a7d (diff)
downloadqpid-python-f92c24912aafd5fd5a0c279fddb9c51123b89df0.tar.gz
Merged revisions 439476-447993,447995-448007,448009-448141,448143-448157,448161-448194,448196-448210,448212-448218,448220-448223,448225-448233,448235,448237-448241,448243-448596,448598-448623,448625-448850,448852-448880,448882-448982,448984-449635,449637-449639,449641-449642,449644-449645,449647-449674,449676-449719,449721-449749,449751-449762,449764-449933,449935-449941,449943-450383,450385,450387-450400,450402-450433,450435-450503,450505-450555,450557-450860,450862-451024,451026-451149,451151-451316,451318-451931,451933-452139,452141-452162,452164-452320,452322,452324-452325,452327-452333,452335-452429,452431-452528,452530-452545,452547-453192,453194-453195,453197-453536,453538,453540-453656,453658-454676,454678-454735,454737,454739-454781,454783-462728,462730-462819,462821-462833,462835-462839,462841-463071,463073-463178,463180-463308,463310-463362,463364-463375,463377-463396,463398-463402,463404-463409,463411-463661,463663-463670,463672-463673,463675-464493,464495-464502,464504-464576,464578-464613,464615-464628,464630,464632-464866,464868-464899,464901-464942,464944-464949,464951-465004,465006-465016,465018-465053,465055-465165,465167-465321,465323-465406,465408-465427,465429-465431,465433-465548,465550-466044,466047-466075,466077,466079-466081,466083-466099,466101-466112,466114-466126,466128-466240,466242-466971,466973-466978,466980-467309,467311-467312,467316-467328,467330-467485,467487-467588,467590-467604,467606-467699,467701-467706,467708-467749,467751-468069,468071-468537,468539-469241,469244-469246,469248-469318,469320-469421,469423,469425-469429,469431-469435,469437-469462,469464-469469,469472-469477,469479-469490,469492-469503,469505-469529,469531-469598,469600-469624,469626-469737,469739-469752,469754-469806,469808-469928,469930-469953,469955-470011,470013-470109,470111-470335,470338-470339,470341-470379,470381,470383-470399,470401-470446,470448-470741,470743-470758,470760-470809,470811-470817,470819-470993,470995-471001,471003-471788,471790-471792,471794-472028,472030-472032,472034-472036,472038,472040,472043,472045-472059,472061,472063,472065-472066,472068,472070-472072,472074-472080,472082,472084-472092,472094-472107,472109-472123,472125-472158,472160-472165,472167-472172,472174-472457,472459-472460,472462-472464,472466-472470,472472-472483,472486-472491,472493-472494,472496-472497,472499,472501-472503,472505-472512,472514-472544,472546-472556,472558-472560,472562-472572,472574-472587,472589-472591,472593-472605,472607,472609-472731,472733-472786,472788-472843,472845-472849,472851-472859,472861-472878,472880-472903,472905,472907-472988,472990-472991,472993-473071,473073-473086,473088-473090,473093,473095-473096,473098-473106,473108-473110,473112-473185,473187-473260,473262,473268-473270,473275-473279,473281,473284-473287,473289-473295,473297-473306,473308-473330,473332-473335,473337,473339-473344,473346-473351,473353-473355,473357-473358,473361-473471,473473-473497,473499-473535,473537-473567,473569-473888,473890-474451,474454-474492,474494-474563,474565-474843,474845-474865,474867-474932,474934-475035,475037-475144,475146-475180,475182-475265,475267-475285,475287,475289-475293,475295-475296,475298-475302,475304-475631,475633-475649,475651-475748,475750-475752,475754-476107,476109-476302,476304-476413,476415-476430,476432-476700,476702-476868,476870-477147,477149-477213,477215-477263,477265-477340,477342-477635,477637-477789,477791-477825,477827-477841,477843,477846-477852,477854,477856,477858-477865,477867-477894,477896-478022,478024-478182,478184-478211,478213-478233,478235-478236,478238-478241,478243-478252,478254-478259,478261-478263,478265,478267-478269,478271-478286,478288-478342,478344-478379,478381-478412,478414-478443,478445-478636,478639-478658,478660-478821,478823-478853,478855-478922,478924-478962,478965-478974,478976-479029,479031-479049,479051-479210,479212-479214,479216-479407,479409-479415,479417-479425,479427-479559,479561-479639,479641-479676,479678-479685,479687-480030,480033-480086,480091-480093,480095-480118,480120-480139,480141,480143-480148,480150-480156,480158-480163,480165-480177,480179-480189,480191-480193,480195-480198,480200-480220,480222-480282,480284-480292,480294-480308,480310-480317,480320-480422,480424,480426-480581,480583-480656,480658-480692,480695-480702,480704,480706-480710,480712-480910,480913-480933,480935-480945,480947-480972,480974-480993,480995-481034,481036-481158,481161-481174,481176-481220,481222-481234,481236-481260,481263-481264,481266-481296,481298-481304,481306-481311,481313-481332,481334,481336-481380,481382-481441,481443-482144,482146-482180,482182-482193,482195-482232,482234-482236,482239,482241-482242,482244-482247,482250-482251,482253,482256-482261,482264-482288,482290-482364,482366,482368,482370-482554,482556,482558-482569,482572-482636,482638,482640-482696,482698-482722,482724-482732,482734-482771,482774-482957,482959-483045,483047-483105,483108,483110-483115,483117,483119-483127,483130-483134,483136-483148,483150-483158,483160-483164,483166-483178,483180-483391,483393-483400,483402-483403,483405-483418,483420-483421,483425-483436,483438-483470,483472-483502,483504-483558,483560-483599,483601-483637,483639-483644,483646-483659,483661-483670,483672-483878,483880-483910,483912-483915,483917-483940,483942,483944-483968,483970-483972,483974-483976,483978,483980-484612,484614-484657,484659-484693,484695-484718,484720-484842,484844-484847,484849-484986,484988-485019,485021-485489,485491-485544,485546-485591,485593,485595-485697,485699-485729,485731-485734,485736-485779,485781-485787,485789-485851,485853,485855-486007,486009,486011-486020,486022-486083,486085-486097,486099-486117,486120-486131,486133-486148,486150-486161,486163-486164,486166-486197,486199-486205,486208-486247,486249-486253,486256-486427,486429-486431,486433-486554,486556-486573,486575-486593,486595,486597-486609,486611-486619,486622,486625,486627-486641,486643-486645,486649-486687,486689-486721,486723-486730,486732-486746,486748-486759,486761,486763-486777,486779-486782,486784-486788,486790,486792,486794-486796,486798-487175,487178,487180-487213,487215,487217-487267,487269-487284,487286-487298,487300-487358,487360-487367,487369-487382,487384-487434,487436-487480,487482-487547,487549-487561,487563-487565,487567-487578,487580-487615,487617-487622,487624,487626,487628,487630-487635,487637-487703,487705-487777,487780-487781,487783-487800,487802-487803,487805-487820,487822-487848,487850-487902,487904-488103,488105-488133,488135-488158,488160-488163,488165-488187,488189-488216,488218-488248,488250-488278,488280,488282-488303,488305-488313,488315-488342,488344-488351,488353-488376,488378-488449,488451-488593,488595,488597-488623,488625-488700,488702-488704,488706-488710,488714,488716-488725,488727-488744,488746-488770,488772-488798,488800,488802-488807,488809,488811-488829,488831-488843,488845-488851,488853-489069,489071-489077,489079-489081,489084-489102,489104-489105,489107-489109,489111-489112,489114-489139,489141-489178,489181-489203,489205-489211,489213,489216-489329,489332-489402,489404-489417,489419-489421,489423-489643,489645-489690,489692-489703,489705-489714,489716-489747,489749-489753,489755-489803,489805-489904,489906-490372,490374-490504,490506-490604,490606-490707,490710-490733,490735-490871,490873-490984,490986-491028,491030,491032-491071,491073-491119,491121-491576,491578-491672,491674-491800,491802-491838,491840-491878,491880-492183,492185-492279,492281-492317,492319-492513,492515-492584,492586-492587,492589-492601,492603-492635,492637-492640,492642-492717,492719-492723,492725-492729,492731-492755,492757-492901,492903-492955,492957-492962,492964-492997,492999-493002,493004-493041,493043-493059,493062-493063,493065-493086,493088-493125,493127-493139,493141-493150,493152-493871,493873-494017,494019-494030,494032-494041,494043-494091,494093-494120,494122-494354,494356-494436,494438-494539,494541-494552,494554-494586,494588-494649,494651,494653-494654,494656-494657,494659-494764,494766-494768,494770-494796,494798-494799,494802,494804-494860,494862-494903,494905-494906,494908-495019,495021-495160,495162-495168,495171-495188,495190-495229,495231-495254,495256-495303,495305-495313,495315-495336,495338-495372,495374-495379,495381-495454,495457-495459,495462-495516,495518-495524,495526-495531,495533-495548,495551-495553,495555,495557-495558,495560,495562-495573,495575-495583,495585-495594,495596-495628,495630-495638,495640-495651,495653-495660,495662-495753,495755-496259,496261-496262,496264-496269,496271-496275,496277-496301,496303-496316,496318-496383,496385-496413,496415-496495,496497-496625,496627-496636,496638-496640,496642-496647,496650-496657,496659-496660,496663-496664,496666-496677,496679-496681,496683-496730,496732-496750,496752,496754-496784,496786-496832,496834-496840,496842-496990,496992-496995,496997-497340,497343-497351,497353-497403,497405-497424,497426-497438,497440-497481,497483-497497,497499-497765,497767-497769,497771-497775,497777-497778,497780,497782-497783,497785,497787-497812,497814-497871,497873-497877,497879-498573,498575-498588,498590,498592,498594-498636,498638-498669,498671-498686,498688-498689,498691-498719,498721-498964,498966-498969,498971-498973,498975-498982,498985-499035,499037-499040,499042,499044-499048,499050-499082,499084-499086,499088-499164,499167-499169,499171-499355,499357-499370,499372-499373,499375-499391,499393,499395-499425,499428,499430-499445,499447-499455,499457-499460,499462-499465,499467,499469-499489,499491-499492,499494-499531,499533-499562,499566-499627,499629-499715,499717-499732,499734-499755,499758-499763,499765-499780,499782-499795,499797-499802,499804-499844,499846,499848-499850,499852-499863,499865-499873,499875-499974,499976-499978,499980-500263,500265-500283,500285-500309,500311-501000,501002,501012-501057,501059-501095,501097-501390,501392-501410,501413-501447,501449-501454,501456,501458-501464,501466-501471,501473-501803,501805-501913,501915-501916,501918-501919,501921-501944,501946-502171,502173-502177,502181,502183-502247,502250-502252,502254-502260,502262-502267,502270,502272,502274-502575,502577-502609,502611-502619,502621-502626,502628-502654,502656-503592,503594-503603,503605-503608,503610-503636,503638-503645,503647-503705,503707-503789,503791-504024,504026-504111,504113-504506,504508-504735,504737-504863,504865-504867,504869-504914,504916-505241,505243-505254,505257-505267,505269-505354,505356-505891,505893-505971,505973-506400,506402-506404,506407-506438,506440-506516,506518-506541,506543-506966,506968-506971,506973-507095,507097-507108,507111-507454,507456,507459-507471,507473-507556,507558,507560-507581,507585-507594,507597,507599-507608,507610-507728,507730-507893,507895-507937,507940-508234,508236-508350,508352-508365,508367-508380,508383,508386-508415,508417-508648,508650-508941,508943-509146,509148-509171,509173-509175,509179-509201,509203-509207,509209-509215,509217-509222,509224-509477,509480-509627,509629-509634,509636-509641,509643-509736,509738-509931,509933-510059,510061-510075,510077-510158,510161-510896,510898-510938,510940-511388,511390-511922,511924-512287,512289-512698,512702-512813,512815-512817,512819-513359,513361-513370,513372-514702,514704-514886,514888-514902,514904-515126,515129-515141,515143-515516,515518-515534,515536-515538,515540-515648,515650-515651,515653-516070,516072-516411,516413-516448,516450,516452-517637,517639-517647,517649-517659,517661-517663,517665-517677,517679-517682,517684-517744,517746-518085,518087-518175,518177-518558,518560-518568,518571-518666,518668,518670-518699,518701-518987,518990-518992,518994-519908,519910-519932,519934-520414,520416-520842,520844-520937,520939-521362,521364-521681,521683-521704,521706-521709,521711-521714,521716-521781,521783-521792,521794-522462,522464-522527,522529-522534,522536-522566,522568-522958,522960,522962-522966,522968-522976,522978-522980,522982-522988,522992-522993,522995-523244,523246-523746,523748-524049,524051-524738,524741-524742,524744-524762,524764,524766,524768-525486,525488-525530,525532,525534,525537-525552,525554-525765,525767-525776,525778-525784,525789-525803,525805-525816,525818-525828,525830-525861,525863-525866,525868-526090,526092-526112,526114-526116,526119-526121,526123-526149,526151-526153,526155-526156,526160-526165,526167-526186,526188-526193,526196-526197,526200-526665,526667-526682,526686-526690,526693,526695-526708,526710-526713,526715-526775,526777-526802,526804-526806,526808-527048,527051-527052,527054-527181,527183-527486,527488-527492,527494-527498,527500-527508,527510-527517,527519-527536,527538-527555,527559-527802,527804-527842,527844-527847,527849-527875,527877-527940,527942-527958,527960-527971,527973-528002,528004,528006-528423,528425-529232,529234-529245,529247-529296,529298-529634,529636-529658,529660-529665,529667-529668,529670-530033,530035-530036,530038-530040,530045-530046,530050-530051,530053-530431,530433-530436,530439-530440,530443,530445-530446,530448,530450-530682,530684,530687-530696,530698-530733,530735-530776,530778-530795,530799,530801-530811,530813-530818,530820-530837,530839-531436,531438-531455,531457,531459-531511,531514,531516,531519-531523,531525,531528-531858,531860-531864,531866-531907,531909-531916,531918-531936,531938-531988,531990-532001,532003-532371,532373-532465,532467-532727,532729-532765,532767-532785,532788-532790,532792-532793,532795-533064,533066-533074,533076,533080-533130,533132-533139,533142-533703,533705-533720,533722-533763,533766-533818,533820-533839,533841-533859,533862-534035,534037-534112,534114-534116,534118-534472,534474-534477,534479-534762,534764-534896,534898-534902,534904-535253,535255-535308,535310-535808,535810-535873,535875-536007,536009-536140,536142-536162,536165-536242,536244-536252,536254-536278,536280-536338,536340-536448,536450-536479,536481-536482,536484-536485,536487-536495,536497,536500-536505,536507-536561,536563-536570,536572,536574-536583,536586-536823,536825-537014,537016-537018,537020-537025,537027-537028,537030-537160,537162-537170,537172-537672,537674-537781,537783-537833,537836-537840,537842-537844,537846-537953,537955-538034,538036-538078,538080-538083,538085-538097,538099-538108,538110-538239,538241-538881,538883-538906,538908-538911,538913-538921,538923-539177,539179-539190,539192-539475,539477-539500,539502-539593,539595-539782,539784-539787,539789-540106,540108-540168,540170-540510,540512-541919,541921-544507,544509-544865,544867-545145,545147-547177,547179-547627 via svnmerge from
https://svn.apache.org/repos/asf/incubator/qpid/branches/M2 ........ r539470 | ritchiem | 2007-05-18 14:50:59 +0100 (Fri, 18 May 2007) | 1 line QPID-401 Integrated python tests with maven tested on windows CMD.exe and linux FC5 ........ r539481 | ritchiem | 2007-05-18 15:30:06 +0100 (Fri, 18 May 2007) | 1 line QPID-401 Update to allow -Dskip-python-tests to disable python checking ........ r539484 | ritchiem | 2007-05-18 15:35:13 +0100 (Fri, 18 May 2007) | 1 line QPID-401 Update to allow -Dskip-python-tests to disable python checking ........ r541247 | rgodfrey | 2007-05-24 10:57:00 +0100 (Thu, 24 May 2007) | 1 line QPID-482 : Small performance tweaks ........ r542484 | rupertlssmith | 2007-05-29 11:52:29 +0100 (Tue, 29 May 2007) | 1 line Can now pass property to skip python tests, set in settings.xml ........ r542789 | ritchiem | 2007-05-30 11:09:28 +0100 (Wed, 30 May 2007) | 1 line Update to ensure fastinstall profile skips the broker python tests. ........ r543496 | rupertlssmith | 2007-06-01 15:33:07 +0100 (Fri, 01 Jun 2007) | 1 line QPID-402: FailoverException falling through to client. All blocking operations now wrapped in failover support wrappers. ........ r544109 | ritchiem | 2007-06-04 10:47:53 +0100 (Mon, 04 Jun 2007) | 7 lines Addition of a sustained test client. This is currently setup for running a pub/sub test. The test allows for multiple clients to connect and participate in testing the broker throughput. A single producer continually sends messages to a topic which the clients then send batched results back about. The producer uses the timings in the reports to update the rate at which it sends messages. Ideally reaching a steady state where all messages produced are received by everyone within a specified time frame. ........ r544422 | ritchiem | 2007-06-05 09:50:54 +0100 (Tue, 05 Jun 2007) | 1 line Added documentation on how to run the sustained tests. ........ r546096 | rupertlssmith | 2007-06-11 12:23:08 +0100 (Mon, 11 Jun 2007) | 1 line Set up top dir location and path to parent pom. Needed in preparation for deploy and release plugins. ........ r546190 | rupertlssmith | 2007-06-11 17:43:57 +0100 (Mon, 11 Jun 2007) | 1 line Removed log4j dependency from client. Using slf4j instead, end-user to supply logging implementation as desired. Log4j used for tests. ........ r546441 | rupertlssmith | 2007-06-12 10:52:29 +0100 (Tue, 12 Jun 2007) | 1 line QPID-465, now throws UnsupportedOperationException when sending to a null queue in QueueSender. ........ r546458 | ritchiem | 2007-06-12 12:41:17 +0100 (Tue, 12 Jun 2007) | 1 line Added repository info for running mvn rat:check ........ r547627 | ritchiem | 2007-06-15 12:21:40 +0100 (Fri, 15 Jun 2007) | 1 line QPID-511 adjusted to use the ReadWriteThreadModel rather than setting editing the filterChain directly which could cause problems when using an InVM transport due to the way the InVM transport alters the filter chain during a connect call. ........ git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@547730 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/broker/pom.xml68
-rwxr-xr-xjava/broker/python-test.xml32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/Main.java8
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java18
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java22
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java130
-rw-r--r--java/client/example/pom.xml8
-rw-r--r--java/client/pom.xml34
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnection.java214
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQDestination.java8
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java75
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession.java3457
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java169
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java111
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/Closeable.java47
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/JMSAMQException.java28
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java29
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverException.java22
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java124
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverNoopSupport.java54
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverProtectedOperation.java28
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverRetrySupport.java128
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverState.java29
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverSupport.java81
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java17
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java13
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java15
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java16
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java15
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java36
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java24
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java17
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java54
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java44
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java40
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java36
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java56
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessageFactory.java64
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java247
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/MessageConverter.java20
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java230
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java20
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java144
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatConfig.java13
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java20
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java23
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java22
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java14
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandler.java24
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java35
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/StateWaiter.java18
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java2
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java23
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java23
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java27
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/util/FlowControllingBlockingQueue.java11
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java45
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java36
-rw-r--r--java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java67
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/DispatcherTest.java94
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerImmediatePrefetch.java26
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java102
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/MessageListenerTest.java47
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java108
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java135
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java57
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java49
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/LargeMessageTest.java39
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java351
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java31
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java50
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java133
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/SelectorTest.java28
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java25
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java57
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/close/CloseTests.java27
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java42
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java79
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java141
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java39
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java10
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java15
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java101
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/close/CloseBeforeAckTest.java55
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java72
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java28
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java49
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/message/StreamMessageTest.java84
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java27
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/transacted/CommitRollbackTest.java34
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java52
-rw-r--r--java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java31
-rw-r--r--java/common/pom.xml16
-rw-r--r--java/common/src/main/java/org/apache/qpid/AMQConnectionClosedException.java9
-rw-r--r--java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java15
-rw-r--r--java/common/src/main/java/org/apache/qpid/codec/AMQCodecFactory.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/common/QpidProperties.java7
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQDataBlock.java10
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java46
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java26
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java16
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java125
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java152
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java5
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java11
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java14
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java11
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/FieldTable.java187
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java23
-rw-r--r--java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java11
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java13
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java94
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/FileUtils.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java7
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java326
-rw-r--r--java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java19
-rw-r--r--java/integrationtests/docs/RunningSustainedTests.txt15
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java9
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java74
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java4
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningCoordinatorTest.java28
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningTestDecorator.java200
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java87
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase1DummyRun.java8
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java9
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestClient.java567
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestCoordinator.java219
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/sustained/TestClient.java157
-rw-r--r--java/integrationtests/src/main/java/org/apache/qpid/sustained/TestCoordinator.java117
-rw-r--r--java/management/eclipse-plugin/pom.xml11
-rw-r--r--java/perftests/RunningPerformanceTests.txt2
-rw-r--r--java/perftests/pom.xml20
-rw-r--r--java/pom.xml27
-rw-r--r--java/systests/pom.xml9
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java11
-rw-r--r--java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java (renamed from java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnection.java)559
138 files changed, 7160 insertions, 4781 deletions
diff --git a/java/broker/pom.xml b/java/broker/pom.xml
index 2cf8a563f0..85ec5da3bf 100644
--- a/java/broker/pom.xml
+++ b/java/broker/pom.xml
@@ -15,7 +15,7 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
- -->
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -44,6 +44,11 @@
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
@@ -58,7 +63,14 @@
<artifactId>commons-lang</artifactId>
</dependency>
- <!-- Test Dependencies -->
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -120,6 +132,7 @@
</configuration>
</plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -145,6 +158,57 @@
</testResource>
</testResources>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>${antrun.version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant-nodeps</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ </dependencies>
+
+ <executions>
+ <execution>
+ <id>python_test</id>
+ <phase>test</phase>
+ <configuration>
+ <tasks>
+
+ <condition property="broker.dir"
+ value="${user.dir}${file.separator}..${file.separator}broker"
+ else="${user.dir}">
+ <equals arg1="${topDirectoryLocation}" arg2="." />
+ </condition>
+
+ <condition property="skip-python-tests" value="true">
+ <isset property="skip.python.tests"/>
+ </condition>
+
+ <property name="command"
+ value="python run-tests -v -I java_failing.txt"/>
+ <!--value="bash -c 'python run-tests -v -I java_failing.txt'"/>-->
+
+ <ant antfile="python-test.xml" inheritRefs="true">
+ <target name="run-tests" />
+ </ant>
+
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+
</build>
</project>
diff --git a/java/broker/python-test.xml b/java/broker/python-test.xml
new file mode 100755
index 0000000000..8ade392d1c
--- /dev/null
+++ b/java/broker/python-test.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ====================================================================== -->
+<!-- Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. -->
+<!-- ====================================================================== -->
+
+<project basedir="." default="default">
+
+ <target name="default" >
+ <echo message="Used via maven to run python tests."/>
+ </target>
+
+ <property name="pythondir" value="../../python"/>
+
+ <target name="run-tests" unless="skip-python-tests">
+
+ <echo message="Starting Broker with command"/>
+
+ <java classname="org.apache.qpid.server.RunBrokerWithCommand"
+ fork="true"
+ dir="${pythondir}"
+ failonerror="true"
+ >
+ <arg value="${command}"/>
+
+ <classpath refid="maven.test.classpath"/>
+ <sysproperty key="QPID_HOME" value="${broker.dir}"/>
+ <sysproperty key="QPID_WORK" value="${broker.dir}${file.separator}target"/>
+ </java>
+
+ </target>
+</project>
diff --git a/java/broker/src/main/java/org/apache/qpid/server/Main.java b/java/broker/src/main/java/org/apache/qpid/server/Main.java
index 6f970730ec..29ea69caf7 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/Main.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/Main.java
@@ -24,6 +24,7 @@ import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.BindException;
import java.util.Collection;
import java.util.List;
import org.apache.commons.cli.CommandLine;
@@ -171,7 +172,8 @@ public class Main
}
else if (commandLine.hasOption("v"))
{
- String ver = "Qpid 0.9.0.0";
+ String ver = QpidProperties.getVersionString();
+
StringBuilder protocol = new StringBuilder("AMQP version(s) [major.minor]: ");
boolean first = true;
@@ -357,7 +359,7 @@ public class Main
* @todo Partially implements top-level error handler. Better to let these errors fall through to a single
* top-level handler.
*/
- protected void bind(int port, ConnectorConfiguration connectorConfig)
+ protected void bind(int port, ConnectorConfiguration connectorConfig) throws BindException
{
String bindAddr = commandLine.getOptionValue("b");
if (bindAddr == null)
@@ -425,6 +427,8 @@ public class Main
catch (Exception e)
{
_logger.error("Unable to bind service to registry: " + e, e);
+ //fixme this need tidying up
+ throw new BindException(e.getMessage());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java b/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java
index 28b2489142..8462ed9557 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java
@@ -182,10 +182,8 @@ public class ProtocolOutputConverterImpl implements ProtocolOutputConverter
deliveryTag, pb.getExchange(), messageHandle.isRedelivered(),
pb.getRoutingKey());
- ByteBuffer buf = ByteBuffer.allocate((int) deliverFrame.getSize()); // XXX: Could cast be a problem?
- deliverFrame.writePayload(buf);
- buf.flip();
- return buf;
+
+ return deliverFrame.toByteBuffer();
}
private ByteBuffer createEncodedGetOkFrame(AMQMessage message, int channelId, long deliveryTag, int queueSize)
@@ -201,10 +199,8 @@ public class ProtocolOutputConverterImpl implements ProtocolOutputConverter
queueSize,
messageHandle.isRedelivered(),
pb.getRoutingKey());
- ByteBuffer buf = ByteBuffer.allocate((int) getOkFrame.getSize()); // XXX: Could cast be a problem?
- getOkFrame.writePayload(buf);
- buf.flip();
- return buf;
+
+ return getOkFrame.toByteBuffer();
}
public byte getProtocolMinorVersion()
@@ -225,10 +221,8 @@ public class ProtocolOutputConverterImpl implements ProtocolOutputConverter
message.getMessagePublishInfo().getExchange(),
replyCode, replyText,
message.getMessagePublishInfo().getRoutingKey());
- ByteBuffer buf = ByteBuffer.allocate((int) returnFrame.getSize()); // XXX: Could cast be a problem?
- returnFrame.writePayload(buf);
- buf.flip();
- return buf;
+
+ return returnFrame.toByteBuffer();
}
public void writeReturn(AMQMessage message, int channelId, int replyCode, AMQShortString replyText)
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java b/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
index 0fb5e6d88a..2aa759b35d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
@@ -717,7 +717,9 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
public void deliver(StoreContext context, AMQShortString name, AMQMessage msg, boolean deliverFirst) throws AMQException
{
- if (_log.isDebugEnabled())
+
+ final boolean debugEnabled = _log.isDebugEnabled();
+ if (debugEnabled)
{
_log.debug(debugIdentity() + "deliver :first(" + deliverFirst + ") :" + msg);
}
@@ -732,7 +734,7 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
if (s == null) //no-one can take the message right now.
{
- if (_log.isDebugEnabled())
+ if (debugEnabled)
{
_log.debug(debugIdentity() + "Testing Message(" + msg + ") for Queued Delivery:" + currentStatus());
}
@@ -744,7 +746,7 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
_lock.unlock();
//Pre Deliver to all subscriptions
- if (_log.isDebugEnabled())
+ if (debugEnabled)
{
_log.debug(debugIdentity() + "We have " + _subscriptions.getSubscriptions().size() +
" subscribers to give the message to:" + currentStatus());
@@ -755,7 +757,7 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
// stop if the message gets delivered whilst PreDelivering if we have a shared queue.
if (_queue.isShared() && msg.getDeliveredToConsumer())
{
- if (_log.isDebugEnabled())
+ if (debugEnabled)
{
_log.debug(debugIdentity() + "Stopping PreDelivery as message(" + System.identityHashCode(msg) +
") is already delivered.");
@@ -766,7 +768,7 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
// Only give the message to those that want them.
if (sub.hasInterest(msg))
{
- if (_log.isDebugEnabled())
+ if (debugEnabled)
{
_log.debug(debugIdentity() + "Queuing message(" + System.identityHashCode(msg) +
") for PreDelivery for subscriber(" + System.identityHashCode(sub) + ")");
@@ -795,9 +797,9 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
}
else
{
- if (_log.isInfoEnabled())
+ if (debugEnabled)
{
- _log.info(debugIdentity() + " Subscription(" + System.identityHashCode(s) + ") became " +
+ _log.debug(debugIdentity() + " Subscription(" + System.identityHashCode(s) + ") became " +
"suspended between nextSubscriber and send for message:" + msg.debugIdentity());
}
}
@@ -805,9 +807,9 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
if (!msg.isTaken(_queue))
{
- if (_log.isInfoEnabled())
+ if (debugEnabled)
{
- _log.info(debugIdentity() + " Message(" + msg.debugIdentity() + ") has not been taken so recursing!:" +
+ _log.debug(debugIdentity() + " Message(" + msg.debugIdentity() + ") has not been taken so recursing!:" +
" Subscriber:" + System.identityHashCode(s));
}
@@ -815,7 +817,7 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
}
else
{
- if (_log.isDebugEnabled())
+ if (debugEnabled)
{
_log.debug(debugIdentity() + " Message(" + msg.toString() +
") has been taken so disregarding deliver request to Subscriber:" +
diff --git a/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java b/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java
new file mode 100644
index 0000000000..1ebecbacb6
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *
+ */
+package org.apache.qpid.server;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+public class RunBrokerWithCommand
+{
+ public static void main(String[] args)
+ {
+ //Start broker
+
+ try
+ {
+
+ String[] fudge = new String[1];
+ fudge[0] = "-v";
+ new Main(fudge).startup();
+ }
+ catch (Exception e)
+ {
+ System.out.println("Unable to start broker due to: " + e.getMessage());
+
+ e.printStackTrace();
+ exit(1);
+ }
+
+ Logger.getRootLogger().setLevel(Level.ERROR);
+
+ //run command
+ try
+ {
+ Process task = Runtime.getRuntime().exec(args[0]);
+ System.out.println("Started Proccess: " + args[0]);
+
+ InputStream inputStream = task.getInputStream();
+
+ InputStream errorStream = task.getErrorStream();
+
+ Thread out = new Thread(new Outputter("[OUT]", new BufferedReader(new InputStreamReader(inputStream))));
+ Thread err = new Thread(new Outputter("[ERR]", new BufferedReader(new InputStreamReader(errorStream))));
+
+ out.start();
+ err.start();
+
+ out.join();
+ err.join();
+
+ System.out.println("Waiting for process to exit: " + args[0]);
+ task.waitFor();
+ System.out.println("Done Proccess: " + args[0]);
+
+ }
+ catch (IOException e)
+ {
+ System.out.println("Proccess had problems: " + e.getMessage());
+ exit(1);
+ }
+ catch (InterruptedException e)
+ {
+ System.out.println("Proccess had problems: " + e.getMessage());
+
+ exit(1);
+ }
+
+
+ exit(0);
+ }
+
+ private static void exit(int i)
+ {
+ Logger.getRootLogger().setLevel(Level.INFO);
+ System.exit(i);
+ }
+
+ static class Outputter implements Runnable
+ {
+
+ BufferedReader reader;
+ String prefix;
+
+ Outputter(String s, BufferedReader r)
+ {
+ prefix = s;
+ reader = r;
+ }
+
+ public void run()
+ {
+ String line;
+ try
+ {
+ while ((line = reader.readLine()) != null)
+ {
+ System.out.println(prefix + line);
+ }
+ }
+ catch (IOException e)
+ {
+ System.out.println("Error occured reading; " + e.getMessage());
+ }
+ }
+
+ }
+
+}
diff --git a/java/client/example/pom.xml b/java/client/example/pom.xml
index ac0081c00b..dd5b7a9c65 100644
--- a/java/client/example/pom.xml
+++ b/java/client/example/pom.xml
@@ -34,7 +34,7 @@
</parent>
<properties>
- <topDirectoryLocation>..</topDirectoryLocation>
+ <topDirectoryLocation>../..</topDirectoryLocation>
<amqj.logging.level>warn</amqj.logging.level>
</properties>
@@ -43,12 +43,18 @@
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-common</artifactId>
</dependency>
+
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-client</artifactId>
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
</dependency>
diff --git a/java/client/pom.xml b/java/client/pom.xml
index 2e720cdb71..c36c54a10f 100644
--- a/java/client/pom.xml
+++ b/java/client/pom.xml
@@ -31,6 +31,7 @@
<groupId>org.apache.qpid</groupId>
<artifactId>qpid</artifactId>
<version>1.0-incubating-M2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<properties>
@@ -47,6 +48,12 @@
<artifactId>qpid-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
@@ -55,13 +62,6 @@
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
- <!-- commons collection exports log4j v1.2.7 which doesn't have trace()-->
- <exclusions>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
@@ -75,6 +75,13 @@
</dependency>
<!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency> <!-- for inVm Broker -->
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-broker</artifactId>
@@ -82,19 +89,6 @@
</dependency>
<dependency>
- <groupId>jmscts</groupId>
- <artifactId>jmscts</artifactId>
- <version>0.5-b2</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>jms</groupId>
- <artifactId>jms</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index 2c92cfb85e..ebbbac5e6e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -20,34 +20,14 @@
*/
package org.apache.qpid.client;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.nio.channels.UnresolvedAddressException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.jms.*;
-import javax.jms.IllegalStateException;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
-import javax.naming.StringRefAddr;
-
import org.apache.log4j.Logger;
-
import org.apache.qpid.AMQConnectionFailureException;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQUndeliveredException;
import org.apache.qpid.AMQUnresolvedAddressException;
-import org.apache.qpid.client.failover.FailoverSupport;
+import org.apache.qpid.client.failover.FailoverException;
+import org.apache.qpid.client.failover.FailoverProtectedOperation;
+import org.apache.qpid.client.failover.FailoverRetrySupport;
import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.client.transport.TransportConnection;
@@ -68,6 +48,37 @@ import org.apache.qpid.jms.FailoverPolicy;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.url.URLSyntaxException;
+import javax.jms.ConnectionConsumer;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicSession;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.nio.channels.UnresolvedAddressException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
public class AMQConnection extends Closeable implements Connection, QueueConnection, TopicConnection, Referenceable
{
private static final Logger _logger = Logger.getLogger(AMQConnection.class);
@@ -163,7 +174,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
* @throws URLSyntaxException
*/
public AMQConnection(String broker, String username, String password, String clientName, String virtualHost)
- throws AMQException, URLSyntaxException
+ throws AMQException, URLSyntaxException
{
this(new AMQConnectionURL(
ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
@@ -182,7 +193,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
* @throws URLSyntaxException
*/
public AMQConnection(String broker, String username, String password, String clientName, String virtualHost,
- SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
+ SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
{
this(new AMQConnectionURL(
ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
@@ -191,28 +202,28 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public AMQConnection(String host, int port, String username, String password, String clientName, String virtualHost)
- throws AMQException, URLSyntaxException
+ throws AMQException, URLSyntaxException
{
this(host, port, false, username, password, clientName, virtualHost, null);
}
public AMQConnection(String host, int port, String username, String password, String clientName, String virtualHost,
- SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
+ SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
{
this(host, port, false, username, password, clientName, virtualHost, sslConfig);
}
public AMQConnection(String host, int port, boolean useSSL, String username, String password, String clientName,
- String virtualHost, SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
+ String virtualHost, SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
{
this(new AMQConnectionURL(
useSSL
? (ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
- + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
- + "'" + "," + ConnectionURL.OPTIONS_SSL + "='true'")
+ + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
+ + "'" + "," + ConnectionURL.OPTIONS_SSL + "='true'")
: (ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
- + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
- + "'" + "," + ConnectionURL.OPTIONS_SSL + "='false'")), sslConfig);
+ + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
+ + "'" + "," + ConnectionURL.OPTIONS_SSL + "='false'")), sslConfig);
}
public AMQConnection(String connection) throws AMQException, URLSyntaxException
@@ -226,8 +237,8 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
/**
- * @todo Some horrible stuff going on here with setting exceptions to be non-null to detect if an exception
- * was thrown during the connection! Intention not clear. Use a flag anyway, not exceptions... Will fix soon.
+ * @todo Some horrible stuff going on here with setting exceptions to be non-null to detect if an exception was
+ * thrown during the connection! Intention not clear. Use a flag anyway, not exceptions... Will fix soon.
*/
public AMQConnection(ConnectionURL connectionURL, SSLConfiguration sslConfig) throws AMQException
{
@@ -294,7 +305,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
if (_logger.isInfoEnabled())
{
_logger.info("Unable to connect to broker at " + _failoverPolicy.getCurrentBrokerDetails(),
- e.getCause());
+ e.getCause());
}
}
}
@@ -332,7 +343,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
if (lastException instanceof UnresolvedAddressException)
{
e = new AMQUnresolvedAddressException(message, _failoverPolicy.getCurrentBrokerDetails().toString(),
- null);
+ null);
}
if (e.getCause() != null)
@@ -446,7 +457,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
if (_logger.isInfoEnabled())
{
_logger.info(e.getMessage() + ":Unable to connect to broker at "
- + _failoverPolicy.getCurrentBrokerDetails());
+ + _failoverPolicy.getCurrentBrokerDetails());
}
}
}
@@ -485,96 +496,96 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public org.apache.qpid.jms.Session createSession(final boolean transacted, final int acknowledgeMode, final int prefetch)
- throws JMSException
+ throws JMSException
{
return createSession(transacted, acknowledgeMode, prefetch, prefetch);
}
public org.apache.qpid.jms.Session createSession(final boolean transacted, final int acknowledgeMode,
- final int prefetchHigh, final int prefetchLow) throws JMSException
+ final int prefetchHigh, final int prefetchLow) throws JMSException
{
checkNotClosed();
+
if (channelLimitReached())
{
throw new ChannelLimitReachedException(_maximumChannelCount);
}
- else
- {
- return (org.apache.qpid.jms.Session) new FailoverSupport()
+
+ return new FailoverRetrySupport<org.apache.qpid.jms.Session, JMSException>(
+ new FailoverProtectedOperation<org.apache.qpid.jms.Session, JMSException>()
+ {
+ public org.apache.qpid.jms.Session execute() throws JMSException, FailoverException
{
- public Object operation() throws JMSException
+ int channelId = _idFactory.incrementAndGet();
+
+ if (_logger.isDebugEnabled())
{
- int channelId = _idFactory.incrementAndGet();
+ _logger.debug("Write channel open frame for channel id " + channelId);
+ }
- if (_logger.isDebugEnabled())
+ // We must create the session and register it before actually sending the frame to the server to
+ // open it, so that there is no window where we could receive data on the channel and not be set
+ // up to handle it appropriately.
+ AMQSession session =
+ new AMQSession(AMQConnection.this, channelId, transacted, acknowledgeMode, prefetchHigh,
+ prefetchLow);
+ // _protocolHandler.addSessionByChannel(channelId, session);
+ registerSession(channelId, session);
+
+ boolean success = false;
+ try
+ {
+ createChannelOverWire(channelId, prefetchHigh, prefetchLow, transacted);
+ success = true;
+ }
+ catch (AMQException e)
+ {
+ JMSException jmse = new JMSException("Error creating session: " + e);
+ jmse.setLinkedException(e);
+ throw jmse;
+ }
+ finally
+ {
+ if (!success)
{
- _logger.debug("Write channel open frame for channel id " + channelId);
+ deregisterSession(channelId);
}
+ }
- // We must create the session and register it before actually sending the frame to the server to
- // open it, so that there is no window where we could receive data on the channel and not be set
- // up to handle it appropriately.
- AMQSession session =
- new AMQSession(AMQConnection.this, channelId, transacted, acknowledgeMode, prefetchHigh,
- prefetchLow);
- // _protocolHandler.addSessionByChannel(channelId, session);
- registerSession(channelId, session);
-
- boolean success = false;
+ if (_started)
+ {
try
{
- createChannelOverWire(channelId, prefetchHigh, prefetchLow, transacted);
- success = true;
+ session.start();
}
catch (AMQException e)
{
- JMSException jmse = new JMSException("Error creating session: " + e);
- jmse.setLinkedException(e);
- throw jmse;
+ throw new JMSAMQException(e);
}
- finally
- {
- if (!success)
- {
- deregisterSession(channelId);
- }
- }
-
- if (_started)
- {
- try
- {
- session.start();
- }
- catch (AMQException e)
- {
- throw new JMSAMQException(e);
- }
- }
-
- return session;
}
- }.execute(this);
- }
+
+ return session;
+ }
+ }, this).execute();
}
private void createChannelOverWire(int channelId, int prefetchHigh, int prefetchLow, boolean transacted)
- throws AMQException
+ throws AMQException, FailoverException
{
// TODO: Be aware of possible changes to parameter order as versions change.
_protocolHandler.syncWrite(ChannelOpenBody.createAMQFrame(channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(), null), // outOfBand
- ChannelOpenOkBody.class);
+ _protocolHandler.getProtocolMinorVersion(), null), // outOfBand
+ ChannelOpenOkBody.class);
// todo send low water mark when protocol allows.
// todo Be aware of possible changes to parameter order as versions change.
_protocolHandler.syncWrite(BasicQosBody.createAMQFrame(channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(), false, // global
- prefetchHigh, // prefetchCount
- 0), // prefetchSize
- BasicQosOkBody.class);
+ _protocolHandler.getProtocolMinorVersion(), false, // global
+ prefetchHigh, // prefetchCount
+ 0), // prefetchSize
+ BasicQosOkBody.class);
if (transacted)
{
@@ -585,11 +596,12 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
// TODO: Be aware of possible changes to parameter order as versions change.
_protocolHandler.syncWrite(TxSelectBody.createAMQFrame(channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion()), TxSelectOkBody.class);
+ _protocolHandler.getProtocolMinorVersion()), TxSelectOkBody.class);
}
}
- private void reopenChannel(int channelId, int prefetchHigh, int prefetchLow, boolean transacted) throws AMQException
+ private void reopenChannel(int channelId, int prefetchHigh, int prefetchLow, boolean transacted)
+ throws AMQException, FailoverException
{
try
{
@@ -861,7 +873,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector,
- ServerSessionPool sessionPool, int maxMessages) throws JMSException
+ ServerSessionPool sessionPool, int maxMessages) throws JMSException
{
checkNotClosed();
@@ -869,7 +881,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool,
- int maxMessages) throws JMSException
+ int maxMessages) throws JMSException
{
checkNotClosed();
@@ -877,7 +889,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool,
- int maxMessages) throws JMSException
+ int maxMessages) throws JMSException
{
checkNotClosed();
@@ -885,7 +897,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector,
- ServerSessionPool sessionPool, int maxMessages) throws JMSException
+ ServerSessionPool sessionPool, int maxMessages) throws JMSException
{
// TODO Auto-generated method stub
checkNotClosed();
@@ -1077,8 +1089,8 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
if (code != null)
{
je =
- new JMSException(Integer.toString(code.getCode()), "Exception thrown against " + toString() + ": "
- + cause);
+ new JMSException(Integer.toString(code.getCode()), "Exception thrown against " + toString() + ": "
+ + cause);
}
else
{
@@ -1142,7 +1154,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
* For all sessions, and for all consumers in those sessions, resubscribe. This is called during failover handling.
* The caller must hold the failover mutex before calling this method.
*/
- public void resubscribeSessions() throws JMSException, AMQException
+ public void resubscribeSessions() throws JMSException, AMQException, FailoverException
{
ArrayList sessions = new ArrayList(_sessions.values());
_logger.info(MessageFormat.format("Resubscribing sessions = {0} sessions.size={1}", sessions, sessions.size())); // FIXME: removeKey?
@@ -1184,7 +1196,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
public Reference getReference() throws NamingException
{
return new Reference(AMQConnection.class.getName(), new StringRefAddr(AMQConnection.class.getName(), toURL()),
- AMQConnectionFactory.class.getName(), null); // factory location
+ AMQConnectionFactory.class.getName(), null); // factory location
}
public SSLConfiguration getSSLConfiguration()
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
index 585991d905..cc5af07b20 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
@@ -60,9 +60,9 @@ public abstract class AMQDestination implements Destination, Referenceable
private static final int IS_EXCLUSIVE_MASK = 0x2;
private static final int IS_AUTODELETE_MASK = 0x4;
- public static final byte QUEUE_TYPE = 1;
- public static final byte TOPIC_TYPE = 2;
- public static final byte UNKNOWN_TYPE = 3;
+ public static final Integer QUEUE_TYPE = Integer.valueOf(1);
+ public static final Integer TOPIC_TYPE = Integer.valueOf(2);
+ public static final Integer UNKNOWN_TYPE = Integer.valueOf(3);
protected AMQDestination(String url) throws URLSyntaxException
{
@@ -213,7 +213,7 @@ public abstract class AMQDestination implements Destination, Referenceable
}
public String toURL()
- {
+ {
String url = _url;
if(url == null)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java b/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
index 4662f80c5b..28e5992b26 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
@@ -20,9 +20,8 @@
*/
package org.apache.qpid.client;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.concurrent.atomic.AtomicBoolean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
@@ -30,12 +29,13 @@ import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
-import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.concurrent.atomic.AtomicBoolean;
public class AMQQueueBrowser implements QueueBrowser
{
- private static final Logger _logger = Logger.getLogger(AMQQueueBrowser.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(AMQQueueBrowser.class);
private AtomicBoolean _isClosed = new AtomicBoolean();
private final AMQSession _session;
@@ -43,20 +43,21 @@ public class AMQQueueBrowser implements QueueBrowser
private final ArrayList<BasicMessageConsumer> _consumers = new ArrayList<BasicMessageConsumer>();
private final String _messageSelector;
-
AMQQueueBrowser(AMQSession session, AMQQueue queue, String messageSelector) throws JMSException
{
_session = session;
_queue = queue;
- _messageSelector = (messageSelector == null) || (messageSelector.trim().length() == 0) ? null : messageSelector;
+ _messageSelector = ((messageSelector == null) || (messageSelector.trim().length() == 0)) ? null : messageSelector;
// Create Consumer to verify message selector.
- BasicMessageConsumer consumer = (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false);
- consumer.close();
+ BasicMessageConsumer consumer =
+ (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false);
+ consumer.close();
}
public Queue getQueue() throws JMSException
{
checkState();
+
return _queue;
}
@@ -66,6 +67,7 @@ public class AMQQueueBrowser implements QueueBrowser
{
throw new IllegalStateException("Queue Browser");
}
+
if (_session.isClosed())
{
throw new IllegalStateException("Session is closed");
@@ -77,47 +79,48 @@ public class AMQQueueBrowser implements QueueBrowser
{
checkState();
+
return _messageSelector;
}
public Enumeration getEnumeration() throws JMSException
{
checkState();
- final BasicMessageConsumer consumer = (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false);
+ final BasicMessageConsumer consumer =
+ (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false);
_consumers.add(consumer);
return new Enumeration()
- {
-
-
- Message _nextMessage = consumer.receive();
-
-
- public boolean hasMoreElements()
{
- _logger.info("QB:hasMoreElements:" + (_nextMessage != null));
- return (_nextMessage != null);
- }
- public Object nextElement()
- {
- Message msg = _nextMessage;
- try
+ Message _nextMessage = consumer.receive();
+
+ public boolean hasMoreElements()
{
- _logger.info("QB:nextElement about to receive");
+ _logger.info("QB:hasMoreElements:" + (_nextMessage != null));
- _nextMessage = consumer.receive();
- _logger.info("QB:nextElement received:" + _nextMessage);
+ return (_nextMessage != null);
}
- catch (JMSException e)
+
+ public Object nextElement()
{
- _logger.warn("Exception caught while queue browsing", e);
- _nextMessage = null;
+ Message msg = _nextMessage;
+ try
+ {
+ _logger.info("QB:nextElement about to receive");
+
+ _nextMessage = consumer.receive();
+ _logger.info("QB:nextElement received:" + _nextMessage);
+ }
+ catch (JMSException e)
+ {
+ _logger.warn("Exception caught while queue browsing", e);
+ _nextMessage = null;
+ }
+
+ return msg;
}
-
- return msg;
- }
- };
+ };
}
public void close() throws JMSException
@@ -126,8 +129,8 @@ public class AMQQueueBrowser implements QueueBrowser
{
consumer.close();
}
+
_consumers.clear();
}
-
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
index 8796a225ba..c2b7bc26c4 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
@@ -20,47 +20,15 @@
*/
package org.apache.qpid.client;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Arrays;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.jms.BytesMessage;
-import javax.jms.Destination;
-import javax.jms.IllegalStateException;
-import javax.jms.InvalidDestinationException;
-import javax.jms.InvalidSelectorException;
-import javax.jms.JMSException;
-import javax.jms.MapMessage;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueBrowser;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.StreamMessage;
-import javax.jms.TemporaryQueue;
-import javax.jms.TemporaryTopic;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.jms.TopicSubscriber;
-
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQUndeliveredException;
-import org.apache.qpid.AMQInvalidRoutingKeyException;
import org.apache.qpid.AMQInvalidArgumentException;
-import org.apache.qpid.client.failover.FailoverSupport;
+import org.apache.qpid.AMQInvalidRoutingKeyException;
+import org.apache.qpid.AMQUndeliveredException;
+import org.apache.qpid.client.failover.FailoverException;
+import org.apache.qpid.client.failover.FailoverNoopSupport;
+import org.apache.qpid.client.failover.FailoverProtectedOperation;
+import org.apache.qpid.client.failover.FailoverRetrySupport;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.JMSBytesMessage;
import org.apache.qpid.client.message.JMSMapMessage;
@@ -70,21 +38,20 @@ import org.apache.qpid.client.message.JMSTextMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage;
import org.apache.qpid.client.protocol.AMQProtocolHandler;
-import org.apache.qpid.client.protocol.BlockingMethodFrameListener;
import org.apache.qpid.client.util.FlowControllingBlockingQueue;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.AccessRequestBody;
-import org.apache.qpid.framing.AccessRequestOkBody;
import org.apache.qpid.framing.BasicAckBody;
import org.apache.qpid.framing.BasicConsumeBody;
import org.apache.qpid.framing.BasicConsumeOkBody;
import org.apache.qpid.framing.BasicRecoverBody;
+import org.apache.qpid.framing.BasicRecoverOkBody;
+import org.apache.qpid.framing.BasicRejectBody;
import org.apache.qpid.framing.ChannelCloseBody;
import org.apache.qpid.framing.ChannelCloseOkBody;
import org.apache.qpid.framing.ChannelFlowBody;
+import org.apache.qpid.framing.ChannelFlowOkBody;
import org.apache.qpid.framing.ExchangeBoundBody;
import org.apache.qpid.framing.ExchangeBoundOkBody;
import org.apache.qpid.framing.ExchangeDeclareBody;
@@ -92,358 +59,242 @@ import org.apache.qpid.framing.ExchangeDeclareOkBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.FieldTableFactory;
import org.apache.qpid.framing.QueueBindBody;
+import org.apache.qpid.framing.QueueBindOkBody;
import org.apache.qpid.framing.QueueDeclareBody;
+import org.apache.qpid.framing.QueueDeclareOkBody;
import org.apache.qpid.framing.QueueDeleteBody;
import org.apache.qpid.framing.QueueDeleteOkBody;
import org.apache.qpid.framing.TxCommitBody;
import org.apache.qpid.framing.TxCommitOkBody;
import org.apache.qpid.framing.TxRollbackBody;
import org.apache.qpid.framing.TxRollbackOkBody;
-import org.apache.qpid.framing.QueueBindOkBody;
-import org.apache.qpid.framing.QueueDeclareOkBody;
-import org.apache.qpid.framing.ChannelFlowOkBody;
-import org.apache.qpid.framing.BasicRecoverOkBody;
-import org.apache.qpid.framing.BasicRejectBody;
import org.apache.qpid.jms.Session;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.url.AMQBindingURL;
import org.apache.qpid.url.URLSyntaxException;
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidSelectorException;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ */
public class AMQSession extends Closeable implements Session, QueueSession, TopicSession
{
+ /** Used for debugging. */
private static final Logger _logger = Logger.getLogger(AMQSession.class);
+ /** Used for debugging in the dispatcher. */
+ private static final Logger _dispatcherLogger = Logger.getLogger(Dispatcher.class);
+
+ /** The default maximum number of prefetched message at which to suspend the channel. */
public static final int DEFAULT_PREFETCH_HIGH_MARK = 5000;
+
+ /** The default minimum number of prefetched messages at which to resume the channel. */
public static final int DEFAULT_PREFETCH_LOW_MARK = 2500;
+ /**
+ * The default value for immediate flag used by producers created by this session is false. That is, a consumer does
+ * not need to be attached to a queue.
+ */
+ protected static final boolean DEFAULT_IMMEDIATE = false;
+
+ /**
+ * The default value for mandatory flag used by producers created by this session is true. That is, server will not
+ * silently drop messages where no queue is connected to the exchange for the message.
+ */
+ protected static final boolean DEFAULT_MANDATORY = true;
+
+ /** System property to enable strict AMQP compliance. */
+ public static final String STRICT_AMQP = "STRICT_AMQP";
+
+ /** Strict AMQP default setting. */
+ public static final String STRICT_AMQP_DEFAULT = "false";
+
+ /** System property to enable failure if strict AMQP compliance is violated. */
+ public static final String STRICT_AMQP_FATAL = "STRICT_AMQP_FATAL";
+
+ /** Strickt AMQP failure default. */
+ public static final String STRICT_AMQP_FATAL_DEFAULT = "true";
+
+ /** System property to enable immediate message prefetching. */
+ public static final String IMMEDIATE_PREFETCH = "IMMEDIATE_PREFETCH";
+
+ /** Immediate message prefetch default. */
+ public static final String IMMEDIATE_PREFETCH_DEFAULT = "false";
+
+ /** The connection to which this session belongs. */
private AMQConnection _connection;
+ /** Used to indicate whether or not this is a transactional session. */
private boolean _transacted;
+ /** Holds the sessions acknowledgement mode. */
private int _acknowledgeMode;
+ /** Holds this session unique identifier, used to distinguish it from other sessions. */
private int _channelId;
+ /** @todo This does not appear to be set? */
private int _ticket;
+ /** Holds the high mark for prefetched message, at which the session is suspended. */
private int _defaultPrefetchHighMark = DEFAULT_PREFETCH_HIGH_MARK;
+
+ /** Holds the low mark for prefetched messages, below which the session is resumed. */
private int _defaultPrefetchLowMark = DEFAULT_PREFETCH_LOW_MARK;
+ /** Holds the message listener, if any, which is attached to this session. */
private MessageListener _messageListener = null;
+ /** Used to indicate that this session has been started at least once. */
private AtomicBoolean _startedAtLeastOnce = new AtomicBoolean(false);
/**
- * Used to reference durable subscribers so they requests for unsubscribe can be handled correctly. Note this only
- * keeps a record of subscriptions which have been created in the current instance. It does not remember
- * subscriptions between executions of the client
+ * Used to reference durable subscribers so that requests for unsubscribe can be handled correctly. Note this only
+ * keeps a record of subscriptions which have been created in the current instance. It does not remember
+ * subscriptions between executions of the client.
*/
private final ConcurrentHashMap<String, TopicSubscriberAdaptor> _subscriptions =
new ConcurrentHashMap<String, TopicSubscriberAdaptor>();
+
+ /**
+ * Holds a mapping from message consumers to their identifying names, so that their subscriptions may be looked up
+ * in the {@link #_subscriptions} map.
+ */
private final ConcurrentHashMap<BasicMessageConsumer, String> _reverseSubscriptionMap =
new ConcurrentHashMap<BasicMessageConsumer, String>();
- /** Used in the consume method. We generate the consume tag on the client so that we can use the nowait feature. */
- private int _nextTag = 1;
-
- /** This queue is bounded and is used to store messages before being dispatched to the consumer */
+ /**
+ * Used to hold incoming messages.
+ *
+ * @todo Weaken the type once {@link FlowControllingBlockingQueue} implements Queue.
+ */
private final FlowControllingBlockingQueue _queue;
+ /** Holds the dispatcher thread for this session. */
private Dispatcher _dispatcher;
+ /** Holds the message factory factory for this session. */
private MessageFactoryRegistry _messageFactoryRegistry;
- /** Set of all producers created by this session */
- private Map _producers = new ConcurrentHashMap();
-
- /** Maps from consumer tag (String) to JMSMessageConsumer instance */
- private Map<AMQShortString, BasicMessageConsumer> _consumers = new ConcurrentHashMap<AMQShortString, BasicMessageConsumer>();
-
- /** Maps from destination to count of JMSMessageConsumers */
- private ConcurrentHashMap<Destination, AtomicInteger> _destinationConsumerCount =
- new ConcurrentHashMap<Destination, AtomicInteger>();
+ /** Holds all of the producers created by this session, keyed by their unique identifiers. */
+ private Map<Long, MessageProducer> _producers = new ConcurrentHashMap<Long, MessageProducer>();
/**
- * Default value for immediate flag used by producers created by this session is false, i.e. a consumer does not
- * need to be attached to a queue
+ * Used as a source of unique identifiers so that the consumers can be tagged to match them to BasicConsume
+ * methods.
*/
- protected static final boolean DEFAULT_IMMEDIATE = false;
+ private int _nextTag = 1;
/**
- * Default value for mandatory flag used by producers created by this sessio is true, i.e. server will not silently
- * drop messages where no queue is connected to the exchange for the message
+ * Maps from identifying tags to message consumers, in order to pass dispatch incoming messages to the right
+ * consumer.
*/
- protected static final boolean DEFAULT_MANDATORY = true;
+ private Map<AMQShortString, BasicMessageConsumer> _consumers =
+ new ConcurrentHashMap<AMQShortString, BasicMessageConsumer>();
+
+ /** Provides a count of consumers on destinations, in order to be able to know if a destination has consumers. */
+ private ConcurrentHashMap<Destination, AtomicInteger> _destinationConsumerCount =
+ new ConcurrentHashMap<Destination, AtomicInteger>();
/**
- * The counter of the next producer id. This id is generated by the session and used only to allow the producer to
- * identify itself to the session when deregistering itself. <p/> Access to this id does not require to be
- * synchronized since according to the JMS specification only one thread of control is allowed to create producers
- * for any given session instance.
+ * Used as a source of unique identifiers for producers within the session.
+ *
+ * <p/> Access to this id does not require to be synchronized since according to the JMS specification only one
+ * thread of control is allowed to create producers for any given session instance.
*/
private long _nextProducerId;
-
/**
* Set when recover is called. This is to handle the case where recover() is called by application code during
- * onMessage() processing. We need to make sure we do not send an auto ack if recover was called.
+ * onMessage() processing to enure that an auto ack is not sent.
*/
private boolean _inRecovery;
+ /** Used to indicates that the connection to which this session belongs, has been stopped. */
private boolean _connectionStopped;
+ /** Used to indicate that this session has a message listener attached to it. */
private boolean _hasMessageListeners;
+ /** Used to indicate that this session has been suspended. */
private boolean _suspended;
+ /**
+ * Used to protect the suspension of this session, so that critical code can be executed during suspension, without
+ * the session being resumed by other threads.
+ */
private final Object _suspensionLock = new Object();
- /** Boolean to control immediate prefetch . Records the first call to the dispatcher to prevent further flow(true) */
+ /**
+ * Used to ensure that onlt the first call to start the dispatcher can unsuspend the channel.
+ *
+ * @todo This is accessed only within a synchronized method, so does not need to be atomic.
+ */
private final AtomicBoolean _firstDispatcher = new AtomicBoolean(true);
- /** System property to enable strickt AMQP compliance */
- public static final String STRICT_AMQP = "STRICT_AMQP";
- /** Strickt AMQP default */
- public static final String STRICT_AMQP_DEFAULT = "false";
+ /** Used to indicate that the session should start pre-fetching messages as soon as it is started. */
+ private final boolean _immediatePrefetch;
+ /** Indicates that warnings should be generated on violations of the strict AMQP. */
private final boolean _strictAMQP;
- /** System property to enable strickt AMQP compliance */
- public static final String STRICT_AMQP_FATAL = "STRICT_AMQP_FATAL";
- /** Strickt AMQP default */
- public static final String STRICT_AMQP_FATAL_DEFAULT = "true";
-
+ /** Indicates that runtime exceptions should be generated on vilations of the strict AMQP. */
private final boolean _strictAMQPFATAL;
- /** System property to enable immediate message prefetching */
- public static final String IMMEDIATE_PREFETCH = "IMMEDIATE_PREFETCH";
- /** Immediate message prefetch default */
- public static final String IMMEDIATE_PREFETCH_DEFAULT = "false";
-
- private final boolean _immediatePrefetch;
-
- private static final Logger _dispatcherLogger = Logger.getLogger(Dispatcher.class);
-
- /** Responsible for decoding a message fragment and passing it to the appropriate message consumer. */
- private class Dispatcher extends Thread
- {
-
- /** Track the 'stopped' state of the dispatcher, a session starts in the stopped state. */
- private final AtomicBoolean _closed = new AtomicBoolean(false);
-
- private final Object _lock = new Object();
-
- public Dispatcher()
- {
- super("Dispatcher-Channel-" + _channelId);
- if (_dispatcherLogger.isInfoEnabled())
- {
- _dispatcherLogger.info(getName() + " created");
- }
- }
-
- public void run()
- {
- if (_dispatcherLogger.isInfoEnabled())
- {
- _dispatcherLogger.info(getName() + " started");
- }
-
- UnprocessedMessage message;
-
- // Allow disptacher to start stopped
- synchronized (_lock)
- {
- while (connectionStopped())
- {
- try
- {
- _lock.wait();
- }
- catch (InterruptedException e)
- {
- // ignore
- }
- }
- }
-
- try
- {
- while (!_closed.get() && (message = (UnprocessedMessage) _queue.take()) != null)
- {
- synchronized (_lock)
- {
-
- while (connectionStopped())
- {
- _lock.wait();
- }
-
- dispatchMessage(message);
-
- while (connectionStopped())
- {
- _lock.wait();
- }
-
- }
-
- }
- }
- catch (InterruptedException e)
- {
- //ignore
- }
- if (_dispatcherLogger.isInfoEnabled())
- {
- _dispatcherLogger.info(getName() + " thread terminating for channel " + _channelId);
- }
- }
-
- // only call while holding lock
- final boolean connectionStopped()
- {
- return _connectionStopped;
- }
-
- boolean setConnectionStopped(boolean connectionStopped)
- {
- boolean currently;
- synchronized (_lock)
- {
- currently = _connectionStopped;
- _connectionStopped = connectionStopped;
- _lock.notify();
-
- if (_dispatcherLogger.isDebugEnabled())
- {
- _dispatcherLogger.debug("Set Dispatcher Connection " + (connectionStopped ? "Stopped" : "Started") +
- ": Currently " + (currently ? "Stopped" : "Started"));
- }
- }
- return currently;
- }
-
- private void dispatchMessage(UnprocessedMessage message)
- {
- if (message.getDeliverBody() != null)
- {
- final BasicMessageConsumer consumer = (BasicMessageConsumer) _consumers.get(message.getDeliverBody().consumerTag);
-
- if (consumer == null || consumer.isClosed())
- {
- if (_dispatcherLogger.isInfoEnabled())
- {
- if (consumer == null)
- {
- _dispatcherLogger.info("Received a message(" + System.identityHashCode(message) + ")" +
- "[" + message.getDeliverBody().deliveryTag + "] from queue " +
- message.getDeliverBody().consumerTag +
- " )without a handler - rejecting(requeue)...");
- }
- else
- {
- _dispatcherLogger.info("Received a message(" + System.identityHashCode(message) + ")" +
- "[" + message.getDeliverBody().deliveryTag + "] from queue " +
- " consumer(" + consumer.debugIdentity() +
- ") is closed rejecting(requeue)...");
- }
- }
- // Don't reject if we're already closing
- if (!_closed.get())
- {
- rejectMessage(message, true);
- }
- }
- else
- {
- consumer.notifyMessage(message, _channelId);
- }
- }
- }
-
- public void close()
- {
- _closed.set(true);
- interrupt();
-
- //fixme awaitTermination
-
- }
-
- public void rollback()
- {
-
- synchronized (_lock)
- {
- boolean isStopped = connectionStopped();
-
- if (!isStopped)
- {
- setConnectionStopped(true);
- }
-
- rejectAllMessages(true);
-
- _dispatcherLogger.debug("Session Pre Dispatch Queue cleared");
-
- for (BasicMessageConsumer consumer : _consumers.values())
- {
- if (!consumer.isNoConsume())
- {
- consumer.rollback();
- }
- else
- {
- // should perhaps clear the _SQ here.
- //consumer._synchronousQueue.clear();
- consumer.clearReceiveQueue();
- }
-
-
- }
-
- setConnectionStopped(isStopped);
- }
-
- }
-
- public void rejectPending(BasicMessageConsumer consumer)
- {
- synchronized (_lock)
- {
- boolean stopped = _dispatcher.connectionStopped();
-
- if (!stopped)
- {
- _dispatcher.setConnectionStopped(true);
- }
-
- // Reject messages on pre-receive queue
- consumer.rollback();
-
- // Reject messages on pre-dispatch queue
- rejectMessagesForConsumerTag(consumer.getConsumerTag(), true);
-
- // closeConsumer
- consumer.markClosed();
-
- _dispatcher.setConnectionStopped(stopped);
-
- }
- }
- }
-
-
-
+ /**
+ * Creates a new session on a connection.
+ *
+ * @param con The connection on which to create the session.
+ * @param channelId The unique identifier for the session.
+ * @param transacted Indicates whether or not the session is transactional.
+ * @param acknowledgeMode The acknoledgement mode for the session.
+ * @param messageFactoryRegistry The message factory factory for the session.
+ * @param defaultPrefetchHighMark The maximum number of messages to prefetched before suspending the session.
+ * @param defaultPrefetchLowMark The number of prefetched messages at which to resume the session.
+ */
AMQSession(AMQConnection con, int channelId, boolean transacted, int acknowledgeMode,
MessageFactoryRegistry messageFactoryRegistry, int defaultPrefetchHighMark, int defaultPrefetchLowMark)
{
_strictAMQP = Boolean.parseBoolean(System.getProperties().getProperty(STRICT_AMQP, STRICT_AMQP_DEFAULT));
- _strictAMQPFATAL = Boolean.parseBoolean(System.getProperties().getProperty(STRICT_AMQP_FATAL, STRICT_AMQP_FATAL_DEFAULT));
- _immediatePrefetch = _strictAMQP || Boolean.parseBoolean(System.getProperties().getProperty(IMMEDIATE_PREFETCH, IMMEDIATE_PREFETCH_DEFAULT));
+ _strictAMQPFATAL =
+ Boolean.parseBoolean(System.getProperties().getProperty(STRICT_AMQP_FATAL, STRICT_AMQP_FATAL_DEFAULT));
+ _immediatePrefetch =
+ _strictAMQP
+ || Boolean.parseBoolean(System.getProperties().getProperty(IMMEDIATE_PREFETCH, IMMEDIATE_PREFETCH_DEFAULT));
_connection = con;
_transacted = transacted;
@@ -455,6 +306,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
_acknowledgeMode = acknowledgeMode;
}
+
_channelId = channelId;
_messageFactoryRegistry = messageFactoryRegistry;
_defaultPrefetchHighMark = defaultPrefetchHighMark;
@@ -462,27 +314,32 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
if (_acknowledgeMode == NO_ACKNOWLEDGE)
{
- _queue = new FlowControllingBlockingQueue(_defaultPrefetchHighMark, _defaultPrefetchLowMark,
- new FlowControllingBlockingQueue.ThresholdListener()
- {
- public void aboveThreshold(int currentValue)
- {
- if (_acknowledgeMode == NO_ACKNOWLEDGE)
- {
- _logger.warn("Above threshold(" + _defaultPrefetchHighMark + ") so suspending channel. Current value is " + currentValue);
- new Thread(new SuspenderRunner(true)).start();
- }
- }
-
- public void underThreshold(int currentValue)
- {
- if (_acknowledgeMode == NO_ACKNOWLEDGE)
- {
- _logger.warn("Below threshold(" + _defaultPrefetchLowMark + ") so unsuspending channel. Current value is " + currentValue);
- new Thread(new SuspenderRunner(false)).start();
- }
- }
- });
+ _queue =
+ new FlowControllingBlockingQueue(_defaultPrefetchHighMark, _defaultPrefetchLowMark,
+ new FlowControllingBlockingQueue.ThresholdListener()
+ {
+ public void aboveThreshold(int currentValue)
+ {
+ if (_acknowledgeMode == NO_ACKNOWLEDGE)
+ {
+ _logger.debug(
+ "Above threshold(" + _defaultPrefetchHighMark
+ + ") so suspending channel. Current value is " + currentValue);
+ new Thread(new SuspenderRunner(true)).start();
+ }
+ }
+
+ public void underThreshold(int currentValue)
+ {
+ if (_acknowledgeMode == NO_ACKNOWLEDGE)
+ {
+ _logger.debug(
+ "Below threshold(" + _defaultPrefetchLowMark
+ + ") so unsuspending channel. Current value is " + currentValue);
+ new Thread(new SuspenderRunner(false)).start();
+ }
+ }
+ });
}
else
{
@@ -490,183 +347,141 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
-
- AMQSession(AMQConnection con, int channelId, boolean transacted, int acknowledgeMode, int defaultPrefetchHigh, int defaultPrefetchLow)
- {
- this(con, channelId, transacted, acknowledgeMode, MessageFactoryRegistry.newDefaultRegistry(), defaultPrefetchHigh, defaultPrefetchLow);
- }
-
- public AMQConnection getAMQConnection()
- {
- return _connection;
- }
-
- public BytesMessage createBytesMessage() throws JMSException
+ /**
+ * Creates a new session on a connection with the default message factory factory.
+ *
+ * @param con The connection on which to create the session.
+ * @param channelId The unique identifier for the session.
+ * @param transacted Indicates whether or not the session is transactional.
+ * @param acknowledgeMode The acknoledgement mode for the session.
+ * @param defaultPrefetchHigh The maximum number of messages to prefetched before suspending the session.
+ * @param defaultPrefetchLow The number of prefetched messages at which to resume the session.
+ */
+ AMQSession(AMQConnection con, int channelId, boolean transacted, int acknowledgeMode, int defaultPrefetchHigh,
+ int defaultPrefetchLow)
{
- synchronized (_connection.getFailoverMutex())
- {
- checkNotClosed();
- return new JMSBytesMessage();
- }
+ this(con, channelId, transacted, acknowledgeMode, MessageFactoryRegistry.newDefaultRegistry(), defaultPrefetchHigh,
+ defaultPrefetchLow);
}
- public MapMessage createMapMessage() throws JMSException
+ /**
+ * Acknowledges all unacknowledged messages on the session, for all message consumers on the session.
+ *
+ * @throws IllegalStateException If the session is closed.
+ */
+ public void acknowledge() throws IllegalStateException
{
- synchronized (_connection.getFailoverMutex())
+ if (isClosed())
{
- checkNotClosed();
- return new JMSMapMessage();
+ throw new IllegalStateException("Session is already closed");
}
- }
-
- public javax.jms.Message createMessage() throws JMSException
- {
- return createBytesMessage();
- }
- public ObjectMessage createObjectMessage() throws JMSException
- {
- synchronized (_connection.getFailoverMutex())
+ for (BasicMessageConsumer consumer : _consumers.values())
{
- checkNotClosed();
- return (ObjectMessage) new JMSObjectMessage();
+ consumer.acknowledge();
}
}
- public ObjectMessage createObjectMessage(Serializable object) throws JMSException
- {
- ObjectMessage msg = createObjectMessage();
- msg.setObject(object);
- return msg;
- }
-
- public StreamMessage createStreamMessage() throws JMSException
+ /**
+ * Acknowledge one or many messages.
+ *
+ * @param deliveryTag The tag of the last message to be acknowledged.
+ * @param multiple <tt>true</tt> to acknowledge all messages up to and including the one specified by the
+ * delivery tag, <tt>false</tt> to just acknowledge that message.
+ *
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ public void acknowledgeMessage(long deliveryTag, boolean multiple)
{
- synchronized (_connection.getFailoverMutex())
- {
- checkNotClosed();
-
- return new JMSStreamMessage();
- }
- }
+ final AMQFrame ackFrame =
+ BasicAckBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(), deliveryTag,
+ multiple);
- public TextMessage createTextMessage() throws JMSException
- {
- synchronized (_connection.getFailoverMutex())
+ if (_logger.isDebugEnabled())
{
- checkNotClosed();
-
- return new JMSTextMessage();
+ _logger.debug("Sending ack for delivery tag " + deliveryTag + " on channel " + _channelId);
}
- }
-
- public TextMessage createTextMessage(String text) throws JMSException
- {
-
- TextMessage msg = createTextMessage();
- msg.setText(text);
- return msg;
- }
-
- public boolean getTransacted() throws JMSException
- {
- checkNotClosed();
- return _transacted;
- }
-
- public int getAcknowledgeMode() throws JMSException
- {
- checkNotClosed();
- return _acknowledgeMode;
- }
-
- public void commit() throws JMSException
- {
- checkTransacted();
- try
- {
- // Acknowledge up to message last delivered (if any) for each consumer.
- //need to send ack for messages delivered to consumers so far
- for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
- {
- //Sends acknowledgement to server
- i.next().acknowledgeLastDelivered();
- }
-
- // Commits outstanding messages sent and outstanding acknowledgements.
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQProtocolHandler handler = getProtocolHandler();
- handler.syncWrite(TxCommitBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion()),
- TxCommitOkBody.class);
- }
- catch (AMQException e)
- {
- JMSException exception = new JMSException("Failed to commit: " + e.getMessage());
- exception.setLinkedException(e);
- throw exception;
- }
+ getProtocolHandler().writeFrame(ackFrame);
}
-
- public void rollback() throws JMSException
+ /**
+ * Binds the named queue, with the specified routing key, to the named exchange.
+ *
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param queueName The name of the queue to bind.
+ * @param routingKey The routing key to bind the queue with.
+ * @param arguments Additional arguments.
+ * @param exchangeName The exchange to bind the queue on.
+ *
+ * @throws AMQException If the queue cannot be bound for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ * @todo Document the additional arguments that may be passed in the field table. Are these for headers exchanges?
+ */
+ public void bindQueue(final AMQShortString queueName, final AMQShortString routingKey, final FieldTable arguments,
+ final AMQShortString exchangeName) throws AMQException
{
- synchronized (_suspensionLock)
+ /*new FailoverRetrySupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()*/
+ new FailoverNoopSupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()
{
- checkTransacted();
- try
- {
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
-
- boolean isSuspended = isSuspended();
-
- if (!isSuspended)
- {
- suspendChannel(true);
- }
-
- if (_dispatcher != null)
- {
- _dispatcher.rollback();
- }
-
- _connection.getProtocolHandler().syncWrite(
- TxRollbackBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion()), TxRollbackOkBody.class);
-
-
- if (!isSuspended)
- {
- suspendChannel(false);
- }
- }
- catch (AMQException e)
+ public Object execute() throws AMQException, FailoverException
{
- throw (JMSException) (new JMSException("Failed to rollback: " + e).initCause(e));
+ AMQFrame queueBind =
+ QueueBindBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ arguments, // arguments
+ exchangeName, // exchange
+ false, // nowait
+ queueName, // queue
+ routingKey, // routingKey
+ getTicket()); // ticket
+
+ getProtocolHandler().syncWrite(queueBind, QueueBindOkBody.class);
+
+ return null;
}
- }
+ }, _connection).execute();
}
+ /**
+ * Closes the session with no timeout.
+ *
+ * @throws JMSException If the JMS provider fails to close the session due to some internal error.
+ */
public void close() throws JMSException
{
close(-1);
}
+ /**
+ * Closes the session.
+ *
+ * <p/>Note that this operation succeeds automatically if a fail-over interupts the sycnronous request to close the
+ * channel. This is because the channel is marked as closed before the request to close it is made, so the fail-over
+ * should not re-open it.
+ *
+ * @param timeout The timeout in milliseconds to wait for the session close acknoledgement from the broker.
+ *
+ * @throws JMSException If the JMS provider fails to close the session due to some internal error.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ * @todo Not certain about the logic of ignoring the failover exception, because the channel won't be re-opened. May
+ * need to examine this more carefully.
+ * @todo Note that taking the failover mutex doesn't prevent this operation being interrupted by a failover, because
+ * the failover process sends the failover event before acquiring the mutex itself.
+ */
public void close(long timeout) throws JMSException
{
if (_logger.isInfoEnabled())
{
- _logger.info("Closing session: " + this + ":" + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 6));
+ _logger.info("Closing session: " + this + ":"
+ + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 6));
}
// We must close down all producers and consumers in an orderly fashion. This is the only method
- // that can be called from a different thread of control from the one controlling the session
+ // that can be called from a different thread of control from the one controlling the session.
synchronized (_connection.getFailoverMutex())
{
- //Ensure we only try and close an open session.
+ // Ensure we only try and close an open session.
if (!_closed.getAndSet(true))
{
// we pass null since this is not an error case
@@ -676,18 +491,18 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
getProtocolHandler().closeSession(this);
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQFrame frame = ChannelCloseBody.createAMQFrame(getChannelId(),
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
- new AMQShortString("JMS client closing channel")); // replyText
+
+ final AMQFrame frame =
+ ChannelCloseBody.createAMQFrame(getChannelId(), getProtocolMajorVersion(), getProtocolMinorVersion(),
+ 0, // classId
+ 0, // methodId
+ AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
+ new AMQShortString("JMS client closing channel")); // replyText
getProtocolHandler().syncWrite(frame, ChannelCloseOkBody.class, timeout);
- // When control resumes at this point, a reply will have been received that
- // indicates the broker has closed the channel successfully
+ // When control resumes at this point, a reply will have been received that
+ // indicates the broker has closed the channel successfully.
}
catch (AMQException e)
{
@@ -695,6 +510,13 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
jmse.setLinkedException(e);
throw jmse;
}
+ // This is ignored because the channel is already marked as closed so the fail-over process will
+ // not re-open it.
+ catch (FailoverException e)
+ {
+ _logger.debug(
+ "Got FailoverException during channel close, ignored as channel already marked as closed.");
+ }
finally
{
_connection.deregisterSession(_channelId);
@@ -703,65 +525,6 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
- private AMQProtocolHandler getProtocolHandler()
- {
- return _connection.getProtocolHandler();
- }
-
-
- private byte getProtocolMinorVersion()
- {
- return getProtocolHandler().getProtocolMinorVersion();
- }
-
- private byte getProtocolMajorVersion()
- {
- return getProtocolHandler().getProtocolMajorVersion();
- }
-
-
- /**
- * Close all producers or consumers. This is called either in the error case or when closing the session normally.
- *
- * @param amqe the exception, may be null to indicate no error has occurred
- */
- private void closeProducersAndConsumers(AMQException amqe) throws JMSException
- {
- JMSException jmse = null;
- try
- {
- closeProducers();
- }
- catch (JMSException e)
- {
- _logger.error("Error closing session: " + e, e);
- jmse = e;
- }
- try
- {
- closeConsumers(amqe);
- }
- catch (JMSException e)
- {
- _logger.error("Error closing session: " + e, e);
- if (jmse == null)
- {
- jmse = e;
- }
- }
- if (jmse != null)
- {
- throw jmse;
- }
- }
-
-
- public boolean isSuspended()
- {
- return _suspended;
- }
-
-
/**
* Called when the server initiates the closure of the session unilaterally.
*
@@ -783,738 +546,341 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
amqe = new AMQException(null, "Closing session forcibly", e);
}
+
_connection.deregisterSession(_channelId);
closeProducersAndConsumers(amqe);
}
}
/**
- * Called to mark the session as being closed. Useful when the session needs to be made invalid, e.g. after failover
- * when the client has veoted resubscription. <p/> The caller of this method must already hold the failover mutex.
+ * Commits all messages done in this transaction and releases any locks currently held.
+ *
+ * <p/>If the commit fails, because the commit itself is interrupted by a fail-over between requesting that the
+ * commit be done, and receiving an acknowledgement that it has been done, then a JMSException will be thrown. The
+ * client will be unable to determine whether or not the commit actually happened on the broker in this case.
+ *
+ * @throws JMSException If the JMS provider fails to commit the transaction due to some internal error. This does
+ * not mean that the commit is known to have failed, merely that it is not known whether it
+ * failed or not.
+ * @todo Be aware of possible changes to parameter order as versions change.
*/
- void markClosed()
+ public void commit() throws JMSException
{
- _closed.set(true);
- _connection.deregisterSession(_channelId);
- markClosedProducersAndConsumers();
-
- }
+ checkTransacted();
- private void markClosedProducersAndConsumers()
- {
- try
- {
- // no need for a markClosed* method in this case since there is no protocol traffic closing a producer
- closeProducers();
- }
- catch (JMSException e)
- {
- _logger.error("Error closing session: " + e, e);
- }
try
{
- markClosedConsumers();
- }
- catch (JMSException e)
- {
- _logger.error("Error closing session: " + e, e);
- }
- }
+ // Acknowledge up to message last delivered (if any) for each consumer.
+ // need to send ack for messages delivered to consumers so far
+ for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
+ {
+ // Sends acknowledgement to server
+ i.next().acknowledgeLastDelivered();
+ }
- /**
- * Called to close message producers cleanly. This may or may <b>not</b> be as a result of an error. There is
- * currently no way of propagating errors to message producers (this is a JMS limitation).
- */
- private void closeProducers() throws JMSException
- {
- // we need to clone the list of producers since the close() method updates the _producers collection
- // which would result in a concurrent modification exception
- final ArrayList clonedProducers = new ArrayList(_producers.values());
+ // Commits outstanding messages sent and outstanding acknowledgements.
+ final AMQProtocolHandler handler = getProtocolHandler();
- final Iterator it = clonedProducers.iterator();
- while (it.hasNext())
- {
- final BasicMessageProducer prod = (BasicMessageProducer) it.next();
- prod.close();
+ handler.syncWrite(TxCommitBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion()),
+ TxCommitOkBody.class);
}
- // at this point the _producers map is empty
- }
-
- /**
- * Called to close message consumers cleanly. This may or may <b>not</b> be as a result of an error.
- *
- * @param error not null if this is a result of an error occurring at the connection level
- */
- private void closeConsumers(Throwable error) throws JMSException
- {
- if (_dispatcher != null)
+ catch (AMQException e)
{
- _dispatcher.close();
- _dispatcher = null;
+ throw new JMSAMQException("Failed to commit: " + e.getMessage(), e);
}
- // we need to clone the list of consumers since the close() method updates the _consumers collection
- // which would result in a concurrent modification exception
- final ArrayList<BasicMessageConsumer> clonedConsumers = new ArrayList(_consumers.values());
-
- final Iterator<BasicMessageConsumer> it = clonedConsumers.iterator();
- while (it.hasNext())
+ catch (FailoverException e)
{
- final BasicMessageConsumer con = it.next();
- if (error != null)
- {
- con.notifyError(error);
- }
- else
- {
- con.close();
- }
+ throw new JMSAMQException("Fail-over interrupted commit. Status of the commit is uncertain.", e);
}
- // at this point the _consumers map will be empty
}
- private void markClosedConsumers() throws JMSException
+ public void confirmConsumerCancelled(AMQShortString consumerTag)
{
- if (_dispatcher != null)
- {
- _dispatcher.close();
- _dispatcher = null;
- }
- // we need to clone the list of consumers since the close() method updates the _consumers collection
- // which would result in a concurrent modification exception
- final ArrayList<BasicMessageConsumer> clonedConsumers = new ArrayList<BasicMessageConsumer>(_consumers.values());
-
- final Iterator<BasicMessageConsumer> it = clonedConsumers.iterator();
- while (it.hasNext())
- {
- final BasicMessageConsumer con = it.next();
- con.markClosed();
- }
- // at this point the _consumers map will be empty
- }
- /**
- * Asks the broker to resend all unacknowledged messages for the session.
- *
- * @throws JMSException
- */
- public void recover() throws JMSException
- {
- checkNotClosed();
- checkNotTransacted(); // throws IllegalStateException if a transacted session
- // this is set only here, and the before the consumer's onMessage is called it is set to false
- _inRecovery = true;
- try
+ // Remove the consumer from the map
+ BasicMessageConsumer consumer = (BasicMessageConsumer) _consumers.get(consumerTag);
+ if (consumer != null)
{
-
- boolean isSuspended = isSuspended();
-
- if (!isSuspended)
+ // fixme this isn't right.. needs to check if _queue contains data for this consumer
+ if (consumer.isAutoClose()) // && _queue.isEmpty())
{
- suspendChannel(true);
+ consumer.closeWhenNoMessages(true);
}
- for (BasicMessageConsumer consumer : _consumers.values())
+ if (!consumer.isNoConsume())
{
- consumer.clearUnackedMessages();
- }
+ // Clean the Maps up first
+ // Flush any pending messages for this consumerTag
+ if (_dispatcher != null)
+ {
+ _logger.info("Dispatcher is not null");
+ }
+ else
+ {
+ _logger.info("Dispatcher is null so created stopped dispatcher");
- if (_dispatcher != null)
- {
- _dispatcher.rollback();
- }
+ startDistpatcherIfNecessary(true);
+ }
- if (isStrictAMQP())
- {
- // We can't use the BasicRecoverBody-OK method as it isn't part of the spec.
- _connection.getProtocolHandler().writeFrame(BasicRecoverBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- false)); // requeue
- _logger.warn("Session Recover cannot be guaranteed with STRICT_AMQP. Messages may arrive out of order.");
+ _dispatcher.rejectPending(consumer);
}
else
{
+ // Just close the consumer
+ // fixme the CancelOK is being processed before the arriving messages..
+ // The dispatcher is still to process them so the server sent in order but the client
+ // has yet to receive before the close comes in.
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- _connection.getProtocolHandler().syncWrite(BasicRecoverBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- false) // requeue
- , BasicRecoverOkBody.class);
- }
- if (!isSuspended)
- {
- suspendChannel(false);
+ // consumer.markClosed();
}
}
- catch (AMQException e)
+ else
{
- throw new JMSAMQException(e);
+ _logger.warn("Unable to confirm cancellation of consumer (" + consumerTag + "). Not found in consumer map.");
}
- }
-
- boolean isInRecovery()
- {
- return _inRecovery;
- }
- void setInRecovery(boolean inRecovery)
- {
- _inRecovery = inRecovery;
}
- public void acknowledge() throws JMSException
+ public QueueBrowser createBrowser(Queue queue) throws JMSException
{
- if (isClosed())
- {
- throw new IllegalStateException("Session is already closed");
- }
- for (BasicMessageConsumer consumer : _consumers.values())
+ if (isStrictAMQP())
{
- consumer.acknowledge();
+ throw new UnsupportedOperationException();
}
-
- }
-
-
- public MessageListener getMessageListener() throws JMSException
- {
-// checkNotClosed();
- return _messageListener;
- }
-
- public void setMessageListener(MessageListener listener) throws JMSException
- {
-// checkNotClosed();
-//
-// if (_dispatcher != null && !_dispatcher.connectionStopped())
-// {
-// throw new javax.jms.IllegalStateException("Attempt to set listener while session is started.");
-// }
-//
-// // We are stopped
-// for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
-// {
-// BasicMessageConsumer consumer = i.next();
-//
-// if (consumer.isReceiving())
-// {
-// throw new javax.jms.IllegalStateException("Another thread is already receiving synchronously.");
-// }
-// }
-//
-// _messageListener = listener;
-//
-// for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
-// {
-// i.next().setMessageListener(_messageListener);
-// }
-
+ return createBrowser(queue, null);
}
- public void run()
+ public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException
{
- throw new java.lang.UnsupportedOperationException();
- }
+ if (isStrictAMQP())
+ {
+ throw new UnsupportedOperationException();
+ }
- public BasicMessageProducer createProducer(Destination destination, boolean mandatory,
- boolean immediate, boolean waitUntilSent)
- throws JMSException
- {
- return createProducerImpl(destination, mandatory, immediate, waitUntilSent);
- }
+ checkNotClosed();
+ checkValidQueue(queue);
- public BasicMessageProducer createProducer(Destination destination, boolean mandatory, boolean immediate)
- throws JMSException
- {
- return createProducerImpl(destination, mandatory, immediate);
+ return new AMQQueueBrowser(this, (AMQQueue) queue, messageSelector);
}
- public BasicMessageProducer createProducer(Destination destination, boolean immediate)
+ public MessageConsumer createBrowserConsumer(Destination destination, String messageSelector, boolean noLocal)
throws JMSException
{
- return createProducerImpl(destination, DEFAULT_MANDATORY, immediate);
- }
-
- public BasicMessageProducer createProducer(Destination destination) throws JMSException
- {
- return createProducerImpl(destination, DEFAULT_MANDATORY, DEFAULT_IMMEDIATE);
- }
+ checkValidDestination(destination);
- private BasicMessageProducer createProducerImpl(Destination destination, boolean mandatory,
- boolean immediate)
- throws JMSException
- {
- return createProducerImpl(destination, mandatory, immediate, false);
+ return createConsumerImpl(destination, _defaultPrefetchHighMark, _defaultPrefetchLowMark, noLocal, false,
+ messageSelector, null, true, true);
}
- private BasicMessageProducer createProducerImpl(final Destination destination, final boolean mandatory,
- final boolean immediate, final boolean waitUntilSent)
- throws JMSException
+ public BytesMessage createBytesMessage() throws JMSException
{
- return (BasicMessageProducer) new FailoverSupport()
+ synchronized (_connection.getFailoverMutex())
{
- public Object operation() throws JMSException
- {
- checkNotClosed();
- long producerId = getNextProducerId();
- BasicMessageProducer producer = new BasicMessageProducer(_connection, (AMQDestination) destination, _transacted, _channelId,
- AMQSession.this, getProtocolHandler(),
- producerId, immediate, mandatory, waitUntilSent);
- registerProducer(producerId, producer);
- return producer;
- }
- }.execute(_connection);
- }
-
- /**
- * Creates a QueueReceiver
- *
- * @param destination
- *
- * @return QueueReceiver - a wrapper around our MessageConsumer
- *
- * @throws JMSException
- */
- public QueueReceiver createQueueReceiver(Destination destination) throws JMSException
- {
- checkValidDestination(destination);
- AMQQueue dest = (AMQQueue) destination;
- BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(destination);
- return new QueueReceiverAdaptor(dest, consumer);
- }
+ checkNotClosed();
- /**
- * Creates a QueueReceiver using a message selector
- *
- * @param destination
- * @param messageSelector
- *
- * @return QueueReceiver - a wrapper around our MessageConsumer
- *
- * @throws JMSException
- */
- public QueueReceiver createQueueReceiver(Destination destination, String messageSelector) throws JMSException
- {
- checkValidDestination(destination);
- AMQQueue dest = (AMQQueue) destination;
- BasicMessageConsumer consumer = (BasicMessageConsumer)
- createConsumer(destination, messageSelector);
- return new QueueReceiverAdaptor(dest, consumer);
+ return new JMSBytesMessage();
+ }
}
public MessageConsumer createConsumer(Destination destination) throws JMSException
{
checkValidDestination(destination);
- return createConsumerImpl(destination,
- _defaultPrefetchHighMark,
- _defaultPrefetchLowMark,
- false,
- false,
- null,
- null,
- false,
- false);
+
+ return createConsumerImpl(destination, _defaultPrefetchHighMark, _defaultPrefetchLowMark, false, false, null, null,
+ false, false);
}
public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException
{
checkValidDestination(destination);
- return createConsumerImpl(destination,
- _defaultPrefetchHighMark,
- _defaultPrefetchLowMark,
- false,
- false,
- messageSelector,
- null,
- false,
- false);
+
+ return createConsumerImpl(destination, _defaultPrefetchHighMark, _defaultPrefetchLowMark, false, false,
+ messageSelector, null, false, false);
}
public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal)
throws JMSException
{
checkValidDestination(destination);
- return createConsumerImpl(destination,
- _defaultPrefetchHighMark,
- _defaultPrefetchLowMark,
- noLocal,
- false,
- messageSelector,
- null,
- false,
- false);
+
+ return createConsumerImpl(destination, _defaultPrefetchHighMark, _defaultPrefetchLowMark, noLocal, false,
+ messageSelector, null, false, false);
}
- public MessageConsumer createBrowserConsumer(Destination destination,
- String messageSelector,
- boolean noLocal)
- throws JMSException
- {
- checkValidDestination(destination);
- return createConsumerImpl(destination,
- _defaultPrefetchHighMark,
- _defaultPrefetchLowMark,
- noLocal,
- false,
- messageSelector,
- null,
- true,
- true);
- }
-
- public MessageConsumer createConsumer(Destination destination,
- int prefetch,
- boolean noLocal,
- boolean exclusive,
+ public MessageConsumer createConsumer(Destination destination, int prefetch, boolean noLocal, boolean exclusive,
String selector) throws JMSException
{
checkValidDestination(destination);
+
return createConsumerImpl(destination, prefetch, prefetch, noLocal, exclusive, selector, null, false, false);
}
-
- public MessageConsumer createConsumer(Destination destination,
- int prefetchHigh,
- int prefetchLow,
- boolean noLocal,
- boolean exclusive,
- String selector) throws JMSException
+ public MessageConsumer createConsumer(Destination destination, int prefetchHigh, int prefetchLow, boolean noLocal,
+ boolean exclusive, String selector) throws JMSException
{
checkValidDestination(destination);
+
return createConsumerImpl(destination, prefetchHigh, prefetchLow, noLocal, exclusive, selector, null, false, false);
}
- public MessageConsumer createConsumer(Destination destination,
- int prefetch,
- boolean noLocal,
- boolean exclusive,
- String selector,
- FieldTable rawSelector) throws JMSException
+ public MessageConsumer createConsumer(Destination destination, int prefetch, boolean noLocal, boolean exclusive,
+ String selector, FieldTable rawSelector) throws JMSException
{
checkValidDestination(destination);
- return createConsumerImpl(destination, prefetch, prefetch, noLocal, exclusive,
- selector, rawSelector, false, false);
+
+ return createConsumerImpl(destination, prefetch, prefetch, noLocal, exclusive, selector, rawSelector, false, false);
}
- public MessageConsumer createConsumer(Destination destination,
- int prefetchHigh,
- int prefetchLow,
- boolean noLocal,
- boolean exclusive,
- String selector,
- FieldTable rawSelector) throws JMSException
+ public MessageConsumer createConsumer(Destination destination, int prefetchHigh, int prefetchLow, boolean noLocal,
+ boolean exclusive, String selector, FieldTable rawSelector) throws JMSException
{
checkValidDestination(destination);
- return createConsumerImpl(destination, prefetchHigh, prefetchLow, noLocal, exclusive,
- selector, rawSelector, false, false);
+
+ return createConsumerImpl(destination, prefetchHigh, prefetchLow, noLocal, exclusive, selector, rawSelector, false,
+ false);
}
- protected MessageConsumer createConsumerImpl(final Destination destination,
- final int prefetchHigh,
- final int prefetchLow,
- final boolean noLocal,
- final boolean exclusive,
- String selector,
- final FieldTable rawSelector,
- final boolean noConsume,
- final boolean autoClose) throws JMSException
+ public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException
{
- checkTemporaryDestination(destination);
-
- final String messageSelector;
- if (_strictAMQP && !(selector == null || selector.equals("")))
+ checkNotClosed();
+ AMQTopic origTopic = checkValidTopic(topic);
+ AMQTopic dest = AMQTopic.createDurableTopic(origTopic, name, _connection);
+ TopicSubscriberAdaptor subscriber = _subscriptions.get(name);
+ if (subscriber != null)
{
- if (_strictAMQPFATAL)
+ if (subscriber.getTopic().equals(topic))
{
- throw new UnsupportedOperationException("Selectors not currently supported by AMQP.");
+ throw new IllegalStateException("Already subscribed to topic " + topic + " with subscription exchange "
+ + name);
}
else
{
- messageSelector = null;
+ unsubscribe(name);
}
}
else
{
- messageSelector = selector;
- }
-
- return (org.apache.qpid.jms.MessageConsumer) new FailoverSupport()
- {
- public Object operation() throws JMSException
+ AMQShortString topicName;
+ if (topic instanceof AMQTopic)
{
- checkNotClosed();
-
- AMQDestination amqd = (AMQDestination) destination;
+ topicName = ((AMQTopic) topic).getDestinationName();
+ }
+ else
+ {
+ topicName = new AMQShortString(topic.getTopicName());
+ }
- final AMQProtocolHandler protocolHandler = getProtocolHandler();
- // TODO: Define selectors in AMQP
- // TODO: construct the rawSelector from the selector string if rawSelector == null
- final FieldTable ft = FieldTableFactory.newFieldTable();
- //if (rawSelector != null)
- // ft.put("headers", rawSelector.getDataAsBytes());
- if (rawSelector != null)
+ if (_strictAMQP)
+ {
+ if (_strictAMQPFATAL)
{
- ft.addAll(rawSelector);
+ throw new UnsupportedOperationException("JMS Durable not currently supported by AMQP.");
}
-
- BasicMessageConsumer consumer = new BasicMessageConsumer(_channelId, _connection, amqd, messageSelector, noLocal,
- _messageFactoryRegistry, AMQSession.this,
- protocolHandler, ft, prefetchHigh, prefetchLow, exclusive,
- _acknowledgeMode, noConsume, autoClose);
-
- if (_messageListener != null)
+ else
{
- consumer.setMessageListener(_messageListener);
+ _logger.warn("Unable to determine if subscription already exists for '" + topicName + "' "
+ + "for creation durableSubscriber. Requesting queue deletion regardless.");
}
- try
- {
- registerConsumer(consumer, false);
- }
- catch (AMQInvalidArgumentException ise)
- {
- JMSException ex = new InvalidSelectorException(ise.getMessage());
- ex.setLinkedException(ise);
- throw ex;
- }
- catch (AMQInvalidRoutingKeyException e)
+ deleteQueue(dest.getAMQQueueName());
+ }
+ else
+ {
+ // if the queue is bound to the exchange but NOT for this topic, then the JMS spec
+ // says we must trash the subscription.
+ if (isQueueBound(dest.getExchangeName(), dest.getAMQQueueName())
+ && !isQueueBound(dest.getExchangeName(), dest.getAMQQueueName(), topicName))
{
- JMSException ide = new InvalidDestinationException("Invalid routing key:" + amqd.getRoutingKey().toString());
- ide.setLinkedException(e);
- throw ide;
+ deleteQueue(dest.getAMQQueueName());
}
- catch (AMQException e)
- {
- JMSException ex = new JMSException("Error registering consumer: " + e);
+ }
+ }
- if (_logger.isDebugEnabled())
- {
- e.printStackTrace();
- }
- ex.setLinkedException(e);
- throw ex;
- }
+ subscriber = new TopicSubscriberAdaptor(dest, (BasicMessageConsumer) createConsumer(dest));
- synchronized (destination)
- {
- _destinationConsumerCount.putIfAbsent(destination, new AtomicInteger());
- _destinationConsumerCount.get(destination).incrementAndGet();
- }
+ _subscriptions.put(name, subscriber);
+ _reverseSubscriptionMap.put(subscriber.getMessageConsumer(), name);
- return consumer;
- }
- }.execute(_connection);
+ return subscriber;
}
- private void checkTemporaryDestination(Destination destination)
+ /** Note, currently this does not handle reuse of the same name with different topics correctly. */
+ public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal)
throws JMSException
{
- if ((destination instanceof TemporaryDestination))
- {
- _logger.debug("destination is temporary");
- final TemporaryDestination tempDest = (TemporaryDestination) destination;
- if (tempDest.getSession() != this)
- {
- _logger.debug("destination is on different session");
- throw new JMSException("Cannot consume from a temporary destination created onanother session");
- }
- if (tempDest.isDeleted())
- {
- _logger.debug("destination is deleted");
- throw new JMSException("Cannot consume from a deleted destination");
- }
- }
- }
+ checkNotClosed();
+ checkValidTopic(topic);
+ AMQTopic dest = AMQTopic.createDurableTopic((AMQTopic) topic, name, _connection);
+ BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(dest, messageSelector, noLocal);
+ TopicSubscriberAdaptor subscriber = new TopicSubscriberAdaptor(dest, consumer);
+ _subscriptions.put(name, subscriber);
+ _reverseSubscriptionMap.put(subscriber.getMessageConsumer(), name);
+ return subscriber;
+ }
- public boolean hasConsumer(Destination destination)
+ public MapMessage createMapMessage() throws JMSException
{
- AtomicInteger counter = _destinationConsumerCount.get(destination);
+ synchronized (_connection.getFailoverMutex())
+ {
+ checkNotClosed();
- return (counter != null) && (counter.get() != 0);
+ return new JMSMapMessage();
+ }
}
- public void declareExchange(AMQShortString name, AMQShortString type, boolean nowait) throws AMQException
+ public javax.jms.Message createMessage() throws JMSException
{
- declareExchange(name, type, getProtocolHandler(), nowait);
+ return createBytesMessage();
}
- private void declareExchange(AMQDestination amqd, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException
+ public ObjectMessage createObjectMessage() throws JMSException
{
- declareExchange(amqd.getExchangeName(), amqd.getExchangeClass(), protocolHandler, nowait);
+ synchronized (_connection.getFailoverMutex())
+ {
+ checkNotClosed();
+
+ return (ObjectMessage) new JMSObjectMessage();
+ }
}
- private void declareExchange(AMQShortString name, AMQShortString type, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException
+ public ObjectMessage createObjectMessage(Serializable object) throws JMSException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame exchangeDeclare = ExchangeDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- false, // autoDelete
- false, // durable
- name, // exchange
- false, // internal
- nowait, // nowait
- false, // passive
- getTicket(), // ticket
- type); // type
+ ObjectMessage msg = createObjectMessage();
+ msg.setObject(object);
- protocolHandler.syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
+ return msg;
}
-
- public void createQueue(AMQShortString name, boolean autoDelete, boolean durable, boolean exclusive) throws AMQException
+ public BasicMessageProducer createProducer(Destination destination) throws JMSException
{
- AMQFrame queueDeclare = QueueDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- autoDelete, // autoDelete
- durable, // durable
- exclusive, // exclusive
- false, // nowait
- false, // passive
- name, // queue
- getTicket()); // ticket
-
- getProtocolHandler().syncWrite(queueDeclare, QueueDeclareOkBody.class);
-
+ return createProducerImpl(destination, DEFAULT_MANDATORY, DEFAULT_IMMEDIATE);
}
-
- public void bindQueue(AMQShortString queueName, AMQShortString routingKey, FieldTable arguments, AMQShortString exchangeName) throws AMQException
+ public BasicMessageProducer createProducer(Destination destination, boolean immediate) throws JMSException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueBind = QueueBindBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- arguments, // arguments
- exchangeName, // exchange
- false, // nowait
- queueName, // queue
- routingKey, // routingKey
- getTicket()); // ticket
-
-
- getProtocolHandler().syncWrite(queueBind, QueueBindOkBody.class);
+ return createProducerImpl(destination, DEFAULT_MANDATORY, immediate);
}
- /**
- * Declare the queue.
- *
- * @param amqd
- * @param protocolHandler
- *
- * @return the queue name. This is useful where the broker is generating a queue name on behalf of the client.
- *
- * @throws AMQException
- */
- private AMQShortString declareQueue(AMQDestination amqd, AMQProtocolHandler protocolHandler) throws AMQException
+ public BasicMessageProducer createProducer(Destination destination, boolean mandatory, boolean immediate)
+ throws JMSException
{
- // For queues (but not topics) we generate the name in the client rather than the
- // server. This allows the name to be reused on failover if required. In general,
- // the destination indicates whether it wants a name generated or not.
- if (amqd.isNameRequired())
- {
- amqd.setQueueName(protocolHandler.generateQueueName());
- }
-
- //TODO verify the destiation is valid. else throw
-
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueDeclare = QueueDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- amqd.isAutoDelete(), // autoDelete
- amqd.isDurable(), // durable
- amqd.isExclusive(), // exclusive
- false, // nowait
- false, // passive
- amqd.getAMQQueueName(), // queue
- getTicket()); // ticket
-
- protocolHandler.syncWrite(queueDeclare, QueueDeclareOkBody.class);
- return amqd.getAMQQueueName();
+ return createProducerImpl(destination, mandatory, immediate);
}
- private void bindQueue(AMQDestination amqd, AMQShortString queueName, AMQProtocolHandler protocolHandler, FieldTable ft) throws AMQException
+ public BasicMessageProducer createProducer(Destination destination, boolean mandatory, boolean immediate,
+ boolean waitUntilSent) throws JMSException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueBind = QueueBindBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- ft, // arguments
- amqd.getExchangeName(), // exchange
- false, // nowait
- queueName, // queue
- amqd.getRoutingKey(), // routingKey
- getTicket()); // ticket
-
-
- protocolHandler.syncWrite(queueBind, QueueBindOkBody.class);
+ return createProducerImpl(destination, mandatory, immediate, waitUntilSent);
}
- /**
- * Register to consume from the queue.
- *
- * @param queueName
- *
- * @return the consumer tag generated by the broker
- */
- private void consumeFromQueue(BasicMessageConsumer consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler,
- boolean nowait, String messageSelector) throws AMQException
+ public TopicPublisher createPublisher(Topic topic) throws JMSException
{
- //need to generate a consumer tag on the client so we can exploit the nowait flag
- AMQShortString tag = new AMQShortString(Integer.toString(_nextTag++));
-
- FieldTable arguments = FieldTableFactory.newFieldTable();
- if (messageSelector != null && !messageSelector.equals(""))
- {
- arguments.put(AMQPFilterTypes.JMS_SELECTOR.getValue(), messageSelector);
- }
- if (consumer.isAutoClose())
- {
- arguments.put(AMQPFilterTypes.AUTO_CLOSE.getValue(), Boolean.TRUE);
- }
- if (consumer.isNoConsume())
- {
- arguments.put(AMQPFilterTypes.NO_CONSUME.getValue(), Boolean.TRUE);
- }
-
- consumer.setConsumerTag(tag);
- // we must register the consumer in the map before we actually start listening
- _consumers.put(tag, consumer);
+ checkNotClosed();
- try
- {
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame jmsConsume = BasicConsumeBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- arguments, // arguments
- tag, // consumerTag
- consumer.isExclusive(), // exclusive
- consumer.getAcknowledgeMode() == Session.NO_ACKNOWLEDGE, // noAck
- consumer.isNoLocal(), // noLocal
- nowait, // nowait
- queueName, // queue
- getTicket()); // ticket
- if (nowait)
- {
- protocolHandler.writeFrame(jmsConsume);
- }
- else
- {
- protocolHandler.syncWrite(jmsConsume, BasicConsumeOkBody.class);
- }
- }
- catch (AMQException e)
- {
- // clean-up the map in the event of an error
- _consumers.remove(tag);
- throw e;
- }
+ return new TopicPublisherAdapter((BasicMessageProducer) createProducer(topic), topic);
}
public Queue createQueue(String queueName) throws JMSException
@@ -1540,9 +906,79 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
- public AMQShortString getDefaultQueueExchangeName()
+ /**
+ * Declares the named queue.
+ *
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param name The name of the queue to declare.
+ * @param autoDelete
+ * @param durable Flag to indicate that the queue is durable.
+ * @param exclusive Flag to indicate that the queue is exclusive to this client.
+ *
+ * @throws AMQException If the queue cannot be declared for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ public void createQueue(final AMQShortString name, final boolean autoDelete, final boolean durable,
+ final boolean exclusive) throws AMQException
{
- return _connection.getDefaultQueueExchangeName();
+ new FailoverRetrySupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()
+ {
+ public Object execute() throws AMQException, FailoverException
+ {
+ AMQFrame queueDeclare =
+ QueueDeclareBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ null, // arguments
+ autoDelete, // autoDelete
+ durable, // durable
+ exclusive, // exclusive
+ false, // nowait
+ false, // passive
+ name, // queue
+ getTicket()); // ticket
+
+ getProtocolHandler().syncWrite(queueDeclare, QueueDeclareOkBody.class);
+
+ return null;
+ }
+ }, _connection).execute();
+ }
+
+ /**
+ * Creates a QueueReceiver
+ *
+ * @param destination
+ *
+ * @return QueueReceiver - a wrapper around our MessageConsumer
+ *
+ * @throws JMSException
+ */
+ public QueueReceiver createQueueReceiver(Destination destination) throws JMSException
+ {
+ checkValidDestination(destination);
+ AMQQueue dest = (AMQQueue) destination;
+ BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(destination);
+
+ return new QueueReceiverAdaptor(dest, consumer);
+ }
+
+ /**
+ * Creates a QueueReceiver using a message selector
+ *
+ * @param destination
+ * @param messageSelector
+ *
+ * @return QueueReceiver - a wrapper around our MessageConsumer
+ *
+ * @throws JMSException
+ */
+ public QueueReceiver createQueueReceiver(Destination destination, String messageSelector) throws JMSException
+ {
+ checkValidDestination(destination);
+ AMQQueue dest = (AMQQueue) destination;
+ BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(destination, messageSelector);
+
+ return new QueueReceiverAdaptor(dest, consumer);
}
/**
@@ -1559,6 +995,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
checkNotClosed();
AMQQueue dest = (AMQQueue) queue;
BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(dest);
+
return new QueueReceiverAdaptor(dest, consumer);
}
@@ -1576,47 +1013,29 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
checkNotClosed();
AMQQueue dest = (AMQQueue) queue;
- BasicMessageConsumer consumer = (BasicMessageConsumer)
- createConsumer(dest, messageSelector);
+ BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(dest, messageSelector);
+
return new QueueReceiverAdaptor(dest, consumer);
}
public QueueSender createSender(Queue queue) throws JMSException
{
checkNotClosed();
- //return (QueueSender) createProducer(queue);
+
+ // return (QueueSender) createProducer(queue);
return new QueueSenderAdapter(createProducer(queue), queue);
}
- public Topic createTopic(String topicName) throws JMSException
+ public StreamMessage createStreamMessage() throws JMSException
{
- checkNotClosed();
-
- if (topicName.indexOf('/') == -1)
- {
- return new AMQTopic(getDefaultTopicExchangeName(), new AMQShortString(topicName));
- }
- else
+ synchronized (_connection.getFailoverMutex())
{
- try
- {
- return new AMQTopic(new AMQBindingURL(topicName));
- }
- catch (URLSyntaxException urlse)
- {
- JMSException jmse = new JMSException(urlse.getReason());
- jmse.setLinkedException(urlse);
+ checkNotClosed();
- throw jmse;
- }
+ return new JMSStreamMessage();
}
}
- public AMQShortString getDefaultTopicExchangeName()
- {
- return _connection.getDefaultTopicExchangeName();
- }
-
/**
* Creates a non-durable subscriber
*
@@ -1630,7 +1049,8 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
checkNotClosed();
AMQTopic dest = checkValidTopic(topic);
- //AMQTopic dest = new AMQTopic(topic.getTopicName());
+
+ // AMQTopic dest = new AMQTopic(topic.getTopicName());
return new TopicSubscriberAdaptor(dest, (BasicMessageConsumer) createConsumer(dest));
}
@@ -1649,150 +1069,396 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
checkNotClosed();
AMQTopic dest = checkValidTopic(topic);
- //AMQTopic dest = new AMQTopic(topic.getTopicName());
+
+ // AMQTopic dest = new AMQTopic(topic.getTopicName());
return new TopicSubscriberAdaptor(dest, (BasicMessageConsumer) createConsumer(dest, messageSelector, noLocal));
}
- public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException
+ public TemporaryQueue createTemporaryQueue() throws JMSException
{
+ checkNotClosed();
+ return new AMQTemporaryQueue(this);
+ }
+ public TemporaryTopic createTemporaryTopic() throws JMSException
+ {
checkNotClosed();
- AMQTopic origTopic = checkValidTopic(topic);
- AMQTopic dest = AMQTopic.createDurableTopic(origTopic, name, _connection);
- TopicSubscriberAdaptor subscriber = _subscriptions.get(name);
- if (subscriber != null)
+
+ return new AMQTemporaryTopic(this);
+ }
+
+ public TextMessage createTextMessage() throws JMSException
+ {
+ synchronized (_connection.getFailoverMutex())
{
- if (subscriber.getTopic().equals(topic))
+ checkNotClosed();
+
+ return new JMSTextMessage();
+ }
+ }
+
+ public TextMessage createTextMessage(String text) throws JMSException
+ {
+
+ TextMessage msg = createTextMessage();
+ msg.setText(text);
+
+ return msg;
+ }
+
+ public Topic createTopic(String topicName) throws JMSException
+ {
+ checkNotClosed();
+
+ if (topicName.indexOf('/') == -1)
+ {
+ return new AMQTopic(getDefaultTopicExchangeName(), new AMQShortString(topicName));
+ }
+ else
+ {
+ try
{
- throw new IllegalStateException("Already subscribed to topic " + topic + " with subscription exchange " +
- name);
+ return new AMQTopic(new AMQBindingURL(topicName));
}
- else
+ catch (URLSyntaxException urlse)
{
- unsubscribe(name);
+ JMSException jmse = new JMSException(urlse.getReason());
+ jmse.setLinkedException(urlse);
+
+ throw jmse;
}
}
+ }
+
+ public void declareExchange(AMQShortString name, AMQShortString type, boolean nowait) throws AMQException
+ {
+ declareExchange(name, type, getProtocolHandler(), nowait);
+ }
+
+ public int getAcknowledgeMode() throws JMSException
+ {
+ checkNotClosed();
+
+ return _acknowledgeMode;
+ }
+
+ public AMQConnection getAMQConnection()
+ {
+ return _connection;
+ }
+
+ public int getChannelId()
+ {
+ return _channelId;
+ }
+
+ public int getDefaultPrefetch()
+ {
+ return _defaultPrefetchHighMark;
+ }
+
+ public int getDefaultPrefetchHigh()
+ {
+ return _defaultPrefetchHighMark;
+ }
+
+ public int getDefaultPrefetchLow()
+ {
+ return _defaultPrefetchLowMark;
+ }
+
+ public AMQShortString getDefaultQueueExchangeName()
+ {
+ return _connection.getDefaultQueueExchangeName();
+ }
+
+ public AMQShortString getDefaultTopicExchangeName()
+ {
+ return _connection.getDefaultTopicExchangeName();
+ }
+
+ public MessageListener getMessageListener() throws JMSException
+ {
+ // checkNotClosed();
+ return _messageListener;
+ }
+
+ public AMQShortString getTemporaryQueueExchangeName()
+ {
+ return _connection.getTemporaryQueueExchangeName();
+ }
+
+ public AMQShortString getTemporaryTopicExchangeName()
+ {
+ return _connection.getTemporaryTopicExchangeName();
+ }
+
+ public int getTicket()
+ {
+ return _ticket;
+ }
+
+ public boolean getTransacted() throws JMSException
+ {
+ checkNotClosed();
+
+ return _transacted;
+ }
+
+ public boolean hasConsumer(Destination destination)
+ {
+ AtomicInteger counter = _destinationConsumerCount.get(destination);
+
+ return (counter != null) && (counter.get() != 0);
+ }
+
+ public boolean isStrictAMQP()
+ {
+ return _strictAMQP;
+ }
+
+ public boolean isSuspended()
+ {
+ return _suspended;
+ }
+
+ /**
+ * Invoked by the MINA IO thread (indirectly) when a message is received from the transport. Puts the message onto
+ * the queue read by the dispatcher.
+ *
+ * @param message the message that has been received
+ */
+ public void messageReceived(UnprocessedMessage message)
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Message["
+ + ((message.getDeliverBody() == null) ? ("B:" + message.getBounceBody()) : ("D:" + message.getDeliverBody()))
+ + "] received in session with channel id " + _channelId);
+ }
+
+ if (message.getDeliverBody() == null)
+ {
+ // Return of the bounced message.
+ returnBouncedMessage(message);
+ }
else
{
- AMQShortString topicName;
- if (topic instanceof AMQTopic)
+ _queue.add(message);
+ }
+ }
+
+ /**
+ * Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.
+ *
+ * <p/>All consumers deliver messages in a serial order. Acknowledging a received message automatically acknowledges
+ * all messages that have been delivered to the client.
+ *
+ * <p/>Restarting a session causes it to take the following actions:
+ *
+ * <ul> <li>Stop message delivery.</li> <li>Mark all messages that might have been delivered but not acknowledged as
+ * "redelivered". <li>Restart the delivery sequence including all unacknowledged messages that had been previously
+ * delivered. Redelivered messages do not have to be delivered in exactly their original delivery order.</li> </ul>
+ *
+ * <p/>If the recover operation is interrupted by a fail-over, between asking that the broker begin recovery and
+ * receiving acknolwedgement that it hasm then a JMSException will be thrown. In this case it will not be possible
+ * for the client to determine whether the broker is going to recover the session or not.
+ *
+ * @throws JMSException If the JMS provider fails to stop and restart message delivery due to some internal error.
+ * Not that this does not necessarily mean that the recovery has failed, but simply that it is
+ * not possible to tell if it has or not.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ public void recover() throws JMSException
+ {
+ // Ensure that the session is open.
+ checkNotClosed();
+
+ // Ensure that the session is not transacted.
+ checkNotTransacted();
+
+ // this is set only here, and the before the consumer's onMessage is called it is set to false
+ _inRecovery = true;
+ try
+ {
+
+ boolean isSuspended = isSuspended();
+
+ if (!isSuspended)
{
- topicName = ((AMQTopic) topic).getDestinationName();
+ suspendChannel(true);
}
- else
+
+ for (BasicMessageConsumer consumer : _consumers.values())
{
- topicName = new AMQShortString(topic.getTopicName());
+ consumer.clearUnackedMessages();
}
- if (_strictAMQP)
+ if (_dispatcher != null)
{
- if (_strictAMQPFATAL)
- {
- throw new UnsupportedOperationException("JMS Durable not currently supported by AMQP.");
- }
- else
- {
- _logger.warn("Unable to determine if subscription already exists for '" + topicName + "' "
- + "for creation durableSubscriber. Requesting queue deletion regardless.");
- }
+ _dispatcher.rollback();
+ }
- deleteQueue(dest.getAMQQueueName());
+ if (isStrictAMQP())
+ {
+ // We can't use the BasicRecoverBody-OK method as it isn't part of the spec.
+ _connection.getProtocolHandler().writeFrame(BasicRecoverBody.createAMQFrame(_channelId,
+ getProtocolMajorVersion(), getProtocolMinorVersion(), false)); // requeue
+ _logger.warn("Session Recover cannot be guaranteed with STRICT_AMQP. Messages may arrive out of order.");
}
else
{
- // if the queue is bound to the exchange but NOT for this topic, then the JMS spec
- // says we must trash the subscription.
- if (isQueueBound(dest.getExchangeName(), dest.getAMQQueueName()) &&
- !isQueueBound(dest.getExchangeName(), dest.getAMQQueueName(), topicName))
- {
- deleteQueue(dest.getAMQQueueName());
- }
- }
- }
-
- subscriber = new TopicSubscriberAdaptor(dest, (BasicMessageConsumer) createConsumer(dest));
- _subscriptions.put(name, subscriber);
- _reverseSubscriptionMap.put(subscriber.getMessageConsumer(), name);
-
- return subscriber;
- }
+ _connection.getProtocolHandler().syncWrite(
+ BasicRecoverBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(), false) // requeue
+ , BasicRecoverOkBody.class);
+ }
- void deleteQueue(AMQShortString queueName) throws JMSException
- {
- try
- {
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueDeleteFrame = QueueDeleteBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- false, // ifEmpty
- false, // ifUnused
- true, // nowait
- queueName, // queue
- getTicket()); // ticket
- getProtocolHandler().syncWrite(queueDeleteFrame, QueueDeleteOkBody.class);
+ if (!isSuspended)
+ {
+ suspendChannel(false);
+ }
}
catch (AMQException e)
{
- throw new JMSAMQException(e);
+ throw new JMSAMQException("Recover failed: " + e.getMessage(), e);
+ }
+ catch (FailoverException e)
+ {
+ throw new JMSAMQException("Recovery was interrupted by fail-over. Recovery status is not known.", e);
}
}
- /** Note, currently this does not handle reuse of the same name with different topics correctly. */
- public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal)
- throws JMSException
+ public void rejectMessage(UnprocessedMessage message, boolean requeue)
{
- checkNotClosed();
- checkValidTopic(topic);
- AMQTopic dest = AMQTopic.createDurableTopic((AMQTopic) topic, name, _connection);
- BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(dest, messageSelector, noLocal);
- TopicSubscriberAdaptor subscriber = new TopicSubscriberAdaptor(dest, consumer);
- _subscriptions.put(name, subscriber);
- _reverseSubscriptionMap.put(subscriber.getMessageConsumer(), name);
- return subscriber;
- }
- public TopicPublisher createPublisher(Topic topic) throws JMSException
- {
- checkNotClosed();
- return new TopicPublisherAdapter((BasicMessageProducer) createProducer(topic), topic);
+ if (_logger.isTraceEnabled())
+ {
+ _logger.trace("Rejecting Unacked message:" + message.getDeliverBody().deliveryTag);
+ }
+
+ rejectMessage(message.getDeliverBody().deliveryTag, requeue);
}
- public QueueBrowser createBrowser(Queue queue) throws JMSException
+ public void rejectMessage(AbstractJMSMessage message, boolean requeue)
{
- if (isStrictAMQP())
+ if (_logger.isTraceEnabled())
{
- throw new UnsupportedOperationException();
+ _logger.trace("Rejecting Abstract message:" + message.getDeliveryTag());
}
- return createBrowser(queue, null);
+ rejectMessage(message.getDeliveryTag(), requeue);
+
}
- public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException
+ public void rejectMessage(long deliveryTag, boolean requeue)
{
- if (isStrictAMQP())
+ if ((_acknowledgeMode == CLIENT_ACKNOWLEDGE) || (_acknowledgeMode == SESSION_TRANSACTED))
{
- throw new UnsupportedOperationException();
- }
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Rejecting delivery tag:" + deliveryTag);
+ }
- checkNotClosed();
- checkValidQueue(queue);
- return new AMQQueueBrowser(this, (AMQQueue) queue, messageSelector);
+ AMQFrame basicRejectBody =
+ BasicRejectBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(), deliveryTag,
+ requeue);
+
+ _connection.getProtocolHandler().writeFrame(basicRejectBody);
+ }
}
- public TemporaryQueue createTemporaryQueue() throws JMSException
+ /**
+ * Commits all messages done in this transaction and releases any locks currently held.
+ *
+ * <p/>If the rollback fails, because the rollback itself is interrupted by a fail-over between requesting that the
+ * rollback be done, and receiving an acknowledgement that it has been done, then a JMSException will be thrown. The
+ * client will be unable to determine whether or not the rollback actually happened on the broker in this case.
+ *
+ * @throws JMSException If the JMS provider fails to rollback the transaction due to some internal error. This does
+ * not mean that the rollback is known to have failed, merely that it is not known whether it
+ * failed or not.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ public void rollback() throws JMSException
{
- checkNotClosed();
- return new AMQTemporaryQueue(this);
+ synchronized (_suspensionLock)
+ {
+ checkTransacted();
+
+ try
+ {
+ boolean isSuspended = isSuspended();
+
+ if (!isSuspended)
+ {
+ suspendChannel(true);
+ }
+
+ if (_dispatcher != null)
+ {
+ _dispatcher.rollback();
+ }
+
+ _connection.getProtocolHandler().syncWrite(TxRollbackBody.createAMQFrame(_channelId,
+ getProtocolMajorVersion(), getProtocolMinorVersion()), TxRollbackOkBody.class);
+
+ if (!isSuspended)
+ {
+ suspendChannel(false);
+ }
+ }
+ catch (AMQException e)
+ {
+ throw new JMSAMQException("Failed to rollback: " + e, e);
+ }
+ catch (FailoverException e)
+ {
+ throw new JMSAMQException("Fail-over interrupted rollback. Status of the rollback is uncertain.", e);
+ }
+ }
}
- public TemporaryTopic createTemporaryTopic() throws JMSException
+ public void run()
{
- checkNotClosed();
- return new AMQTemporaryTopic(this);
+ throw new java.lang.UnsupportedOperationException();
}
+ public void setMessageListener(MessageListener listener) throws JMSException
+ {
+ // checkNotClosed();
+ //
+ // if (_dispatcher != null && !_dispatcher.connectionStopped())
+ // {
+ // throw new javax.jms.IllegalStateException("Attempt to set listener while session is started.");
+ // }
+ //
+ // // We are stopped
+ // for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
+ // {
+ // BasicMessageConsumer consumer = i.next();
+ //
+ // if (consumer.isReceiving())
+ // {
+ // throw new javax.jms.IllegalStateException("Another thread is already receiving synchronously.");
+ // }
+ // }
+ //
+ // _messageListener = listener;
+ //
+ // for (Iterator<BasicMessageConsumer> i = _consumers.values().iterator(); i.hasNext();)
+ // {
+ // i.next().setMessageListener(_messageListener);
+ // }
+
+ }
+
+ /*public void setTicket(int ticket)
+ {
+ _ticket = ticket;
+ }*/
+
public void unsubscribe(String name) throws JMSException
{
checkNotClosed();
@@ -1835,189 +1501,246 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
- boolean isQueueBound(AMQShortString exchangeName, AMQShortString queueName) throws JMSException
+ protected MessageConsumer createConsumerImpl(final Destination destination, final int prefetchHigh,
+ final int prefetchLow, final boolean noLocal, final boolean exclusive, String selector, final FieldTable rawSelector,
+ final boolean noConsume, final boolean autoClose) throws JMSException
{
- return isQueueBound(exchangeName, queueName, null);
- }
+ checkTemporaryDestination(destination);
- boolean isQueueBound(AMQShortString exchangeName, AMQShortString queueName, AMQShortString routingKey) throws JMSException
- {
+ final String messageSelector;
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame boundFrame = ExchangeBoundBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- exchangeName, // exchange
- queueName, // queue
- routingKey); // routingKey
- AMQMethodEvent response = null;
- try
+ if (_strictAMQP && !((selector == null) || selector.equals("")))
{
- response = getProtocolHandler().syncWrite(boundFrame, ExchangeBoundOkBody.class);
+ if (_strictAMQPFATAL)
+ {
+ throw new UnsupportedOperationException("Selectors not currently supported by AMQP.");
+ }
+ else
+ {
+ messageSelector = null;
+ }
}
- catch (AMQException e)
+ else
{
- throw new JMSAMQException(e);
+ messageSelector = selector;
}
- ExchangeBoundOkBody responseBody = (ExchangeBoundOkBody) response.getMethod();
- return (responseBody.replyCode == 0); //ExchangeBoundHandler.OK); Remove Broker compile dependency
- }
- private void checkTransacted() throws JMSException
- {
- if (!getTransacted())
- {
- throw new IllegalStateException("Session is not transacted");
- }
- }
+ return new FailoverRetrySupport<MessageConsumer, JMSException>(
+ new FailoverProtectedOperation<MessageConsumer, JMSException>()
+ {
+ public MessageConsumer execute() throws JMSException, FailoverException
+ {
+ checkNotClosed();
- private void checkNotTransacted() throws JMSException
- {
- if (getTransacted())
- {
- throw new IllegalStateException("Session is transacted");
- }
+ AMQDestination amqd = (AMQDestination) destination;
+
+ final AMQProtocolHandler protocolHandler = getProtocolHandler();
+ // TODO: Define selectors in AMQP
+ // TODO: construct the rawSelector from the selector string if rawSelector == null
+ final FieldTable ft = FieldTableFactory.newFieldTable();
+ // if (rawSelector != null)
+ // ft.put("headers", rawSelector.getDataAsBytes());
+ if (rawSelector != null)
+ {
+ ft.addAll(rawSelector);
+ }
+
+ BasicMessageConsumer consumer =
+ new BasicMessageConsumer(_channelId, _connection, amqd, messageSelector, noLocal,
+ _messageFactoryRegistry, AMQSession.this, protocolHandler, ft, prefetchHigh, prefetchLow,
+ exclusive, _acknowledgeMode, noConsume, autoClose);
+
+ if (_messageListener != null)
+ {
+ consumer.setMessageListener(_messageListener);
+ }
+
+ try
+ {
+ registerConsumer(consumer, false);
+ }
+ catch (AMQInvalidArgumentException ise)
+ {
+ JMSException ex = new InvalidSelectorException(ise.getMessage());
+ ex.setLinkedException(ise);
+ throw ex;
+ }
+ catch (AMQInvalidRoutingKeyException e)
+ {
+ JMSException ide =
+ new InvalidDestinationException("Invalid routing key:" + amqd.getRoutingKey().toString());
+ ide.setLinkedException(e);
+ throw ide;
+ }
+ catch (AMQException e)
+ {
+ JMSException ex = new JMSException("Error registering consumer: " + e);
+
+ if (_logger.isDebugEnabled())
+ {
+ e.printStackTrace();
+ }
+
+ ex.setLinkedException(e);
+ throw ex;
+ }
+
+ synchronized (destination)
+ {
+ _destinationConsumerCount.putIfAbsent(destination, new AtomicInteger());
+ _destinationConsumerCount.get(destination).incrementAndGet();
+ }
+
+ return consumer;
+ }
+ }, _connection).execute();
}
/**
- * Invoked by the MINA IO thread (indirectly) when a message is received from the transport. Puts the message onto
- * the queue read by the dispatcher.
+ * Called by the MessageConsumer when closing, to deregister the consumer from the map from consumerTag to consumer
+ * instance.
*
- * @param message the message that has been received
+ * @param consumer the consum
*/
- public void messageReceived(UnprocessedMessage message)
+ void deregisterConsumer(BasicMessageConsumer consumer)
{
- if (_logger.isDebugEnabled())
+ if (_consumers.remove(consumer.getConsumerTag()) != null)
{
- _logger.debug("Message[" + (message.getDeliverBody() == null ?
- "B:" + message.getBounceBody() : "D:" + message.getDeliverBody())
- + "] received in session with channel id " + _channelId);
- }
+ String subscriptionName = _reverseSubscriptionMap.remove(consumer);
+ if (subscriptionName != null)
+ {
+ _subscriptions.remove(subscriptionName);
+ }
- if (message.getDeliverBody() == null)
- {
- // Return of the bounced message.
- returnBouncedMessage(message);
- }
- else
- {
- _queue.add(message);
+ Destination dest = consumer.getDestination();
+ synchronized (dest)
+ {
+ if (_destinationConsumerCount.get(dest).decrementAndGet() == 0)
+ {
+ _destinationConsumerCount.remove(dest);
+ }
+ }
}
}
- private void returnBouncedMessage(final UnprocessedMessage message)
+ void deregisterProducer(long producerId)
{
- _connection.performConnectionTask(
- new Runnable()
- {
- public void run()
- {
- try
- {
- // Bounced message is processed here, away from the mina thread
- AbstractJMSMessage bouncedMessage = _messageFactoryRegistry.createMessage(0,
- false,
- message.getBounceBody().exchange,
- message.getBounceBody().routingKey,
- message.getContentHeader(),
- message.getBodies());
-
- AMQConstant errorCode = AMQConstant.getConstant(message.getBounceBody().replyCode);
- AMQShortString reason = message.getBounceBody().replyText;
- _logger.debug("Message returned with error code " + errorCode + " (" + reason + ")");
-
- //@TODO should this be moved to an exception handler of sorts. Somewhere errors are converted to correct execeptions.
- if (errorCode == AMQConstant.NO_CONSUMERS)
- {
- _connection.exceptionReceived(new AMQNoConsumersException("Error: " + reason, bouncedMessage, null));
- }
- else if (errorCode == AMQConstant.NO_ROUTE)
- {
- _connection.exceptionReceived(new AMQNoRouteException("Error: " + reason, bouncedMessage, null));
- }
- else
- {
- _connection.exceptionReceived(new AMQUndeliveredException(errorCode, "Error: " + reason, bouncedMessage, null));
- }
+ _producers.remove(new Long(producerId));
+ }
- }
- catch (Exception e)
- {
- _logger.error("Caught exception trying to raise undelivered message exception (dump follows) - ignoring...", e);
- }
- }
- });
+ boolean isInRecovery()
+ {
+ return _inRecovery;
+ }
+
+ boolean isQueueBound(AMQShortString exchangeName, AMQShortString queueName) throws JMSException
+ {
+ return isQueueBound(exchangeName, queueName, null);
}
/**
- * Acknowledge a message or several messages. This method can be called via AbstractJMSMessage or from a
- * BasicConsumer. The former where the mode is CLIENT_ACK and the latter where the mode is AUTO_ACK or similar.
+ * Tests whether or not the specified queue is bound to the specified exchange under a particular routing key.
*
- * @param deliveryTag the tag of the last message to be acknowledged
- * @param multiple if true will acknowledge all messages up to and including the one specified by the delivery
- * tag
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param exchangeName The exchange name to test for binding against.
+ * @param queueName The queue name to check if bound.
+ * @param routingKey The routing key to check if the queue is bound under.
+ *
+ * @return <tt>true</tt> if the queue is bound to the exchange and routing key, <tt>false</tt> if not.
+ *
+ * @throws JMSException If the query fails for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
*/
- public void acknowledgeMessage(long deliveryTag, boolean multiple)
+ boolean isQueueBound(final AMQShortString exchangeName, final AMQShortString queueName, final AMQShortString routingKey)
+ throws JMSException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQFrame ackFrame = BasicAckBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- deliveryTag, // deliveryTag
- multiple); // multiple
- if (_logger.isDebugEnabled())
+ try
{
- _logger.debug("Sending ack for delivery tag " + deliveryTag + " on channel " + _channelId);
+ AMQMethodEvent response =
+ new FailoverRetrySupport<AMQMethodEvent, AMQException>(
+ new FailoverProtectedOperation<AMQMethodEvent, AMQException>()
+ {
+ public AMQMethodEvent execute() throws AMQException, FailoverException
+ {
+ AMQFrame boundFrame =
+ ExchangeBoundBody.createAMQFrame(_channelId, getProtocolMajorVersion(),
+ getProtocolMinorVersion(), exchangeName, // exchange
+ queueName, // queue
+ routingKey); // routingKey
+
+ return getProtocolHandler().syncWrite(boundFrame, ExchangeBoundOkBody.class);
+
+ }
+ }, _connection).execute();
+
+ // Extract and return the response code from the query.
+ ExchangeBoundOkBody responseBody = (ExchangeBoundOkBody) response.getMethod();
+
+ return (responseBody.replyCode == 0);
+ }
+ catch (AMQException e)
+ {
+ throw new JMSAMQException("Queue bound query failed: " + e.getMessage(), e);
}
- getProtocolHandler().writeFrame(ackFrame);
}
- public int getDefaultPrefetch()
+ /**
+ * Called to mark the session as being closed. Useful when the session needs to be made invalid, e.g. after failover
+ * when the client has veoted resubscription. <p/> The caller of this method must already hold the failover mutex.
+ */
+ void markClosed()
{
- return _defaultPrefetchHighMark;
+ _closed.set(true);
+ _connection.deregisterSession(_channelId);
+ markClosedProducersAndConsumers();
+
}
- public int getDefaultPrefetchHigh()
+ /**
+ * Resubscribes all producers and consumers. This is called when performing failover.
+ *
+ * @throws AMQException
+ */
+ void resubscribe() throws AMQException
{
- return _defaultPrefetchHighMark;
+ resubscribeProducers();
+ resubscribeConsumers();
}
- public int getDefaultPrefetchLow()
+ void setHasMessageListeners()
{
- return _defaultPrefetchLowMark;
+ _hasMessageListeners = true;
}
- public int getChannelId()
+ void setInRecovery(boolean inRecovery)
{
- return _channelId;
+ _inRecovery = inRecovery;
}
+ /**
+ * Starts the session, which ensures that it is not suspended and that its event dispatcher is running.
+ *
+ * @throws AMQException If the session cannot be started for any reason.
+ * @todo This should be controlled by _stopped as it pairs with the stop method fixme or check the
+ * FlowControlledBlockingQueue _queue to see if we have flow controlled. will result in sending Flow messages for
+ * each subsequent call to flow.. only need to do this if we have called stop.
+ */
void start() throws AMQException
{
- //fixme This should be controlled by _stopped as it pairs with the stop method
- //fixme or check the FlowControlledBlockingQueue _queue to see if we have flow controlled.
- //will result in sending Flow messages for each subsequent call to flow.. only need to do this
- // if we have called stop.
+ // Check if the session has perviously been started and suspended, in which case it must be unsuspended.
if (_startedAtLeastOnce.getAndSet(true))
{
- //then we stopped this and are restarting, so signal server to resume delivery
suspendChannel(false);
}
+ // If the event dispatcher is not running then start it too.
if (hasMessageListeners())
{
startDistpatcherIfNecessary();
}
}
- private boolean hasMessageListeners()
- {
- return _hasMessageListeners;
- }
-
- void setHasMessageListeners()
- {
- _hasMessageListeners = true;
- }
-
synchronized void startDistpatcherIfNecessary()
{
// If IMMEDIATE_PREFETCH is not set then we need to start fetching
@@ -2032,7 +1755,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
catch (AMQException e)
{
- _logger.info("Suspending channel threw an exception:" + e);
+ _logger.info("Unsuspending channel threw an exception:" + e);
}
}
}
@@ -2057,7 +1780,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
void stop() throws AMQException
{
- //stop the server delivering messages to this session
+ // Stop the server delivering messages to this session.
suspendChannel(true);
if (_dispatcher != null)
@@ -2066,320 +1789,552 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
- /**
- * Callers must hold the failover mutex before calling this method.
+ /*
+ * Binds the named queue, with the specified routing key, to the named exchange.
*
- * @param consumer
+ * <p/>Note that this operation automatically retries in the event of fail-over.
*
- * @throws AMQException
+ * @param queueName The name of the queue to bind.
+ * @param routingKey The routing key to bind the queue with.
+ * @param arguments Additional arguments.
+ * @param exchangeName The exchange to bind the queue on.
+ *
+ * @throws AMQException If the queue cannot be bound for any reason.
*/
- void registerConsumer(BasicMessageConsumer consumer, boolean nowait) throws AMQException
+ /*private void bindQueue(AMQDestination amqd, AMQShortString queueName, AMQProtocolHandler protocolHandler, FieldTable ft)
+ throws AMQException, FailoverException
{
- AMQDestination amqd = consumer.getDestination();
-
- AMQProtocolHandler protocolHandler = getProtocolHandler();
-
- declareExchange(amqd, protocolHandler, false);
-
- AMQShortString queueName = declareQueue(amqd, protocolHandler);
-
- bindQueue(amqd, queueName, protocolHandler, consumer.getRawSelectorFieldTable());
+ AMQFrame queueBind =
+ QueueBindBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(), ft, // arguments
+ amqd.getExchangeName(), // exchange
+ false, // nowait
+ queueName, // queue
+ amqd.getRoutingKey(), // routingKey
+ getTicket()); // ticket
- // If IMMEDIATE_PREFETCH is not required then suspsend the channel to delay prefetch
- if (!_immediatePrefetch)
- {
- // The dispatcher will be null if we have just created this session
- // so suspend the channel before we register our consumer so that we don't
- // start prefetching until a receive/mListener is set.
- if (_dispatcher == null)
- {
- if (!isSuspended())
- {
- try
- {
- suspendChannel(true);
- _logger.info("Prefetching delayed existing messages will not flow until requested via receive*() or setML().");
- }
- catch (AMQException e)
- {
- _logger.info("Suspending channel threw an exception:" + e);
- }
- }
- }
- }
- else
- {
- _logger.info("Immediately prefetching existing messages to new consumer.");
- }
+ protocolHandler.syncWrite(queueBind, QueueBindOkBody.class);
+ }*/
- try
- {
- consumeFromQueue(consumer, queueName, protocolHandler, nowait, consumer.getMessageSelector());
- }
- catch (JMSException e) //thrown by getMessageSelector
+ private void checkNotTransacted() throws JMSException
+ {
+ if (getTransacted())
{
- throw new AMQException(null, e.getMessage(), e);
+ throw new IllegalStateException("Session is transacted");
}
}
- /**
- * Called by the MessageConsumer when closing, to deregister the consumer from the map from consumerTag to consumer
- * instance.
- *
- * @param consumer the consum
- */
- void deregisterConsumer(BasicMessageConsumer consumer)
+ private void checkTemporaryDestination(Destination destination) throws JMSException
{
- if (_consumers.remove(consumer.getConsumerTag()) != null)
+ if ((destination instanceof TemporaryDestination))
{
- String subscriptionName = _reverseSubscriptionMap.remove(consumer);
- if (subscriptionName != null)
+ _logger.debug("destination is temporary");
+ final TemporaryDestination tempDest = (TemporaryDestination) destination;
+ if (tempDest.getSession() != this)
{
- _subscriptions.remove(subscriptionName);
+ _logger.debug("destination is on different session");
+ throw new JMSException("Cannot consume from a temporary destination created onanother session");
}
- Destination dest = consumer.getDestination();
- synchronized (dest)
+ if (tempDest.isDeleted())
{
- if (_destinationConsumerCount.get(dest).decrementAndGet() == 0)
- {
- _destinationConsumerCount.remove(dest);
- }
+ _logger.debug("destination is deleted");
+ throw new JMSException("Cannot consume from a deleted destination");
}
}
}
- private void registerProducer(long producerId, MessageProducer producer)
+ private void checkTransacted() throws JMSException
{
- _producers.put(new Long(producerId), producer);
+ if (!getTransacted())
+ {
+ throw new IllegalStateException("Session is not transacted");
+ }
}
- void deregisterProducer(long producerId)
+ private void checkValidDestination(Destination destination) throws InvalidDestinationException
{
- _producers.remove(new Long(producerId));
+ if (destination == null)
+ {
+ throw new javax.jms.InvalidDestinationException("Invalid Queue");
+ }
}
- private long getNextProducerId()
+ private void checkValidQueue(Queue queue) throws InvalidDestinationException
{
- return ++_nextProducerId;
+ if (queue == null)
+ {
+ throw new javax.jms.InvalidDestinationException("Invalid Queue");
+ }
}
- /**
- * Resubscribes all producers and consumers. This is called when performing failover.
- *
- * @throws AMQException
+ /*
+ * I could have combined the last 3 methods, but this way it improves readability
*/
- void resubscribe() throws AMQException
+ private AMQTopic checkValidTopic(Topic topic) throws JMSException
{
- resubscribeProducers();
- resubscribeConsumers();
+ if (topic == null)
+ {
+ throw new javax.jms.InvalidDestinationException("Invalid Topic");
+ }
+
+ if ((topic instanceof TemporaryDestination) && (((TemporaryDestination) topic).getSession() != this))
+ {
+ throw new javax.jms.InvalidDestinationException(
+ "Cannot create a subscription on a temporary topic created in another session");
+ }
+
+ if (!(topic instanceof AMQTopic))
+ {
+ throw new javax.jms.InvalidDestinationException(
+ "Cannot create a subscription on topic created for another JMS Provider, class of topic provided is: "
+ + topic.getClass().getName());
+ }
+
+ return (AMQTopic) topic;
}
- private void resubscribeProducers() throws AMQException
+ /**
+ * Called to close message consumers cleanly. This may or may <b>not</b> be as a result of an error.
+ *
+ * @param error not null if this is a result of an error occurring at the connection level
+ */
+ private void closeConsumers(Throwable error) throws JMSException
{
- ArrayList producers = new ArrayList(_producers.values());
- _logger.info(MessageFormat.format("Resubscribing producers = {0} producers.size={1}", producers, producers.size())); // FIXME: removeKey
- for (Iterator it = producers.iterator(); it.hasNext();)
+ if (_dispatcher != null)
{
- BasicMessageProducer producer = (BasicMessageProducer) it.next();
- producer.resubscribe();
+ _dispatcher.close();
+ _dispatcher = null;
}
+ // we need to clone the list of consumers since the close() method updates the _consumers collection
+ // which would result in a concurrent modification exception
+ final ArrayList<BasicMessageConsumer> clonedConsumers = new ArrayList<BasicMessageConsumer>(_consumers.values());
+
+ final Iterator<BasicMessageConsumer> it = clonedConsumers.iterator();
+ while (it.hasNext())
+ {
+ final BasicMessageConsumer con = it.next();
+ if (error != null)
+ {
+ con.notifyError(error);
+ }
+ else
+ {
+ con.close();
+ }
+ }
+ // at this point the _consumers map will be empty
}
- private void resubscribeConsumers() throws AMQException
+ /**
+ * Called to close message producers cleanly. This may or may <b>not</b> be as a result of an error. There is
+ * currently no way of propagating errors to message producers (this is a JMS limitation).
+ */
+ private void closeProducers() throws JMSException
{
- ArrayList consumers = new ArrayList(_consumers.values());
- _consumers.clear();
+ // we need to clone the list of producers since the close() method updates the _producers collection
+ // which would result in a concurrent modification exception
+ final ArrayList clonedProducers = new ArrayList(_producers.values());
- for (Iterator it = consumers.iterator(); it.hasNext();)
+ final Iterator it = clonedProducers.iterator();
+ while (it.hasNext())
{
- BasicMessageConsumer consumer = (BasicMessageConsumer) it.next();
- registerConsumer(consumer, true);
+ final BasicMessageProducer prod = (BasicMessageProducer) it.next();
+ prod.close();
}
+ // at this point the _producers map is empty
}
- private void suspendChannel(boolean suspend) throws AMQException
+ /**
+ * Close all producers or consumers. This is called either in the error case or when closing the session normally.
+ *
+ * @param amqe the exception, may be null to indicate no error has occurred
+ */
+ private void closeProducersAndConsumers(AMQException amqe) throws JMSException
{
- synchronized (_suspensionLock)
+ JMSException jmse = null;
+ try
{
- if (_logger.isDebugEnabled())
+ closeProducers();
+ }
+ catch (JMSException e)
+ {
+ _logger.error("Error closing session: " + e, e);
+ jmse = e;
+ }
+
+ try
+ {
+ closeConsumers(amqe);
+ }
+ catch (JMSException e)
+ {
+ _logger.error("Error closing session: " + e, e);
+ if (jmse == null)
{
- _logger.debug("Setting channel flow : " + (suspend ? "suspended" : "unsuspended"));
+ jmse = e;
}
+ }
- _suspended = suspend;
-
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame channelFlowFrame = ChannelFlowBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- !suspend); // active
-
- _connection.getProtocolHandler().syncWrite(channelFlowFrame, ChannelFlowOkBody.class);
+ if (jmse != null)
+ {
+ throw jmse;
}
}
-
- public void confirmConsumerCancelled(AMQShortString consumerTag)
+ /**
+ * Register to consume from the queue.
+ *
+ * @param queueName
+ */
+ private void consumeFromQueue(BasicMessageConsumer consumer, AMQShortString queueName,
+ AMQProtocolHandler protocolHandler, boolean nowait, String messageSelector) throws AMQException, FailoverException
{
+ // need to generate a consumer tag on the client so we can exploit the nowait flag
+ AMQShortString tag = new AMQShortString(Integer.toString(_nextTag++));
- // Remove the consumer from the map
- BasicMessageConsumer consumer = (BasicMessageConsumer) _consumers.get(consumerTag);
- if (consumer != null)
+ FieldTable arguments = FieldTableFactory.newFieldTable();
+ if ((messageSelector != null) && !messageSelector.equals(""))
{
-// fixme this isn't right.. needs to check if _queue contains data for this consumer
- if (consumer.isAutoClose())// && _queue.isEmpty())
- {
- consumer.closeWhenNoMessages(true);
- }
+ arguments.put(AMQPFilterTypes.JMS_SELECTOR.getValue(), messageSelector);
+ }
- if (!consumer.isNoConsume())
- {
- //Clean the Maps up first
- //Flush any pending messages for this consumerTag
- if (_dispatcher != null)
- {
- _logger.info("Dispatcher is not null");
- }
- else
- {
- _logger.info("Dispatcher is null so created stopped dispatcher");
+ if (consumer.isAutoClose())
+ {
+ arguments.put(AMQPFilterTypes.AUTO_CLOSE.getValue(), Boolean.TRUE);
+ }
- startDistpatcherIfNecessary(true);
- }
+ if (consumer.isNoConsume())
+ {
+ arguments.put(AMQPFilterTypes.NO_CONSUME.getValue(), Boolean.TRUE);
+ }
- _dispatcher.rejectPending(consumer);
+ consumer.setConsumerTag(tag);
+ // we must register the consumer in the map before we actually start listening
+ _consumers.put(tag, consumer);
+
+ try
+ {
+ // TODO: Be aware of possible changes to parameter order as versions change.
+ AMQFrame jmsConsume =
+ BasicConsumeBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(), arguments, // arguments
+ tag, // consumerTag
+ consumer.isExclusive(), // exclusive
+ consumer.getAcknowledgeMode() == Session.NO_ACKNOWLEDGE, // noAck
+ consumer.isNoLocal(), // noLocal
+ nowait, // nowait
+ queueName, // queue
+ getTicket()); // ticket
+
+ if (nowait)
+ {
+ protocolHandler.writeFrame(jmsConsume);
}
else
{
- //Just close the consumer
- //fixme the CancelOK is being processed before the arriving messages..
- // The dispatcher is still to process them so the server sent in order but the client
- // has yet to receive before the close comes in.
-
-// consumer.markClosed();
+ protocolHandler.syncWrite(jmsConsume, BasicConsumeOkBody.class);
}
}
- else
+ catch (AMQException e)
{
- _logger.warn("Unable to confirm cancellation of consumer (" + consumerTag + "). Not found in consumer map.");
+ // clean-up the map in the event of an error
+ _consumers.remove(tag);
+ throw e;
}
+ }
+ private BasicMessageProducer createProducerImpl(Destination destination, boolean mandatory, boolean immediate)
+ throws JMSException
+ {
+ return createProducerImpl(destination, mandatory, immediate, false);
+ }
+ private BasicMessageProducer createProducerImpl(final Destination destination, final boolean mandatory,
+ final boolean immediate, final boolean waitUntilSent) throws JMSException
+ {
+ return new FailoverRetrySupport<BasicMessageProducer, JMSException>(
+ new FailoverProtectedOperation<BasicMessageProducer, JMSException>()
+ {
+ public BasicMessageProducer execute() throws JMSException, FailoverException
+ {
+ checkNotClosed();
+ long producerId = getNextProducerId();
+ BasicMessageProducer producer =
+ new BasicMessageProducer(_connection, (AMQDestination) destination, _transacted, _channelId,
+ AMQSession.this, getProtocolHandler(), producerId, immediate, mandatory, waitUntilSent);
+ registerProducer(producerId, producer);
+
+ return producer;
+ }
+ }, _connection).execute();
}
- /*
- * I could have combined the last 3 methods, but this way it improves readability
- */
- private AMQTopic checkValidTopic(Topic topic) throws JMSException
+ private void declareExchange(AMQDestination amqd, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException
{
- if (topic == null)
- {
- throw new javax.jms.InvalidDestinationException("Invalid Topic");
- }
- if ((topic instanceof TemporaryDestination) && ((TemporaryDestination) topic).getSession() != this)
- {
- throw new javax.jms.InvalidDestinationException("Cannot create a subscription on a temporary topic created in another session");
- }
- if (!(topic instanceof AMQTopic))
- {
- throw new javax.jms.InvalidDestinationException("Cannot create a subscription on topic created for another JMS Provider, class of topic provided is: " + topic.getClass().getName());
- }
- return (AMQTopic) topic;
+ declareExchange(amqd.getExchangeName(), amqd.getExchangeClass(), protocolHandler, nowait);
}
- private void checkValidQueue(Queue queue) throws InvalidDestinationException
+ /**
+ * Declares the named exchange and type of exchange.
+ *
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param name The name of the exchange to declare.
+ * @param type The type of the exchange to declare.
+ * @param protocolHandler The protocol handler to process the communication through.
+ * @param nowait
+ *
+ * @throws AMQException If the exchange cannot be declared for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ private void declareExchange(final AMQShortString name, final AMQShortString type,
+ final AMQProtocolHandler protocolHandler, final boolean nowait) throws AMQException
{
- if (queue == null)
+ new FailoverNoopSupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()
{
- throw new javax.jms.InvalidDestinationException("Invalid Queue");
- }
+ public Object execute() throws AMQException, FailoverException
+ {
+ AMQFrame exchangeDeclare =
+ ExchangeDeclareBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ null, // arguments
+ false, // autoDelete
+ false, // durable
+ name, // exchange
+ false, // internal
+ nowait, // nowait
+ false, // passive
+ getTicket(), // ticket
+ type); // type
+
+ protocolHandler.syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
+
+ return null;
+ }
+ }, _connection).execute();
}
- private void checkValidDestination(Destination destination) throws InvalidDestinationException
+ /**
+ * Declares a queue for a JMS destination.
+ *
+ * <p/>Note that for queues but not topics the name is generated in the client rather than the server. This allows
+ * the name to be reused on failover if required. In general, the destination indicates whether it wants a name
+ * generated or not.
+ *
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param amqd The destination to declare as a queue.
+ * @param protocolHandler The protocol handler to communicate through.
+ *
+ * @return The name of the decalred queue. This is useful where the broker is generating a queue name on behalf of
+ * the client.
+ *
+ * @throws AMQException If the queue cannot be declared for any reason.
+ * @todo Verify the destiation is valid or throw an exception.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ private AMQShortString declareQueue(final AMQDestination amqd, final AMQProtocolHandler protocolHandler)
+ throws AMQException
{
- if (destination == null)
+ /*return new FailoverRetrySupport<AMQShortString, AMQException>(*/
+ return new FailoverNoopSupport<AMQShortString, AMQException>(
+ new FailoverProtectedOperation<AMQShortString, AMQException>()
+ {
+ public AMQShortString execute() throws AMQException, FailoverException
+ {
+ // Generate the queue name if the destination indicates that a client generated name is to be used.
+ if (amqd.isNameRequired())
+ {
+ amqd.setQueueName(protocolHandler.generateQueueName());
+ }
+
+ AMQFrame queueDeclare =
+ QueueDeclareBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ null, // arguments
+ amqd.isAutoDelete(), // autoDelete
+ amqd.isDurable(), // durable
+ amqd.isExclusive(), // exclusive
+ false, // nowait
+ false, // passive
+ amqd.getAMQQueueName(), // queue
+ getTicket()); // ticket
+
+ protocolHandler.syncWrite(queueDeclare, QueueDeclareOkBody.class);
+
+ return amqd.getAMQQueueName();
+ }
+ }, _connection).execute();
+ }
+
+ /**
+ * Undeclares the specified queue.
+ *
+ * <p/>Note that this operation automatically retries in the event of fail-over.
+ *
+ * @param queueName The name of the queue to delete.
+ *
+ * @throws JMSException If the queue could not be deleted for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ private void deleteQueue(final AMQShortString queueName) throws JMSException
+ {
+ try
{
- throw new javax.jms.InvalidDestinationException("Invalid Queue");
+ new FailoverRetrySupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()
+ {
+ public Object execute() throws AMQException, FailoverException
+ {
+ AMQFrame queueDeleteFrame =
+ QueueDeleteBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ false, // ifEmpty
+ false, // ifUnused
+ true, // nowait
+ queueName, // queue
+ getTicket()); // ticket
+
+ getProtocolHandler().syncWrite(queueDeleteFrame, QueueDeleteOkBody.class);
+
+ return null;
+ }
+ }, _connection).execute();
+ }
+ catch (AMQException e)
+ {
+ throw new JMSAMQException("The queue deletion failed: " + e.getMessage(), e);
}
}
-
- public AMQShortString getTemporaryTopicExchangeName()
+ private long getNextProducerId()
{
- return _connection.getTemporaryTopicExchangeName();
+ return ++_nextProducerId;
}
- public AMQShortString getTemporaryQueueExchangeName()
+ private AMQProtocolHandler getProtocolHandler()
{
- return _connection.getTemporaryQueueExchangeName();
+ return _connection.getProtocolHandler();
}
-
- public int getTicket()
+ private byte getProtocolMajorVersion()
{
- return _ticket;
+ return getProtocolHandler().getProtocolMajorVersion();
}
- public void setTicket(int ticket)
+ private byte getProtocolMinorVersion()
{
- _ticket = ticket;
+ return getProtocolHandler().getProtocolMinorVersion();
}
+ private boolean hasMessageListeners()
+ {
+ return _hasMessageListeners;
+ }
- public void requestAccess(AMQShortString realm, boolean exclusive, boolean passive, boolean active, boolean write, boolean read) throws AMQException
+ private void markClosedConsumers() throws JMSException
{
- getProtocolHandler().writeCommandFrameAndWaitForReply(AccessRequestBody.createAMQFrame(getChannelId(),
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- active,
- exclusive,
- passive,
- read,
- realm,
- write),
- new BlockingMethodFrameListener(_channelId)
- {
-
- public boolean processMethod(int channelId, AMQMethodBody frame) throws AMQException
- {
- if (frame instanceof AccessRequestOkBody)
- {
- setTicket(((AccessRequestOkBody) frame).getTicket());
- return true;
- }
- else
- {
- return false;
- }
- }
- });
+ if (_dispatcher != null)
+ {
+ _dispatcher.close();
+ _dispatcher = null;
+ }
+ // we need to clone the list of consumers since the close() method updates the _consumers collection
+ // which would result in a concurrent modification exception
+ final ArrayList<BasicMessageConsumer> clonedConsumers = new ArrayList<BasicMessageConsumer>(_consumers.values());
+ final Iterator<BasicMessageConsumer> it = clonedConsumers.iterator();
+ while (it.hasNext())
+ {
+ final BasicMessageConsumer con = it.next();
+ con.markClosed();
+ }
+ // at this point the _consumers map will be empty
}
- private class SuspenderRunner implements Runnable
+ private void markClosedProducersAndConsumers()
{
- private boolean _suspend;
+ try
+ {
+ // no need for a markClosed* method in this case since there is no protocol traffic closing a producer
+ closeProducers();
+ }
+ catch (JMSException e)
+ {
+ _logger.error("Error closing session: " + e, e);
+ }
- public SuspenderRunner(boolean suspend)
+ try
{
- _suspend = suspend;
+ markClosedConsumers();
}
+ catch (JMSException e)
+ {
+ _logger.error("Error closing session: " + e, e);
+ }
+ }
- public void run()
+ /**
+ * Callers must hold the failover mutex before calling this method.
+ *
+ * @param consumer
+ *
+ * @throws AMQException
+ */
+ private void registerConsumer(BasicMessageConsumer consumer, boolean nowait) throws AMQException // , FailoverException
+ {
+ AMQDestination amqd = consumer.getDestination();
+
+ AMQProtocolHandler protocolHandler = getProtocolHandler();
+
+ declareExchange(amqd, protocolHandler, false);
+
+ AMQShortString queueName = declareQueue(amqd, protocolHandler);
+
+ // bindQueue(amqd, queueName, protocolHandler, consumer.getRawSelectorFieldTable());
+ bindQueue(queueName, amqd.getRoutingKey(), consumer.getRawSelectorFieldTable(), amqd.getExchangeName());
+
+ // If IMMEDIATE_PREFETCH is not required then suspsend the channel to delay prefetch
+ if (!_immediatePrefetch)
{
- try
- {
- suspendChannel(_suspend);
- }
- catch (AMQException e)
+ // The dispatcher will be null if we have just created this session
+ // so suspend the channel before we register our consumer so that we don't
+ // start prefetching until a receive/mListener is set.
+ if (_dispatcher == null)
{
- _logger.warn("Unable to suspend channel");
+ if (!isSuspended())
+ {
+ try
+ {
+ suspendChannel(true);
+ _logger.info(
+ "Prefetching delayed existing messages will not flow until requested via receive*() or setML().");
+ }
+ catch (AMQException e)
+ {
+ _logger.info("Suspending channel threw an exception:" + e);
+ }
+ }
}
}
+ else
+ {
+ _logger.info("Immediately prefetching existing messages to new consumer.");
+ }
+
+ try
+ {
+ consumeFromQueue(consumer, queueName, protocolHandler, nowait, consumer.getMessageSelector());
+ }
+ catch (JMSException e) // thrown by getMessageSelector
+ {
+ throw new AMQException(null, e.getMessage(), e);
+ }
+ catch (FailoverException e)
+ {
+ throw new AMQException(null, "Fail-over exception interrupted basic consume.", e);
+ }
}
+ private void registerProducer(long producerId, MessageProducer producer)
+ {
+ _producers.put(new Long(producerId), producer);
+ }
private void rejectAllMessages(boolean requeue)
{
@@ -2396,8 +2351,8 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
Iterator messages = _queue.iterator();
if (_logger.isInfoEnabled())
{
- _logger.info("Rejecting messages from _queue for Consumer tag(" + consumerTag +
- ") (PDispatchQ) requeue:" + requeue);
+ _logger.info("Rejecting messages from _queue for Consumer tag(" + consumerTag + ") (PDispatchQ) requeue:"
+ + requeue);
if (messages.hasNext())
{
@@ -2412,12 +2367,12 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
UnprocessedMessage message = (UnprocessedMessage) messages.next();
- if (consumerTag == null || message.getDeliverBody().consumerTag.equals(consumerTag))
+ if ((consumerTag == null) || message.getDeliverBody().consumerTag.equals(consumerTag))
{
if (_logger.isDebugEnabled())
{
- _logger.debug("Removing message(" + System.identityHashCode(message) +
- ") from _queue DT:" + message.getDeliverBody().deliveryTag);
+ _logger.debug("Removing message(" + System.identityHashCode(message) + ") from _queue DT:"
+ + message.getDeliverBody().deliveryTag);
}
messages.remove();
@@ -2432,50 +2387,360 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
-
- public void rejectMessage(UnprocessedMessage message, boolean requeue)
+ private void resubscribeConsumers() throws AMQException
{
+ ArrayList consumers = new ArrayList(_consumers.values());
+ _consumers.clear();
- if (_logger.isTraceEnabled())
+ for (Iterator it = consumers.iterator(); it.hasNext();)
{
- _logger.trace("Rejecting Unacked message:" + message.getDeliverBody().deliveryTag);
+ BasicMessageConsumer consumer = (BasicMessageConsumer) it.next();
+ registerConsumer(consumer, true);
}
-
- rejectMessage(message.getDeliverBody().deliveryTag, requeue);
}
- public void rejectMessage(AbstractJMSMessage message, boolean requeue)
+ private void resubscribeProducers() throws AMQException
{
- if (_logger.isTraceEnabled())
+ ArrayList producers = new ArrayList(_producers.values());
+ _logger.info(MessageFormat.format("Resubscribing producers = {0} producers.size={1}", producers, producers.size())); // FIXME: removeKey
+ for (Iterator it = producers.iterator(); it.hasNext();)
{
- _logger.trace("Rejecting Abstract message:" + message.getDeliveryTag());
+ BasicMessageProducer producer = (BasicMessageProducer) it.next();
+ producer.resubscribe();
}
- rejectMessage(message.getDeliveryTag(), requeue);
-
}
- public void rejectMessage(long deliveryTag, boolean requeue)
+ private void returnBouncedMessage(final UnprocessedMessage message)
{
- if (_acknowledgeMode == CLIENT_ACKNOWLEDGE ||
- _acknowledgeMode == SESSION_TRANSACTED)
+ _connection.performConnectionTask(new Runnable()
{
- if (_logger.isDebugEnabled())
+ public void run()
{
- _logger.debug("Rejecting delivery tag:" + deliveryTag);
+ try
+ {
+ // Bounced message is processed here, away from the mina thread
+ AbstractJMSMessage bouncedMessage =
+ _messageFactoryRegistry.createMessage(0, false, message.getBounceBody().exchange,
+ message.getBounceBody().routingKey, message.getContentHeader(), message.getBodies());
+
+ AMQConstant errorCode = AMQConstant.getConstant(message.getBounceBody().replyCode);
+ AMQShortString reason = message.getBounceBody().replyText;
+ _logger.debug("Message returned with error code " + errorCode + " (" + reason + ")");
+
+ // @TODO should this be moved to an exception handler of sorts. Somewhere errors are converted to correct execeptions.
+ if (errorCode == AMQConstant.NO_CONSUMERS)
+ {
+ _connection.exceptionReceived(new AMQNoConsumersException("Error: " + reason, bouncedMessage, null));
+ }
+ else if (errorCode == AMQConstant.NO_ROUTE)
+ {
+ _connection.exceptionReceived(new AMQNoRouteException("Error: " + reason, bouncedMessage, null));
+ }
+ else
+ {
+ _connection.exceptionReceived(
+ new AMQUndeliveredException(errorCode, "Error: " + reason, bouncedMessage, null));
+ }
+
+ }
+ catch (Exception e)
+ {
+ _logger.error(
+ "Caught exception trying to raise undelivered message exception (dump follows) - ignoring...",
+ e);
+ }
}
- AMQFrame basicRejectBody = BasicRejectBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- deliveryTag,
- requeue);
+ });
+ }
- _connection.getProtocolHandler().writeFrame(basicRejectBody);
+ /**
+ * Suspends or unsuspends this session.
+ *
+ * @param suspend <tt>true</tt> indicates that the session should be suspended, <tt>false<tt> indicates that it
+ * should be unsuspended.
+ *
+ * @throws AMQException If the session cannot be suspended for any reason.
+ * @todo Be aware of possible changes to parameter order as versions change.
+ */
+ private void suspendChannel(boolean suspend) throws AMQException // , FailoverException
+ {
+ synchronized (_suspensionLock)
+ {
+ try
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Setting channel flow : " + (suspend ? "suspended" : "unsuspended"));
+ }
+
+ _suspended = suspend;
+
+ AMQFrame channelFlowFrame =
+ ChannelFlowBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion(),
+ !suspend);
+
+ _connection.getProtocolHandler().syncWrite(channelFlowFrame, ChannelFlowOkBody.class);
+ }
+ catch (FailoverException e)
+ {
+ throw new AMQException(null, "Fail-over interrupted suspend/unsuspend channel.", e);
+ }
}
}
- public boolean isStrictAMQP()
+ /** Responsible for decoding a message fragment and passing it to the appropriate message consumer. */
+ private class Dispatcher extends Thread
{
- return _strictAMQP;
+
+ /** Track the 'stopped' state of the dispatcher, a session starts in the stopped state. */
+ private final AtomicBoolean _closed = new AtomicBoolean(false);
+
+ private final Object _lock = new Object();
+
+ public Dispatcher()
+ {
+ super("Dispatcher-Channel-" + _channelId);
+ if (_dispatcherLogger.isInfoEnabled())
+ {
+ _dispatcherLogger.info(getName() + " created");
+ }
+ }
+
+ public void close()
+ {
+ _closed.set(true);
+ interrupt();
+
+ // fixme awaitTermination
+
+ }
+
+ public void rejectPending(BasicMessageConsumer consumer)
+ {
+ synchronized (_lock)
+ {
+ boolean stopped = _dispatcher.connectionStopped();
+
+ if (!stopped)
+ {
+ _dispatcher.setConnectionStopped(true);
+ }
+
+ // Reject messages on pre-receive queue
+ consumer.rollback();
+
+ // Reject messages on pre-dispatch queue
+ rejectMessagesForConsumerTag(consumer.getConsumerTag(), true);
+
+ // closeConsumer
+ consumer.markClosed();
+
+ _dispatcher.setConnectionStopped(stopped);
+
+ }
+ }
+
+ public void rollback()
+ {
+
+ synchronized (_lock)
+ {
+ boolean isStopped = connectionStopped();
+
+ if (!isStopped)
+ {
+ setConnectionStopped(true);
+ }
+
+ rejectAllMessages(true);
+
+ _dispatcherLogger.debug("Session Pre Dispatch Queue cleared");
+
+ for (BasicMessageConsumer consumer : _consumers.values())
+ {
+ if (!consumer.isNoConsume())
+ {
+ consumer.rollback();
+ }
+ else
+ {
+ // should perhaps clear the _SQ here.
+ // consumer._synchronousQueue.clear();
+ consumer.clearReceiveQueue();
+ }
+
+ }
+
+ setConnectionStopped(isStopped);
+ }
+
+ }
+
+ public void run()
+ {
+ if (_dispatcherLogger.isInfoEnabled())
+ {
+ _dispatcherLogger.info(getName() + " started");
+ }
+
+ UnprocessedMessage message;
+
+ // Allow disptacher to start stopped
+ synchronized (_lock)
+ {
+ while (connectionStopped())
+ {
+ try
+ {
+ _lock.wait();
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+ }
+ }
+
+ try
+ {
+ while (!_closed.get() && ((message = (UnprocessedMessage) _queue.take()) != null))
+ {
+ synchronized (_lock)
+ {
+
+ while (connectionStopped())
+ {
+ _lock.wait();
+ }
+
+ dispatchMessage(message);
+
+ while (connectionStopped())
+ {
+ _lock.wait();
+ }
+
+ }
+
+ }
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+
+ if (_dispatcherLogger.isInfoEnabled())
+ {
+ _dispatcherLogger.info(getName() + " thread terminating for channel " + _channelId);
+ }
+ }
+
+ // only call while holding lock
+ final boolean connectionStopped()
+ {
+ return _connectionStopped;
+ }
+
+ boolean setConnectionStopped(boolean connectionStopped)
+ {
+ boolean currently;
+ synchronized (_lock)
+ {
+ currently = _connectionStopped;
+ _connectionStopped = connectionStopped;
+ _lock.notify();
+
+ if (_dispatcherLogger.isDebugEnabled())
+ {
+ _dispatcherLogger.debug("Set Dispatcher Connection " + (connectionStopped ? "Stopped" : "Started")
+ + ": Currently " + (currently ? "Stopped" : "Started"));
+ }
+ }
+
+ return currently;
+ }
+
+ private void dispatchMessage(UnprocessedMessage message)
+ {
+ if (message.getDeliverBody() != null)
+ {
+ final BasicMessageConsumer consumer =
+ (BasicMessageConsumer) _consumers.get(message.getDeliverBody().consumerTag);
+
+ if ((consumer == null) || consumer.isClosed())
+ {
+ if (_dispatcherLogger.isInfoEnabled())
+ {
+ if (consumer == null)
+ {
+ _dispatcherLogger.info("Received a message(" + System.identityHashCode(message) + ")" + "["
+ + message.getDeliverBody().deliveryTag + "] from queue "
+ + message.getDeliverBody().consumerTag + " )without a handler - rejecting(requeue)...");
+ }
+ else
+ {
+ _dispatcherLogger.info("Received a message(" + System.identityHashCode(message) + ")" + "["
+ + message.getDeliverBody().deliveryTag + "] from queue " + " consumer("
+ + consumer.debugIdentity() + ") is closed rejecting(requeue)...");
+ }
+ }
+ // Don't reject if we're already closing
+ if (!_closed.get())
+ {
+ rejectMessage(message, true);
+ }
+ }
+ else
+ {
+ consumer.notifyMessage(message, _channelId);
+ }
+ }
+ }
}
+ /*public void requestAccess(AMQShortString realm, boolean exclusive, boolean passive, boolean active, boolean write,
+ boolean read) throws AMQException
+ {
+ getProtocolHandler().writeCommandFrameAndWaitForReply(AccessRequestBody.createAMQFrame(getChannelId(),
+ getProtocolMajorVersion(), getProtocolMinorVersion(), active, exclusive, passive, read, realm, write),
+ new BlockingMethodFrameListener(_channelId)
+ {
+
+ public boolean processMethod(int channelId, AMQMethodBody frame) // throws AMQException
+ {
+ if (frame instanceof AccessRequestOkBody)
+ {
+ setTicket(((AccessRequestOkBody) frame).getTicket());
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ });
+ }*/
+
+ private class SuspenderRunner implements Runnable
+ {
+ private boolean _suspend;
+
+ public SuspenderRunner(boolean suspend)
+ {
+ _suspend = suspend;
+ }
+
+ public void run()
+ {
+ try
+ {
+ suspendChannel(_suspend);
+ }
+ catch (AMQException e)
+ {
+ _logger.warn("Unable to suspend channel");
+ }
+ }
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
index 1c3cdbcb65..dfac0d45a8 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
@@ -20,22 +20,8 @@
*/
package org.apache.qpid.client;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-
-import org.apache.log4j.Logger;
-
import org.apache.qpid.AMQException;
+import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage;
@@ -48,9 +34,25 @@ import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.jms.MessageConsumer;
import org.apache.qpid.jms.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
public class BasicMessageConsumer extends Closeable implements MessageConsumer
{
- private static final Logger _logger = Logger.getLogger(BasicMessageConsumer.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BasicMessageConsumer.class);
/** The connection being used by this consumer */
private AMQConnection _connection;
@@ -140,9 +142,9 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
private List<StackTraceElement> _closedStack = null;
protected BasicMessageConsumer(int channelId, AMQConnection connection, AMQDestination destination,
- String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory, AMQSession session,
- AMQProtocolHandler protocolHandler, FieldTable rawSelectorFieldTable, int prefetchHigh, int prefetchLow,
- boolean exclusive, int acknowledgeMode, boolean noConsume, boolean autoClose)
+ String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory, AMQSession session,
+ AMQProtocolHandler protocolHandler, FieldTable rawSelectorFieldTable, int prefetchHigh, int prefetchLow,
+ boolean exclusive, int acknowledgeMode, boolean noConsume, boolean autoClose)
{
_channelId = channelId;
_connection = connection;
@@ -219,7 +221,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_logger.isDebugEnabled())
{
_logger.debug("Session stopped : Message listener(" + messageListener + ") set for destination "
- + _destination);
+ + _destination);
}
}
else
@@ -468,7 +470,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_closedStack != null)
{
_logger.trace(_consumerTag + " close():"
- + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 6));
+ + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 6));
_logger.trace(_consumerTag + " previously:" + _closedStack.toString());
}
else
@@ -481,9 +483,9 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
{
// TODO: Be aware of possible changes to parameter order as versions change.
final AMQFrame cancelFrame =
- BasicCancelBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(), _consumerTag, // consumerTag
- false); // nowait
+ BasicCancelBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
+ _protocolHandler.getProtocolMinorVersion(), _consumerTag, // consumerTag
+ false); // nowait
try
{
@@ -497,10 +499,11 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
}
catch (AMQException e)
{
- // _logger.error("Error closing consumer: " + e, e);
- JMSException jmse = new JMSException("Error closing consumer: " + e);
- jmse.setLinkedException(e);
- throw jmse;
+ throw new JMSAMQException("Error closing consumer: " + e, e);
+ }
+ catch (FailoverException e)
+ {
+ throw new JMSAMQException("FailoverException interrupted basic cancel.", e);
}
}
else
@@ -540,7 +543,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_closedStack != null)
{
_logger.trace(_consumerTag + " markClosed():"
- + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 8));
+ + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 8));
_logger.trace(_consumerTag + " previously:" + _closedStack.toString());
}
else
@@ -572,9 +575,9 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
try
{
AbstractJMSMessage jmsMessage =
- _messageFactory.createMessage(messageFrame.getDeliverBody().deliveryTag,
- messageFrame.getDeliverBody().redelivered, messageFrame.getDeliverBody().exchange,
- messageFrame.getDeliverBody().routingKey, messageFrame.getContentHeader(), messageFrame.getBodies());
+ _messageFactory.createMessage(messageFrame.getDeliverBody().deliveryTag,
+ messageFrame.getDeliverBody().redelivered, messageFrame.getDeliverBody().exchange,
+ messageFrame.getDeliverBody().routingKey, messageFrame.getContentHeader(), messageFrame.getBodies());
if (debug)
{
@@ -659,15 +662,15 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
switch (_acknowledgeMode)
{
- case Session.PRE_ACKNOWLEDGE:
- _session.acknowledgeMessage(msg.getDeliveryTag(), false);
- break;
+ case Session.PRE_ACKNOWLEDGE:
+ _session.acknowledgeMessage(msg.getDeliveryTag(), false);
+ break;
- case Session.CLIENT_ACKNOWLEDGE:
- // we set the session so that when the user calls acknowledge() it can call the method on session
- // to send out the appropriate frame
- msg.setAMQSession(_session);
- break;
+ case Session.CLIENT_ACKNOWLEDGE:
+ // we set the session so that when the user calls acknowledge() it can call the method on session
+ // to send out the appropriate frame
+ msg.setAMQSession(_session);
+ break;
}
}
@@ -677,55 +680,55 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
switch (_acknowledgeMode)
{
- case Session.CLIENT_ACKNOWLEDGE:
- if (isNoConsume())
- {
- _session.acknowledgeMessage(msg.getDeliveryTag(), false);
- }
+ case Session.CLIENT_ACKNOWLEDGE:
+ if (isNoConsume())
+ {
+ _session.acknowledgeMessage(msg.getDeliveryTag(), false);
+ }
- break;
+ break;
- case Session.DUPS_OK_ACKNOWLEDGE:
- if (++_outstanding >= _prefetchHigh)
- {
- _dups_ok_acknowledge_send = true;
- }
+ case Session.DUPS_OK_ACKNOWLEDGE:
+ if (++_outstanding >= _prefetchHigh)
+ {
+ _dups_ok_acknowledge_send = true;
+ }
- if (_outstanding <= _prefetchLow)
- {
- _dups_ok_acknowledge_send = false;
- }
+ if (_outstanding <= _prefetchLow)
+ {
+ _dups_ok_acknowledge_send = false;
+ }
- if (_dups_ok_acknowledge_send)
+ if (_dups_ok_acknowledge_send)
+ {
+ if (!_session.isInRecovery())
{
- if (!_session.isInRecovery())
- {
- _session.acknowledgeMessage(msg.getDeliveryTag(), true);
- }
+ _session.acknowledgeMessage(msg.getDeliveryTag(), true);
}
+ }
- break;
+ break;
- case Session.AUTO_ACKNOWLEDGE:
- // we do not auto ack a message if the application code called recover()
- if (!_session.isInRecovery())
- {
- _session.acknowledgeMessage(msg.getDeliveryTag(), false);
- }
+ case Session.AUTO_ACKNOWLEDGE:
+ // we do not auto ack a message if the application code called recover()
+ if (!_session.isInRecovery())
+ {
+ _session.acknowledgeMessage(msg.getDeliveryTag(), false);
+ }
- break;
+ break;
- case Session.SESSION_TRANSACTED:
- if (isNoConsume())
- {
- _session.acknowledgeMessage(msg.getDeliveryTag(), false);
- }
- else
- {
- _receivedDeliveryTags.add(msg.getDeliveryTag());
- }
+ case Session.SESSION_TRANSACTED:
+ if (isNoConsume())
+ {
+ _session.acknowledgeMessage(msg.getDeliveryTag(), false);
+ }
+ else
+ {
+ _receivedDeliveryTags.add(msg.getDeliveryTag());
+ }
- break;
+ break;
}
}
@@ -757,7 +760,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_closedStack != null)
{
_logger.trace(_consumerTag + " notifyError():"
- + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 8));
+ + Arrays.asList(Thread.currentThread().getStackTrace()).subList(3, 8));
_logger.trace(_consumerTag + " previously" + _closedStack.toString());
}
else
@@ -817,7 +820,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
}
}
- public void acknowledge() throws JMSException
+ public void acknowledge() // throws JMSException
{
if (!isClosed())
{
@@ -877,7 +880,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_logger.isDebugEnabled())
{
_logger.debug("Rejecting the messages(" + _receivedDeliveryTags.size() + ") in _receivedDTs (RQ)"
- + "for consumer with tag:" + _consumerTag);
+ + "for consumer with tag:" + _consumerTag);
}
Long tag = _receivedDeliveryTags.poll();
@@ -907,7 +910,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (_logger.isDebugEnabled())
{
_logger.debug("Rejecting the messages(" + _synchronousQueue.size() + ") in _syncQueue (PRQ)"
- + "for consumer with tag:" + _consumerTag);
+ + "for consumer with tag:" + _consumerTag);
}
Iterator iterator = _synchronousQueue.iterator();
@@ -931,7 +934,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
else
{
_logger.error("Queue contained a :" + o.getClass()
- + " unable to reject as it is not an AbstractJMSMessage. Will be cleared");
+ + " unable to reject as it is not an AbstractJMSMessage. Will be cleared");
iterator.remove();
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
index bd7cc94582..0ee4882ec2 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
@@ -20,8 +20,23 @@
*/
package org.apache.qpid.client;
-import java.io.UnsupportedEncodingException;
-import java.util.UUID;
+import org.apache.mina.common.ByteBuffer;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.message.AbstractJMSMessage;
+import org.apache.qpid.client.message.MessageConverter;
+import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.BasicConsumeBody;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.BasicPublishBody;
+import org.apache.qpid.framing.CompositeAMQDataBlock;
+import org.apache.qpid.framing.ContentBody;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.ExchangeDeclareBody;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.BytesMessage;
import javax.jms.DeliveryMode;
@@ -36,24 +51,12 @@ import javax.jms.StreamMessage;
import javax.jms.TextMessage;
import javax.jms.Topic;
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.client.message.AbstractJMSMessage;
-import org.apache.qpid.client.message.MessageConverter;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.BasicConsumeBody;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
-import org.apache.qpid.framing.BasicPublishBody;
-import org.apache.qpid.framing.CompositeAMQDataBlock;
-import org.apache.qpid.framing.ContentBody;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.ExchangeDeclareBody;
+import java.io.UnsupportedEncodingException;
+import java.util.UUID;
public class BasicMessageProducer extends Closeable implements org.apache.qpid.jms.MessageProducer
{
- protected final Logger _logger = Logger.getLogger(getClass());
+ protected final Logger _logger = LoggerFactory.getLogger(getClass());
private AMQConnection _connection;
@@ -119,14 +122,14 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
private final boolean _mandatory;
private final boolean _waitUntilSent;
-
+
private boolean _disableMessageId;
-
+
private static final ContentBody[] NO_CONTENT_BODIES = new ContentBody[0];
protected BasicMessageProducer(AMQConnection connection, AMQDestination destination, boolean transacted, int channelId,
- AMQSession session, AMQProtocolHandler protocolHandler, long producerId,
- boolean immediate, boolean mandatory, boolean waitUntilSent)
+ AMQSession session, AMQProtocolHandler protocolHandler, long producerId, boolean immediate, boolean mandatory,
+ boolean waitUntilSent)
{
_connection = connection;
_destination = destination;
@@ -160,15 +163,15 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
// TODO: Be aware of possible changes to parameter order as versions change.
AMQFrame declare =
ExchangeDeclareBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(), null, // arguments
- false, // autoDelete
- false, // durable
- destination.getExchangeName(), // exchange
- false, // internal
- true, // nowait
- false, // passive
- _session.getTicket(), // ticket
- destination.getExchangeClass()); // type
+ _protocolHandler.getProtocolMinorVersion(), null, // arguments
+ false, // autoDelete
+ false, // durable
+ destination.getExchangeName(), // exchange
+ false, // internal
+ true, // nowait
+ false, // passive
+ _session.getTicket(), // ticket
+ destination.getExchangeClass()); // type
_protocolHandler.writeFrame(declare);
}
@@ -205,7 +208,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
if ((i != DeliveryMode.NON_PERSISTENT) && (i != DeliveryMode.PERSISTENT))
{
throw new JMSException("DeliveryMode must be either NON_PERSISTENT or PERSISTENT. Value of " + i
- + " is illegal");
+ + " is illegal");
}
_deliveryMode = i;
@@ -317,12 +320,12 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
{
validateDestination(destination);
sendImpl((AMQDestination) destination, message, _deliveryMode, _messagePriority, _timeToLive, _mandatory,
- _immediate);
+ _immediate);
}
}
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
- throws JMSException
+ throws JMSException
{
checkPreConditions();
checkDestination(destination);
@@ -334,7 +337,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
}
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive,
- boolean mandatory) throws JMSException
+ boolean mandatory) throws JMSException
{
checkPreConditions();
checkDestination(destination);
@@ -346,7 +349,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
}
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive,
- boolean mandatory, boolean immediate) throws JMSException
+ boolean mandatory, boolean immediate) throws JMSException
{
checkPreConditions();
checkDestination(destination);
@@ -358,7 +361,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
}
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive,
- boolean mandatory, boolean immediate, boolean waitUntilSent) throws JMSException
+ boolean mandatory, boolean immediate, boolean waitUntilSent) throws JMSException
{
checkPreConditions();
checkDestination(destination);
@@ -366,7 +369,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
{
validateDestination(destination);
sendImpl((AMQDestination) destination, message, deliveryMode, priority, timeToLive, mandatory, immediate,
- waitUntilSent);
+ waitUntilSent);
}
}
@@ -412,7 +415,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
else
{
throw new JMSException("Unable to send message, due to class conversion error: "
- + message.getClass().getName());
+ + message.getClass().getName());
}
}
}
@@ -422,14 +425,14 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
if (!(destination instanceof AMQDestination))
{
throw new JMSException("Unsupported destination class: "
- + ((destination != null) ? destination.getClass() : null));
+ + ((destination != null) ? destination.getClass() : null));
}
declareDestination((AMQDestination) destination);
}
protected void sendImpl(AMQDestination destination, Message message, int deliveryMode, int priority, long timeToLive,
- boolean mandatory, boolean immediate) throws JMSException
+ boolean mandatory, boolean immediate) throws JMSException
{
sendImpl(destination, message, deliveryMode, priority, timeToLive, mandatory, immediate, _waitUntilSent);
}
@@ -447,23 +450,23 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
* @throws JMSException
*/
protected void sendImpl(AMQDestination destination, Message origMessage, int deliveryMode, int priority, long timeToLive,
- boolean mandatory, boolean immediate, boolean wait) throws JMSException
+ boolean mandatory, boolean immediate, boolean wait) throws JMSException
{
checkTemporaryDestination(destination);
origMessage.setJMSDestination(destination);
AbstractJMSMessage message = convertToNativeMessage(origMessage);
-
- if(_disableMessageId)
+
+ if (_disableMessageId)
{
- message.setJMSMessageID(null);
+ message.setJMSMessageID(null);
}
else
{
- if (message.getJMSMessageID() == null)
- {
- message.setJMSMessageID(UUID.randomUUID().toString());
- }
+ if (message.getJMSMessageID() == null)
+ {
+ message.setJMSMessageID(UUID.randomUUID().toString());
+ }
}
int type;
@@ -486,9 +489,8 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
AMQFrame publishFrame =
- BasicPublishBody.createAMQFrame(
- _channelId, _protocolHandler.getProtocolMajorVersion(), _protocolHandler.getProtocolMinorVersion(),
- destination.getExchangeName(), // exchange
+ BasicPublishBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
+ _protocolHandler.getProtocolMinorVersion(), destination.getExchangeName(), // exchange
immediate, // immediate
mandatory, // mandatory
destination.getRoutingKey(), // routingKey
@@ -535,9 +537,8 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
AMQFrame contentHeaderFrame =
ContentHeaderBody.createAMQFrame(_channelId,
- BasicConsumeBody.getClazz(_protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion()), 0,
- contentHeaderProperties, size);
+ BasicConsumeBody.getClazz(_protocolHandler.getProtocolMajorVersion(),
+ _protocolHandler.getProtocolMinorVersion()), 0, contentHeaderProperties, size);
if (_logger.isDebugEnabled())
{
_logger.debug("Sending content header frame to " + destination);
@@ -685,6 +686,6 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
public boolean isBound(AMQDestination destination) throws JMSException
{
- return _session.isQueueBound(destination.getExchangeName(),null,destination.getRoutingKey());
+ return _session.isQueueBound(destination.getExchangeName(), null, destination.getRoutingKey());
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/Closeable.java b/java/client/src/main/java/org/apache/qpid/client/Closeable.java
index d246dc3931..7e119343a1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/Closeable.java
+++ b/java/client/src/main/java/org/apache/qpid/client/Closeable.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,12 +20,29 @@
*/
package org.apache.qpid.client;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
-/** Provides support for orderly shutdown of an object. */
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Captures the 'closed' state of an object, that is initially open, can be tested to see if it is closed, and provides
+ * a 'close' method to close it.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Mark an object as closed.
+ * <tr><td> Check if an object is closed.
+ * <tr><td> Raise a JMS exception if an object is closed.
+ * </table>
+ *
+ * @todo Might be better to make this an interface. This whole class doesn't really encapsulate a terribly neat
+ * piece of re-usable functionality. A simple interface defining a close method would suffice.
+ *
+ * @todo The convenience method {@link #checkNotClosed} is not that helpfull, what if the caller wants to do something
+ * other than throw an exception? It doesn't really represent a very usefull re-usable piece of code. Consider
+ * inlining it and dropping the method.
+ */
public abstract class Closeable
{
/**
@@ -34,6 +51,11 @@ public abstract class Closeable
*/
protected final AtomicBoolean _closed = new AtomicBoolean(false);
+ /**
+ * Checks if this is closed, and raises a JMSException if it is.
+ *
+ * @throws JMSException If this is closed.
+ */
protected void checkNotClosed() throws JMSException
{
if (isClosed())
@@ -42,13 +64,20 @@ public abstract class Closeable
}
}
+ /**
+ * Checks if this is closed.
+ *
+ * @return <tt>true</tt> if this is closed, <tt>false</tt> otherwise.
+ */
public boolean isClosed()
{
-// synchronized (_closed)
- {
- return _closed.get();
- }
+ return _closed.get();
}
+ /**
+ * Closes this object.
+ *
+ * @throws JMSException If this cannot be closed for any reason.
+ */
public abstract void close() throws JMSException;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/JMSAMQException.java b/java/client/src/main/java/org/apache/qpid/client/JMSAMQException.java
index d1237cff49..0927ca3625 100644
--- a/java/client/src/main/java/org/apache/qpid/client/JMSAMQException.java
+++ b/java/client/src/main/java/org/apache/qpid/client/JMSAMQException.java
@@ -18,29 +18,12 @@
* under the License.
*
*/
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
package org.apache.qpid.client;
-import javax.jms.JMSException;
-
import org.apache.qpid.AMQException;
+import javax.jms.JMSException;
+
/**
* JMSException does not accept wrapped exceptions in its constructor. Presumably this is because it is a relatively old
* Java exception class, before this was added as a default to Throwable. This exception class accepts wrapped exceptions
@@ -50,8 +33,6 @@ import org.apache.qpid.AMQException;
* <tr><th> Responsibilities <th> Collaborations
* <tr><td> Accept wrapped exceptions as a JMSException.
* </table>
- *
- * @author Apache Software Foundation
*/
public class JMSAMQException extends JMSException
{
@@ -71,6 +52,11 @@ public class JMSAMQException extends JMSException
}
}
+ /**
+ * @param s The underlying exception.
+ *
+ * @deprecated Use the other constructor and write a helpfull message. This one will be deleted.
+ */
public JMSAMQException(AMQException s)
{
super(s.getMessage(), String.valueOf(s.getErrorCode()));
diff --git a/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java b/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java
index a219f7d655..9eb826ba62 100644
--- a/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java
+++ b/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java
@@ -2,12 +2,12 @@ package org.apache.qpid.client;
import javax.jms.Destination;
import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueSender;
-import javax.jms.InvalidDestinationException;
public class QueueSenderAdapter implements QueueSender
{
@@ -25,6 +25,7 @@ public class QueueSenderAdapter implements QueueSender
public Queue getQueue() throws JMSException
{
checkPreConditions();
+
return _queue;
}
@@ -40,15 +41,13 @@ public class QueueSenderAdapter implements QueueSender
_delegate.send(queue, msg);
}
- public void publish(Message msg, int deliveryMode, int priority, long timeToLive)
- throws JMSException
+ public void publish(Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException
{
checkPreConditions();
_delegate.send(msg, deliveryMode, priority, timeToLive);
}
- public void send(Queue queue, Message msg, int deliveryMode, int priority, long timeToLive)
- throws JMSException
+ public void send(Queue queue, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException
{
checkPreConditions(queue);
_delegate.send(queue, msg, deliveryMode, priority, timeToLive);
@@ -63,36 +62,42 @@ public class QueueSenderAdapter implements QueueSender
public int getDeliveryMode() throws JMSException
{
checkPreConditions();
+
return _delegate.getDeliveryMode();
}
public Destination getDestination() throws JMSException
{
checkPreConditions();
+
return _delegate.getDestination();
}
public boolean getDisableMessageID() throws JMSException
{
checkPreConditions();
+
return _delegate.getDisableMessageID();
}
public boolean getDisableMessageTimestamp() throws JMSException
{
checkPreConditions();
+
return _delegate.getDisableMessageTimestamp();
}
public int getPriority() throws JMSException
{
checkPreConditions();
+
return _delegate.getPriority();
}
public long getTimeToLive() throws JMSException
{
checkPreConditions();
+
return _delegate.getTimeToLive();
}
@@ -102,8 +107,7 @@ public class QueueSenderAdapter implements QueueSender
_delegate.send(dest, msg);
}
- public void send(Message msg, int deliveryMode, int priority, long timeToLive)
- throws JMSException
+ public void send(Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException
{
checkPreConditions();
_delegate.send(msg, deliveryMode, priority, timeToLive);
@@ -159,15 +163,21 @@ public class QueueSenderAdapter implements QueueSender
AMQSession session = ((BasicMessageProducer) _delegate).getSession();
- if (session == null || session.isClosed())
+ if ((session == null) || session.isClosed())
{
throw new javax.jms.IllegalStateException("Invalid Session");
}
+ if (queue == null)
+ {
+ throw new UnsupportedOperationException("Queue is null.");
+ }
+
if (!(queue instanceof AMQDestination))
{
throw new InvalidDestinationException("Queue: " + queue + " is not a valid Qpid queue");
}
+
AMQDestination destination = (AMQDestination) queue;
if (!destination.isValidated() && checkQueueBeforePublish())
{
@@ -185,7 +195,8 @@ public class QueueSenderAdapter implements QueueSender
}
else
{
- throw new InvalidDestinationException("Queue: " + queue + " is not a valid destination (no bindings on server");
+ throw new InvalidDestinationException("Queue: " + queue
+ + " is not a valid destination (no bindings on server");
}
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverException.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverException.java
index 95899d533a..037b0dc2d1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverException.java
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverException.java
@@ -21,14 +21,26 @@
package org.apache.qpid.client.failover;
/**
- * This exception is thrown when failover is taking place and otherparts of the client need to know about this.
+ * FailoverException is used to indicate that a synchronous request has failed to receive the reply that it is waiting
+ * for because the fail-over process has been started whilst it was waiting for its reply. Synchronous methods generally
+ * raise this exception to indicate that they must be re-tried once the fail-over process has completed.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Used to indicate failure of a synchronous request due to fail-over.
+ * </table>
*
* @todo This exception is created and passed as an argument to a method, rather than thrown. The exception is being
- * used to represent a signal, passed out to other threads. Use of exceptions as arguments rather than as
- * exceptions is extremly confusing. Eliminate. Use a Condition or set a flag and check it instead. Also
- * FailoverException is Runtime but handled and should only use Runtimes for non-handleable conditions.
+ * used to represent an event, passed out to other threads. Use of exceptions as arguments rather than as
+ * exceptions is extremly confusing. Ideally use a condition or set a flag and check it instead.
+ * This exceptions-as-events pattern seems to be in a similar style to Mina code, which is not pretty, but
+ * potentially acceptable for that reason. We have the option of extending the mina model to add more events
+ * to it, that is, anything that is interested in handling failover as an event occurs below the main
+ * amq event handler, which knows the specific interface of the qpid handlers, which can pass this down as
+ * an explicit event, without it being an exception. Add failover method to BlockingMethodFrameListener,
+ * have it set a flag or interrupt the waiting thread, which then creates and raises this exception.
*/
-public class FailoverException extends RuntimeException
+public class FailoverException extends Exception
{
public FailoverException(String message)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
index 00eac7f2af..8e66aec0d6 100644
--- a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,59 +20,108 @@
*/
package org.apache.qpid.client.failover;
-import java.util.concurrent.CountDownLatch;
-
import org.apache.log4j.Logger;
+
import org.apache.mina.common.IoSession;
+
import org.apache.qpid.AMQDisconnectedException;
import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.client.state.AMQStateManager;
+import java.util.concurrent.CountDownLatch;
+
/**
- * When failover is required, we need a separate thread to handle the establishment of the new connection and
- * the transfer of subscriptions.
- * </p>
- * The reason this needs to be a separate thread is because you cannot do this work inside the MINA IO processor
- * thread. One significant task is the connection setup which involves a protocol exchange until a particular state
- * is achieved. However if you do this in the MINA thread, you have to block until the state is achieved which means
- * the IO processor is not able to do anything at all.
+ * FailoverHandler is a continuation that performs the failover procedure on a protocol session. As described in the
+ * class level comment for {@link AMQProtocolHandler}, a protocol connection can span many physical transport
+ * connections, failing over to a new connection if the transport connection fails. The procedure to establish a new
+ * connection is expressed as a continuation, in order that it may be run in a seperate thread to the i/o thread that
+ * detected the failure and is used to handle the communication to establish a new connection.
+ *
+ * </p>The reason this needs to be a separate thread is because this work cannot be done inside the i/o processor
+ * thread. The significant task is the connection setup which involves a protocol exchange until a particular state
+ * is achieved. This procedure waits until the state is achieved which would prevent the i/o thread doing the work
+ * it needs to do to achieve the new state.
+ *
+ * <p/>The failover procedure does the following:
+ *
+ * <ol>
+ * <li>Sets the failing over condition to true.</li>
+ * <li>Creates a {@link FailoverException} and gets the protocol connection handler to propagate this event to all
+ * interested parties.</li>
+ * <li>Takes the failover mutex on the protocol connection handler.</li>
+ * <li>Abandons the fail over if any of the interested parties vetoes it. The mutex is released and the condition
+ * reset.</li>
+ * <li>Creates a new {@link AMQStateManager} and re-established the connection through it.</li>
+ * <li>Informs the AMQConnection if the connection cannot be re-established.</li>
+ * <li>Recreates all sessions from the old connection to the new.</li>
+ * <li>Resets the failing over condition and releases the mutex.</li>
+ * </ol>
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Update fail-over state <td> {@link AMQProtocolHandler}
+ * </table>
+ *
+ * @todo The failover latch and mutex are used like a lock and condition. If the retrotranlator supports lock/condition
+ * then could change over to using them. 1.4 support still needed.
+ *
+ * @todo If the condition is set to null on a vetoes fail-over and there are already other threads waiting on the
+ * condition, they will never be released. It might be an idea to reset the condition in a finally block.
+ *
+ * @todo Creates a {@link AMQDisconnectedException} and passes it to the AMQConnection. No need to use an
+ * exception-as-argument here, could just as easily call a specific method for this purpose on AMQConnection.
+ *
+ * @todo Creates a {@link FailoverException} and propagates it to the MethodHandlers. No need to use an
+ * exception-as-argument here, could just as easily call a specific method for this purpose on
+ * {@link org.apache.qpid.protocol.AMQMethodListener}.
*/
public class FailoverHandler implements Runnable
{
+ /** Used for debugging. */
private static final Logger _logger = Logger.getLogger(FailoverHandler.class);
+ /** Holds the MINA session for the connection that has failed, not the connection that is being failed onto. */
private final IoSession _session;
+
+ /** Holds the protocol handler for the failed connection, upon which the new connection is to be set up. */
private AMQProtocolHandler _amqProtocolHandler;
- /**
- * Used where forcing the failover host
- */
+ /** Used to hold the host to fail over to. This is optional and if not set a reconnect to the previous host is tried. */
private String _host;
- /**
- * Used where forcing the failover port
- */
+ /** Used to hold the port to fail over to. */
private int _port;
+ /**
+ * Creates a failover handler on a protocol session, for a particular MINA session (network connection).
+ *
+ * @param amqProtocolHandler The protocol handler that spans the failover.
+ * @param session The MINA session, for the failing connection.
+ */
public FailoverHandler(AMQProtocolHandler amqProtocolHandler, IoSession session)
{
_amqProtocolHandler = amqProtocolHandler;
_session = session;
}
+ /**
+ * Performs the failover procedure. See the class level comment, {@link FailoverHandler}, for a description of the
+ * failover procedure.
+ */
public void run()
{
if (Thread.currentThread().isDaemon())
{
throw new IllegalStateException("FailoverHandler must run on a non-daemon thread.");
}
- //Thread.currentThread().setName("Failover Thread");
+ // Create a latch, upon which tasks that must not run in parallel with a failover can wait for completion of
+ // the fail over.
_amqProtocolHandler.setFailoverLatch(new CountDownLatch(1));
// We wake up listeners. If they can handle failover, they will extend the
- // FailoverSupport class and will in turn block on the latch until failover
- // has completed before retrying the operation
+ // FailoverRetrySupport class and will in turn block on the latch until failover
+ // has completed before retrying the operation.
_amqProtocolHandler.propagateExceptionToWaiters(new FailoverException("Failing over about to start"));
// Since failover impacts several structures we protect them all with a single mutex. These structures
@@ -99,8 +148,10 @@ public class FailoverHandler implements Runnable
{
_amqProtocolHandler.getConnection().exceptionReceived(new AMQDisconnectedException("Failover was vetoed by client", null));
}
+
_amqProtocolHandler.getFailoverLatch().countDown();
_amqProtocolHandler.setFailoverLatch(null);
+
return;
}
@@ -119,6 +170,7 @@ public class FailoverHandler implements Runnable
{
failoverSucceeded = _amqProtocolHandler.getConnection().attemptReconnection();
}
+
if (!failoverSucceeded)
{
_amqProtocolHandler.setStateManager(existingStateManager);
@@ -140,6 +192,7 @@ public class FailoverHandler implements Runnable
{
_logger.info("Client vetoed automatic resubscription");
}
+
_amqProtocolHandler.getConnection().fireFailoverComplete();
_amqProtocolHandler.setFailoverState(FailoverState.NOT_STARTED);
_logger.info("Connection failover completed successfully");
@@ -148,35 +201,36 @@ public class FailoverHandler implements Runnable
{
_logger.info("Failover process failed - exception being propagated by protocol handler");
_amqProtocolHandler.setFailoverState(FailoverState.FAILED);
- try
- {
- _amqProtocolHandler.exceptionCaught(_session, e);
- }
+ /*try
+ {*/
+ _amqProtocolHandler.exceptionCaught(_session, e);
+ /*}
catch (Exception ex)
{
_logger.error("Error notifying protocol session of error: " + ex, ex);
- }
+ }*/
}
}
}
- _amqProtocolHandler.getFailoverLatch().countDown();
- }
- public String getHost()
- {
- return _host;
+ _amqProtocolHandler.getFailoverLatch().countDown();
}
+ /**
+ * Sets the host name to fail over to. This is optional and if not set a reconnect to the previous host is tried.
+ *
+ * @param host The host name to fail over to.
+ */
public void setHost(String host)
{
_host = host;
}
- public int getPort()
- {
- return _port;
- }
-
+ /**
+ * Sets the port to fail over to.
+ *
+ * @param port The port to fail over to.
+ */
public void setPort(int port)
{
_port = port;
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverNoopSupport.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverNoopSupport.java
new file mode 100644
index 0000000000..8c05db3232
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverNoopSupport.java
@@ -0,0 +1,54 @@
+package org.apache.qpid.client.failover;
+
+import org.apache.qpid.client.AMQConnection;
+
+/**
+ * FailoverNoopSupport is a {@link FailoverSupport} implementation that does not really provide any failover support
+ * at all. It wraps a {@link FailoverProtectedOperation} but should that operation throw {@link FailoverException} this
+ * support class simply re-raises that exception as an IllegalStateException. This support wrapper should only be
+ * used where the caller can be certain that the failover protected operation cannot acutally throw a failover exception,
+ * for example, because the caller already holds a lock preventing that condition from arising.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Perform a fail-over protected operation raising providing no handling of fail-over conditions.
+ * </table>
+ */
+public class FailoverNoopSupport<T, E extends Exception> implements FailoverSupport<T, E>
+{
+ /** The protected operation that is to be retried in the event of fail-over. */
+ FailoverProtectedOperation<T, E> operation;
+
+ /** The connection on which the fail-over protected operation is to be performed. */
+ AMQConnection connection;
+
+ /**
+ * Creates an automatic retrying fail-over handler for the specified operation.
+ *
+ * @param operation The fail-over protected operation to wrap in this handler.
+ */
+ public FailoverNoopSupport(FailoverProtectedOperation<T, E> operation, AMQConnection con)
+ {
+ this.operation = operation;
+ this.connection = con;
+ }
+
+ /**
+ * Delegates to another continuation which is to be provided with fail-over handling.
+ *
+ * @return The return value from the delegated to continuation.
+ * @throws E Any exception that the delegated to continuation may raise.
+ */
+ public T execute() throws E
+ {
+ try
+ {
+ return operation.execute();
+ }
+ catch (FailoverException e)
+ {
+ throw new IllegalStateException("Fail-over interupted no-op failover support. "
+ + "No-op support should only be used where the caller is certain fail-over cannot occur.", e);
+ }
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverProtectedOperation.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverProtectedOperation.java
new file mode 100644
index 0000000000..054add07f7
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverProtectedOperation.java
@@ -0,0 +1,28 @@
+package org.apache.qpid.client.failover;
+
+/**
+ * FailoverProtectedOperation is a continuation for an operation that may throw a {@link FailoverException} because
+ * it has been interrupted by the fail-over process. The {@link FailoverRetrySupport} class defines support wrappers
+ * for failover protected operations, in order to provide different handling schemes when failovers occurr.
+ *
+ * <p/>The type of checked exception that the operation may perform has been generified, in order that fail over
+ * protected operations can be defined that raise arbitrary exceptions. The actuall exception types used should not
+ * be sub-classes of FailoverException, or else catching FailoverException in the {@link FailoverRetrySupport} classes
+ * will mask the exception.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities
+ * <tr><td> Perform an operation that may be interrupted by fail-over.
+ * </table>
+ */
+public interface FailoverProtectedOperation<T, E extends Exception>
+{
+ /**
+ * Performs the continuations work.
+ *
+ * @return Provdes scope for the continuation to return an arbitrary value.
+ *
+ * @throws FailoverException If the operation is interrupted by a fail-over notification.
+ */
+ public abstract T execute() throws E, FailoverException;
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverRetrySupport.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverRetrySupport.java
new file mode 100644
index 0000000000..120a07f0fc
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverRetrySupport.java
@@ -0,0 +1,128 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.client.failover;
+
+import org.apache.qpid.client.AMQConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * FailoverRetrySupport is a continuation that wraps another continuation, delaying its execution until it is notified
+ * that a blocking condition has been met, and executing the continuation within a mutex. If the continuation fails, due
+ * to the original condition being broken, whilst the continuation is waiting for a reponse to a synchronous request,
+ * FailoverRetrySupport automatcally rechecks the condition and re-acquires the mutex and re-runs the continution. This
+ * automatic retrying is continued until the continuation succeeds, or throws an exception (different to
+ * FailoverException, which is used to signal the failure of the original condition).
+ *
+ * <p/>The blocking condition used is that the connection is not currently failing over, and the mutex used is the
+ * connection failover mutex, which guards against the fail-over process being run during fail-over vulnerable methods.
+ * These are used like a lock and condition variable.
+ *
+ * <p/>The wrapped operation may throw a FailoverException, this is an exception that can be raised by a
+ * {@link org.apache.qpid.client.protocol.BlockingMethodFrameListener}, in response to it being notified that a
+ * fail-over wants to start whilst it was waiting. Methods that are vulnerable to fail-over are those that are
+ * synchronous, where a failure will prevent them from getting the reply they are waiting for and asynchronous
+ * methods that should not be attempted when a fail-over is in progress.
+ *
+ * <p/>Wrapping a synchronous method in a FailoverRetrySupport will have the effect that the operation will not be
+ * started during fail-over, but be delayed until any current fail-over has completed. Should a fail-over process want
+ * to start whilst waiting for the synchrnous reply, the FailoverRetrySupport will detect this and rety the operation
+ * until it succeeds. Synchronous methods are usually coordinated with a
+ * {@link org.apache.qpid.client.protocol.BlockingMethodFrameListener} which is notified when a fail-over process wants
+ * to start and throws a FailoverException in response to this.
+ *
+ * <p/>Wrapping an asynchronous method in a FailoverRetrySupport will have the effect that the operation will not be
+ * started during fail-over, but be delayed until any current fail-over has completed.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Provide a continuation synchronized on a fail-over lock and condition.
+ * <tr><td> Automatically retry the continuation accross fail-overs until it succeeds, or raises an exception.
+ * </table>
+ *
+ * @todo Another continuation. Could use an interface Continuation (as described in other todos, for example, see
+ * {@link org.apache.qpid.pool.Job}). Then have a wrapping continuation (this), which blocks on an arbitrary
+ * Condition or Latch (specified in constructor call), that this blocks on before calling the wrapped Continuation.
+ * Must work on Java 1.4, so check retrotranslator works on Lock/Condition or latch first. Argument and return type
+ * to match wrapped condition as type parameters. Rename to AsyncConditionalContinuation or something like that.
+ *
+ * @todo InterruptedException not handled well.
+ */
+public class FailoverRetrySupport<T, E extends Exception> implements FailoverSupport<T, E>
+{
+ /** Used for debugging. */
+ private static final Logger _log = LoggerFactory.getLogger(FailoverRetrySupport.class);
+
+ /** The protected operation that is to be retried in the event of fail-over. */
+ FailoverProtectedOperation<T, E> operation;
+
+ /** The connection on which the fail-over protected operation is to be performed. */
+ AMQConnection connection;
+
+ /**
+ * Creates an automatic retrying fail-over handler for the specified operation.
+ *
+ * @param operation The fail-over protected operation to wrap in this handler.
+ */
+ public FailoverRetrySupport(FailoverProtectedOperation<T, E> operation, AMQConnection con)
+ {
+ this.operation = operation;
+ this.connection = con;
+ }
+
+ /**
+ * Delays a continuation until the "not failing over" condition is met on the specified connection. Repeats
+ * until the operation throws AMQException or succeeds without being interrupted by fail-over.
+ *
+ * @return The result of executing the continuation.
+ *
+ * @throws E Any underlying exception is allowed to fall through.
+ */
+ public T execute() throws E
+ {
+ while (true)
+ {
+ try
+ {
+ connection.blockUntilNotFailingOver();
+ }
+ catch (InterruptedException e)
+ {
+ _log.debug("Interrupted: " + e, e);
+
+ return null;
+ }
+
+ synchronized (connection.getFailoverMutex())
+ {
+ try
+ {
+ return operation.execute();
+ }
+ catch (FailoverException e)
+ {
+ _log.debug("Failover exception caught during operation: " + e, e);
+ }
+ }
+ }
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverState.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverState.java
index e5787439ec..807a5f7d13 100644
--- a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverState.java
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverState.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,27 +21,42 @@
package org.apache.qpid.client.failover;
/**
- * Enumeration of failover states. Used to handle failover from within AMQProtocolHandler where MINA events need to be
- * dealt with and can happen during failover.
+ * Defines the possible states of the failover process; not started, in progress, failed.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Represent a one of the states of the fail-over process.
+ * </table>
*/
public final class FailoverState
{
+ /** The string description on this state. */
private final String _state;
- /** Failover has not yet been attempted on this connection */
+ /** Failover has not yet been attempted on this connection. */
public static final FailoverState NOT_STARTED = new FailoverState("NOT STARTED");
- /** Failover has been requested on this connection but has not completed */
+ /** Failover has been requested on this connection but has not completed. */
public static final FailoverState IN_PROGRESS = new FailoverState("IN PROGRESS");
- /** Failover has been attempted and failed */
+ /** Failover has been attempted and failed. */
public static final FailoverState FAILED = new FailoverState("FAILED");
+ /**
+ * Creates a type safe enumeration of a fail-over state.
+ *
+ * @param state The fail-over state description string.
+ */
private FailoverState(String state)
{
_state = state;
}
+ /**
+ * Prints this state, mainly for debugging purposes.
+ *
+ * @return The string description of this state.
+ */
public String toString()
{
return "FailoverState: " + _state;
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverSupport.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverSupport.java
index a005bc5fdf..478482741c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverSupport.java
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverSupport.java
@@ -1,65 +1,26 @@
-/*
+package org.apache.qpid.client.failover;
+
+/**
+ * FailoverSupport defines an interface for different types of fail-over handlers, that provide different types of
+ * behaviour for handling fail-overs during operations that can be interrupted by the fail-over process. For example,
+ * the support could automatically retry once the fail-over process completes, could prevent an operation from being
+ * started whilst fail-over is running, or could quietly abandon the operation or raise an exception, and so on.
*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities
+ * <tr><td> Perform a fail-over protected operation with handling for fail-over conditions.
+ * </table>
*
+ * @todo Continuation, extend some sort of re-usable Continuation interface, which might look very like this one.
*/
-package org.apache.qpid.client.failover;
-
-import javax.jms.JMSException;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-
-public abstract class FailoverSupport
+public interface FailoverSupport<T, E extends Exception>
{
- private static final Logger _log = Logger.getLogger(FailoverSupport.class);
-
- public Object execute(AMQConnection con) throws JMSException
- {
- // We wait until we are not in the middle of failover before acquiring the mutex and then proceeding.
- // Any method that can potentially block for any reason should use this class so that deadlock will not
- // occur. The FailoverException is propagated by the AMQProtocolHandler to any listeners (e.g. frame listeners)
- // that might be causing a block. When that happens, the exception is caught here and the mutex is released
- // before waiting for the failover to complete (either successfully or unsuccessfully).
- while (true)
- {
- try
- {
- con.blockUntilNotFailingOver();
- }
- catch (InterruptedException e)
- {
- _log.info("Interrupted: " + e, e);
- return null;
- }
- synchronized (con.getFailoverMutex())
- {
- try
- {
- return operation();
- }
- catch (FailoverException e)
- {
- _log.info("Failover exception caught during operation: " + e, e);
- }
- }
- }
- }
-
- protected abstract Object operation() throws JMSException;
+ /**
+ * Delegates to another continuation which is to be provided with fail-over handling.
+ *
+ * @return The return value from the delegated to continuation.
+ *
+ * @throws E Any exception that the delegated to continuation may raise.
+ */
+ public T execute() throws E;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java
index bd8177feb6..8f0ee05b3e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
@@ -28,9 +27,13 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.BasicCancelOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class BasicCancelOkMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(BasicCancelOkMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BasicCancelOkMethodHandler.class);
+
private static final BasicCancelOkMethodHandler _instance = new BasicCancelOkMethodHandler();
public static BasicCancelOkMethodHandler getInstance()
@@ -39,10 +42,10 @@ public class BasicCancelOkMethodHandler implements StateAwareMethodListener
}
private BasicCancelOkMethodHandler()
- {
- }
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
BasicCancelOkBody body = (BasicCancelOkBody) evt.getMethod();
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java
index d34d6688c1..51120da55c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.message.UnprocessedMessage;
import org.apache.qpid.client.protocol.AMQProtocolSession;
@@ -29,9 +28,12 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.BasicDeliverBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class BasicDeliverMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(BasicDeliverMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BasicDeliverMethodHandler.class);
private static final BasicDeliverMethodHandler _instance = new BasicDeliverMethodHandler();
@@ -40,7 +42,8 @@ public class BasicDeliverMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
final UnprocessedMessage msg = new UnprocessedMessage(evt.getChannelId(), (BasicDeliverBody) evt.getMethod());
_logger.debug("New JmsDeliver method received");
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java
index 02573c5d00..0f00c6a26e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.message.UnprocessedMessage;
import org.apache.qpid.client.protocol.AMQProtocolSession;
@@ -29,9 +28,12 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.BasicReturnBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class BasicReturnMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(BasicReturnMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BasicReturnMethodHandler.class);
private static final BasicReturnMethodHandler _instance = new BasicReturnMethodHandler();
@@ -40,10 +42,11 @@ public class BasicReturnMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.debug("New JmsBounce method received");
- final UnprocessedMessage msg = new UnprocessedMessage(evt.getChannelId(),(BasicReturnBody)evt.getMethod());
+ final UnprocessedMessage msg = new UnprocessedMessage(evt.getChannelId(), (BasicReturnBody) evt.getMethod());
protocolSession.unprocessedMessageReceived(msg);
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java
index fbf4d96647..9ed3ef7a60 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQChannelClosedException;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInvalidRoutingKeyException;
@@ -36,9 +35,12 @@ import org.apache.qpid.framing.ChannelCloseOkBody;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ChannelCloseMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ChannelCloseMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseMethodHandler.class);
private static ChannelCloseMethodHandler _handler = new ChannelCloseMethodHandler();
@@ -47,7 +49,8 @@ public class ChannelCloseMethodHandler implements StateAwareMethodListener
return _handler;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.debug("ChannelClose method received");
ChannelCloseBody method = (ChannelCloseBody) evt.getMethod();
@@ -68,6 +71,7 @@ public class ChannelCloseMethodHandler implements StateAwareMethodListener
{
_logger.debug("Channel close received with errorCode " + errorCode + ", and reason " + reason);
}
+
if (errorCode == AMQConstant.NO_CONSUMERS)
{
throw new AMQNoConsumersException("Error: " + reason, null, null);
@@ -94,7 +98,7 @@ public class ChannelCloseMethodHandler implements StateAwareMethodListener
}
}
- //fixme why is this only done when the close is expected...
+ // fixme why is this only done when the close is expected...
// should the above forced closes not also cause a close?
protocolSession.channelClosed(evt.getChannelId(), errorCode, String.valueOf(reason));
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java
index 0826deb2f4..e1fe2697e5 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,16 +20,18 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ChannelCloseOkMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ChannelCloseOkMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseOkMethodHandler.class);
private static final ChannelCloseOkMethodHandler _instance = new ChannelCloseOkMethodHandler();
@@ -38,10 +40,11 @@ public class ChannelCloseOkMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.info("Received channel-close-ok for channel-id " + evt.getChannelId());
- //todo this should do the local closure
+ // todo this should do the local closure
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java
index 1f003649c0..ca3f46d08b 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
@@ -28,23 +27,26 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.ChannelFlowOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ChannelFlowOkMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ChannelFlowOkMethodHandler.class);
- private static final ChannelFlowOkMethodHandler _instance = new ChannelFlowOkMethodHandler();
+ private static final Logger _logger = LoggerFactory.getLogger(ChannelFlowOkMethodHandler.class);
+ private static final ChannelFlowOkMethodHandler _instance = new ChannelFlowOkMethodHandler();
- public static ChannelFlowOkMethodHandler getInstance()
- {
- return _instance;
- }
+ public static ChannelFlowOkMethodHandler getInstance()
+ {
+ return _instance;
+ }
- private ChannelFlowOkMethodHandler()
- {
- }
+ private ChannelFlowOkMethodHandler()
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
- {
- ChannelFlowOkBody method = (ChannelFlowOkBody) evt.getMethod();
- _logger.debug("Received Channel.Flow-Ok message, active = " + method.active);
- }
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
+ {
+ ChannelFlowOkBody method = (ChannelFlowOkBody) evt.getMethod();
+ _logger.debug("Received Channel.Flow-Ok message, active = " + method.active);
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
index d8153f9c97..752f44237d 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQConnectionClosedException;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQAuthenticationException;
@@ -34,9 +33,12 @@ import org.apache.qpid.framing.ConnectionCloseOkBody;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ConnectionCloseMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ConnectionCloseMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ConnectionCloseMethodHandler.class);
private static ConnectionCloseMethodHandler _handler = new ConnectionCloseMethodHandler();
@@ -46,16 +48,16 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
}
private ConnectionCloseMethodHandler()
- {
- }
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.info("ConnectionClose frame received");
ConnectionCloseBody method = (ConnectionCloseBody) evt.getMethod();
// does it matter
- //stateManager.changeState(AMQState.CONNECTION_CLOSING);
+ // stateManager.changeState(AMQState.CONNECTION_CLOSING);
AMQConstant errorCode = AMQConstant.getConstant(method.replyCode);
AMQShortString reason = method.replyText;
@@ -64,7 +66,8 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
{
// TODO: check whether channel id of zero is appropriate
// Be aware of possible changes to parameter order as versions change.
- protocolSession.writeFrame(ConnectionCloseOkBody.createAMQFrame((short) 0, method.getMajor(), method.getMinor()));
+ protocolSession.writeFrame(ConnectionCloseOkBody.createAMQFrame((short) 0, method.getMajor(),
+ method.getMinor()));
if (errorCode != AMQConstant.REPLY_SUCCESS)
{
@@ -74,7 +77,7 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
protocolSession.closeProtocolSession();
- //todo this is a bit of a fudge (could be conssidered such as each new connection needs a new state manager or at least a fresh state.
+ // todo this is a bit of a fudge (could be conssidered such as each new connection needs a new state manager or at least a fresh state.
stateManager.changeState(AMQState.CONNECTION_NOT_STARTED);
throw new AMQAuthenticationException(errorCode, reason == null ? null : reason.toString(), null);
@@ -83,7 +86,6 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
{
_logger.info("Connection close received with error code " + errorCode);
-
throw new AMQConnectionClosedException(errorCode, "Error: " + reason, null);
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java
index 866f65b384..213c0eba6e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
@@ -28,9 +27,12 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.ConnectionRedirectBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ConnectionRedirectMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ConnectionRedirectMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ConnectionRedirectMethodHandler.class);
private static final int DEFAULT_REDIRECT_PORT = 5672;
@@ -42,10 +44,10 @@ public class ConnectionRedirectMethodHandler implements StateAwareMethodListener
}
private ConnectionRedirectMethodHandler()
- {
- }
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.info("ConnectionRedirect frame received");
ConnectionRedirectBody method = (ConnectionRedirectBody) evt.getMethod();
@@ -65,6 +67,7 @@ public class ConnectionRedirectMethodHandler implements StateAwareMethodListener
host = host.substring(0, portIndex);
}
+
protocolSession.failover(host, port);
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
index 157128aebc..59b493a6f7 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
@@ -20,16 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import java.io.UnsupportedEncodingException;
-import java.util.HashSet;
-import java.util.StringTokenizer;
-
-import javax.security.sasl.Sasl;
-import javax.security.sasl.SaslClient;
-import javax.security.sasl.SaslException;
-
-import org.apache.log4j.Logger;
-
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.security.AMQCallbackHandler;
@@ -47,9 +37,20 @@ import org.apache.qpid.framing.FieldTableFactory;
import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.sasl.Sasl;
+import javax.security.sasl.SaslClient;
+import javax.security.sasl.SaslException;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashSet;
+import java.util.StringTokenizer;
+
public class ConnectionStartMethodHandler implements StateAwareMethodListener
{
- private static final Logger _log = Logger.getLogger(ConnectionStartMethodHandler.class);
+ private static final Logger _log = LoggerFactory.getLogger(ConnectionStartMethodHandler.class);
private static final ConnectionStartMethodHandler _instance = new ConnectionStartMethodHandler();
@@ -62,15 +63,14 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
{ }
public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
- throws AMQException
+ throws AMQException
{
_log.debug("public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, "
- + "AMQMethodEvent evt): called");
+ + "AMQMethodEvent evt): called");
ConnectionStartBody body = (ConnectionStartBody) evt.getMethod();
- ProtocolVersion pv = new ProtocolVersion((byte) body.versionMajor,(byte) body.versionMinor);
-
+ ProtocolVersion pv = new ProtocolVersion((byte) body.versionMajor, (byte) body.versionMinor);
// For the purposes of interop, we can make the client accept the broker's version string.
// If it does, it then internally records the version as being the latest one that it understands.
@@ -110,7 +110,7 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
{
SaslClient sc =
Sasl.createSaslClient(new String[] { mechanism }, null, "AMQP", "localhost", null,
- createCallbackHandler(mechanism, protocolSession));
+ createCallbackHandler(mechanism, protocolSession));
if (sc == null)
{
throw new AMQException(null, "Client SASL configuration error: no SaslClient could be created for mechanism " + mechanism
@@ -148,23 +148,22 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
FieldTable clientProperties = FieldTableFactory.newFieldTable();
clientProperties.setString(new AMQShortString(ClientProperties.instance.toString()),
- protocolSession.getClientID());
+ protocolSession.getClientID());
clientProperties.setString(new AMQShortString(ClientProperties.product.toString()),
- QpidProperties.getProductName());
+ QpidProperties.getProductName());
clientProperties.setString(new AMQShortString(ClientProperties.version.toString()),
- QpidProperties.getReleaseVersion());
+ QpidProperties.getReleaseVersion());
clientProperties.setString(new AMQShortString(ClientProperties.platform.toString()), getFullSystemInfo());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
protocolSession.writeFrame(ConnectionStartOkBody.createAMQFrame(evt.getChannelId(),
- protocolSession.getProtocolMajorVersion(),
- protocolSession.getProtocolMinorVersion(),
- clientProperties, // clientProperties
- new AMQShortString(selectedLocale), // locale
- new AMQShortString(mechanism), // mechanism
- saslResponse)); // response
+ protocolSession.getProtocolMajorVersion(), protocolSession.getProtocolMinorVersion(),
+ clientProperties, // clientProperties
+ new AMQShortString(selectedLocale), // locale
+ new AMQShortString(mechanism), // mechanism
+ saslResponse)); // response
}
catch (UnsupportedEncodingException e)
@@ -175,13 +174,12 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
else
{
_log.error("Broker requested Protocol [" + body.versionMajor + "-" + body.versionMinor
- + "] which is not supported by this version of the client library");
+ + "] which is not supported by this version of the client library");
protocolSession.closeProtocolSession();
}
}
-
private String getFullSystemInfo()
{
StringBuffer fullSystemInfo = new StringBuffer();
@@ -221,7 +219,7 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
}
private AMQCallbackHandler createCallbackHandler(String mechanism, AMQProtocolSession protocolSession)
- throws AMQException
+ throws AMQException
{
Class mechanismClass = CallbackHandlerRegistry.getInstance().getCallbackHandlerClass(mechanism);
try
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java
index 67f1a6519f..68556991d7 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.ConnectionTuneParameters;
import org.apache.qpid.client.protocol.AMQProtocolSession;
@@ -34,9 +33,12 @@ import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.ConnectionTuneOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ConnectionTuneMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ConnectionTuneMethodHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ConnectionTuneMethodHandler.class);
private static final ConnectionTuneMethodHandler _instance = new ConnectionTuneMethodHandler();
@@ -46,10 +48,10 @@ public class ConnectionTuneMethodHandler implements StateAwareMethodListener
}
protected ConnectionTuneMethodHandler()
- {
- }
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.debug("ConnectionTune frame received");
ConnectionTuneBody frame = (ConnectionTuneBody) evt.getMethod();
@@ -60,38 +62,36 @@ public class ConnectionTuneMethodHandler implements StateAwareMethodListener
params = new ConnectionTuneParameters();
}
- params.setFrameMax(frame.frameMax);
+ params.setFrameMax(frame.frameMax);
params.setChannelMax(frame.channelMax);
params.setHeartbeat(Integer.getInteger("amqj.heartbeat.delay", frame.heartbeat));
protocolSession.setConnectionTuneParameters(params);
stateManager.changeState(AMQState.CONNECTION_NOT_OPENED);
- protocolSession.writeFrame(createTuneOkFrame(evt.getChannelId(), params,frame.getMajor(), frame.getMinor()));
+ protocolSession.writeFrame(createTuneOkFrame(evt.getChannelId(), params, frame.getMajor(), frame.getMinor()));
String host = protocolSession.getAMQConnection().getVirtualHost();
AMQShortString virtualHost = new AMQShortString("/" + host);
-
- protocolSession.writeFrame(createConnectionOpenFrame(evt.getChannelId(), virtualHost, null, true,frame.getMajor(), frame.getMinor()));
+ protocolSession.writeFrame(createConnectionOpenFrame(evt.getChannelId(), virtualHost, null, true, frame.getMajor(),
+ frame.getMinor()));
}
- protected AMQFrame createConnectionOpenFrame(int channel, AMQShortString path, AMQShortString capabilities, boolean insist, byte major, byte minor)
+ protected AMQFrame createConnectionOpenFrame(int channel, AMQShortString path, AMQShortString capabilities,
+ boolean insist, byte major, byte minor)
{
// Be aware of possible changes to parameter order as versions change.
- return ConnectionOpenBody.createAMQFrame(channel,
- major, minor, // AMQP version (major, minor)
- capabilities, // capabilities
- insist, // insist
- path); // virtualHost
+ return ConnectionOpenBody.createAMQFrame(channel, major, minor, // AMQP version (major, minor)
+ capabilities, // capabilities
+ insist, // insist
+ path); // virtualHost
}
protected AMQFrame createTuneOkFrame(int channel, ConnectionTuneParameters params, byte major, byte minor)
{
// Be aware of possible changes to parameter order as versions change.
- return ConnectionTuneOkBody.createAMQFrame(channel,
- major, minor,
- params.getChannelMax(), // channelMax
- params.getFrameMax(), // frameMax
- params.getHeartbeat()); // heartbeat
+ return ConnectionTuneOkBody.createAMQFrame(channel, major, minor, params.getChannelMax(), // channelMax
+ params.getFrameMax(), // frameMax
+ params.getHeartbeat()); // heartbeat
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java
index 146c705c00..8f9a84a3a6 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java
@@ -17,7 +17,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
@@ -25,32 +24,33 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.ExchangeBoundOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author Apache Software Foundation
*/
public class ExchangeBoundOkMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ExchangeBoundOkMethodHandler.class);
- private static final ExchangeBoundOkMethodHandler _instance = new ExchangeBoundOkMethodHandler();
+ private static final Logger _logger = LoggerFactory.getLogger(ExchangeBoundOkMethodHandler.class);
+ private static final ExchangeBoundOkMethodHandler _instance = new ExchangeBoundOkMethodHandler();
- public static ExchangeBoundOkMethodHandler getInstance()
- {
- return _instance;
- }
+ public static ExchangeBoundOkMethodHandler getInstance()
+ {
+ return _instance;
+ }
- private ExchangeBoundOkMethodHandler()
- {
- }
+ private ExchangeBoundOkMethodHandler()
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
- {
- if (_logger.isDebugEnabled())
- {
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
+ {
+ if (_logger.isDebugEnabled())
+ {
ExchangeBoundOkBody body = (ExchangeBoundOkBody) evt.getMethod();
- _logger.debug("Received Exchange.Bound-Ok message, response code: " + body.replyCode + " text: " +
- body.replyText);
- }
- }
+ _logger.debug("Received Exchange.Bound-Ok message, response code: " + body.replyCode + " text: "
+ + body.replyText);
+ }
+ }
}
-
-
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java
index eaf4721445..81228b4cdc 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java
@@ -17,7 +17,6 @@
*/
package org.apache.qpid.client.handler;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
@@ -25,31 +24,32 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.QueueDeleteOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author Apache Software Foundation
*/
public class QueueDeleteOkMethodHandler implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(QueueDeleteOkMethodHandler.class);
- private static final QueueDeleteOkMethodHandler _instance = new QueueDeleteOkMethodHandler();
+ private static final Logger _logger = LoggerFactory.getLogger(QueueDeleteOkMethodHandler.class);
+ private static final QueueDeleteOkMethodHandler _instance = new QueueDeleteOkMethodHandler();
- public static QueueDeleteOkMethodHandler getInstance()
- {
- return _instance;
- }
+ public static QueueDeleteOkMethodHandler getInstance()
+ {
+ return _instance;
+ }
- private QueueDeleteOkMethodHandler()
- {
- }
+ private QueueDeleteOkMethodHandler()
+ { }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
- {
- if (_logger.isDebugEnabled())
- {
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
+ {
+ if (_logger.isDebugEnabled())
+ {
QueueDeleteOkBody body = (QueueDeleteOkBody) evt.getMethod();
_logger.debug("Received Queue.Delete-Ok message, message count: " + body.messageCount);
- }
- }
+ }
+ }
}
-
-
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
index 13f544516a..2dfeb19268 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
@@ -20,18 +20,10 @@
*/
package org.apache.qpid.client.message;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageNotReadableException;
-import javax.jms.MessageNotWriteableException;
-
import org.apache.commons.collections.map.ReferenceMap;
+
import org.apache.mina.common.ByteBuffer;
+
import org.apache.qpid.AMQException;
import org.apache.qpid.client.*;
import org.apache.qpid.framing.AMQShortString;
@@ -41,6 +33,16 @@ import org.apache.qpid.url.AMQBindingURL;
import org.apache.qpid.url.BindingURL;
import org.apache.qpid.url.URLSyntaxException;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.UUID;
+
public abstract class AbstractJMSMessage extends AMQMessage implements org.apache.qpid.jms.Message
{
private static final Map _destinationCache = Collections.synchronizedMap(new ReferenceMap());
@@ -70,35 +72,32 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
_changedData = (data == null);
_headerAdapter = new JMSHeaderAdapter(((BasicContentHeaderProperties) _contentHeaderProperties).getHeaders());
- _strictAMQP = Boolean.parseBoolean(System.getProperties().getProperty(AMQSession.STRICT_AMQP, AMQSession.STRICT_AMQP_DEFAULT));
+ _strictAMQP =
+ Boolean.parseBoolean(System.getProperties().getProperty(AMQSession.STRICT_AMQP, AMQSession.STRICT_AMQP_DEFAULT));
}
protected AbstractJMSMessage(long deliveryTag, BasicContentHeaderProperties contentHeader, AMQShortString exchange,
- AMQShortString routingKey, ByteBuffer data) throws AMQException
+ AMQShortString routingKey, ByteBuffer data) throws AMQException
{
this(contentHeader, deliveryTag);
Integer type = contentHeader.getHeaders().getInteger(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName());
- int contentType = (type == null) ? AMQDestination.UNKNOWN_TYPE : type.intValue();
AMQDestination dest;
- switch (contentType)
+ if (AMQDestination.QUEUE_TYPE.equals(type))
{
-
- case AMQDestination.QUEUE_TYPE:
- dest = new AMQQueue(exchange, routingKey, routingKey);
- break;
-
- case AMQDestination.TOPIC_TYPE:
- dest = new AMQTopic(exchange, routingKey, null);
- break;
-
- default:
- dest = new AMQUndefinedDestination(exchange, routingKey, null);
- break;
+ dest = new AMQQueue(exchange, routingKey, routingKey);
+ }
+ else if (AMQDestination.TOPIC_TYPE.equals(type))
+ {
+ dest = new AMQTopic(exchange, routingKey, null);
}
- //Destination dest = AMQDestination.createDestination(url);
+ else
+ {
+ dest = new AMQUndefinedDestination(exchange, routingKey, null);
+ }
+ // Destination dest = AMQDestination.createDestination(url);
setJMSDestination(dest);
_data = data;
@@ -202,7 +201,7 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
if (!(destination instanceof AMQDestination))
{
throw new IllegalArgumentException(
- "ReplyTo destination may only be an AMQDestination - passed argument was type " + destination.getClass());
+ "ReplyTo destination may only be an AMQDestination - passed argument was type " + destination.getClass());
}
final AMQDestination amqd = (AMQDestination) destination;
@@ -614,7 +613,6 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
getContentHeaderProperties().setHeaders(messageProperties);
}
-
public JMSHeaderAdapter getJmsHeaders()
{
return _headerAdapter;
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessageFactory.java b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessageFactory.java
index 5deaec4c17..87df7e1337 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessageFactory.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessageFactory.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,51 +20,53 @@
*/
package org.apache.qpid.client.message;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.JMSException;
-
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ContentBody;
import org.apache.qpid.framing.ContentHeaderBody;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+
+import java.util.Iterator;
+import java.util.List;
+
public abstract class AbstractJMSMessageFactory implements MessageFactory
{
- private static final Logger _logger = Logger.getLogger(AbstractJMSMessageFactory.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(AbstractJMSMessageFactory.class);
- protected abstract AbstractJMSMessage createMessage(long messageNbr, ByteBuffer data,
- AMQShortString exchange, AMQShortString routingKey,
- ContentHeaderBody contentHeader) throws AMQException;
+ protected abstract AbstractJMSMessage createMessage(long messageNbr, ByteBuffer data, AMQShortString exchange,
+ AMQShortString routingKey, ContentHeaderBody contentHeader) throws AMQException;
- protected AbstractJMSMessage createMessageWithBody(long messageNbr,
- ContentHeaderBody contentHeader,
- AMQShortString exchange, AMQShortString routingKey,
- List bodies) throws AMQException
+ protected AbstractJMSMessage createMessageWithBody(long messageNbr, ContentHeaderBody contentHeader,
+ AMQShortString exchange, AMQShortString routingKey, List bodies) throws AMQException
{
ByteBuffer data;
final boolean debug = _logger.isDebugEnabled();
// we optimise the non-fragmented case to avoid copying
- if (bodies != null && bodies.size() == 1)
+ if ((bodies != null) && (bodies.size() == 1))
{
- if(debug)
+ if (debug)
{
- _logger.debug("Non-fragmented message body (bodySize=" + contentHeader.bodySize +")");
+ _logger.debug("Non-fragmented message body (bodySize=" + contentHeader.bodySize + ")");
}
- data = ((ContentBody)bodies.get(0)).payload;
+
+ data = ((ContentBody) bodies.get(0)).payload;
}
else if (bodies != null)
{
- if(debug)
+ if (debug)
{
- _logger.debug("Fragmented message body (" + bodies.size() + " frames, bodySize=" + contentHeader.bodySize + ")");
+ _logger.debug("Fragmented message body (" + bodies.size() + " frames, bodySize=" + contentHeader.bodySize
+ + ")");
}
- data = ByteBuffer.allocate((int)contentHeader.bodySize); // XXX: Is cast a problem?
+
+ data = ByteBuffer.allocate((int) contentHeader.bodySize); // XXX: Is cast a problem?
final Iterator it = bodies.iterator();
while (it.hasNext())
{
@@ -72,27 +74,29 @@ public abstract class AbstractJMSMessageFactory implements MessageFactory
data.put(cb.payload);
cb.payload.release();
}
+
data.flip();
}
else // bodies == null
{
data = ByteBuffer.allocate(0);
}
- if(debug)
+
+ if (debug)
{
- _logger.debug("Creating message from buffer with position=" + data.position() + " and remaining=" + data.remaining());
+ _logger.debug("Creating message from buffer with position=" + data.position() + " and remaining="
+ + data.remaining());
}
return createMessage(messageNbr, data, exchange, routingKey, contentHeader);
}
- public AbstractJMSMessage createMessage(long messageNbr, boolean redelivered,
- ContentHeaderBody contentHeader,
- AMQShortString exchange, AMQShortString routingKey,
- List bodies) throws JMSException, AMQException
+ public AbstractJMSMessage createMessage(long messageNbr, boolean redelivered, ContentHeaderBody contentHeader,
+ AMQShortString exchange, AMQShortString routingKey, List bodies) throws JMSException, AMQException
{
final AbstractJMSMessage msg = createMessageWithBody(messageNbr, contentHeader, exchange, routingKey, bodies);
msg.setJMSRedelivered(redelivered);
+
return msg;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
index ae64ac987e..495f09e8fd 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
@@ -14,36 +14,38 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.client.message;
+import org.apache.mina.common.ByteBuffer;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.ContentHeaderBody;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+
import java.nio.charset.CharacterCodingException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import javax.jms.JMSException;
-import javax.jms.MessageFormatException;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.ContentHeaderBody;
-
public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jms.MapMessage
{
- private static final Logger _logger = Logger.getLogger(JMSMapMessage.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(JMSMapMessage.class);
public static final String MIME_TYPE = "jms/map-message";
private static final AMQShortString MIME_TYPE_SHORT_STRING = new AMQShortString(MIME_TYPE);
- private Map<String,Object> _map = new HashMap<String, Object>();
+ private Map<String, Object> _map = new HashMap<String, Object>();
public JMSMapMessage() throws JMSException
{
@@ -56,24 +58,22 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
populateMapFromData();
}
-
- JMSMapMessage(long messageNbr, ContentHeaderBody contentHeader, AMQShortString exchange,
- AMQShortString routingKey, ByteBuffer data) throws AMQException
+ JMSMapMessage(long messageNbr, ContentHeaderBody contentHeader, AMQShortString exchange, AMQShortString routingKey,
+ ByteBuffer data) throws AMQException
{
super(messageNbr, contentHeader, exchange, routingKey, data);
try
{
populateMapFromData();
- }
+ }
catch (JMSException je)
{
throw new AMQException(null, "Error populating MapMessage from ByteBuffer", je);
-
+
}
}
-
public String toBodyString() throws JMSException
{
return _map.toString();
@@ -84,16 +84,14 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
return MIME_TYPE_SHORT_STRING;
}
-
public ByteBuffer getData()
{
- //What if _data is null?
+ // What if _data is null?
writeMapToData();
+
return super.getData();
}
-
-
@Override
public void clearBodyImpl() throws JMSException
{
@@ -105,18 +103,18 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(value instanceof Boolean)
+ if (value instanceof Boolean)
{
- return ((Boolean)value).booleanValue();
+ return ((Boolean) value).booleanValue();
}
- else if((value instanceof String) || (value == null))
+ else if ((value instanceof String) || (value == null))
{
- return Boolean.valueOf((String)value);
+ return Boolean.valueOf((String) value);
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to boolean.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to boolean.");
}
}
@@ -125,18 +123,18 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(value instanceof Byte)
+ if (value instanceof Byte)
{
- return ((Byte)value).byteValue();
+ return ((Byte) value).byteValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Byte.valueOf((String)value).byteValue();
+ return Byte.valueOf((String) value).byteValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to byte.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to byte.");
}
}
@@ -144,51 +142,50 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(value instanceof Short)
+ if (value instanceof Short)
{
- return ((Short)value).shortValue();
+ return ((Short) value).shortValue();
}
- else if(value instanceof Byte)
+ else if (value instanceof Byte)
{
- return ((Byte)value).shortValue();
+ return ((Byte) value).shortValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Short.valueOf((String)value).shortValue();
+ return Short.valueOf((String) value).shortValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to short.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to short.");
}
}
-
public int getInt(String propName) throws JMSException
{
Object value = _map.get(propName);
- if(value instanceof Integer)
+ if (value instanceof Integer)
{
- return ((Integer)value).intValue();
+ return ((Integer) value).intValue();
}
- else if(value instanceof Short)
+ else if (value instanceof Short)
{
- return ((Short)value).intValue();
+ return ((Short) value).intValue();
}
- else if(value instanceof Byte)
+ else if (value instanceof Byte)
{
- return ((Byte)value).intValue();
+ return ((Byte) value).intValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Integer.valueOf((String)value).intValue();
+ return Integer.valueOf((String) value).intValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to int.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to int.");
}
}
@@ -197,30 +194,32 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(value instanceof Long)
+ if (value instanceof Long)
{
- return ((Long)value).longValue();
+ return ((Long) value).longValue();
}
- else if(value instanceof Integer)
+ else if (value instanceof Integer)
{
- return ((Integer)value).longValue();
+ return ((Integer) value).longValue();
}
- if(value instanceof Short)
+
+ if (value instanceof Short)
{
- return ((Short)value).longValue();
+ return ((Short) value).longValue();
}
- if(value instanceof Byte)
+
+ if (value instanceof Byte)
{
- return ((Byte)value).longValue();
+ return ((Byte) value).longValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Long.valueOf((String)value).longValue();
+ return Long.valueOf((String) value).longValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to long.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to long.");
}
}
@@ -229,45 +228,43 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(!_map.containsKey(propName))
+ if (!_map.containsKey(propName))
{
throw new MessageFormatException("Property " + propName + " not present");
}
- else if(value instanceof Character)
+ else if (value instanceof Character)
{
- return ((Character)value).charValue();
+ return ((Character) value).charValue();
}
else if (value == null)
{
- throw new NullPointerException("Property " + propName + " has null value and therefore cannot " +
- "be converted to char.");
+ throw new NullPointerException("Property " + propName + " has null value and therefore cannot "
+ + "be converted to char.");
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to boolan.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to boolan.");
}
}
-
-
public float getFloat(String propName) throws JMSException
{
Object value = _map.get(propName);
- if(value instanceof Float)
+ if (value instanceof Float)
{
- return ((Float)value).floatValue();
+ return ((Float) value).floatValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Float.valueOf((String)value).floatValue();
+ return Float.valueOf((String) value).floatValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to float.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to float.");
}
}
@@ -275,22 +272,22 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(value instanceof Double)
+ if (value instanceof Double)
{
- return ((Double)value).doubleValue();
+ return ((Double) value).doubleValue();
}
- else if(value instanceof Float)
+ else if (value instanceof Float)
{
- return ((Float)value).doubleValue();
+ return ((Float) value).doubleValue();
}
- else if((value instanceof String) || (value==null))
+ else if ((value instanceof String) || (value == null))
{
- return Double.valueOf((String)value).doubleValue();
+ return Double.valueOf((String) value).doubleValue();
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to double.");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to double.");
}
}
@@ -298,14 +295,13 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if((value instanceof String) || (value == null))
+ if ((value instanceof String) || (value == null))
{
return (String) value;
}
- else if(value instanceof byte[])
+ else if (value instanceof byte[])
{
- throw new MessageFormatException("Property " + propName + " of type byte[] " +
- "cannot be converted to String.");
+ throw new MessageFormatException("Property " + propName + " of type byte[] " + "cannot be converted to String.");
}
else
{
@@ -318,18 +314,18 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
{
Object value = _map.get(propName);
- if(!_map.containsKey(propName))
+ if (!_map.containsKey(propName))
{
- throw new MessageFormatException("Property " + propName + " not present");
+ throw new MessageFormatException("Property " + propName + " not present");
}
- else if((value instanceof byte[]) || (value == null))
+ else if ((value instanceof byte[]) || (value == null))
{
- return (byte[])value;
+ return (byte[]) value;
}
else
{
- throw new MessageFormatException("Property " + propName + " of type " +
- value.getClass().getName() + " cannot be converted to byte[].");
+ throw new MessageFormatException("Property " + propName + " of type " + value.getClass().getName()
+ + " cannot be converted to byte[].");
}
}
@@ -343,7 +339,6 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
return Collections.enumeration(_map.keySet());
}
-
public void setBoolean(String propName, boolean b) throws JMSException
{
checkWritable();
@@ -416,46 +411,38 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
public void setBytes(String propName, byte[] bytes, int offset, int length) throws JMSException
{
- if((offset == 0) && (length == bytes.length))
+ if ((offset == 0) && (length == bytes.length))
{
- setBytes(propName,bytes);
+ setBytes(propName, bytes);
}
else
{
byte[] newBytes = new byte[length];
- System.arraycopy(bytes,offset,newBytes,0,length);
- setBytes(propName,newBytes);
+ System.arraycopy(bytes, offset, newBytes, 0, length);
+ setBytes(propName, newBytes);
}
}
public void setObject(String propName, Object value) throws JMSException
- {
+ {
checkWritable();
checkPropertyName(propName);
- if(value instanceof Boolean
- || value instanceof Byte
- || value instanceof Short
- || value instanceof Integer
- || value instanceof Long
- || value instanceof Character
- || value instanceof Float
- || value instanceof Double
- || value instanceof String
- || value instanceof byte[]
- || value == null)
+ if ((value instanceof Boolean) || (value instanceof Byte) || (value instanceof Short) || (value instanceof Integer)
+ || (value instanceof Long) || (value instanceof Character) || (value instanceof Float)
+ || (value instanceof Double) || (value instanceof String) || (value instanceof byte[]) || (value == null))
{
_map.put(propName, value);
}
else
{
- throw new MessageFormatException("Cannot set property " + propName + " to value " + value +
- "of type " + value.getClass().getName() + ".");
+ throw new MessageFormatException("Cannot set property " + propName + " to value " + value + "of type "
+ + value.getClass().getName() + ".");
}
}
private void checkPropertyName(String propName)
{
- if(propName == null || propName.equals(""))
+ if ((propName == null) || propName.equals(""))
{
throw new IllegalArgumentException("Property name cannot be null, or the empty String.");
}
@@ -466,19 +453,18 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
return _map.containsKey(propName);
}
-
private void populateMapFromData() throws JMSException
{
- if(_data != null)
+ if (_data != null)
{
_data.rewind();
final int entries = readIntImpl();
- for(int i = 0; i < entries; i++)
+ for (int i = 0; i < entries; i++)
{
String propName = readStringImpl();
Object value = readObject();
- _map.put(propName,value);
+ _map.put(propName, value);
}
}
else
@@ -492,7 +478,7 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
allocateInitialBuffer();
final int size = _map.size();
writeIntImpl(size);
- for(Map.Entry<String, Object> entry : _map.entrySet())
+ for (Map.Entry<String, Object> entry : _map.entrySet())
{
try
{
@@ -500,10 +486,10 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
}
catch (CharacterCodingException e)
{
- throw new IllegalArgumentException("Cannot encode property key name " + entry.getKey(),e);
-
+ throw new IllegalArgumentException("Cannot encode property key name " + entry.getKey(), e);
}
+
try
{
writeObject(entry.getValue());
@@ -511,14 +497,11 @@ public class JMSMapMessage extends AbstractBytesTypedMessage implements javax.jm
catch (JMSException e)
{
Object value = entry.getValue();
- throw new IllegalArgumentException("Cannot encode property key name " + entry.getKey() +
- " value : " + value + " (type: " + value.getClass().getName() + ").",e);
+ throw new IllegalArgumentException("Cannot encode property key name " + entry.getKey() + " value : " + value
+ + " (type: " + value.getClass().getName() + ").", e);
}
}
}
-
-
-
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/MessageConverter.java b/java/client/src/main/java/org/apache/qpid/client/message/MessageConverter.java
index 0afc8177fc..f6b11c6f6c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/MessageConverter.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/MessageConverter.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,8 @@
*/
package org.apache.qpid.client.message;
-import java.util.Enumeration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
@@ -31,7 +32,7 @@ import javax.jms.ObjectMessage;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;
-import org.apache.log4j.Logger;
+import java.util.Enumeration;
public class MessageConverter
{
@@ -39,7 +40,7 @@ public class MessageConverter
/**
* Log4J logger
*/
- protected final Logger _logger = Logger.getLogger(getClass());
+ protected final Logger _logger = LoggerFactory.getLogger(getClass());
/**
* AbstractJMSMessage which will hold the converted message
@@ -81,6 +82,7 @@ public class MessageConverter
String name = (String) mapNames.nextElement();
nativeMessage.setObject(name, message.getObject(name));
}
+
_newMessage = (AbstractJMSMessage) nativeMessage;
setMessageProperties(message);
}
@@ -121,15 +123,16 @@ public class MessageConverter
}
catch (MessageEOFException e)
{
- //we're at the end so don't mind the exception
+ // we're at the end so don't mind the exception
}
+
_newMessage = (AbstractJMSMessage) nativeMessage;
setMessageProperties(message);
}
public MessageConverter(Message message) throws JMSException
{
- //Send a message with just properties.
+ // Send a message with just properties.
// Throwing away content
BytesMessage nativeMessage = new JMSBytesMessage();
@@ -160,7 +163,7 @@ public class MessageConverter
while (propertyNames.hasMoreElements())
{
String propertyName = String.valueOf(propertyNames.nextElement());
- //TODO: Shouldn't need to check for JMS properties here as don't think getPropertyNames() should return them
+ // TODO: Shouldn't need to check for JMS properties here as don't think getPropertyNames() should return them
if (!propertyName.startsWith("JMSX_"))
{
Object value = message.getObjectProperty(propertyName);
@@ -190,6 +193,7 @@ public class MessageConverter
{
_newMessage.setJMSReplyTo(message.getJMSReplyTo());
}
+
_newMessage.setJMSType(message.getJMSType());
_newMessage.setJMSCorrelationID(message.getJMSCorrelationID());
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
index 5687ad2658..d2d29039ea 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,10 +20,6 @@
*/
package org.apache.qpid.client.protocol;
-import java.util.Iterator;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.CountDownLatch;
-
import org.apache.log4j.Logger;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoHandlerAdapter;
@@ -34,10 +30,10 @@ import org.apache.qpid.AMQConnectionClosedException;
import org.apache.qpid.AMQDisconnectedException;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQTimeoutException;
-import org.apache.qpid.AMQChannelClosedException;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.SSLConfiguration;
+import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.client.failover.FailoverHandler;
import org.apache.qpid.client.failover.FailoverState;
import org.apache.qpid.client.state.AMQState;
@@ -60,9 +56,67 @@ import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.ssl.SSLContextFactory;
+import java.util.Iterator;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.CountDownLatch;
+/**
+ * AMQProtocolHandler is the client side protocol handler for AMQP, it handles all protocol events received from the
+ * network by MINA. The primary purpose of AMQProtocolHandler is to translate the generic event model of MINA into the
+ * specific event model of AMQP, by revealing the type of the received events (from decoded data), and passing the event
+ * on to more specific handlers for the type. In this sense, it channels the richer event model of AMQP, expressed in
+ * terms of methods and so on, through the cruder, general purpose event model of MINA, expressed in terms of "message
+ * received" and so on.
+ *
+ * <p/>There is a 1:1 mapping between an AMQProtocolHandler and an {@link AMQConnection}. The connection class is
+ * exposed to the end user of the AMQP client API, and also implements the JMS Connection API, so provides the public
+ * API calls through which an individual connection can be manipulated. This protocol handler talks to the network
+ * through MINA, in a behind the scenes role; it is not an exposed part of the client API.
+ *
+ * <p/>There is a 1:many mapping between an AMQProtocolHandler and a set of {@link AMQSession}s. At the MINA level,
+ * there is one session per connection. At the AMQP level there can be many channels which are also called sessions in
+ * JMS parlance. The {@link AMQSession}s are managed through an {@link AMQProtocolSession} instance. The protocol
+ * session is similar to the MINA per-connection session, except that it can span the lifecycle of multiple MINA
+ * sessions in the event of failover. See below for more information about this.
+ *
+ * <p/>Mina provides a session container that can be used to store/retrieve arbitrary objects as String named
+ * attributes. A more convenient, type-safe, container for session data is provided in the form of {@link
+ * AMQProtocolSession}.
+ *
+ * <p/>A common way to use MINA is to have a single instance of the event handler, and for MINA to pass in its session
+ * object with every event, and for per-connection data to be held in the MINA session (perhaps using a type-safe
+ * wrapper as described above). This event handler is different, because dealing with failover complicates things. To
+ * the end client of an AMQConnection, a failed over connection is still handled through the same connection instance,
+ * but behind the scenes a new transport connection, and MINA session will have been created. The MINA session object
+ * cannot be used to track the state of the fail-over process, because it is destroyed and a new one is created, as the
+ * old connection is shutdown and a new one created. For this reason, an AMQProtocolHandler is created per AMQConnection
+ * and the protocol session data is held outside of the MINA IOSession.
+ *
+ * <p/>This handler is responsibile for setting up the filter chain to filter all events for this handler through. The
+ * filter chain is set up as a stack of event handers that perform the following functions (working upwards from the
+ * network traffic at the bottom), handing off incoming events to an asynchronous thread pool to do the work, optionally
+ * handling secure sockets encoding/decoding, encoding/decoding the AMQP format itself.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption> <tr><th> Responsibilities <th> Collaborations <tr><td> Create the
+ * filter chain to filter this handlers events. <td> {@link ProtocolCodecFilter}, {@link SSLContextFactory}, {@link
+ * SSLFilter}, {@link ReadWriteThreadModel}.
+ *
+ * <tr><td> Maintain fail-over state. <tr><td> </table>
+ *
+ * @todo Explain the system property: amqj.shared_read_write_pool. How does putting the protocol codec filter before the
+ * async write filter make it a shared pool? The pooling filter uses the same thread pool for reading and writing
+ * anyway, see {@link org.apache.qpid.pool.PoolingFilter}, docs for comments. Will putting the protocol codec filter
+ * before it mean not doing the read/write asynchronously but in the main filter thread?
+ * @todo Use a single handler instance, by shifting everything to do with the 'protocol session' state, including
+ * failover state, into AMQProtocolSession, and tracking that from AMQConnection? The lifecycles of AMQProtocolSesssion
+ * and AMQConnection will be the same, so if there is high cohesion between them, they could be merged, although there
+ * is sense in keeping the session model seperate. Will clarify things by having data held per protocol handler, per
+ * protocol session, per network connection, per channel, in seperate classes, so that lifecycles of the fields match
+ * lifecycles of their containing objects.
+ */
public class AMQProtocolHandler extends IoHandlerAdapter
{
+ /** Used for debugging. */
private static final Logger _logger = Logger.getLogger(AMQProtocolHandler.class);
/**
@@ -74,8 +128,10 @@ public class AMQProtocolHandler extends IoHandlerAdapter
/** Our wrapper for a protocol session that provides access to session values in a typesafe manner. */
private volatile AMQProtocolSession _protocolSession;
+ /** Holds the state of the protocol session. */
private AMQStateManager _stateManager = new AMQStateManager();
+ /** Holds the method listeners, */
private final CopyOnWriteArraySet _frameListeners = new CopyOnWriteArraySet();
/**
@@ -91,15 +147,31 @@ public class AMQProtocolHandler extends IoHandlerAdapter
*/
private FailoverState _failoverState = FailoverState.NOT_STARTED;
+ /** Used to provide a condition to wait upon for operations that are required to wait for failover to complete. */
private CountDownLatch _failoverLatch;
+ /** Defines the default timeout to use for synchronous protocol commands. */
private final long DEFAULT_SYNC_TIMEOUT = 1000 * 30;
+ /**
+ * Creates a new protocol handler, associated with the specified client connection instance.
+ *
+ * @param con The client connection that this is the event handler for.
+ */
public AMQProtocolHandler(AMQConnection con)
{
_connection = con;
}
+ /**
+ * Invoked by MINA when a MINA session for a new connection is created. This method sets up the filter chain on the
+ * session, which filters the events handled by this handler. The filter chain consists of, handing off events to an
+ * asynchronous thread pool, optionally encoding/decoding ssl, encoding/decoding AMQP.
+ *
+ * @param session The MINA session.
+ *
+ * @throws Exception Any underlying exceptions are allowed to fall through to MINA.
+ */
public void sessionCreated(IoSession session) throws Exception
{
_logger.debug("Protocol session created for session " + System.identityHashCode(session));
@@ -119,16 +191,15 @@ public class AMQProtocolHandler extends IoHandlerAdapter
if (_connection.getSSLConfiguration() != null)
{
SSLConfiguration sslConfig = _connection.getSSLConfiguration();
- SSLContextFactory sslFactory = new SSLContextFactory(sslConfig.getKeystorePath(), sslConfig.getKeystorePassword(), sslConfig.getCertType());
+ SSLContextFactory sslFactory =
+ new SSLContextFactory(sslConfig.getKeystorePath(), sslConfig.getKeystorePassword(), sslConfig.getCertType());
SSLFilter sslFilter = new SSLFilter(sslFactory.buildClientContext());
sslFilter.setUseClientMode(true);
session.getFilterChain().addBefore("protocolFilter", "ssl", sslFilter);
}
-
try
{
-
ReadWriteThreadModel threadModel = ReadWriteThreadModel.getInstance();
threadModel.getAsynchronousReadFilter().createNewJobForSession(session);
threadModel.getAsynchronousWriteFilter().createNewJobForSession(session);
@@ -142,35 +213,38 @@ public class AMQProtocolHandler extends IoHandlerAdapter
_protocolSession.init();
}
- public void sessionOpened(IoSession session) throws Exception
- {
- //System.setProperty("foo", "bar");
- }
-
/**
- * When the broker connection dies we can either get sessionClosed() called or exceptionCaught() followed by
- * sessionClosed() depending on whether we were trying to send data at the time of failure.
+ * Called when the network connection is closed. This can happen, either because the client explicitly requested
+ * that the connection be closed, in which case nothing is done, or because the connection died. In the case where
+ * the connection died, an attempt to failover automatically to a new connection may be started. The failover
+ * process will be started, provided that it is the clients policy to allow failover, and provided that a failover
+ * has not already been started or failed.
+ *
+ * <p/>It is important to note that when the connection dies this method may be called or {@link #exceptionCaught}
+ * may be called first followed by this method. This depends on whether the client was trying to send data at the
+ * time of the failure.
*
- * @param session
+ * @param session The MINA session.
*
- * @throws Exception
+ * @todo Clarify: presumably exceptionCaught is called when the client is sending during a connection failure and
+ * not otherwise? The above comment doesn't make that clear.
*/
- public void sessionClosed(IoSession session) throws Exception
+ public void sessionClosed(IoSession session)
{
if (_connection.isClosed())
{
- _logger.info("Session closed called by client");
+ _logger.debug("Session closed called by client");
}
else
{
- _logger.info("Session closed called with failover state currently " + _failoverState);
+ _logger.debug("Session closed called with failover state currently " + _failoverState);
- //reconnetablility was introduced here so as not to disturb the client as they have made their intentions
+ // reconnetablility was introduced here so as not to disturb the client as they have made their intentions
// known through the policy settings.
if ((_failoverState != FailoverState.IN_PROGRESS) && _connection.failoverAllowed())
{
- _logger.info("FAILOVER STARTING");
+ _logger.debug("FAILOVER STARTING");
if (_failoverState == FailoverState.NOT_STARTED)
{
_failoverState = FailoverState.IN_PROGRESS;
@@ -178,12 +252,12 @@ public class AMQProtocolHandler extends IoHandlerAdapter
}
else
{
- _logger.info("Not starting failover as state currently " + _failoverState);
+ _logger.debug("Not starting failover as state currently " + _failoverState);
}
}
else
{
- _logger.info("Failover not allowed by policy.");
+ _logger.debug("Failover not allowed by policy."); // or already in progress?
if (_logger.isDebugEnabled())
{
@@ -199,12 +273,12 @@ public class AMQProtocolHandler extends IoHandlerAdapter
}
else
{
- _logger.info("sessionClose() failover in progress");
+ _logger.debug("sessionClose() failover in progress");
}
}
}
- _logger.info("Protocol Session [" + this + "] closed");
+ _logger.debug("Protocol Session [" + this + "] closed");
}
/** See {@link FailoverHandler} to see rationale for separate thread. */
@@ -223,25 +297,32 @@ public class AMQProtocolHandler extends IoHandlerAdapter
_logger.debug("Protocol Session [" + this + ":" + session + "] idle: " + status);
if (IdleStatus.WRITER_IDLE.equals(status))
{
- //write heartbeat frame:
+ // write heartbeat frame:
_logger.debug("Sent heartbeat");
session.write(HeartbeatBody.FRAME);
HeartbeatDiagnostics.sent();
}
else if (IdleStatus.READER_IDLE.equals(status))
{
- //failover:
+ // failover:
HeartbeatDiagnostics.timeout();
_logger.warn("Timed out while waiting for heartbeat from peer.");
session.close();
}
}
- public void exceptionCaught(IoSession session, Throwable cause) throws Exception
+ /**
+ * Invoked when any exception is thrown by a user IoHandler implementation or by MINA. If the cause is an
+ * IOException, MINA will close the connection automatically.
+ *
+ * @param session The MINA session.
+ * @param cause The exception that triggered this event.
+ */
+ public void exceptionCaught(IoSession session, Throwable cause)
{
if (_failoverState == FailoverState.NOT_STARTED)
{
- //if (!(cause instanceof AMQUndeliveredException) && (!(cause instanceof AMQAuthenticationException)))
+ // if (!(cause instanceof AMQUndeliveredException) && (!(cause instanceof AMQAuthenticationException)))
if (cause instanceof AMQConnectionClosedException)
{
_logger.info("Exception caught therefore going to attempt failover: " + cause, cause);
@@ -250,8 +331,8 @@ public class AMQProtocolHandler extends IoHandlerAdapter
sessionClosed(session);
}
- //FIXME Need to correctly handle other exceptions. Things like ...
-// if (cause instanceof AMQChannelClosedException)
+ // FIXME Need to correctly handle other exceptions. Things like ...
+ // if (cause instanceof AMQChannelClosedException)
// which will cause the JMSSession to end due to a channel close and so that Session needs
// to be removed from the map so we can correctly still call close without an exception when trying to close
// the server closed session. See also CloseChannelMethodHandler as the sessionClose is never called on exception
@@ -261,6 +342,7 @@ public class AMQProtocolHandler extends IoHandlerAdapter
else if (_failoverState == FailoverState.FAILED)
{
_logger.error("Exception caught by protocol handler: " + cause, cause);
+
// we notify the state manager of the error in case we have any clients waiting on a state
// change. Those "waiters" will be interrupted and can handle the exception
AMQException amqe = new AMQException(null, "Protocol handler error: " + cause, cause);
@@ -297,7 +379,7 @@ public class AMQProtocolHandler extends IoHandlerAdapter
final boolean debug = _logger.isDebugEnabled();
final long msgNumber = ++_messageReceivedCount;
- if (debug && (msgNumber % 1000 == 0))
+ if (debug && ((msgNumber % 1000) == 0))
{
_logger.debug("Received " + _messageReceivedCount + " protocol messages");
}
@@ -317,7 +399,8 @@ public class AMQProtocolHandler extends IoHandlerAdapter
_logger.debug("(" + System.identityHashCode(this) + ")Method frame received: " + frame);
}
- final AMQMethodEvent<AMQMethodBody> evt = new AMQMethodEvent<AMQMethodBody>(frame.getChannel(), (AMQMethodBody) bodyFrame);
+ final AMQMethodEvent<AMQMethodBody> evt =
+ new AMQMethodEvent<AMQMethodBody>(frame.getChannel(), (AMQMethodBody) bodyFrame);
try
{
@@ -331,10 +414,16 @@ public class AMQProtocolHandler extends IoHandlerAdapter
final AMQMethodListener listener = (AMQMethodListener) it.next();
wasAnyoneInterested = listener.methodReceived(evt) || wasAnyoneInterested;
}
+ if (!wasAnyoneInterested)
+ {
+ throw new AMQException(null, "AMQMethodEvent " + evt + " was not processed by any listener. Listeners:" + _frameListeners, null);
+ }
}
+
if (!wasAnyoneInterested)
{
- throw new AMQException(null, "AMQMethodEvent " + evt + " was not processed by any listener. Listeners:" + _frameListeners, null);
+ throw new AMQException(null, "AMQMethodEvent " + evt + " was not processed by any listener. Listeners:"
+ + _frameListeners, null);
}
}
catch (AMQException e)
@@ -349,20 +438,20 @@ public class AMQProtocolHandler extends IoHandlerAdapter
listener.error(e);
}
}
+
exceptionCaught(session, e);
}
+
break;
case ContentHeaderBody.TYPE:
- _protocolSession.messageContentHeaderReceived(frame.getChannel(),
- (ContentHeaderBody) bodyFrame);
+ _protocolSession.messageContentHeaderReceived(frame.getChannel(), (ContentHeaderBody) bodyFrame);
break;
case ContentBody.TYPE:
- _protocolSession.messageContentBodyReceived(frame.getChannel(),
- (ContentBody) bodyFrame);
+ _protocolSession.messageContentBodyReceived(frame.getChannel(), (ContentBody) bodyFrame);
break;
case HeartbeatBody.TYPE:
@@ -371,11 +460,13 @@ public class AMQProtocolHandler extends IoHandlerAdapter
{
_logger.debug("Received heartbeat");
}
+
break;
default:
}
+
_connection.bytesReceived(_protocolSession.getIoSession().getReadBytes());
}
@@ -387,10 +478,11 @@ public class AMQProtocolHandler extends IoHandlerAdapter
final boolean debug = _logger.isDebugEnabled();
- if (debug && (sentMessages % 1000 == 0))
+ if (debug && ((sentMessages % 1000) == 0))
{
_logger.debug("Sent " + _messagesOut + " protocol messages");
}
+
_connection.bytesSent(session.getWrittenBytes());
if (debug)
{
@@ -408,7 +500,7 @@ public class AMQProtocolHandler extends IoHandlerAdapter
{
_frameListeners.remove(listener);
}
- */
+ */
public void attainState(AMQState s) throws AMQException
{
getStateManager().attainState(s);
@@ -437,9 +529,8 @@ public class AMQProtocolHandler extends IoHandlerAdapter
* @param frame
* @param listener the blocking listener. Note the calling thread will block.
*/
- public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame,
- BlockingMethodFrameListener listener)
- throws AMQException
+ public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame, BlockingMethodFrameListener listener)
+ throws AMQException, FailoverException
{
return writeCommandFrameAndWaitForReply(frame, listener, DEFAULT_SYNC_TIMEOUT);
}
@@ -451,9 +542,8 @@ public class AMQProtocolHandler extends IoHandlerAdapter
* @param frame
* @param listener the blocking listener. Note the calling thread will block.
*/
- public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame,
- BlockingMethodFrameListener listener, long timeout)
- throws AMQException
+ public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame, BlockingMethodFrameListener listener,
+ long timeout) throws AMQException, FailoverException
{
try
{
@@ -461,6 +551,7 @@ public class AMQProtocolHandler extends IoHandlerAdapter
_protocolSession.writeFrame(frame);
AMQMethodEvent e = listener.blockForFrame(timeout);
+
return e;
// When control resumes before this line, a reply will have been received
// that matches the criteria defined in the blocking listener
@@ -478,25 +569,33 @@ public class AMQProtocolHandler extends IoHandlerAdapter
}
/** More convenient method to write a frame and wait for it's response. */
- public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass) throws AMQException
+ public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass) throws AMQException, FailoverException
{
return syncWrite(frame, responseClass, DEFAULT_SYNC_TIMEOUT);
}
/** More convenient method to write a frame and wait for it's response. */
- public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass, long timeout) throws AMQException
+ public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass, long timeout) throws AMQException, FailoverException
{
- return writeCommandFrameAndWaitForReply(frame,
- new SpecificMethodFrameListener(frame.getChannel(), responseClass), timeout);
+ return writeCommandFrameAndWaitForReply(frame, new SpecificMethodFrameListener(frame.getChannel(), responseClass),
+ timeout);
}
-
-
public void closeSession(AMQSession session) throws AMQException
{
_protocolSession.closeSession(session);
}
+ /**
+ * Closes the connection.
+ *
+ * <p/>If a failover exception occurs whilst closing the connection it is ignored, as the connection is closed
+ * anyway.
+ *
+ * @param timeout The timeout to wait for an acknowledgement to the close request.
+ *
+ * @throws AMQException If the close fails for any reason.
+ */
public void closeConnection(long timeout) throws AMQException
{
getStateManager().changeState(AMQState.CONNECTION_CLOSING);
@@ -504,13 +603,13 @@ public class AMQProtocolHandler extends IoHandlerAdapter
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
- final AMQFrame frame = ConnectionCloseBody.createAMQFrame(0,
- _protocolSession.getProtocolMajorVersion(),
- _protocolSession.getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
- new AMQShortString("JMS client is closing the connection.")); // replyText
+ final AMQFrame frame =
+ ConnectionCloseBody.createAMQFrame(0, _protocolSession.getProtocolMajorVersion(),
+ _protocolSession.getProtocolMinorVersion(), // AMQP version (major, minor)
+ 0, // classId
+ 0, // methodId
+ AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
+ new AMQShortString("JMS client is closing the connection.")); // replyText
try
{
@@ -521,8 +620,10 @@ public class AMQProtocolHandler extends IoHandlerAdapter
{
_protocolSession.closeProtocolSession(false);
}
-
-
+ catch (FailoverException e)
+ {
+ _logger.debug("FailoverException interrupted connection close, ignoring as connection close anyway.");
+ }
}
/** @return the number of bytes read from this protocol session */
@@ -604,7 +705,6 @@ public class AMQProtocolHandler extends IoHandlerAdapter
return _protocolSession.getProtocolMajorVersion();
}
-
public byte getProtocolMinorVersion()
{
return _protocolSession.getProtocolMinorVersion();
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
index f691637cdc..dcab89e9bb 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
@@ -20,16 +20,8 @@
*/
package org.apache.qpid.client.protocol;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.jms.JMSException;
-import javax.security.sasl.SaslClient;
-
import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-
import org.apache.mina.common.CloseFuture;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoSession;
@@ -53,16 +45,24 @@ import org.apache.qpid.framing.VersionSpecificRegistry;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.security.sasl.SaslClient;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
/**
* Wrapper for protocol session that provides type-safe access to session attributes. <p/> The underlying protocol
* session is still available but clients should not use it to obtain session attributes.
*/
public class AMQProtocolSession implements AMQVersionAwareProtocolSession
{
-
protected static final int LAST_WRITE_FUTURE_JOIN_TIMEOUT = 1000 * 60 * 2;
- protected static final Logger _logger = Logger.getLogger(AMQProtocolSession.class);
+ protected static final Logger _logger = LoggerFactory.getLogger(AMQProtocolSession.class);
public static final String PROTOCOL_INITIATION_RECEIVED = "ProtocolInitiatiionReceived";
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java b/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
index 4691d48f29..0ab2e07340 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -27,71 +27,137 @@ import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
+/**
+ * BlockingMethodFrameListener is a 'rendezvous' which acts as a {@link AMQMethodListener} that delegates handling of
+ * incoming methods to a method listener implemented as a sub-class of this and hands off the processed method or
+ * error to a consumer. The producer of the event does not have to wait for the consumer to take the event, so this
+ * differs from a 'rendezvous' in that sense.
+ *
+ * <p/>BlockingMethodFrameListeners are used to coordinate waiting for replies to method calls that expect a response.
+ * They are always used in a 'one-shot' manner, that is, to recieve just one response. Usually the caller has to register
+ * them as method listeners with an event dispatcher and remember to de-register them (in a finally block) once they
+ * have been completed.
+ *
+ * <p/>The {@link #processMethod} must return <tt>true</tt> on any incoming method that it handles. This indicates to
+ * this listeners that the method it is waiting for has arrived. Incoming methods are also filtered by channel prior to
+ * being passed to the {@link #processMethod} method, so responses are only received for a particular channel. The
+ * channel id must be passed to the constructor.
+ *
+ * <p/>Errors from the producer are rethrown to the consumer.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Accept notification of AMQP method events. <td> {@link AMQMethodEvent}
+ * <tr><td> Delegate handling of the method to another method listener. <td> {@link AMQMethodBody}
+ * <tr><td> Block until a method is handled by the delegated to handler.
+ * <tr><td> Propagate the most recent exception to the consumer.
+ * </table>
+ *
+ * @todo Might be neater if this method listener simply wrapped another that provided the method handling using a
+ * methodRecevied method. The processMethod takes an additional channelId, however none of the implementations
+ * seem to use it. So wrapping the listeners is possible.
+ *
+ * @todo What is to stop a blocking method listener, receiving a second method whilst it is registered as a listener,
+ * overwriting the first one before the caller of the block method has had a chance to examine it? If one-shot
+ * behaviour is to be intended it should be enforced, perhaps by always returning false once the blocked for
+ * method has been received.
+ *
+ * @todo Interuption is caught but not handled. This could be allowed to fall through. This might actually be usefull
+ * for fail-over where a thread is blocking when failure happens, it could be interrupted to abandon or retry
+ * when this happens. At the very least, restore the interrupted status flag.
+ *
+ * @todo If the retrotranslator can handle it, could use a SynchronousQueue to implement this rendezvous. Need to
+ * check that SynchronousQueue has a non-blocking put method available.
+ */
public abstract class BlockingMethodFrameListener implements AMQMethodListener
{
+ /** This flag is used to indicate that the blocked for method has been received. */
private volatile boolean _ready = false;
- public abstract boolean processMethod(int channelId, AMQMethodBody frame) throws AMQException;
-
+ /** Used to protect the shared event and ready flag between the producer and consumer. */
private final Object _lock = new Object();
- /**
- * This is set if there is an exception thrown from processCommandFrame and the
- * exception is rethrown to the caller of blockForFrame()
- */
+ /** Used to hold the most recent exception that is passed to the {@link #error(Exception)} method. */
private volatile Exception _error;
+ /** Holds the channel id for the channel upon which this listener is waiting for a response. */
protected int _channelId;
+ /** Holds the incoming method. */
protected AMQMethodEvent _doneEvt = null;
+ /**
+ * Creates a new method listener, that filters incoming method to just those that match the specified channel id.
+ *
+ * @param channelId The channel id to filter incoming methods with.
+ */
public BlockingMethodFrameListener(int channelId)
{
_channelId = channelId;
}
/**
- * This method is called by the MINA dispatching thread. Note that it could
- * be called before blockForFrame() has been called.
+ * Delegates any additional handling of the incoming methods to another handler.
*
- * @param evt the frame event
- * @return true if the listener has dealt with this frame
- * @throws AMQException
+ * @param channelId The channel id of the incoming method.
+ * @param frame The method body.
+ *
+ * @return <tt>true</tt> if the method was handled, <tt>false</tt> otherwise.
*/
- public boolean methodReceived(AMQMethodEvent evt) throws AMQException
+ public abstract boolean processMethod(int channelId, AMQMethodBody frame); // throws AMQException;
+
+ /**
+ * Informs this listener that an AMQP method has been received.
+ *
+ * @param evt The AMQP method.
+ *
+ * @return <tt>true</tt> if this listener has handled the method, <tt>false</tt> otherwise.
+ */
+ public boolean methodReceived(AMQMethodEvent evt) // throws AMQException
{
AMQMethodBody method = evt.getMethod();
- try
+ /*try
+ {*/
+ boolean ready = (evt.getChannelId() == _channelId) && processMethod(evt.getChannelId(), method);
+
+ if (ready)
{
- boolean ready = (evt.getChannelId() == _channelId) && processMethod(evt.getChannelId(), method);
- if (ready)
+ // we only update the flag from inside the synchronized block
+ // so that the blockForFrame method cannot "miss" an update - it
+ // will only ever read the flag from within the synchronized block
+ synchronized (_lock)
{
- // we only update the flag from inside the synchronized block
- // so that the blockForFrame method cannot "miss" an update - it
- // will only ever read the flag from within the synchronized block
- synchronized (_lock)
- {
- _doneEvt = evt;
- _ready = ready;
- _lock.notify();
- }
+ _doneEvt = evt;
+ _ready = ready;
+ _lock.notify();
}
- return ready;
}
+
+ return ready;
+
+ /*}
catch (AMQException e)
{
error(e);
// we rethrow the error here, and the code in the frame dispatcher will go round
// each listener informing them that an exception has been thrown
throw e;
- }
+ }*/
}
/**
- * This method is called by the thread that wants to wait for a frame.
+ * Blocks until a method is received that is handled by the delegated to method listener, or the specified timeout
+ * has passed.
+ *
+ * @param timeout The timeout in milliseconds.
+ *
+ * @return The AMQP method that was received.
+ *
+ * @throws AMQException
+ * @throws FailoverException
*/
- public AMQMethodEvent blockForFrame(long timeout) throws AMQException
+ public AMQMethodEvent blockForFrame(long timeout) throws AMQException, FailoverException
{
synchronized (_lock)
{
@@ -117,24 +183,25 @@ public abstract class BlockingMethodFrameListener implements AMQMethodListener
catch (InterruptedException e)
{
// IGNORE -- //fixme this isn't ideal as being interrupted isn't equivellant to sucess
-// if (!_ready && timeout != -1)
-// {
-// _error = new AMQException("Server did not respond timely");
-// _ready = true;
-// }
+ // if (!_ready && timeout != -1)
+ // {
+ // _error = new AMQException("Server did not respond timely");
+ // _ready = true;
+ // }
}
}
}
+
if (_error != null)
{
if (_error instanceof AMQException)
{
- throw(AMQException) _error;
+ throw (AMQException) _error;
}
else if (_error instanceof FailoverException)
{
- // This should ensure that FailoverException is not wrapped and can be caught.
- throw(FailoverException) _error; // needed to expose FailoverException.
+ // This should ensure that FailoverException is not wrapped and can be caught.
+ throw (FailoverException) _error; // needed to expose FailoverException.
}
else
{
@@ -156,6 +223,7 @@ public abstract class BlockingMethodFrameListener implements AMQMethodListener
// set the error so that the thread that is blocking (against blockForFrame())
// can pick up the exception and rethrow to the caller
_error = e;
+
synchronized (_lock)
{
_ready = true;
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatConfig.java b/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatConfig.java
index 6a7462cd0f..35ea44a331 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatConfig.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatConfig.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,11 +20,12 @@
*/
package org.apache.qpid.client.protocol;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
class HeartbeatConfig
{
- private static final Logger _logger = Logger.getLogger(HeartbeatConfig.class);
+ private static final Logger _logger = LoggerFactory.getLogger(HeartbeatConfig.class);
static final HeartbeatConfig CONFIG = new HeartbeatConfig();
/**
@@ -35,13 +36,13 @@ class HeartbeatConfig
HeartbeatConfig()
{
String property = System.getProperty("amqj.heartbeat.timeoutFactor");
- if(property != null)
+ if (property != null)
{
try
{
timeoutFactor = Float.parseFloat(property);
}
- catch(NumberFormatException e)
+ catch (NumberFormatException e)
{
_logger.warn("Invalid timeout factor (amqj.heartbeat.timeoutFactor): " + property);
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java
index 652468d45d..93cc5e7ec3 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,10 +20,12 @@
*/
package org.apache.qpid.client.protocol;
-import org.apache.log4j.Logger;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A MINA filter that monitors the numbers of messages pending to be sent by MINA. It outputs a message
* when a threshold has been exceeded, and has a frequency configuration so that messages are not output
@@ -32,13 +34,13 @@ import org.apache.mina.common.IoSession;
*/
public class ProtocolBufferMonitorFilter extends IoFilterAdapter
{
- private static final Logger _logger = Logger.getLogger(ProtocolBufferMonitorFilter.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ProtocolBufferMonitorFilter.class);
public static long DEFAULT_FREQUENCY = 5000;
public static int DEFAULT_THRESHOLD = 3000;
- private int _bufferedMessages = 0;
+ private int _bufferedMessages = 0;
private int _threshold;
@@ -58,7 +60,7 @@ public class ProtocolBufferMonitorFilter extends IoFilterAdapter
_outputFrequencyInMillis = frequency;
}
- public void messageReceived( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception
{
_bufferedMessages++;
if (_bufferedMessages > _threshold)
@@ -66,8 +68,8 @@ public class ProtocolBufferMonitorFilter extends IoFilterAdapter
long now = System.currentTimeMillis();
if ((now - _lastMessageOutputTime) > _outputFrequencyInMillis)
{
- _logger.warn("Protocol message buffer exceeded threshold of " + _threshold + ". Current backlog: " +
- _bufferedMessages);
+ _logger.warn("Protocol message buffer exceeded threshold of " + _threshold + ". Current backlog: "
+ + _bufferedMessages);
_lastMessageOutputTime = now;
}
}
@@ -75,7 +77,7 @@ public class ProtocolBufferMonitorFilter extends IoFilterAdapter
nextFilter.messageReceived(session, message);
}
- public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception
{
_bufferedMessages--;
nextFilter.messageSent(session, message);
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java b/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java
index 5c0f1de5bb..140cbdeb75 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java
@@ -20,10 +20,11 @@
*/
package org.apache.qpid.client.security;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import org.apache.qpid.util.FileUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
@@ -31,10 +32,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.util.FileUtils;
-
/**
* CallbackHandlerRegistry is a registry for call back handlers for user authentication and interaction during user
* authentication. It is capable of reading its configuration from a properties file containing call back handler
@@ -60,7 +57,7 @@ import org.apache.qpid.util.FileUtils;
*/
public class CallbackHandlerRegistry
{
- private static final Logger _logger = Logger.getLogger(CallbackHandlerRegistry.class);
+ private static final Logger _logger = LoggerFactory.getLogger(CallbackHandlerRegistry.class);
/** The name of the system property that holds the name of the callback handler properties file. */
private static final String FILE_PROPERTY = "amq.callbackhandler.properties";
@@ -121,7 +118,7 @@ public class CallbackHandlerRegistry
String filename = System.getProperty(FILE_PROPERTY);
InputStream is =
FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME,
- CallbackHandlerRegistry.class.getClassLoader());
+ CallbackHandlerRegistry.class.getClassLoader());
try
{
@@ -167,12 +164,12 @@ public class CallbackHandlerRegistry
_logger.error("Unable to read from file " + filename + ": " + e, e);
}
}
-
+
if (useDefault)
{
is = CallbackHandlerRegistry.class.getResourceAsStream(DEFAULT_RESOURCE_NAME);
}
-
+
return is;
}*/
@@ -207,7 +204,7 @@ public class CallbackHandlerRegistry
if (!AMQCallbackHandler.class.isAssignableFrom(clazz))
{
_logger.warn("SASL provider " + clazz + " does not implement " + AMQCallbackHandler.class
- + ". Skipping");
+ + ". Skipping");
continue;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java b/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
index 04db8044de..803b34b7fa 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
@@ -20,6 +20,13 @@
*/
package org.apache.qpid.client.security;
+import org.apache.qpid.util.FileUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.sasl.SaslClientFactory;
+
import java.io.IOException;
import java.io.InputStream;
import java.security.Security;
@@ -28,13 +35,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-import javax.security.sasl.SaslClientFactory;
-
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.util.FileUtils;
-
/**
* DynamicSaslRegistrar provides a collection of helper methods for reading a configuration file that contains a mapping
* from SASL mechanism names to implementing client factory class names and registering a security provider with the
@@ -55,7 +55,7 @@ import org.apache.qpid.util.FileUtils;
*/
public class DynamicSaslRegistrar
{
- private static final Logger _logger = Logger.getLogger(DynamicSaslRegistrar.class);
+ private static final Logger _logger = LoggerFactory.getLogger(DynamicSaslRegistrar.class);
/** The name of the system property that holds the name of the SASL configuration properties. */
private static final String FILE_PROPERTY = "amq.dynamicsaslregistrar.properties";
@@ -71,8 +71,8 @@ public class DynamicSaslRegistrar
// Open the SASL properties file, using the default name is one is not specified.
String filename = System.getProperty(FILE_PROPERTY);
InputStream is =
- FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME,
- DynamicSaslRegistrar.class.getClassLoader());
+ FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME,
+ DynamicSaslRegistrar.class.getClassLoader());
try
{
@@ -169,7 +169,7 @@ public class DynamicSaslRegistrar
Enumeration e = props.propertyNames();
TreeMap<String, Class<? extends SaslClientFactory>> factoriesToRegister =
- new TreeMap<String, Class<? extends SaslClientFactory>>();
+ new TreeMap<String, Class<? extends SaslClientFactory>>();
while (e.hasMoreElements())
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java b/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
index 5bf120454e..5a2c5ac5c1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
@@ -20,13 +20,13 @@
*/
package org.apache.qpid.client.security;
-import java.security.Provider;
-import java.security.Security;
-import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.security.sasl.SaslClientFactory;
-import org.apache.log4j.Logger;
+import java.security.Provider;
+import java.util.Map;
/**
* JCAProvider is a security provider for SASL client factories that is configured from a map of SASL mechanism names
@@ -40,7 +40,7 @@ import org.apache.log4j.Logger;
*/
public class JCAProvider extends Provider
{
- private static final Logger log = Logger.getLogger(JCAProvider.class);
+ private static final Logger log = LoggerFactory.getLogger(JCAProvider.class);
/**
* Creates the security provider with a map from SASL mechanisms to implementing factories.
@@ -50,9 +50,9 @@ public class JCAProvider extends Provider
public JCAProvider(Map<String, Class<? extends SaslClientFactory>> providerMap)
{
super("AMQSASLProvider", 1.0, "A JCA provider that registers all "
- + "AMQ SASL providers that want to be registered");
+ + "AMQ SASL providers that want to be registered");
register(providerMap);
-// Security.addProvider(this);
+ // Security.addProvider(this);
}
/**
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandler.java b/java/client/src/main/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandler.java
index 46323e8c09..66176dac3c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandler.java
@@ -20,26 +20,24 @@
*/
package org.apache.qpid.client.security;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.sasl.RealmCallback;
-
-import com.sun.crypto.provider.HmacMD5;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.client.protocol.AMQProtocolSession;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
public class UsernameHashedPasswordCallbackHandler implements AMQCallbackHandler
{
- private static final Logger _logger = Logger.getLogger(UsernameHashedPasswordCallbackHandler.class);
+ private static final Logger _logger = LoggerFactory.getLogger(UsernameHashedPasswordCallbackHandler.class);
private AMQProtocolSession _protocolSession;
@@ -91,11 +89,11 @@ public class UsernameHashedPasswordCallbackHandler implements AMQCallbackHandler
byte[] digest = md.digest();
- char[] hash = new char[digest.length ];
+ char[] hash = new char[digest.length];
int index = 0;
for (byte b : digest)
- {
+ {
hash[index++] = (char) b;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
index c995bf40da..bef3180041 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
@@ -20,12 +20,6 @@
*/
package org.apache.qpid.client.state;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.handler.BasicCancelOkMethodHandler;
import org.apache.qpid.client.handler.BasicDeliverMethodHandler;
@@ -58,13 +52,22 @@ import org.apache.qpid.framing.QueueDeleteOkBody;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArraySet;
+
/**
* The state manager is responsible for managing the state of the protocol session. <p/> For each AMQProtocolHandler
* there is a separate state manager.
*/
public class AMQStateManager implements AMQMethodListener
{
- private static final Logger _logger = Logger.getLogger(AMQStateManager.class);
+ private static final Logger _logger = LoggerFactory.getLogger(AMQStateManager.class);
+
private AMQProtocolSession _protocolSession;
/** The current state */
@@ -78,14 +81,13 @@ public class AMQStateManager implements AMQMethodListener
private final CopyOnWriteArraySet _stateListeners = new CopyOnWriteArraySet();
private final Object _stateLock = new Object();
- private static final long MAXIMUM_STATE_WAIT_TIME = 30000l;
+ private static final long MAXIMUM_STATE_WAIT_TIME = 30000L;
public AMQStateManager()
{
this(null);
}
-
public AMQStateManager(AMQProtocolSession protocolSession)
{
this(AMQState.CONNECTION_NOT_STARTED, true, protocolSession);
@@ -179,20 +181,22 @@ public class AMQStateManager implements AMQMethodListener
if (handler != null)
{
handler.methodReceived(this, _protocolSession, evt);
+
return true;
}
+
return false;
}
- protected StateAwareMethodListener findStateTransitionHandler(AMQState currentState,
- AMQMethodBody frame)
- // throws IllegalStateTransitionException
+ protected StateAwareMethodListener findStateTransitionHandler(AMQState currentState, AMQMethodBody frame)
+ // throws IllegalStateTransitionException
{
final Class clazz = frame.getClass();
if (_logger.isDebugEnabled())
{
_logger.debug("Looking for state[" + currentState + "] transition handler for frame " + clazz);
}
+
final Map classToHandlerMap = (Map) _state2HandlersMap.get(currentState);
if (classToHandlerMap == null)
@@ -201,12 +205,14 @@ public class AMQStateManager implements AMQMethodListener
// handler registered for "all" states
return findStateTransitionHandler(null, frame);
}
+
final StateAwareMethodListener handler = (StateAwareMethodListener) classToHandlerMap.get(clazz);
if (handler == null)
{
if (currentState == null)
{
_logger.debug("No state transition handler defined for receiving frame " + frame);
+
return null;
}
else
@@ -222,7 +228,6 @@ public class AMQStateManager implements AMQMethodListener
}
}
-
public void attainState(final AMQState s) throws AMQException
{
synchronized (_stateLock)
@@ -230,7 +235,7 @@ public class AMQStateManager implements AMQMethodListener
final long waitUntilTime = System.currentTimeMillis() + MAXIMUM_STATE_WAIT_TIME;
long waitTime = MAXIMUM_STATE_WAIT_TIME;
- while (_currentState != s && waitTime > 0)
+ while ((_currentState != s) && (waitTime > 0))
{
try
{
@@ -240,11 +245,13 @@ public class AMQStateManager implements AMQMethodListener
{
_logger.warn("Thread interrupted");
}
+
if (_currentState != s)
{
waitTime = waitUntilTime - System.currentTimeMillis();
}
}
+
if (_currentState != s)
{
_logger.warn("State not achieved within permitted time. Current state " + _currentState + ", desired state: " + s);
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/StateWaiter.java b/java/client/src/main/java/org/apache/qpid/client/state/StateWaiter.java
index 1fd657c5fb..8b8453a1b0 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/StateWaiter.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/StateWaiter.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,15 +20,17 @@
*/
package org.apache.qpid.client.state;
-import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Waits for a particular state to be reached.
*/
public class StateWaiter implements StateListener
{
- private static final Logger _logger = Logger.getLogger(StateWaiter.class);
+ private static final Logger _logger = LoggerFactory.getLogger(StateWaiter.class);
private final AMQState _state;
@@ -52,13 +54,13 @@ public class StateWaiter implements StateListener
// The guard is required in case we are woken up by a spurious
// notify().
//
- while (!_newStateAchieved && _throwable == null)
+ while (!_newStateAchieved && (_throwable == null))
{
try
{
_logger.debug("State " + _state + " not achieved so waiting...");
_monitor.wait(TIME_OUT);
- //fixme this won't cause the timeout to exit the loop. need to set _throwable
+ // fixme this won't cause the timeout to exit the loop. need to set _throwable
}
catch (InterruptedException e)
{
@@ -72,7 +74,7 @@ public class StateWaiter implements StateListener
_logger.debug("Throwable reached state waiter: " + _throwable);
if (_throwable instanceof AMQException)
{
- throw(AMQException) _throwable;
+ throw (AMQException) _throwable;
}
else
{
@@ -89,6 +91,7 @@ public class StateWaiter implements StateListener
{
_logger.debug("stateChanged called changing from :" + oldState + " to :" + newState);
}
+
if (_state == newState)
{
_newStateAchieved = true;
@@ -97,6 +100,7 @@ public class StateWaiter implements StateListener
{
_logger.debug("New state reached so notifying monitor");
}
+
_monitor.notifyAll();
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java b/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
index 1c70ded62a..623591e0b6 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
@@ -34,7 +34,7 @@ public class SpecificMethodFrameListener extends BlockingMethodFrameListener
_expectedClass = expectedClass;
}
- public boolean processMethod(int channelId, AMQMethodBody frame) throws AMQException
+ public boolean processMethod(int channelId, AMQMethodBody frame) //throws AMQException
{
return _expectedClass.isInstance(frame);
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
index 04e7e40564..5482e48699 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,28 +20,32 @@
*/
package org.apache.qpid.client.transport;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoConnector;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
import org.apache.mina.transport.socket.nio.SocketSessionConfig;
+
import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.pool.ReadWriteThreadModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
public class SocketTransportConnection implements ITransportConnection
{
- private static final Logger _logger = Logger.getLogger(SocketTransportConnection.class);
+ private static final Logger _logger = LoggerFactory.getLogger(SocketTransportConnection.class);
private static final int DEFAULT_BUFFER_SIZE = 32 * 1024;
private SocketConnectorFactory _socketConnectorFactory;
- static interface SocketConnectorFactory {
+ static interface SocketConnectorFactory
+ {
IoConnector newSocketConnector();
}
@@ -50,8 +54,7 @@ public class SocketTransportConnection implements ITransportConnection
_socketConnectorFactory = socketConnectorFactory;
}
- public void connect(AMQProtocolHandler protocolHandler, BrokerDetails brokerDetail)
- throws IOException
+ public void connect(AMQProtocolHandler protocolHandler, BrokerDetails brokerDetail) throws IOException
{
ByteBuffer.setUseDirectBuffers(Boolean.getBoolean("amqj.enableDirectBuffers"));
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java
index b9193ce14e..459579d920 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java
@@ -20,13 +20,6 @@
*/
package org.apache.qpid.client.transport;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
import org.apache.mina.common.IoConnector;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoServiceConfig;
@@ -34,11 +27,18 @@ import org.apache.mina.transport.socket.nio.SocketConnector;
import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
-import org.apache.qpid.client.AMQBrokerDetails;
import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.pool.ReadWriteThreadModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
/**
* The TransportConnection is a helper class responsible for connecting to an AMQ server. It sets up the underlying
* connector, which currently always uses TCP/IP sockets. It creates the "protocol handler" which deals with MINA
@@ -57,7 +57,7 @@ public class TransportConnection
private static final int TCP = 0;
private static final int VM = 1;
- private static Logger _logger = Logger.getLogger(TransportConnection.class);
+ private static Logger _logger = LoggerFactory.getLogger(TransportConnection.class);
private static final String DEFAULT_QPID_SERVER = "org.apache.qpid.server.protocol.AMQPFastProtocolHandler";
@@ -99,7 +99,7 @@ public class TransportConnection
// FIXME - this needs to be sorted to use the new Mina MultiThread SA.
if (Boolean.getBoolean("qpidnio"))
{
- _logger.fatal("Using Qpid NIO - sysproperty 'qpidnio' is set.");
+ _logger.error("Using Qpid NIO - sysproperty 'qpidnio' is set.");
// result = new org.apache.qpid.nio.SocketConnector(); // non-blocking connector
}
// else
@@ -193,7 +193,7 @@ public class TransportConnection
}
catch (IOException e)
{
- _logger.error(e);
+ _logger.error("Got IOException.", e);
// Try and unbind provider
try
@@ -262,7 +262,6 @@ public class TransportConnection
catch (Exception e)
{
_logger.info("Unable to create InVM Qpid.AMQP on port " + port + ". Because: " + e.getCause());
- _logger.error(e);
String because;
if (e.getCause() == null)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
index 104c4b43d0..d9137dc8b1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,21 +20,25 @@
*/
package org.apache.qpid.client.transport;
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
import org.apache.mina.transport.vmpipe.VmPipeConnector;
+
import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.pool.PoolingFilter;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
+import org.apache.qpid.pool.ReadWriteThreadModel;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
public class VmPipeTransportConnection implements ITransportConnection
{
- private static final Logger _logger = Logger.getLogger(VmPipeTransportConnection.class);
+ private static final Logger _logger = LoggerFactory.getLogger(VmPipeTransportConnection.class);
private static int _port;
@@ -47,14 +51,9 @@ public class VmPipeTransportConnection implements ITransportConnection
{
final VmPipeConnector ioConnector = new VmPipeConnector();
final IoServiceConfig cfg = ioConnector.getDefaultConfig();
- ReferenceCountingExecutorService executorService = ReferenceCountingExecutorService.getInstance();
- PoolingFilter asyncRead = PoolingFilter.createAynschReadPoolingFilter(executorService,
- "AsynchronousReadFilter");
- cfg.getFilterChain().addFirst("AsynchronousReadFilter", asyncRead);
- PoolingFilter asyncWrite = PoolingFilter.createAynschWritePoolingFilter(executorService,
- "AsynchronousWriteFilter");
- cfg.getFilterChain().addLast("AsynchronousWriteFilter", asyncWrite);
-
+
+ cfg.setThreadModel(ReadWriteThreadModel.getInstance());
+
final VmPipeAddress address = new VmPipeAddress(_port);
_logger.info("Attempting connection to " + address);
ConnectFuture future = ioConnector.connect(address, protocolHandler);
diff --git a/java/client/src/main/java/org/apache/qpid/client/util/FlowControllingBlockingQueue.java b/java/client/src/main/java/org/apache/qpid/client/util/FlowControllingBlockingQueue.java
index 642b928d81..0fc39a9318 100644
--- a/java/client/src/main/java/org/apache/qpid/client/util/FlowControllingBlockingQueue.java
+++ b/java/client/src/main/java/org/apache/qpid/client/util/FlowControllingBlockingQueue.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,16 +20,17 @@
*/
package org.apache.qpid.client.util;
-
+import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
-import java.util.Iterator;
/**
* A blocking queue that emits events above a user specified threshold allowing the caller to take action (e.g. flow
* control) to try to prevent the queue growing (much) further. The underlying queue itself is not bounded therefore the
* caller is not obliged to react to the events. <p/> This implementation is <b>only</b> safe where we have a single
* thread adding items and a single (different) thread removing items.
+ *
+ * @todo Make this implement java.util.Queue and hide the implementation. Then different queue types can be substituted.
*/
public class FlowControllingBlockingQueue
{
@@ -81,6 +82,7 @@ public class FlowControllingBlockingQueue
}
}
}
+
return o;
}
@@ -104,4 +106,3 @@ public class FlowControllingBlockingQueue
return _queue.iterator();
}
}
-
diff --git a/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java b/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
index 6ad3fb4bae..6ec883ff0b 100644
--- a/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
+++ b/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,22 +20,23 @@
*/
package org.apache.qpid.jms;
-import org.apache.log4j.Logger;
import org.apache.qpid.jms.failover.FailoverMethod;
import org.apache.qpid.jms.failover.FailoverRoundRobinServers;
import org.apache.qpid.jms.failover.FailoverSingleServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class FailoverPolicy
{
- private static final Logger _logger = Logger.getLogger(FailoverPolicy.class);
+ private static final Logger _logger = LoggerFactory.getLogger(FailoverPolicy.class);
private static final long MINUTE = 60000L;
private static final long DEFAULT_METHOD_TIMEOUT = 1 * MINUTE;
private static final long DEFAULT_FAILOVER_TIMEOUT = 4 * MINUTE;
- private FailoverMethod _methods[] = new FailoverMethod[1];
+ private FailoverMethod[] _methods = new FailoverMethod[1];
private int _currentMethod;
@@ -52,7 +53,7 @@ public class FailoverPolicy
{
FailoverMethod method;
- //todo This should be integrated in to the connection url when it supports
+ // todo This should be integrated in to the connection url when it supports
// multiple strategies.
_methodsRetries = 0;
@@ -72,12 +73,12 @@ public class FailoverPolicy
{
String failoverMethod = connectionDetails.getFailoverMethod();
-/*
- if (failoverMethod.equals(FailoverMethod.RANDOM))
- {
- //todo write a random connection Failover
- }
-*/
+ /*
+ if (failoverMethod.equals(FailoverMethod.RANDOM))
+ {
+ //todo write a random connection Failover
+ }
+ */
if (failoverMethod.equals(FailoverMethod.SINGLE_BROKER))
{
method = new FailoverRoundRobinServers(connectionDetails);
@@ -92,12 +93,12 @@ public class FailoverPolicy
{
try
{
- Class[] constructorSpec = {ConnectionURL.class};
- Object [] params = {connectionDetails};
+ Class[] constructorSpec = { ConnectionURL.class };
+ Object[] params = { connectionDetails };
- method = (FailoverMethod) ClassLoader.getSystemClassLoader().
- loadClass(failoverMethod).
- getConstructor(constructorSpec).newInstance(params);
+ method =
+ (FailoverMethod) ClassLoader.getSystemClassLoader().loadClass(failoverMethod)
+ .getConstructor(constructorSpec).newInstance(params);
}
catch (Exception cnfe)
{
@@ -157,13 +158,13 @@ public class FailoverPolicy
return false;
}
-
}
else
{
if ((now - _lastFailTime) >= DEFAULT_FAILOVER_TIMEOUT)
{
_logger.info("Failover timeout");
+
return false;
}
else
@@ -179,7 +180,6 @@ public class FailoverPolicy
_lastFailTime = _lastMethodTime;
}
-
if (_methods[_currentMethod].failoverAllowed())
{
failoverAllowed = true;
@@ -190,6 +190,7 @@ public class FailoverPolicy
{
nextMethod();
_logger.info("Changing method to " + _methods[_currentMethod].methodName());
+
return failoverAllowed();
}
else
@@ -207,6 +208,7 @@ public class FailoverPolicy
{
_currentMethod++;
_methods[_currentMethod].reset();
+
return true;
}
else
@@ -225,11 +227,13 @@ public class FailoverPolicy
_logger.info("Retrying methods starting with " + _methods[_currentMethod].methodName());
_methods[_currentMethod].reset();
+
return failoverAllowed();
}
else
{
_logger.debug("All failover methods exhausted");
+
return false;
}
}
@@ -278,7 +282,7 @@ public class FailoverPolicy
public FailoverMethod getCurrentMethod()
{
- if (_currentMethod >= 0 && _currentMethod < (_methods.length - 1))
+ if ((_currentMethod >= 0) && (_currentMethod < (_methods.length - 1)))
{
return _methods[_currentMethod];
}
@@ -311,6 +315,7 @@ public class FailoverPolicy
{
sb.append(">");
}
+
sb.append(_methods[i].toString());
}
diff --git a/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java b/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java
index f8325c35ef..4e0d0b79b5 100644
--- a/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java
+++ b/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,13 +20,15 @@
*/
package org.apache.qpid.jms.failover;
-import org.apache.log4j.Logger;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionURL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class FailoverRoundRobinServers implements FailoverMethod
{
- private static final Logger _logger = Logger.getLogger(FailoverRoundRobinServers.class);
+ private static final Logger _logger = LoggerFactory.getLogger(FailoverRoundRobinServers.class);
/** The default number of times to cycle through all servers */
public static final int DEFAULT_CYCLE_RETRIES = 0;
@@ -72,7 +74,7 @@ public class FailoverRoundRobinServers implements FailoverMethod
_connectionDetails = connectionDetails;
- //There is no current broker at startup so set it to -1.
+ // There is no current broker at startup so set it to -1.
_currentBrokerIndex = -1;
String cycleRetries = _connectionDetails.getFailoverOption(ConnectionURL.OPTIONS_FAILOVER_CYCLE);
@@ -104,9 +106,8 @@ public class FailoverRoundRobinServers implements FailoverMethod
public boolean failoverAllowed()
{
- return ((_currentCycleRetries < _cycleRetries)
- || (_currentServerRetry < _serverRetries)
- || (_currentBrokerIndex < (_connectionDetails.getBrokerCount() - 1)));
+ return ((_currentCycleRetries < _cycleRetries) || (_currentServerRetry < _serverRetries)
+ || (_currentBrokerIndex < (_connectionDetails.getBrokerCount() - 1)));
}
public void attainedConnection()
@@ -125,8 +126,6 @@ public class FailoverRoundRobinServers implements FailoverMethod
return _connectionDetails.getBrokerDetails(_currentBrokerIndex);
}
-
-
public BrokerDetails getNextBrokerDetails()
{
if (_currentBrokerIndex == (_connectionDetails.getBrokerCount() - 1))
@@ -137,7 +136,7 @@ public class FailoverRoundRobinServers implements FailoverMethod
{
_currentBrokerIndex = 0;
- setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex ));
+ setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex));
_logger.info("First run using " + _connectionDetails.getBrokerDetails(_currentBrokerIndex));
}
@@ -151,15 +150,15 @@ public class FailoverRoundRobinServers implements FailoverMethod
else
{
_currentCycleRetries++;
- //failed to connect to first broker
+ // failed to connect to first broker
_currentBrokerIndex = 0;
- setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex ));
+ setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex));
// This is zero rather than -1 as we are already retrieving the details.
_currentServerRetry = 0;
}
- //else - should force client to stop as max retries has been reached.
+ // else - should force client to stop as max retries has been reached.
}
else
{
@@ -169,7 +168,7 @@ public class FailoverRoundRobinServers implements FailoverMethod
{
_currentBrokerIndex = 0;
- setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex ));
+ setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex));
_logger.info("First run using " + _connectionDetails.getBrokerDetails(_currentBrokerIndex));
}
@@ -177,13 +176,14 @@ public class FailoverRoundRobinServers implements FailoverMethod
{
_logger.info("Retrying " + _connectionDetails.getBrokerDetails(_currentBrokerIndex));
}
+
_currentServerRetry++;
}
else
{
_currentBrokerIndex++;
- setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex ));
+ setBroker(_connectionDetails.getBrokerDetails(_currentBrokerIndex));
// This is zero rather than -1 as we are already retrieving the details.
_currentServerRetry = 0;
}
@@ -192,7 +192,6 @@ public class FailoverRoundRobinServers implements FailoverMethod
return _connectionDetails.getBrokerDetails(_currentBrokerIndex);
}
-
public void setBroker(BrokerDetails broker)
{
@@ -246,12 +245,13 @@ public class FailoverRoundRobinServers implements FailoverMethod
sb.append(_currentBrokerIndex);
sb.append("\n");
- for(int i=0; i < _connectionDetails.getBrokerCount() ; i++)
+ for (int i = 0; i < _connectionDetails.getBrokerCount(); i++)
{
if (i == _currentBrokerIndex)
{
sb.append(">");
}
+
sb.append(_connectionDetails.getBrokerDetails(i));
sb.append("\n");
}
diff --git a/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java b/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
index 4f6f1561b6..a46c7f3cd5 100644
--- a/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
+++ b/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,38 +20,40 @@
*/
package org.apache.qpid.jndi;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Queue;
-import javax.jms.Topic;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQHeadersExchange;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.url.AMQBindingURL;
import org.apache.qpid.url.BindingURL;
import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.exchange.ExchangeDefaults;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
public class PropertiesFileInitialContextFactory implements InitialContextFactory
{
- protected final Logger _logger = Logger.getLogger(PropertiesFileInitialContextFactory.class);
+ protected final Logger _logger = LoggerFactory.getLogger(PropertiesFileInitialContextFactory.class);
private String CONNECTION_FACTORY_PREFIX = "connectionfactory.";
private String DESTINATION_PREFIX = "destination.";
@@ -78,7 +80,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
if (file != null)
{
_logger.info("Loading Properties from:" + file);
- //Load the properties specified
+ // Load the properties specified
Properties p = new Properties();
p.load(new BufferedInputStream(new FileInputStream(file)));
@@ -93,8 +95,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
}
catch (IOException ioe)
{
- _logger.warn("Unable to load property file specified in Provider_URL:" +
- environment.get(Context.PROVIDER_URL));
+ _logger.warn("Unable to load property file specified in Provider_URL:" + environment.get(Context.PROVIDER_URL));
}
createConnectionFactories(data, environment);
@@ -109,7 +110,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
}
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
protected ReadOnlyContext createContext(Map data, Hashtable environment)
{
return new ReadOnlyContext(environment, data);
@@ -200,6 +201,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
{
_logger.warn("Unable to createFactories:" + urlse);
}
+
return null;
}
@@ -216,6 +218,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
catch (URLSyntaxException urlse)
{
_logger.warn("Unable to destination:" + urlse);
+
return null;
}
@@ -226,6 +229,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
catch (IllegalArgumentException iaw)
{
_logger.warn("Binding: '" + binding + "' not supported");
+
return null;
}
}
@@ -235,17 +239,15 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
*/
protected Queue createQueue(Object value)
{
- if(value instanceof AMQShortString)
+ if (value instanceof AMQShortString)
{
return new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, (AMQShortString) value);
}
else if (value instanceof String)
-
{
return new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString((String) value));
}
else if (value instanceof BindingURL)
-
{
return new AMQQueue((BindingURL) value);
}
@@ -258,16 +260,15 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
*/
protected Topic createTopic(Object value)
{
- if(value instanceof AMQShortString)
+ if (value instanceof AMQShortString)
{
- return new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, (AMQShortString)value);
+ return new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, (AMQShortString) value);
}
else if (value instanceof String)
{
return new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, new AMQShortString((String) value));
}
else if (value instanceof BindingURL)
-
{
return new AMQTopic((BindingURL) value);
}
@@ -293,7 +294,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public String getConnectionPrefix()
{
return CONNECTION_FACTORY_PREFIX;
diff --git a/java/client/src/test/java/org/apache/qpid/client/DispatcherTest.java b/java/client/src/test/java/org/apache/qpid/client/DispatcherTest.java
index 1d85ea47fd..7cca22de6c 100644
--- a/java/client/src/test/java/org/apache/qpid/client/DispatcherTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/DispatcherTest.java
@@ -20,9 +20,13 @@
*/
package org.apache.qpid.client;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@@ -36,11 +40,9 @@ import javax.jms.Session;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery queue
@@ -56,7 +58,7 @@ import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
*/
public class DispatcherTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(DispatcherTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(DispatcherTest.class);
Context _context;
@@ -68,8 +70,8 @@ public class DispatcherTest extends TestCase
MessageProducer _producer;
Session _clientSession, _producerSession;
- private final CountDownLatch _allFirstMessagesSent = new CountDownLatch(1); //all messages Sent Lock
- private final CountDownLatch _allSecondMessagesSent = new CountDownLatch(1); //all messages Sent Lock
+ private final CountDownLatch _allFirstMessagesSent = new CountDownLatch(1); // all messages Sent Lock
+ private final CountDownLatch _allSecondMessagesSent = new CountDownLatch(1); // all messages Sent Lock
private volatile boolean _connectionStopped = false;
@@ -89,14 +91,14 @@ public class DispatcherTest extends TestCase
Queue queue = (Queue) _context.lookup("queue");
- //Create Client 1
+ // Create Client 1
_clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_clientSession = _clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_consumer = _clientSession.createConsumer(queue);
- //Create Producer
+ // Create Producer
_producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_producerConnection.start();
@@ -109,7 +111,6 @@ public class DispatcherTest extends TestCase
{
_producer.send(_producerSession.createTextMessage("Message " + msg));
}
-
}
protected void tearDown() throws Exception
@@ -122,67 +123,63 @@ public class DispatcherTest extends TestCase
TransportConnection.killAllVMBrokers();
}
-
public void testAsynchronousRecieve()
{
-
_logger.info("Test Start");
-
assertTrue(!((AMQConnection) _clientConnection).started());
- //Set default Message Listener
+ // Set default Message Listener
try
{
_consumer.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 1 ML 1 Received Message(" + _receivedCount + "):" + message);
+ public void onMessage(Message message)
+ {
+ _logger.info("Client 1 ML 1 Received Message(" + _receivedCount + "):" + message);
- _receivedCount++;
+ _receivedCount++;
- if (_receivedCount == MSG_COUNT)
- {
- _allFirstMessagesSent.countDown();
- }
+ if (_receivedCount == MSG_COUNT)
+ {
+ _allFirstMessagesSent.countDown();
+ }
- if (_connectionStopped)
- {
- _logger.info("Running with Message:" + _receivedCount);
- }
+ if (_connectionStopped)
+ {
+ _logger.info("Running with Message:" + _receivedCount);
+ }
- if (_connectionStopped && _allFirstMessagesSent.getCount() == 0)
- {
- _receivedCountWhileStopped++;
- }
+ if (_connectionStopped && (_allFirstMessagesSent.getCount() == 0))
+ {
+ _receivedCountWhileStopped++;
+ }
- if (_allFirstMessagesSent.getCount() == 0)
- {
- if (_receivedCount == MSG_COUNT * 2)
+ if (_allFirstMessagesSent.getCount() == 0)
{
- _allSecondMessagesSent.countDown();
+ if (_receivedCount == (MSG_COUNT * 2))
+ {
+ _allSecondMessagesSent.countDown();
+ }
}
}
- }
- });
-
+ });
+
assertTrue("Connecion should not be started", !((AMQConnection) _clientConnection).started());
- _clientConnection.start();
+ _clientConnection.start();
}
catch (JMSException e)
{
_logger.error("Error Setting Default ML on consumer1");
}
-
try
{
_allFirstMessagesSent.await(1000, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
try
@@ -196,7 +193,6 @@ public class DispatcherTest extends TestCase
_logger.error("Error stopping connection");
}
-
try
{
_logger.error("Send additional messages");
@@ -211,14 +207,13 @@ public class DispatcherTest extends TestCase
_logger.error("Unable to send additional messages", e);
}
-
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
- //ignore
+ // ignore
}
try
@@ -233,7 +228,6 @@ public class DispatcherTest extends TestCase
_logger.error("Error Setting Better ML on consumer1", e);
}
-
_logger.info("Waiting upto 2 seconds for messages");
try
@@ -242,17 +236,15 @@ public class DispatcherTest extends TestCase
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
assertEquals("Messages not received correctly", 0, _allFirstMessagesSent.getCount());
assertEquals("Messages not received correctly", 0, _allSecondMessagesSent.getCount());
assertEquals("Client didn't get all messages", MSG_COUNT * 2, _receivedCount);
assertEquals("Messages received while stopped is not 0", 0, _receivedCountWhileStopped);
-
}
-
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(DispatcherTest.class);
diff --git a/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerImmediatePrefetch.java b/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerImmediatePrefetch.java
index 9e48914431..7461f6c200 100644
--- a/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerImmediatePrefetch.java
+++ b/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerImmediatePrefetch.java
@@ -20,27 +20,6 @@
*/
package org.apache.qpid.client;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.spi.InitialContextFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
-
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery
* queue <p/> The message delivery process: Mina puts a message on _queue in AMQSession and the dispatcher thread
@@ -52,17 +31,12 @@ import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
*/
public class MessageListenerMultiConsumerImmediatePrefetch extends MessageListenerMultiConsumerTest
{
-
-
protected void setUp() throws Exception
{
-
System.setProperty(AMQSession.IMMEDIATE_PREFETCH, "true");
super.setUp();
-
}
-
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(MessageListenerMultiConsumerImmediatePrefetch.class);
diff --git a/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java b/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
index c9407d8ff6..20632e245f 100644
--- a/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
@@ -20,9 +20,13 @@
*/
package org.apache.qpid.client;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@@ -35,11 +39,9 @@ import javax.jms.Session;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery
@@ -52,7 +54,7 @@ import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
*/
public class MessageListenerMultiConsumerTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(MessageListenerMultiConsumerTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(MessageListenerMultiConsumerTest.class);
Context _context;
@@ -64,8 +66,7 @@ public class MessageListenerMultiConsumerTest extends TestCase
private MessageConsumer _consumer2;
private Session _clientSession1;
private Queue _queue;
- private final CountDownLatch _allMessagesSent = new CountDownLatch(2); //all messages Sent Lock
-
+ private final CountDownLatch _allMessagesSent = new CountDownLatch(2); // all messages Sent Lock
protected void setUp() throws Exception
{
@@ -77,13 +78,13 @@ public class MessageListenerMultiConsumerTest extends TestCase
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("connectionfactory.connection", "amqp://guest:guest@MLT_ID/test?brokerlist='vm://:1'");
- env.put("queue.queue", "direct://amq.direct//"+this.getClass().getName());
+ env.put("queue.queue", "direct://amq.direct//" + this.getClass().getName());
_context = factory.getInitialContext(env);
_queue = (Queue) _context.lookup("queue");
- //Create Client 1
+ // Create Client 1
_clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_clientConnection.start();
@@ -92,17 +93,16 @@ public class MessageListenerMultiConsumerTest extends TestCase
_consumer1 = _clientSession1.createConsumer(_queue);
- //Create Client 2
+ // Create Client 2
Session clientSession2 = _clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_consumer2 = clientSession2.createConsumer(_queue);
- //Create Producer
+ // Create Producer
Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
producerConnection.start();
-
Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = producerSession.createProducer(_queue);
@@ -124,18 +124,18 @@ public class MessageListenerMultiConsumerTest extends TestCase
TransportConnection.killAllVMBrokers();
}
-
public void testRecieveInterleaved() throws Exception
{
int msg = 0;
int MAX_LOOPS = MSG_COUNT * 2;
- for (int loops = 0; msg < MSG_COUNT || loops < MAX_LOOPS; loops++)
+ for (int loops = 0; (msg < MSG_COUNT) || (loops < MAX_LOOPS); loops++)
{
if (_consumer1.receive(100) != null)
{
msg++;
}
+
if (_consumer2.receive(100) != null)
{
msg++;
@@ -145,39 +145,37 @@ public class MessageListenerMultiConsumerTest extends TestCase
assertEquals("Not all messages received.", MSG_COUNT, msg);
}
-
public void testAsynchronousRecieve() throws Exception
{
_consumer1.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 1 Received Message(" + receivedCount1 + "):" + message);
+ public void onMessage(Message message)
+ {
+ _logger.info("Client 1 Received Message(" + receivedCount1 + "):" + message);
- receivedCount1++;
+ receivedCount1++;
- if (receivedCount1 == MSG_COUNT / 2)
- {
- _allMessagesSent.countDown();
- }
+ if (receivedCount1 == (MSG_COUNT / 2))
+ {
+ _allMessagesSent.countDown();
+ }
- }
- });
+ }
+ });
_consumer2.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 2 Received Message(" + receivedCount2 + "):" + message);
-
- receivedCount2++;
- if (receivedCount2 == MSG_COUNT / 2)
+ public void onMessage(Message message)
{
- _allMessagesSent.countDown();
- }
- }
- });
+ _logger.info("Client 2 Received Message(" + receivedCount2 + "):" + message);
+ receivedCount2++;
+ if (receivedCount2 == (MSG_COUNT / 2))
+ {
+ _allMessagesSent.countDown();
+ }
+ }
+ });
_logger.info("Waiting upto 2 seconds for messages");
@@ -187,7 +185,7 @@ public class MessageListenerMultiConsumerTest extends TestCase
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
assertEquals(MSG_COUNT, receivedCount1 + receivedCount2);
@@ -195,34 +193,37 @@ public class MessageListenerMultiConsumerTest extends TestCase
public void testRecieveC2Only() throws Exception
{
- if (!Boolean.parseBoolean(System.getProperties().
- getProperty(AMQSession.IMMEDIATE_PREFETCH, AMQSession.IMMEDIATE_PREFETCH_DEFAULT)))
+ if (
+ !Boolean.parseBoolean(
+ System.getProperties().getProperty(AMQSession.IMMEDIATE_PREFETCH,
+ AMQSession.IMMEDIATE_PREFETCH_DEFAULT)))
{
_logger.info("Performing Receive only on C2");
for (int msg = 0; msg < MSG_COUNT; msg++)
{
- assertTrue(MSG_COUNT + " msg should be received. Only received:" + msg,
- _consumer2.receive(1000) != null);
+ assertTrue(MSG_COUNT + " msg should be received. Only received:" + msg, _consumer2.receive(1000) != null);
}
}
}
public void testRecieveBoth() throws Exception
{
- if (!Boolean.parseBoolean(System.getProperties().
- getProperty(AMQSession.IMMEDIATE_PREFETCH, AMQSession.IMMEDIATE_PREFETCH_DEFAULT)))
+ if (
+ !Boolean.parseBoolean(
+ System.getProperties().getProperty(AMQSession.IMMEDIATE_PREFETCH,
+ AMQSession.IMMEDIATE_PREFETCH_DEFAULT)))
{
_logger.info("Performing Receive only with two consumers on one session ");
MessageConsumer consumer2 = _clientSession1.createConsumer(_queue);
- for (int msg = 0; msg < MSG_COUNT / 2; msg++)
+ for (int msg = 0; msg < (MSG_COUNT / 2); msg++)
{
assertTrue(_consumer1.receive() != null);
}
- for (int msg = 0; msg < MSG_COUNT / 2; msg++)
+ for (int msg = 0; msg < (MSG_COUNT / 2); msg++)
{
assertTrue(consumer2.receive() != null);
}
@@ -231,20 +232,19 @@ public class MessageListenerMultiConsumerTest extends TestCase
{
_logger.info("Performing Receive only on both C1 and C2");
- for (int msg = 0; msg < MSG_COUNT / 2; msg++)
+ for (int msg = 0; msg < (MSG_COUNT / 2); msg++)
{
assertTrue(_consumer1.receive() != null);
}
- for (int msg = 0; msg < MSG_COUNT / 2; msg++)
+ for (int msg = 0; msg < (MSG_COUNT / 2); msg++)
{
assertTrue(_consumer2.receive() != null);
}
}
}
-
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(MessageListenerMultiConsumerTest.class);
diff --git a/java/client/src/test/java/org/apache/qpid/client/MessageListenerTest.java b/java/client/src/test/java/org/apache/qpid/client/MessageListenerTest.java
index b15742f3aa..87630fad5b 100644
--- a/java/client/src/test/java/org/apache/qpid/client/MessageListenerTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/MessageListenerTest.java
@@ -14,15 +14,19 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.client;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@@ -35,13 +39,9 @@ import javax.jms.Session;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
-import org.apache.qpid.url.BindingURL;
-import org.apache.qpid.url.AMQBindingURL;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery
@@ -54,7 +54,7 @@ import org.apache.qpid.url.AMQBindingURL;
*/
public class MessageListenerTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(MessageListenerTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(MessageListenerTest.class);
Context _context;
@@ -73,6 +73,7 @@ public class MessageListenerTest extends TestCase implements MessageListener
{
TransportConnection.createVMBroker(1);
}
+
InitialContextFactory factory = new PropertiesFileInitialContextFactory();
Hashtable<String, String> env = new Hashtable<String, String>();
@@ -84,7 +85,7 @@ public class MessageListenerTest extends TestCase implements MessageListener
Queue queue = (Queue) _context.lookup("queue");
- //Create Client
+ // Create Client
_clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_clientConnection.start();
@@ -93,7 +94,7 @@ public class MessageListenerTest extends TestCase implements MessageListener
_consumer = clientSession.createConsumer(queue);
- //Create Producer
+ // Create Producer
Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
@@ -123,7 +124,6 @@ public class MessageListenerTest extends TestCase implements MessageListener
}
}
-
public void testSynchronousRecieve() throws Exception
{
for (int msg = 0; msg < MSG_COUNT; msg++)
@@ -144,9 +144,9 @@ public class MessageListenerTest extends TestCase implements MessageListener
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
- //Should have recieved all async messages
+ // Should have recieved all async messages
assertEquals(MSG_COUNT, receivedCount);
}
@@ -156,11 +156,11 @@ public class MessageListenerTest extends TestCase implements MessageListener
_logger.error("Test disabled as initial receive is not called first");
// Perform initial receive to start connection
-// assertTrue(_consumer.receive(2000) != null);
-// receivedCount++;
+ // assertTrue(_consumer.receive(2000) != null);
+ // receivedCount++;
// Sleep to ensure remaining 4 msgs end up on _synchronousQueue
-// Thread.sleep(1000);
+ // Thread.sleep(1000);
// Set the message listener and wait for the messages to come in.
_consumer.setMessageListener(this);
@@ -173,14 +173,13 @@ public class MessageListenerTest extends TestCase implements MessageListener
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
- //Should have recieved all async messages
+ // Should have recieved all async messages
assertEquals(MSG_COUNT, receivedCount);
}
-
public void onMessage(Message message)
{
_logger.info("Received Message(" + receivedCount + "):" + message);
diff --git a/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java b/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java
index 97fbf9876f..5f7ca69554 100644
--- a/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java
@@ -20,9 +20,13 @@
*/
package org.apache.qpid.client;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@@ -36,11 +40,9 @@ import javax.jms.Session;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery
@@ -53,7 +55,7 @@ import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
*/
public class ResetMessageListenerTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(ResetMessageListenerTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ResetMessageListenerTest.class);
Context _context;
@@ -67,8 +69,8 @@ public class ResetMessageListenerTest extends TestCase
MessageProducer _producer;
Session _clientSession, _producerSession;
- private final CountDownLatch _allFirstMessagesSent = new CountDownLatch(2); //all messages Sent Lock
- private final CountDownLatch _allSecondMessagesSent = new CountDownLatch(2); //all messages Sent Lock
+ private final CountDownLatch _allFirstMessagesSent = new CountDownLatch(2); // all messages Sent Lock
+ private final CountDownLatch _allSecondMessagesSent = new CountDownLatch(2); // all messages Sent Lock
protected void setUp() throws Exception
{
@@ -88,17 +90,17 @@ public class ResetMessageListenerTest extends TestCase
Queue queue = (Queue) _context.lookup("queue");
- //Create Client 1
+ // Create Client 1
_clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_clientSession = _clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_consumer1 = _clientSession.createConsumer(queue);
- //Create Client 2 on same session
+ // Create Client 2 on same session
_consumer2 = _clientSession.createConsumer(queue);
- //Create Producer
+ // Create Producer
_producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
_producerConnection.start();
@@ -129,57 +131,55 @@ public class ResetMessageListenerTest extends TestCase
TransportConnection.killAllVMBrokers();
}
-
public void testAsynchronousRecieve()
{
_logger.info("Test Start");
- //Set default Message Listener
+ // Set default Message Listener
try
{
_consumer1.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 1 ML 1 Received Message(" + receivedCount1ML1 + "):" + message);
-
- receivedCount1ML1++;
- if (receivedCount1ML1 == MSG_COUNT / 2)
+ public void onMessage(Message message)
{
- _allFirstMessagesSent.countDown();
+ _logger.info("Client 1 ML 1 Received Message(" + receivedCount1ML1 + "):" + message);
+
+ receivedCount1ML1++;
+ if (receivedCount1ML1 == (MSG_COUNT / 2))
+ {
+ _allFirstMessagesSent.countDown();
+ }
}
- }
- });
+ });
}
catch (JMSException e)
{
_logger.error("Error Setting Default ML on consumer1");
}
-
try
{
_consumer2.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 2 Received Message(" + receivedCount2 + "):" + message);
-
- receivedCount2++;
- if (receivedCount2 == MSG_COUNT / 2)
+ public void onMessage(Message message)
{
- _logger.info("Client 2 received all its messages1");
- _allFirstMessagesSent.countDown();
+ _logger.info("Client 2 Received Message(" + receivedCount2 + "):" + message);
+
+ receivedCount2++;
+ if (receivedCount2 == (MSG_COUNT / 2))
+ {
+ _logger.info("Client 2 received all its messages1");
+ _allFirstMessagesSent.countDown();
+ }
+
+ if (receivedCount2 == MSG_COUNT)
+ {
+ _logger.info("Client 2 received all its messages2");
+ _allSecondMessagesSent.countDown();
+ }
}
-
- if (receivedCount2 == MSG_COUNT)
- {
- _logger.info("Client 2 received all its messages2");
- _allSecondMessagesSent.countDown();
- }
- }
- });
+ });
_clientConnection.start();
}
@@ -189,7 +189,6 @@ public class ResetMessageListenerTest extends TestCase
}
-
try
{
_allFirstMessagesSent.await(1000, TimeUnit.MILLISECONDS);
@@ -197,7 +196,7 @@ public class ResetMessageListenerTest extends TestCase
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
try
@@ -213,18 +212,18 @@ public class ResetMessageListenerTest extends TestCase
try
{
_consumer1.setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _logger.info("Client 1 ML2 Received Message(" + receivedCount1ML1 + "):" + message);
-
- receivedCount1ML2++;
- if (receivedCount1ML2 == MSG_COUNT / 2)
+ public void onMessage(Message message)
{
- _allSecondMessagesSent.countDown();
+ _logger.info("Client 1 ML2 Received Message(" + receivedCount1ML1 + "):" + message);
+
+ receivedCount1ML2++;
+ if (receivedCount1ML2 == (MSG_COUNT / 2))
+ {
+ _allSecondMessagesSent.countDown();
+ }
}
- }
- });
+ });
_clientConnection.start();
}
@@ -260,11 +259,10 @@ public class ResetMessageListenerTest extends TestCase
}
catch (InterruptedException e)
{
- //do nothing
+ // do nothing
}
}
-
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(ResetMessageListenerTest.class);
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java
index 4667a2b3fa..b6f46b4acc 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java
@@ -19,32 +19,30 @@
*/
package org.apache.qpid.test.unit.ack;
-import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.jms.Session;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
-
import javax.jms.TextMessage;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.jms.Session;
+import java.util.concurrent.atomic.AtomicInteger;
public class RecoverTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(RecoverTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(RecoverTest.class);
private Exception _error;
private AtomicInteger count;
@@ -64,16 +62,17 @@ public class RecoverTest extends TestCase
count = null;
}
-
public void testRecoverResendsMsgs() throws Exception
{
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue queue = new AMQQueue(consumerSession.getDefaultQueueExchangeName(),new AMQShortString("someQ"), new AMQShortString("someQ"), false, true);
+ Queue queue =
+ new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("someQ"),
+ new AMQShortString("someQ"), false, true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
- //force synch to ensure the consumer has resulted in a bound queue
- //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.DIRECT_EXCHANGE_NAME, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
+ // force synch to ensure the consumer has resulted in a bound queue
+ // ((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.DIRECT_EXCHANGE_NAME, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
// This is the default now
AMQConnection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
@@ -122,16 +121,17 @@ public class RecoverTest extends TestCase
con.close();
}
-
public void testRecoverResendsMsgsAckOnEarlier() throws Exception
{
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue queue = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false, true);
+ Queue queue =
+ new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("someQ"),
+ new AMQShortString("someQ"), false, true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
- //force synch to ensure the consumer has resulted in a bound queue
- //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.DIRECT_EXCHANGE_NAME, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
+ // force synch to ensure the consumer has resulted in a bound queue
+ // ((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.DIRECT_EXCHANGE_NAME, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
// This is the default now
AMQConnection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
@@ -164,7 +164,6 @@ public class RecoverTest extends TestCase
TextMessage tm4 = (TextMessage) consumer.receive(3000);
assertEquals("msg4", tm4.getText());
-
_logger.info("Received redelivery of two messages. calling acknolwedgeThis() first of those message");
((org.apache.qpid.jms.Message) tm3).acknowledgeThis();
@@ -180,7 +179,6 @@ public class RecoverTest extends TestCase
// all acked so no messages to be delivered
consumerSession.recover();
-
tm = (TextMessage) consumer.receiveNoWait();
assertNull(tm);
_logger.info("No messages redelivered as is expected");
@@ -193,8 +191,12 @@ public class RecoverTest extends TestCase
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue queue = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q1"), new AMQShortString("Q1"), false, true);
- Queue queue2 = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q2"), new AMQShortString("Q2"), false, true);
+ Queue queue =
+ new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q1"), new AMQShortString("Q1"),
+ false, true);
+ Queue queue2 =
+ new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q2"), new AMQShortString("Q2"),
+ false, true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
MessageConsumer consumer2 = consumerSession.createConsumer(queue2);
@@ -232,68 +234,72 @@ public class RecoverTest extends TestCase
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
final Session consumerSession = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue queue = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q3"), new AMQShortString("Q3"), false, true);
+ Queue queue =
+ new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q3"), new AMQShortString("Q3"),
+ false, true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
MessageProducer producer = consumerSession.createProducer(queue);
producer.send(consumerSession.createTextMessage("hello"));
-
final Object lock = new Object();
consumer.setMessageListener(new MessageListener()
- {
-
-
-
- public void onMessage(Message message)
{
- try
+
+ public void onMessage(Message message)
{
- count.incrementAndGet();
- if (count.get() == 1)
+ try
{
- if(message.getJMSRedelivered())
+ count.incrementAndGet();
+ if (count.get() == 1)
{
- setError(new Exception("Message marked as redilvered on what should be first delivery attempt"));
+ if (message.getJMSRedelivered())
+ {
+ setError(
+ new Exception("Message marked as redilvered on what should be first delivery attempt"));
+ }
+
+ consumerSession.recover();
}
- consumerSession.recover();
- }
- else if (count.get() == 2)
- {
- if(!message.getJMSRedelivered())
+ else if (count.get() == 2)
{
- setError(new Exception("Message not marked as redilvered on what should be second delivery attempt"));
+ if (!message.getJMSRedelivered())
+ {
+ setError(
+ new Exception(
+ "Message not marked as redilvered on what should be second delivery attempt"));
+ }
+ }
+ else
+ {
+ System.err.println(message);
+ fail("Message delivered too many times!: " + count);
}
}
- else
+ catch (JMSException e)
{
- System.err.println(message);
- fail("Message delivered too many times!: " + count);
+ _logger.error("Error recovering session: " + e, e);
+ setError(e);
+ }
+
+ synchronized (lock)
+ {
+ lock.notify();
}
}
- catch (JMSException e)
- {
- _logger.error("Error recovering session: " + e, e);
- setError(e);
- }
- synchronized(lock)
- {
- lock.notify();
- }
- }
- });
+ });
con.start();
long waitTime = 300000L;
long waitUntilTime = System.currentTimeMillis() + waitTime;
- synchronized(lock)
+ synchronized (lock)
{
- while((count.get() <= 1) && (waitTime > 0))
+ while ((count.get() <= 1) && (waitTime > 0))
{
lock.wait(waitTime);
- if(count.get() <= 1)
+ if (count.get() <= 1)
{
waitTime = waitUntilTime - System.currentTimeMillis();
}
@@ -302,15 +308,16 @@ public class RecoverTest extends TestCase
Thread.sleep(1000);
- if(count.get() != 2)
+ if (count.get() != 2)
{
System.err.println("Count != 2 : " + count);
}
- assertTrue(count.get() == 2);
+
+ assertTrue(count.get() == 2);
con.close();
- if(_error != null)
+ if (_error != null)
{
throw _error;
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
index a350330c71..da1b46ee2c 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,9 +19,20 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ByteBuffer;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.message.JMSBytesMessage;
+import org.apache.qpid.testutil.VMBrokerSetup;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.BytesMessage;
import javax.jms.Connection;
@@ -34,21 +45,13 @@ import javax.jms.MessageNotWriteableException;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQDestination;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.message.JMSBytesMessage;
-import org.apache.qpid.testutil.VMBrokerSetup;
-import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class BytesMessageTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(BytesMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BytesMessageTest.class);
private Connection _connection;
private Destination _destination;
@@ -102,7 +105,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
void send(int count) throws JMSException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -115,7 +118,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
}
catch (MessageNotReadableException mnwe)
{
- //normal execution
+ // normal execution
}
byte[] data = ("Message " + i).getBytes();
@@ -127,7 +130,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
void waitFor(int count) throws InterruptedException
{
- synchronized(received)
+ synchronized (received)
{
while (received.size() < count)
{
@@ -146,8 +149,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
buffer.get(data);
actual.add(data);
-
- //Check Body Write Status
+ // Check Body Write Status
try
{
m.writeBoolean(true);
@@ -155,7 +157,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearBody();
@@ -169,8 +171,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
Assert.fail("Message should be writeable");
}
-
- //Check property write status
+ // Check property write status
try
{
m.setStringProperty("test", "test");
@@ -178,7 +179,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearProperties();
@@ -219,6 +220,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
{
errors.add("Found " + actual.next() + " but no more expected values.");
}
+
if (!errors.isEmpty())
{
throw new RuntimeException(errors.toString());
@@ -231,6 +233,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
{
throw new RuntimeException("Expected length " + expected.length + " got " + actual.length);
}
+
for (int i = 0; i < expected.length; i++)
{
if (expected[i] != actual[i])
@@ -242,7 +245,7 @@ public class BytesMessageTest extends TestCase implements MessageListener
public void onMessage(Message message)
{
- synchronized(received)
+ synchronized (received)
{
received.add((JMSBytesMessage) message);
received.notify();
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java
index 9e2918770a..aff496becf 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,19 +20,10 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import javax.jms.BytesMessage;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
@@ -43,10 +34,21 @@ import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.FieldTableFactory;
import org.apache.qpid.testutil.VMBrokerSetup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
public class FieldTableMessageTest extends TestCase implements MessageListener
{
-
- private static final Logger _logger = Logger.getLogger(FieldTableMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(FieldTableMessageTest.class);
private AMQConnection _connection;
private AMQDestination _destination;
@@ -67,10 +69,9 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
super.tearDown();
}
-
private void init(AMQConnection connection) throws Exception
{
- init(connection, new AMQQueue(connection,randomize("FieldTableMessageTest"), true));
+ init(connection, new AMQQueue(connection, randomize("FieldTableMessageTest"), true));
}
private void init(AMQConnection connection, AMQDestination destination) throws Exception
@@ -79,11 +80,11 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
_destination = destination;
_session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- //set up a slow consumer
+ // set up a slow consumer
_session.createConsumer(destination).setMessageListener(this);
connection.start();
- //_expected = new FieldTableTest().load("FieldTableTest2.properties");
+ // _expected = new FieldTableTest().load("FieldTableTest2.properties");
_expected = load();
}
@@ -111,7 +112,7 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
void send(int count) throws JMSException, IOException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -123,7 +124,7 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
void waitFor(int count) throws InterruptedException
{
- synchronized(received)
+ synchronized (received)
{
while (received.size() < count)
{
@@ -139,7 +140,7 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
ByteBuffer buffer = ((JMSBytesMessage) m).getData();
FieldTable actual = FieldTableFactory.newFieldTable(buffer, buffer.remaining());
for (String key : _expected.keys())
- {
+ {
assertEquals("Values for " + key + " did not match", _expected.getObject(key), actual.getObject(key));
}
}
@@ -147,7 +148,7 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
public void onMessage(Message message)
{
- synchronized(received)
+ synchronized (received)
{
received.add((JMSBytesMessage) message);
received.notify();
@@ -162,9 +163,9 @@ public class FieldTableMessageTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
FieldTableMessageTest test = new FieldTableMessageTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = (argv.length == 0) ? "vm://:1" : argv[0];
test.setUp();
- test._count = argv.length > 1 ? Integer.parseInt(argv[1]) : 5;
+ test._count = (argv.length > 1) ? Integer.parseInt(argv[1]) : 5;
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/LargeMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/LargeMessageTest.java
index 3830d61701..ffc7be82f0 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/LargeMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/LargeMessageTest.java
@@ -14,32 +14,36 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.test.unit.basic;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
+
import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.message.JMSTextMessage;
+import org.apache.qpid.client.transport.TransportConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Destination;
-import javax.jms.Session;
-import javax.jms.MessageConsumer;
import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
+import javax.jms.Session;
import javax.jms.TextMessage;
-import java.util.List;
+
import java.util.ArrayList;
+import java.util.List;
public class LargeMessageTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(LargeMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(LargeMessageTest.class);
private AMQConnection _connection;
private Destination _destination;
@@ -68,7 +72,7 @@ public class LargeMessageTest extends TestCase
private void init(AMQConnection connection) throws Exception
{
- Destination destination = new AMQQueue(connection,"LargeMessageTest", true);
+ Destination destination = new AMQQueue(connection, "LargeMessageTest", true);
init(connection, destination);
}
@@ -84,7 +88,7 @@ public class LargeMessageTest extends TestCase
// Test boundary of 1 packet to 2 packets
public void test64kminus1()
{
- checkLargeMessage(64 * 1024 - 1);
+ checkLargeMessage((64 * 1024) - 1);
}
public void test64k()
@@ -94,13 +98,13 @@ public class LargeMessageTest extends TestCase
public void test64kplus1()
{
- checkLargeMessage(64 * 1024 + 1);
+ checkLargeMessage((64 * 1024) + 1);
}
- //Test packet boundary of 3 packtes
+ // Test packet boundary of 3 packtes
public void test128kminus1()
{
- checkLargeMessage(128 * 1024 - 1);
+ checkLargeMessage((128 * 1024) - 1);
}
public void test128k()
@@ -110,7 +114,7 @@ public class LargeMessageTest extends TestCase
public void test128kplus1()
{
- checkLargeMessage(128 * 1024 + 1);
+ checkLargeMessage((128 * 1024) + 1);
}
// Testing larger messages
@@ -167,10 +171,10 @@ public class LargeMessageTest extends TestCase
{
builder.append(ch);
- if (i % 1000 == 0)
+ if ((i % 1000) == 0)
{
ch++;
- if (ch == 'z' + 1)
+ if (ch == ('z' + 1))
{
ch = 'a';
}
@@ -180,7 +184,6 @@ public class LargeMessageTest extends TestCase
return builder.toString();
}
-
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(LargeMessageTest.class);
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
index 75eb3a8d5e..6708fefa86 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
@@ -20,9 +20,17 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.message.JMSMapMessage;
+import org.apache.qpid.client.transport.TransportConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -34,20 +42,13 @@ import javax.jms.MessageNotWriteableException;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.message.JMSMapMessage;
-import org.apache.qpid.client.transport.TransportConnection;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class MapMessageTest extends TestCase implements MessageListener
{
-
- private static final Logger _logger = Logger.getLogger(MapMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(MapMessageTest.class);
private AMQConnection _connection;
private Destination _destination;
@@ -57,7 +58,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private static final String MESSAGE = "Message ";
private int _count = 100;
public String _connectionString = "vm://:1";
- private byte[] _bytes = {99, 98, 97, 96, 95};
+ private byte[] _bytes = { 99, 98, 97, 96, 95 };
private static final float _smallfloat = 100.0f;
protected void setUp() throws Exception
@@ -83,7 +84,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void init(AMQConnection connection) throws Exception
{
- Destination destination = new AMQQueue(connection,randomize("MapMessageTest"), true);
+ Destination destination = new AMQQueue(connection, randomize("MapMessageTest"), true);
init(connection, destination);
}
@@ -93,7 +94,7 @@ public class MapMessageTest extends TestCase implements MessageListener
_destination = destination;
_session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- //set up a slow consumer
+ // set up a slow consumer
_session.createConsumer(destination).setMessageListener(this);
connection.start();
}
@@ -109,7 +110,7 @@ public class MapMessageTest extends TestCase implements MessageListener
void send(int count) throws JMSException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -123,7 +124,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void setMapValues(MapMessage message, int i) throws JMSException
{
- message.setBoolean("odd", i / 2 == 0);
+ message.setBoolean("odd", (i / 2) == 0);
message.setByte("byte", (byte) Byte.MAX_VALUE);
message.setBytes("bytes", _bytes);
message.setChar("char", (char) 'c');
@@ -136,7 +137,7 @@ public class MapMessageTest extends TestCase implements MessageListener
message.setShort("short", (short) Short.MAX_VALUE);
message.setString("message", MESSAGE + i);
- //Test Setting Object Values
+ // Test Setting Object Values
message.setObject("object-bool", true);
message.setObject("object-byte", Byte.MAX_VALUE);
message.setObject("object-bytes", _bytes);
@@ -147,7 +148,7 @@ public class MapMessageTest extends TestCase implements MessageListener
message.setObject("object-long", Long.MAX_VALUE);
message.setObject("object-short", Short.MAX_VALUE);
- //Set a null String value
+ // Set a null String value
message.setString("nullString", null);
// Highlight protocol problem
message.setString("emptyString", "");
@@ -159,10 +160,9 @@ public class MapMessageTest extends TestCase implements MessageListener
long waitTime = 30000L;
long waitUntilTime = System.currentTimeMillis() + 30000L;
-
- synchronized(received)
+ synchronized (received)
{
- while(received.size() < count && waitTime>0)
+ while ((received.size() < count) && (waitTime > 0))
{
if (received.size() < count)
{
@@ -174,6 +174,7 @@ public class MapMessageTest extends TestCase implements MessageListener
waitTime = waitUntilTime - System.currentTimeMillis();
}
}
+
if (received.size() < count)
{
throw new Exception("Timed-out. Waiting for " + count + " only got " + received.size());
@@ -236,7 +237,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -246,10 +247,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("message");
@@ -257,7 +258,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
try
@@ -267,8 +268,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
+
try
{
m.getLong("message");
@@ -276,10 +278,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("message");
@@ -287,9 +289,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("message");
@@ -297,9 +299,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (NumberFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("message");
@@ -307,7 +309,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(MESSAGE + m.getInt("messageNumber"), m.getString("message"));
@@ -316,7 +318,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void testShort(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("short");
@@ -324,7 +326,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -334,12 +336,12 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(Short.MAX_VALUE, m.getShort("short"));
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("short");
@@ -347,14 +349,14 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(Short.MAX_VALUE, m.getInt("short"));
Assert.assertEquals(Short.MAX_VALUE, m.getLong("short"));
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("short");
@@ -362,9 +364,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("short");
@@ -372,9 +374,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("short");
@@ -382,7 +384,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Short.MAX_VALUE, m.getString("short"));
@@ -391,7 +393,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void testLong(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("long");
@@ -399,7 +401,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -409,7 +411,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -419,10 +421,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("long");
@@ -430,7 +432,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
try
@@ -440,12 +442,12 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(Long.MAX_VALUE, m.getLong("long"));
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("long");
@@ -453,9 +455,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("long");
@@ -463,9 +465,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("long");
@@ -473,7 +475,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Long.MAX_VALUE, m.getString("long"));
@@ -482,7 +484,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void testDouble(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("double");
@@ -490,7 +492,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -500,7 +502,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -510,10 +512,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("double");
@@ -521,7 +523,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
try
@@ -531,8 +533,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
+
try
{
m.getLong("double");
@@ -540,10 +543,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("double");
@@ -551,13 +554,12 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
-
Assert.assertEquals(Double.MAX_VALUE, m.getDouble("double"));
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("double");
@@ -565,17 +567,16 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Double.MAX_VALUE, m.getString("double"));
}
-
private void testFloat(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("float");
@@ -583,7 +584,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -593,7 +594,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -603,10 +604,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("float");
@@ -614,7 +615,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
try
@@ -624,8 +625,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
+
try
{
m.getLong("float");
@@ -633,15 +635,14 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
-
Assert.assertEquals(Float.MAX_VALUE, m.getFloat("float"));
Assert.assertEquals(_smallfloat, (float) m.getDouble("smallfloat"));
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("float");
@@ -649,17 +650,16 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Float.MAX_VALUE, m.getString("float"));
}
-
private void testInt(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("int");
@@ -667,7 +667,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -677,7 +677,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -687,10 +687,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("int");
@@ -698,14 +698,14 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(Integer.MAX_VALUE, m.getInt("int"));
Assert.assertEquals(Integer.MAX_VALUE, (int) m.getLong("int"));
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("int");
@@ -713,9 +713,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("int");
@@ -723,9 +723,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("int");
@@ -733,17 +733,16 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Integer.MAX_VALUE, m.getString("int"));
}
-
private void testChar(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("char");
@@ -751,7 +750,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -761,7 +760,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -771,7 +770,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals('c', m.getChar("char"));
@@ -783,8 +782,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
+
try
{
m.getLong("char");
@@ -792,10 +792,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("char");
@@ -803,9 +803,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("char");
@@ -813,9 +813,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("char");
@@ -823,7 +823,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + 'c', m.getString("char"));
@@ -831,7 +831,7 @@ public class MapMessageTest extends TestCase implements MessageListener
private void testBytes(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("bytes");
@@ -839,7 +839,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -849,7 +849,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -859,10 +859,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("bytes");
@@ -870,7 +870,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
try
@@ -880,7 +880,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
try
@@ -890,10 +890,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("bytes");
@@ -901,9 +901,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("bytes");
@@ -911,10 +911,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
-
assertBytesEqual(_bytes, m.getBytes("bytes"));
try
@@ -924,15 +923,14 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
-
}
private void testByte(JMSMapMessage m) throws JMSException
{
- //Try bad reads
+ // Try bad reads
try
{
m.getBoolean("byte");
@@ -940,14 +938,14 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals(Byte.MAX_VALUE, m.getByte("byte"));
Assert.assertEquals((short) Byte.MAX_VALUE, m.getShort("byte"));
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("byte");
@@ -955,15 +953,15 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
- //Reading a byte as an int is ok
+ // Reading a byte as an int is ok
Assert.assertEquals((short) Byte.MAX_VALUE, m.getInt("byte"));
Assert.assertEquals((short) Byte.MAX_VALUE, m.getLong("byte"));
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("byte");
@@ -971,9 +969,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("byte");
@@ -981,9 +979,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("byte");
@@ -991,7 +989,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + Byte.MAX_VALUE, m.getString("byte"));
@@ -1003,7 +1001,7 @@ public class MapMessageTest extends TestCase implements MessageListener
Assert.assertEquals((m.getInt("messageNumber") / 2) == 0, m.getBoolean("odd"));
- //Try bad reads
+ // Try bad reads
try
{
m.getByte("odd");
@@ -1011,10 +1009,10 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getShort("odd");
@@ -1022,9 +1020,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getChar("odd");
@@ -1032,9 +1030,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException npe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getInt("odd");
@@ -1042,9 +1040,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getLong("odd");
@@ -1052,9 +1050,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getFloat("odd");
@@ -1062,9 +1060,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getDouble("odd");
@@ -1072,9 +1070,9 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
- //Try bad reads
+ // Try bad reads
try
{
m.getBytes("odd");
@@ -1082,16 +1080,15 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageFormatException nfe)
{
- //normal execution
+ // normal execution
}
Assert.assertEquals("" + ((m.getInt("messageNumber") / 2) == 0), m.getString("odd"));
}
-
private void testPropertyWriteStatus(JMSMapMessage m) throws JMSException
{
- //Check property write status
+ // Check property write status
try
{
m.setStringProperty("test", "test");
@@ -1099,7 +1096,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearProperties();
@@ -1123,7 +1120,7 @@ public class MapMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearBody();
@@ -1138,54 +1135,51 @@ public class MapMessageTest extends TestCase implements MessageListener
}
}
-
-
-
private void testMapValues(JMSMapMessage m, int count) throws JMSException
{
- //Test get<Primiative>
+ // Test get<Primiative>
- //Boolean
- assertEqual(count / 2 == 0, m.getBoolean("odd"));
- assertEqual("" + (count / 2 == 0), m.getString("odd"));
+ // Boolean
+ assertEqual((count / 2) == 0, m.getBoolean("odd"));
+ assertEqual("" + ((count / 2) == 0), m.getString("odd"));
- //Byte
+ // Byte
assertEqual(Byte.MAX_VALUE, m.getByte("byte"));
assertEqual("" + Byte.MAX_VALUE, m.getString("byte"));
- //Bytes
+ // Bytes
assertBytesEqual(_bytes, m.getBytes("bytes"));
- //Char
+ // Char
assertEqual('c', m.getChar("char"));
- //Double
+ // Double
assertEqual(Double.MAX_VALUE, m.getDouble("double"));
assertEqual("" + Double.MAX_VALUE, m.getString("double"));
- //Float
+ // Float
assertEqual(Float.MAX_VALUE, m.getFloat("float"));
assertEqual(_smallfloat, (float) m.getDouble("smallfloat"));
assertEqual("" + Float.MAX_VALUE, m.getString("float"));
- //Integer
+ // Integer
assertEqual(Integer.MAX_VALUE, m.getInt("int"));
assertEqual("" + Integer.MAX_VALUE, m.getString("int"));
assertEqual(count, m.getInt("messageNumber"));
- //long
+ // long
assertEqual(Long.MAX_VALUE, m.getLong("long"));
assertEqual("" + Long.MAX_VALUE, m.getString("long"));
- //Short
+ // Short
assertEqual(Short.MAX_VALUE, m.getShort("short"));
assertEqual("" + Short.MAX_VALUE, m.getString("short"));
assertEqual((int) Short.MAX_VALUE, m.getInt("short"));
- //String
+ // String
assertEqual(MESSAGE + count, m.getString("message"));
- //Test getObjects
+ // Test getObjects
assertEqual(true, m.getObject("object-bool"));
assertEqual(Byte.MAX_VALUE, m.getObject("object-byte"));
assertBytesEqual(_bytes, (byte[]) m.getObject("object-bytes"));
@@ -1196,7 +1190,7 @@ public class MapMessageTest extends TestCase implements MessageListener
assertEqual(Long.MAX_VALUE, m.getObject("object-long"));
assertEqual(Short.MAX_VALUE, m.getObject("object-short"));
- //Check Special values
+ // Check Special values
assertTrue(m.getString("nullString") == null);
assertEqual("", m.getString("emptyString"));
}
@@ -1211,7 +1205,6 @@ public class MapMessageTest extends TestCase implements MessageListener
}
}
-
private static void assertEqual(Iterator expected, Iterator actual)
{
List<String> errors = new ArrayList<String>();
@@ -1234,6 +1227,7 @@ public class MapMessageTest extends TestCase implements MessageListener
{
errors.add("Found " + actual.next() + " but no more expected values.");
}
+
if (!errors.isEmpty())
{
throw new RuntimeException(errors.toString());
@@ -1250,7 +1244,7 @@ public class MapMessageTest extends TestCase implements MessageListener
public void onMessage(Message message)
{
- synchronized(received)
+ synchronized (received)
{
_logger.info("****************** Recevied Messgage:" + (JMSMapMessage) message);
received.add((JMSMapMessage) message);
@@ -1266,12 +1260,13 @@ public class MapMessageTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
MapMessageTest test = new MapMessageTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = (argv.length == 0) ? "vm://:1" : argv[0];
test.setUp();
if (argv.length > 1)
{
test._count = Integer.parseInt(argv[1]);
}
+
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java
index ddb21ed3e5..65b3d60ad9 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java
@@ -19,12 +19,6 @@
*/
package org.apache.qpid.test.unit.basic;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
import junit.framework.TestCase;
import org.apache.qpid.client.AMQConnection;
@@ -33,11 +27,19 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQTopic;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
public class MultipleConnectionTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(MultipleConnectionTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(MultipleConnectionTest.class);
public static final String _defaultBroker = "vm://:1";
public String _connectionString = _defaultBroker;
@@ -64,6 +66,7 @@ public class MultipleConnectionTest extends TestCase
_counters[i] = new MessageCounter(_sessions[i].toString());
_sessions[i].createConsumer(dest).setMessageListener(_counters[i]);
}
+
_connection.start();
}
@@ -128,8 +131,10 @@ public class MultipleConnectionTest extends TestCase
{
break;
}
+
wait(timeLeft);
}
+
return expected <= _count;
}
@@ -144,7 +149,6 @@ public class MultipleConnectionTest extends TestCase
}
}
-
protected void setUp() throws Exception
{
super.setUp();
@@ -183,7 +187,7 @@ public class MultipleConnectionTest extends TestCase
public static void main(String[] argv) throws Exception
{
- String broker = argv.length > 0 ? argv[0] : _defaultBroker;
+ String broker = (argv.length > 0) ? argv[0] : _defaultBroker;
MultipleConnectionTest test = new MultipleConnectionTest();
test._connectionString = broker;
@@ -195,12 +199,9 @@ public class MultipleConnectionTest extends TestCase
String broker = _connectionString;
int messages = 10;
- AMQTopic topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME,"amq.topic");
+ AMQTopic topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, "amq.topic");
- Receiver[] receivers = new Receiver[]{
- new Receiver(broker, topic, 2),
- new Receiver(broker, topic, 14)
- };
+ Receiver[] receivers = new Receiver[] { new Receiver(broker, topic, 2), new Receiver(broker, topic, 14) };
Publisher publisher = new Publisher(broker, topic);
for (int i = 0; i < messages; i++)
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
index aee9002354..9237555734 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
@@ -19,17 +19,6 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.MessageProducer;
-
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -39,11 +28,24 @@ import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.message.JMSObjectMessage;
import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageNotWriteableException;
+import javax.jms.MessageProducer;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class ObjectMessageTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(ObjectMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ObjectMessageTest.class);
private AMQConnection _connection;
private AMQDestination _destination;
@@ -75,7 +77,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
private void init(AMQConnection connection) throws Exception
{
- init(connection, new AMQQueue(connection,randomize("ObjectMessageTest"), true));
+ init(connection, new AMQQueue(connection, randomize("ObjectMessageTest"), true));
}
private void init(AMQConnection connection, AMQDestination destination) throws Exception
@@ -84,7 +86,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
_destination = destination;
_session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- //set up a slow consumer
+ // set up a slow consumer
_session.createConsumer(destination).setMessageListener(this);
connection.start();
}
@@ -101,7 +103,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
void send(int count) throws JMSException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -113,7 +115,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
void waitFor(int count) throws InterruptedException
{
- synchronized(received)
+ synchronized (received)
{
while (received.size() < count)
{
@@ -136,7 +138,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearBody();
@@ -150,7 +152,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
Assert.fail("Message should be writeable");
}
- //Check property write status
+ // Check property write status
try
{
m.setStringProperty("test", "test");
@@ -158,7 +160,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearProperties();
@@ -200,6 +202,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
{
errors.add("Found " + actual.next() + " but no more expected values.");
}
+
if (!errors.isEmpty())
{
throw new RuntimeException(errors.toString());
@@ -216,7 +219,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
public void onMessage(Message message)
{
- synchronized(received)
+ synchronized (received)
{
received.add((JMSObjectMessage) message);
received.notify();
@@ -244,7 +247,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
public boolean equals(Object o)
{
- return o instanceof Payload && ((Payload) o).data.equals(data);
+ return (o instanceof Payload) && ((Payload) o).data.equals(data);
}
public String toString()
@@ -256,12 +259,13 @@ public class ObjectMessageTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
ObjectMessageTest test = new ObjectMessageTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = (argv.length == 0) ? "vm://:1" : argv[0];
test.setUp();
if (argv.length > 1)
{
test._count = Integer.parseInt(argv[1]);
}
+
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java
index 90784b0772..dce9667ff2 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java
@@ -20,10 +20,19 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.math.BigDecimal;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.message.AMQMessage;
+import org.apache.qpid.client.message.JMSTextMessage;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.framing.AMQShortString;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -33,22 +42,14 @@ import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.message.JMSTextMessage;
-import org.apache.qpid.client.message.AMQMessage;
-import org.apache.qpid.framing.AMQShortString;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class PropertyValueTest extends TestCase implements MessageListener
{
-
- private static final Logger _logger = Logger.getLogger(PropertyValueTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(PropertyValueTest.class);
private int count = 0;
private AMQConnection _connection;
@@ -83,7 +84,7 @@ public class PropertyValueTest extends TestCase implements MessageListener
_destination = destination;
_session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- //set up a slow consumer
+ // set up a slow consumer
_session.createConsumer(destination).setMessageListener(this);
connection.start();
}
@@ -136,7 +137,7 @@ public class PropertyValueTest extends TestCase implements MessageListener
void send(int count) throws JMSException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -152,14 +153,14 @@ public class PropertyValueTest extends TestCase implements MessageListener
m.setIntProperty("Int", (int) Integer.MAX_VALUE);
m.setJMSCorrelationID("Correlation");
- //fixme the m.setJMSMessage has no effect
+ // fixme the m.setJMSMessage has no effect
producer.setPriority(8);
m.setJMSPriority(3);
- // Queue
+ // Queue
Queue q;
- if (i / 2 == 0)
+ if ((i / 2) == 0)
{
q = _session.createTemporaryQueue();
}
@@ -173,8 +174,8 @@ public class PropertyValueTest extends TestCase implements MessageListener
_logger.trace("Message:" + m);
- Assert.assertEquals("Check temp queue has been set correctly",
- m.getJMSReplyTo().toString(), m.getStringProperty("TempQueue"));
+ Assert.assertEquals("Check temp queue has been set correctly", m.getJMSReplyTo().toString(),
+ m.getStringProperty("TempQueue"));
m.setJMSType("Test");
m.setLongProperty("UnsignedInt", (long) 4294967295L);
@@ -183,18 +184,17 @@ public class PropertyValueTest extends TestCase implements MessageListener
m.setShortProperty("Short", (short) Short.MAX_VALUE);
m.setStringProperty("String", "Test");
- //AMQP Specific values
+ // AMQP Specific values
// Timestamp
long nano = System.nanoTime();
m.setStringProperty("time-str", String.valueOf(nano));
((AMQMessage) m).setTimestampProperty(new AMQShortString("time"), nano);
- //Decimal
+ // Decimal
BigDecimal bd = new BigDecimal(Integer.MAX_VALUE);
((AMQMessage) m).setDecimalProperty(new AMQShortString("decimal"), bd.setScale(Byte.MAX_VALUE));
-
bd = new BigDecimal((long) Integer.MAX_VALUE + 1L);
try
@@ -207,10 +207,10 @@ public class PropertyValueTest extends TestCase implements MessageListener
// normal path.
}
-
try
{
- ((AMQMessage) m).setDecimalProperty(new AMQShortString("decimal-bad-scale"), bd.setScale(Byte.MAX_VALUE + 1));
+ ((AMQMessage) m).setDecimalProperty(new AMQShortString("decimal-bad-scale"),
+ bd.setScale(Byte.MAX_VALUE + 1));
fail("UnsupportedOperationException should be thrown as scale can't be correctly transmitted");
}
catch (UnsupportedOperationException uoe)
@@ -218,7 +218,7 @@ public class PropertyValueTest extends TestCase implements MessageListener
// normal path.
}
- //Void
+ // Void
((AMQMessage) m).setVoidProperty(new AMQShortString("void"));
_logger.debug("Sending Msg:" + m);
@@ -244,58 +244,53 @@ public class PropertyValueTest extends TestCase implements MessageListener
{
actual.add(m.getText());
- //Check Properties
-
- Assert.assertEquals("Check Boolean properties are correctly transported",
- true, m.getBooleanProperty("Bool"));
- Assert.assertEquals("Check Byte properties are correctly transported",
- (byte) Byte.MAX_VALUE, m.getByteProperty("Byte"));
- Assert.assertEquals("Check Double properties are correctly transported",
- (double) Double.MAX_VALUE, m.getDoubleProperty("Double"));
- Assert.assertEquals("Check Float properties are correctly transported",
- (float) Float.MAX_VALUE, m.getFloatProperty("Float"));
- Assert.assertEquals("Check Int properties are correctly transported",
- (int) Integer.MAX_VALUE, m.getIntProperty("Int"));
- Assert.assertEquals("Check CorrelationID properties are correctly transported",
- "Correlation", m.getJMSCorrelationID());
- Assert.assertEquals("Check Priority properties are correctly transported",
- 8, m.getJMSPriority());
+ // Check Properties
+
+ Assert.assertEquals("Check Boolean properties are correctly transported", true, m.getBooleanProperty("Bool"));
+ Assert.assertEquals("Check Byte properties are correctly transported", (byte) Byte.MAX_VALUE,
+ m.getByteProperty("Byte"));
+ Assert.assertEquals("Check Double properties are correctly transported", (double) Double.MAX_VALUE,
+ m.getDoubleProperty("Double"));
+ Assert.assertEquals("Check Float properties are correctly transported", (float) Float.MAX_VALUE,
+ m.getFloatProperty("Float"));
+ Assert.assertEquals("Check Int properties are correctly transported", (int) Integer.MAX_VALUE,
+ m.getIntProperty("Int"));
+ Assert.assertEquals("Check CorrelationID properties are correctly transported", "Correlation",
+ m.getJMSCorrelationID());
+ Assert.assertEquals("Check Priority properties are correctly transported", 8, m.getJMSPriority());
// Queue
- Assert.assertEquals("Check ReplyTo properties are correctly transported",
- m.getStringProperty("TempQueue"), m.getJMSReplyTo().toString());
+ Assert.assertEquals("Check ReplyTo properties are correctly transported", m.getStringProperty("TempQueue"),
+ m.getJMSReplyTo().toString());
- Assert.assertEquals("Check Type properties are correctly transported",
- "Test", m.getJMSType());
+ Assert.assertEquals("Check Type properties are correctly transported", "Test", m.getJMSType());
- Assert.assertEquals("Check Short properties are correctly transported",
- (short) Short.MAX_VALUE, m.getShortProperty("Short"));
- Assert.assertEquals("Check UnsignedInt properties are correctly transported",
- (long) 4294967295L, m.getLongProperty("UnsignedInt"));
- Assert.assertEquals("Check Long properties are correctly transported",
- (long) Long.MAX_VALUE, m.getLongProperty("Long"));
- Assert.assertEquals("Check String properties are correctly transported",
- "Test", m.getStringProperty("String"));
+ Assert.assertEquals("Check Short properties are correctly transported", (short) Short.MAX_VALUE,
+ m.getShortProperty("Short"));
+ Assert.assertEquals("Check UnsignedInt properties are correctly transported", (long) 4294967295L,
+ m.getLongProperty("UnsignedInt"));
+ Assert.assertEquals("Check Long properties are correctly transported", (long) Long.MAX_VALUE,
+ m.getLongProperty("Long"));
+ Assert.assertEquals("Check String properties are correctly transported", "Test", m.getStringProperty("String"));
// AMQP Tests Specific values
- Assert.assertEquals("Check Timestamp properties are correctly transported",
- m.getStringProperty("time-str"),
- ((AMQMessage) m).getTimestampProperty(new AMQShortString("time")).toString());
+ Assert.assertEquals("Check Timestamp properties are correctly transported", m.getStringProperty("time-str"),
+ ((AMQMessage) m).getTimestampProperty(new AMQShortString("time")).toString());
- //Decimal
+ // Decimal
BigDecimal bd = new BigDecimal(Integer.MAX_VALUE);
- Assert.assertEquals("Check decimal properties are correctly transported",
- bd.setScale(Byte.MAX_VALUE),
- ((AMQMessage) m).getDecimalProperty(new AMQShortString("decimal")));
+ Assert.assertEquals("Check decimal properties are correctly transported", bd.setScale(Byte.MAX_VALUE),
+ ((AMQMessage) m).getDecimalProperty(new AMQShortString("decimal")));
- //Void
+ // Void
((AMQMessage) m).setVoidProperty(new AMQShortString("void"));
Assert.assertTrue("Check void properties are correctly transported",
- ((AMQMessage) m).getPropertyHeaders().containsKey("void"));
+ ((AMQMessage) m).getPropertyHeaders().containsKey("void"));
}
+
received.clear();
assertEqual(messages.iterator(), actual.iterator());
@@ -325,6 +320,7 @@ public class PropertyValueTest extends TestCase implements MessageListener
{
errors.add("Found " + actual.next() + " but no more expected values.");
}
+
if (!errors.isEmpty())
{
throw new RuntimeException(errors.toString());
@@ -356,12 +352,13 @@ public class PropertyValueTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
PropertyValueTest test = new PropertyValueTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = (argv.length == 0) ? "vm://:1" : argv[0];
test.setUp();
if (argv.length > 1)
{
test._count = Integer.parseInt(argv[1]);
}
+
test.testOnce();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SelectorTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SelectorTest.java
index cc4bb441a4..40c712c1c9 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SelectorTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SelectorTest.java
@@ -20,14 +20,8 @@
*/
package org.apache.qpid.test.unit.basic;
-import javax.jms.DeliveryMode;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
@@ -35,10 +29,17 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.BasicMessageProducer;
import org.apache.qpid.client.transport.TransportConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
public class SelectorTest extends TestCase implements MessageListener
{
-
- private final static Logger _logger = org.apache.log4j.Logger.getLogger(SelectorTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(SelectorTest.class);
private AMQConnection _connection;
private AMQDestination _destination;
@@ -70,13 +71,12 @@ public class SelectorTest extends TestCase implements MessageListener
_destination = destination;
connection.start();
-
String selector = null;
-// selector = "Cost = 2 AND JMSDeliveryMode=" + DeliveryMode.NON_PERSISTENT;
-// selector = "JMSType = Special AND Cost = 2 AND AMQMessageID > 0 AND JMSDeliveryMode=" + DeliveryMode.NON_PERSISTENT;
+ // selector = "Cost = 2 AND JMSDeliveryMode=" + DeliveryMode.NON_PERSISTENT;
+ // selector = "JMSType = Special AND Cost = 2 AND AMQMessageID > 0 AND JMSDeliveryMode=" + DeliveryMode.NON_PERSISTENT;
_session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- //_session.createConsumer(destination).setMessageListener(this);
+ // _session.createConsumer(destination).setMessageListener(this);
_session.createConsumer(destination, selector).setMessageListener(this);
}
@@ -103,7 +103,7 @@ public class SelectorTest extends TestCase implements MessageListener
if (count == 0)
{
fail("Did not get message!");
- //throw new RuntimeException("Did not get message!");
+ // throw new RuntimeException("Did not get message!");
}
}
finally
@@ -128,7 +128,7 @@ public class SelectorTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
SelectorTest test = new SelectorTest();
- test._connectionString = argv.length == 0 ? "localhost:5672" : argv[0];
+ test._connectionString = (argv.length == 0) ? "localhost:5672" : argv[0];
test.setUp();
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java
index 8e2d59475a..cc18169a5b 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,23 +20,25 @@
*/
package org.apache.qpid.test.unit.basic;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-
import junit.framework.TestCase;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.testutil.VMBrokerSetup;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.log4j.Logger;
+import org.apache.qpid.testutil.VMBrokerSetup;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
public class SessionStartTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(SessionStartTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(SessionStartTest.class);
private AMQConnection _connection;
private AMQDestination _destination;
@@ -57,7 +59,8 @@ public class SessionStartTest extends TestCase implements MessageListener
private void init(AMQConnection connection) throws Exception
{
- init(connection, new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("SessionStartTest")), true));
+ init(connection,
+ new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("SessionStartTest")), true));
}
private void init(AMQConnection connection, AMQDestination destination) throws Exception
@@ -107,7 +110,7 @@ public class SessionStartTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
SessionStartTest test = new SessionStartTest();
- test._connectionString = argv.length == 0 ? "localhost:5672" : argv[0];
+ test._connectionString = (argv.length == 0) ? "localhost:5672" : argv[0];
test.setUp();
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
index f24355552a..000fb9ab88 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,9 +20,18 @@
*/
package org.apache.qpid.test.unit.basic;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.message.JMSTextMessage;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.testutil.VMBrokerSetup;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -32,20 +41,13 @@ import javax.jms.MessageNotWriteableException;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.message.JMSTextMessage;
-import org.apache.qpid.testutil.VMBrokerSetup;
-import org.apache.qpid.framing.AMQShortString;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class TextMessageTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(TextMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(TextMessageTest.class);
private AMQConnection _connection;
private Destination _destination;
@@ -75,7 +77,8 @@ public class TextMessageTest extends TestCase implements MessageListener
private void init(AMQConnection connection) throws Exception
{
- Destination destination = new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("TextMessageTest")), true);
+ Destination destination =
+ new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("TextMessageTest")), true);
init(connection, destination);
}
@@ -85,7 +88,7 @@ public class TextMessageTest extends TestCase implements MessageListener
_destination = destination;
_session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- //set up a slow consumer
+ // set up a slow consumer
_session.createConsumer(destination).setMessageListener(this);
connection.start();
}
@@ -102,7 +105,7 @@ public class TextMessageTest extends TestCase implements MessageListener
void send(int count) throws JMSException
{
- //create a publisher
+ // create a publisher
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
@@ -118,7 +121,7 @@ public class TextMessageTest extends TestCase implements MessageListener
void waitFor(int count) throws InterruptedException
{
- synchronized(received)
+ synchronized (received)
{
while (received.size() < count)
{
@@ -134,7 +137,7 @@ public class TextMessageTest extends TestCase implements MessageListener
{
actual.add(m.getText());
- //Check body write status
+ // Check body write status
try
{
m.setText("Test text");
@@ -142,7 +145,7 @@ public class TextMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearBody();
@@ -156,7 +159,7 @@ public class TextMessageTest extends TestCase implements MessageListener
Assert.fail("Message should be writeable");
}
- //Check property write status
+ // Check property write status
try
{
m.setStringProperty("test", "test");
@@ -164,7 +167,7 @@ public class TextMessageTest extends TestCase implements MessageListener
}
catch (MessageNotWriteableException mnwe)
{
- //normal execution
+ // normal execution
}
m.clearProperties();
@@ -205,6 +208,7 @@ public class TextMessageTest extends TestCase implements MessageListener
{
errors.add("Found " + actual.next() + " but no more expected values.");
}
+
if (!errors.isEmpty())
{
throw new RuntimeException(errors.toString());
@@ -221,7 +225,7 @@ public class TextMessageTest extends TestCase implements MessageListener
public void onMessage(Message message)
{
- synchronized(received)
+ synchronized (received)
{
received.add((JMSTextMessage) message);
received.notify();
@@ -236,12 +240,13 @@ public class TextMessageTest extends TestCase implements MessageListener
public static void main(String[] argv) throws Exception
{
TextMessageTest test = new TextMessageTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = (argv.length == 0) ? "vm://:1" : argv[0];
test.setUp();
if (argv.length > 1)
{
test._count = Integer.parseInt(argv[1]);
}
+
test.test();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/close/CloseTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/close/CloseTests.java
index 505af361bc..690ba7f01b 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/close/CloseTests.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/close/CloseTests.java
@@ -14,35 +14,35 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.test.unit.basic.close;
import junit.framework.TestCase;
-import org.apache.qpid.client.transport.TransportConnection;
+
+import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.url.AMQBindingURL;
-import org.apache.log4j.Logger;
+import org.apache.qpid.url.URLSyntaxException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.jms.Session;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
+import javax.jms.Session;
public class CloseTests extends TestCase
{
-
- private static final Logger _logger = Logger.getLogger(CloseTests.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(CloseTests.class);
private static final String BROKER = "vm://:1";
-
protected void setUp() throws Exception
{
super.setUp();
@@ -57,12 +57,11 @@ public class CloseTests extends TestCase
TransportConnection.killVMBroker(1);
}
-
public void testCloseQueueReceiver() throws AMQException, URLSyntaxException, JMSException
{
AMQConnection connection = new AMQConnection(BROKER, "guest", "guest", this.getName(), "test");
- Session session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
+ Session session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
AMQQueue queue = new AMQQueue(new AMQBindingURL("test-queue"));
MessageConsumer consumer = session.createConsumer(queue);
@@ -76,6 +75,6 @@ public class CloseTests extends TestCase
consumer.close();
_logger.info("Closed Consumer");
-
+
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
index 4a114321aa..85fcf6d95a 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
@@ -14,30 +14,32 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.test.unit.client.channelclose;
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.state.AMQStateManager;
-import org.apache.qpid.client.state.StateAwareMethodListener;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
-import org.apache.qpid.client.AMQNoConsumersException;
-import org.apache.qpid.client.AMQNoRouteException;
-import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQInvalidRoutingKeyException;
import org.apache.qpid.AMQChannelClosedException;
+import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInvalidArgumentException;
-import org.apache.qpid.framing.ChannelCloseBody;
+import org.apache.qpid.AMQInvalidRoutingKeyException;
+import org.apache.qpid.client.AMQNoConsumersException;
+import org.apache.qpid.client.AMQNoRouteException;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+import org.apache.qpid.client.state.AMQStateManager;
+import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.ChannelCloseBody;
+import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.protocol.AMQMethodEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListener
{
- private static final Logger _logger = Logger.getLogger(ChannelCloseMethodHandlerNoCloseOk.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseMethodHandlerNoCloseOk.class);
private static ChannelCloseMethodHandlerNoCloseOk _handler = new ChannelCloseMethodHandlerNoCloseOk();
@@ -46,7 +48,8 @@ public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListe
return _handler;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ throws AMQException
{
_logger.debug("ChannelClose method received");
ChannelCloseBody method = (ChannelCloseBody) evt.getMethod();
@@ -59,9 +62,9 @@ public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListe
}
// For this test Method Handler .. don't send Close-OK
-// // TODO: Be aware of possible changes to parameter order as versions change.
-// AMQFrame frame = ChannelCloseOkBody.createAMQFrame(evt.getChannelId(), method.getMajor(), method.getMinor());
-// protocolSession.writeFrame(frame);
+ // // TODO: Be aware of possible changes to parameter order as versions change.
+ // AMQFrame frame = ChannelCloseOkBody.createAMQFrame(evt.getChannelId(), method.getMajor(), method.getMinor());
+ // protocolSession.writeFrame(frame);
if (errorCode != AMQConstant.REPLY_SUCCESS)
{
_logger.error("Channel close received with errorCode " + errorCode + ", and reason " + reason);
@@ -91,6 +94,7 @@ public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListe
}
}
+
protocolSession.channelClosed(evt.getChannelId(), errorCode, String.valueOf(reason));
}
-} \ No newline at end of file
+}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
index c7f1bb3065..6753ed48e4 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,10 +20,17 @@
*/
package org.apache.qpid.test.unit.client.channelclose;
-import java.util.ArrayList;
-import java.util.List;
+import junit.framework.TestCase;
+
+import junit.textui.TestRunner;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.transport.TransportConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@@ -33,14 +40,8 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
-import junit.framework.TestCase;
-import junit.textui.TestRunner;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.transport.TransportConnection;
-
+import java.util.ArrayList;
+import java.util.List;
/**
* Due to bizarre exception handling all sessions are closed if you get
@@ -66,10 +67,9 @@ public class ChannelCloseOkTest extends TestCase
private final List<Message> _received1 = new ArrayList<Message>();
private final List<Message> _received2 = new ArrayList<Message>();
- private final static Logger _log = Logger.getLogger(ChannelCloseOkTest.class);
+ private static final Logger _log = LoggerFactory.getLogger(ChannelCloseOkTest.class);
public String _connectionString = "vm://:1";
-
protected void setUp() throws Exception
{
super.setUp();
@@ -77,34 +77,34 @@ public class ChannelCloseOkTest extends TestCase
TransportConnection.createVMBroker(1);
_connection = new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "test");
- _destination1 = new AMQQueue(_connection,"q1", true);
+ _destination1 = new AMQQueue(_connection, "q1", true);
_destination2 = new AMQQueue(_connection, "q2", true);
_session1 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_session1.createConsumer(_destination1).setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _log.debug("consumer 1 got message [" + getTextMessage(message) + "]");
- synchronized(_received1)
+ public void onMessage(Message message)
{
- _received1.add(message);
- _received1.notify();
+ _log.debug("consumer 1 got message [" + getTextMessage(message) + "]");
+ synchronized (_received1)
+ {
+ _received1.add(message);
+ _received1.notify();
+ }
}
- }
- });
+ });
_session2 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_session2.createConsumer(_destination2).setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
{
- _log.debug("consumer 2 got message [" + getTextMessage(message) + "]");
- synchronized(_received2)
+ public void onMessage(Message message)
{
- _received2.add(message);
- _received2.notify();
+ _log.debug("consumer 2 got message [" + getTextMessage(message) + "]");
+ synchronized (_received2)
+ {
+ _received2.add(message);
+ _received2.notify();
+ }
}
- }
- });
+ });
_connection.start();
}
@@ -145,12 +145,12 @@ public class ChannelCloseOkTest extends TestCase
public void testWithExceptionListener() throws Exception
{
_connection.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException jmsException)
{
- _log.warn("onException - "+jmsException.getMessage());
- }
- });
+ public void onException(JMSException jmsException)
+ {
+ _log.warn("onException - " + jmsException.getMessage());
+ }
+ });
doTest();
}
@@ -175,6 +175,7 @@ public class ChannelCloseOkTest extends TestCase
send(_session1, _destination1, "" + i);
send(_session2, _destination2, "" + i);
}
+
waitFor(_received1, num + 1);
waitFor(_received2, num + 1);
@@ -184,7 +185,7 @@ public class ChannelCloseOkTest extends TestCase
}
private void sendAndWait(Session session, Destination destination, String message, List<Message> received, int count)
- throws JMSException, InterruptedException
+ throws JMSException, InterruptedException
{
send(session, destination, message);
waitFor(received, count);
@@ -199,7 +200,7 @@ public class ChannelCloseOkTest extends TestCase
private void waitFor(List<Message> received, int count) throws InterruptedException
{
- synchronized(received)
+ synchronized (received)
{
while (received.size() < count)
{
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
index 51bbe7d0e6..87984e8c49 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
@@ -14,46 +14,48 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.test.unit.client.channelclose;
import junit.framework.TestCase;
-import javax.jms.Connection;
-import javax.jms.Session;
-
-import javax.jms.JMSException;
-import javax.jms.ExceptionListener;
-import javax.jms.MessageProducer;
-import javax.jms.MessageConsumer;
-import javax.jms.Message;
-import javax.jms.TextMessage;
-import javax.jms.Queue;
-
-import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.ChannelCloseOkBody;
import org.apache.qpid.framing.ChannelOpenBody;
import org.apache.qpid.framing.ChannelOpenOkBody;
-import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.ExchangeDeclareBody;
import org.apache.qpid.framing.ExchangeDeclareOkBody;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.ChannelCloseOkBody;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQTimeoutException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.jms.ConnectionListener;
-import org.apache.log4j.Logger;
+import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.url.URLSyntaxException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Connection;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
public class ChannelCloseTest extends TestCase implements ExceptionListener, ConnectionListener
{
- private static final Logger _logger = Logger.getLogger(ChannelCloseTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseTest.class);
Connection _connection;
private String _brokerlist = "vm://:1";
@@ -73,15 +75,14 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
TransportConnection.killAllVMBrokers();
}
-
/*
close channel, use chanel with same id ensure error.
- */
- public void testReusingChannelAfterFullClosure()
+ */
+ public void testReusingChannelAfterFullClosure() throws Exception
{
_connection = newConnection();
- //Create Producer
+ // Create Producer
try
{
_connection.start();
@@ -113,6 +114,7 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
{
_logger.info("Exception occured was:" + e.getErrorCode());
}
+
assertEquals("Connection should be closed", AMQConstant.CHANNEL_ERROR, e.getErrorCode());
_connection = newConnection();
@@ -134,29 +136,27 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
/*
close channel and send guff then send ok no errors
*/
- public void testSendingMethodsAfterClose()
+ public void testSendingMethodsAfterClose() throws Exception
{
try
{
- _connection = new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='"
- + _brokerlist + "'");
+ _connection = new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='" + _brokerlist + "'");
((AMQConnection) _connection).setConnectionListener(this);
-
_connection.setExceptionListener(this);
- //Change the StateManager for one that doesn't respond with Close-OKs
+ // Change the StateManager for one that doesn't respond with Close-OKs
AMQStateManager oldStateManager = ((AMQConnection) _connection).getProtocolHandler().getStateManager();
_session = _connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
_connection.start();
- //Test connection
+ // Test connection
checkSendingMessage();
- //Set StateManager to manager that ignores Close-oks
+ // Set StateManager to manager that ignores Close-oks
AMQProtocolSession protocolSession = ((AMQConnection) _connection).getProtocolHandler().getProtocolSession();
AMQStateManager newStateManager = new NoCloseOKStateManager(protocolSession);
newStateManager.changeState(oldStateManager.getCurrentState());
@@ -214,7 +214,7 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
createChannelAndTest(TEST_CHANNEL);
- //Test connection is still ok
+ // Test connection is still ok
checkSendingMessage();
@@ -248,9 +248,9 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
}
}
- private void createChannelAndTest(int channel)
+ private void createChannelAndTest(int channel) throws FailoverException
{
- //Create A channel
+ // Create A channel
try
{
createChannel(channel);
@@ -274,14 +274,14 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
private void sendClose(int channel)
{
- AMQFrame frame = ChannelCloseOkBody.createAMQFrame(channel,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion());
+ AMQFrame frame =
+ ChannelCloseOkBody.createAMQFrame(channel,
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion());
((AMQConnection) _connection).getProtocolHandler().writeFrame(frame);
}
-
private void checkSendingMessage() throws JMSException
{
TEST++;
@@ -307,8 +307,7 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
AMQConnection connection = null;
try
{
- connection = new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='"
- + _brokerlist + "'");
+ connection = new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='" + _brokerlist + "'");
connection.setConnectionListener(this);
@@ -330,24 +329,24 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
fail("Creating new connection when:" + e.getMessage());
}
-
return connection;
}
- private void declareExchange(int channelId, String _type, String _name, boolean nowait) throws AMQException
+ private void declareExchange(int channelId, String _type, String _name, boolean nowait)
+ throws AMQException, FailoverException
{
- AMQFrame exchangeDeclare = ExchangeDeclareBody.createAMQFrame(channelId,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(),
- null, // arguments
- false, // autoDelete
- false, // durable
- new AMQShortString(_name), // exchange
- false, // internal
- nowait, // nowait
- true, // passive
- 0, // ticket
- new AMQShortString(_type)); // type
+ AMQFrame exchangeDeclare =
+ ExchangeDeclareBody.createAMQFrame(channelId,
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(), null, // arguments
+ false, // autoDelete
+ false, // durable
+ new AMQShortString(_name), // exchange
+ false, // internal
+ nowait, // nowait
+ true, // passive
+ 0, // ticket
+ new AMQShortString(_type)); // type
if (nowait)
{
@@ -355,36 +354,31 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
}
else
{
- ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class, SYNC_TIMEOUT);
+ ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class,
+ SYNC_TIMEOUT);
}
}
- private void createChannel(int channelId) throws AMQException
+ private void createChannel(int channelId) throws AMQException, FailoverException
{
- ((AMQConnection) _connection).getProtocolHandler().syncWrite(
- ChannelOpenBody.createAMQFrame(channelId,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(),
- null), // outOfBand
- ChannelOpenOkBody.class);
+ ((AMQConnection) _connection).getProtocolHandler().syncWrite(ChannelOpenBody.createAMQFrame(channelId,
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
+ ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(), null), // outOfBand
+ ChannelOpenOkBody.class);
}
-
public void onException(JMSException jmsException)
{
- //_logger.info("CCT" + jmsException);
+ // _logger.info("CCT" + jmsException);
fail(jmsException.getMessage());
}
public void bytesSent(long count)
- {
- }
+ { }
public void bytesReceived(long count)
- {
-
- }
+ { }
public boolean preFailover(boolean redirect)
{
@@ -397,6 +391,5 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
}
public void failoverComplete()
- {
- }
+ { }
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
index e077bddd8d..19ef612bcc 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,14 +20,16 @@
*/
package org.apache.qpid.test.unit.client.forwardall;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Message;
+import javax.jms.MessageListener;
/**
* Declare a private temporary response queue,
@@ -37,8 +39,7 @@ import org.apache.log4j.Logger;
*/
public class Client implements MessageListener
{
-
- private static final Logger _logger = Logger.getLogger(Client.class);
+ private static final Logger _logger = LoggerFactory.getLogger(Client.class);
private final AMQConnection _connection;
private final AMQSession _session;
@@ -55,10 +56,11 @@ public class Client implements MessageListener
_connection = connection;
_expected = expected;
_session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- AMQQueue response = new AMQQueue(_connection.getDefaultQueueExchangeName(), new AMQShortString("ResponseQueue"), true);
+ AMQQueue response =
+ new AMQQueue(_connection.getDefaultQueueExchangeName(), new AMQShortString("ResponseQueue"), true);
_session.createConsumer(response).setMessageListener(this);
_connection.start();
- AMQQueue service = new SpecialQueue(_connection,"ServiceQueue");
+ AMQQueue service = new SpecialQueue(_connection, "ServiceQueue");
Message request = _session.createTextMessage("Request!");
request.setJMSReplyTo(response);
_session.createProducer(service).send(request);
@@ -72,27 +74,27 @@ public class Client implements MessageListener
public synchronized void onMessage(Message response)
{
-
- _logger.info("Received " + (++_count) + " of " + _expected + " responses.");
- if(_count == _expected)
+
+ _logger.info("Received " + (++_count) + " of " + _expected + " responses.");
+ if (_count == _expected)
{
notifyAll();
}
-
}
synchronized void waitUntilComplete() throws Exception
{
- if(_count < _expected)
+ if (_count < _expected)
{
wait(10000L);
}
- if(_count < _expected)
+
+ if (_count < _expected)
{
- throw new Exception("Didn't receive all messages... got " + _count + " expected " + _expected);
+ throw new Exception("Didn't receive all messages... got " + _count + " expected " + _expected);
}
}
@@ -105,7 +107,8 @@ public class Client implements MessageListener
{
final String connectionString;
final int expected;
- if (argv.length == 0) {
+ if (argv.length == 0)
+ {
connectionString = "localhost:5672";
expected = 100;
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java
index 69c5fc3aa9..9c354ee260 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -23,7 +23,9 @@ package org.apache.qpid.test.unit.client.forwardall;
import junit.framework.TestCase;
import org.apache.qpid.testutil.VMBrokerSetup;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Runs the Service's and Client parts of the test in the same process
@@ -31,7 +33,7 @@ import org.apache.log4j.Logger;
*/
public class CombinedTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(CombinedTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(CombinedTest.class);
protected void setUp() throws Exception
{
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java
index 8482227961..be16f6b7ae 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,14 +20,14 @@
*/
package org.apache.qpid.test.unit.client.forwardall;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jms.JMSException;
public class ServiceCreator implements Runnable
{
- private static final Logger _logger = Logger.getLogger(ServiceCreator.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(ServiceCreator.class);
private static Thread[] threads;
private static ServiceCreator[] _services;
@@ -67,7 +67,7 @@ public class ServiceCreator implements Runnable
}
catch (JMSException e)
{
- //ignore
+ // ignore
}
}
}
@@ -77,7 +77,7 @@ public class ServiceCreator implements Runnable
threads = new Thread[services];
_services = new ServiceCreator[services];
ServiceCreator runner = new ServiceCreator(broker);
- //start services
+ // start services
_logger.info("Starting " + services + " services...");
for (int i = 0; i < services; i++)
{
@@ -106,6 +106,7 @@ public class ServiceCreator implements Runnable
connectionString = argv[0];
services = Integer.parseInt(argv[1]);
}
+
start(connectionString, services);
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java
index 11a6b4b5c5..cd03b523d1 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,17 +20,6 @@
*/
package org.apache.qpid.test.unit.client.message;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-
import junit.framework.TestCase;
import org.apache.qpid.client.AMQConnection;
@@ -38,11 +27,24 @@ import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.testutil.VMBrokerSetup;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
public class ObjectMessageTest extends TestCase implements MessageListener
{
- private static final Logger _logger = Logger.getLogger(ObjectMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ObjectMessageTest.class);
private AMQConnection connection;
private AMQDestination destination;
@@ -59,15 +61,15 @@ public class ObjectMessageTest extends TestCase implements MessageListener
{
super.setUp();
connection = new AMQConnection(_broker, "guest", "guest", randomize("Client"), "test");
- destination = new AMQQueue(connection,randomize("LatencyTest"), true);
+ destination = new AMQQueue(connection, randomize("LatencyTest"), true);
session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- //set up a consumer
+ // set up a consumer
session.createConsumer(destination).setMessageListener(this);
connection.start();
- //create a publisher
- producer = session.createProducer(destination, false, false, true);
+ // create a publisher
+ producer = session.createProducer(destination, false, false, true);
A a1 = new A(1, "A");
A a2 = new A(2, "a");
B b = new B(1, "B");
@@ -77,7 +79,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
c.put("B", b);
c.put("String", "String");
- data = new Serializable[]{a1, a2, b, c, "Hello World!", new Integer(1001)};
+ data = new Serializable[] { a1, a2, b, c, "Hello World!", new Integer(1001) };
}
protected void tearDown() throws Exception
@@ -86,8 +88,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
}
public ObjectMessageTest()
- {
- }
+ { }
ObjectMessageTest(String broker) throws Exception
{
@@ -118,60 +119,60 @@ public class ObjectMessageTest extends TestCase implements MessageListener
{
String testStringProperty = "TestStringProperty";
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestStringProperty",testStringProperty);
+ msg.setObjectProperty("TestStringProperty", testStringProperty);
assertEquals(testStringProperty, msg.getObjectProperty("TestStringProperty"));
}
public void testSetObjectPropertyForBoolean() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestBooleanProperty",Boolean.TRUE);
+ msg.setObjectProperty("TestBooleanProperty", Boolean.TRUE);
assertEquals(Boolean.TRUE, msg.getObjectProperty("TestBooleanProperty"));
}
public void testSetObjectPropertyForByte() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestByteProperty",Byte.MAX_VALUE);
+ msg.setObjectProperty("TestByteProperty", Byte.MAX_VALUE);
assertEquals(Byte.MAX_VALUE, msg.getObjectProperty("TestByteProperty"));
}
public void testSetObjectPropertyForShort() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestShortProperty",Short.MAX_VALUE);
+ msg.setObjectProperty("TestShortProperty", Short.MAX_VALUE);
assertEquals(Short.MAX_VALUE, msg.getObjectProperty("TestShortProperty"));
}
+
public void testSetObjectPropertyForInteger() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestIntegerProperty",Integer.MAX_VALUE);
+ msg.setObjectProperty("TestIntegerProperty", Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, msg.getObjectProperty("TestIntegerProperty"));
}
public void testSetObjectPropertyForDouble() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestDoubleProperty",Double.MAX_VALUE);
+ msg.setObjectProperty("TestDoubleProperty", Double.MAX_VALUE);
assertEquals(Double.MAX_VALUE, msg.getObjectProperty("TestDoubleProperty"));
}
public void testSetObjectPropertyForFloat() throws Exception
{
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestFloatProperty",Float.MAX_VALUE);
+ msg.setObjectProperty("TestFloatProperty", Float.MAX_VALUE);
assertEquals(Float.MAX_VALUE, msg.getObjectProperty("TestFloatProperty"));
}
public void testSetObjectPropertyForByteArray() throws Exception
{
- byte[] array = {1,2,3,4,5};
+ byte[] array = { 1, 2, 3, 4, 5 };
ObjectMessage msg = session.createObjectMessage(data[0]);
- msg.setObjectProperty("TestByteArrayProperty",array);
- assertTrue(Arrays.equals(array,(byte[])msg.getObjectProperty("TestByteArrayProperty")));
+ msg.setObjectProperty("TestByteArrayProperty", array);
+ assertTrue(Arrays.equals(array, (byte[]) msg.getObjectProperty("TestByteArrayProperty")));
}
-
public void testSetObjectForNull() throws Exception
{
ObjectMessage msg = session.createObjectMessage();
@@ -179,13 +180,12 @@ public class ObjectMessageTest extends TestCase implements MessageListener
assertNull(msg.getObject());
}
-
private void send() throws Exception
{
for (int i = 0; i < data.length; i++)
{
ObjectMessage msg;
- if (i % 2 == 0)
+ if ((i % 2) == 0)
{
msg = session.createObjectMessage(data[i]);
}
@@ -194,6 +194,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
msg = session.createObjectMessage();
msg.setObject(data[i]);
}
+
producer.send(msg);
}
}
@@ -205,16 +206,19 @@ public class ObjectMessageTest extends TestCase implements MessageListener
{
throw new Exception("Expected " + data.length + " objects, got " + actual.length);
}
+
for (int i = 0; i < data.length; i++)
{
if (actual[i] instanceof Exception)
{
throw new Exception("Error on receive of " + data[i], ((Exception) actual[i]));
}
+
if (actual[i] == null)
{
throw new Exception("Expected " + data[i] + " got null");
}
+
if (!data[i].equals(actual[i]))
{
throw new Exception("Expected " + data[i] + " got " + actual[i]);
@@ -222,7 +226,6 @@ public class ObjectMessageTest extends TestCase implements MessageListener
}
}
-
private void close() throws Exception
{
session.close();
@@ -236,6 +239,7 @@ public class ObjectMessageTest extends TestCase implements MessageListener
{
wait();
}
+
waiting = false;
}
@@ -260,21 +264,21 @@ public class ObjectMessageTest extends TestCase implements MessageListener
items.add(e);
}
- synchronized(this)
- {
- received++;
- notify();
- }
+ synchronized (this)
+ {
+ received++;
+ notify();
+ }
}
-
public static void main(String[] argv) throws Exception
{
- String broker = argv.length > 0 ? argv[0] : "vm://:1";
+ String broker = (argv.length > 0) ? argv[0] : "vm://:1";
if ("-help".equals(broker))
{
System.out.println("Usage: <broker>");
}
+
new ObjectMessageTest(broker).testSendAndReceive();
}
@@ -296,12 +300,12 @@ public class ObjectMessageTest extends TestCase implements MessageListener
public boolean equals(Object o)
{
- return o instanceof A && equals((A) o);
+ return (o instanceof A) && equals((A) o);
}
protected boolean equals(A a)
{
- return areEqual(a.sValue, sValue) && a.iValue == iValue;
+ return areEqual(a.sValue, sValue) && (a.iValue == iValue);
}
}
@@ -317,17 +321,16 @@ public class ObjectMessageTest extends TestCase implements MessageListener
protected boolean equals(A a)
{
- return super.equals(a) && a instanceof B && time == ((B) a).time;
+ return super.equals(a) && (a instanceof B) && (time == ((B) a).time);
}
}
private static class C extends HashMap implements Serializable
- {
- }
+ { }
private static boolean areEqual(Object a, Object b)
{
- return a == null ? b == null : a.equals(b);
+ return (a == null) ? (b == null) : a.equals(b);
}
private static String randomize(String in)
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/close/CloseBeforeAckTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/close/CloseBeforeAckTest.java
index 117696196e..5a61480f6a 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/close/CloseBeforeAckTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/close/CloseBeforeAckTest.java
@@ -20,22 +20,23 @@
*/
package org.apache.qpid.test.unit.close;
-import javax.jms.Connection;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.Session;
-
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.transport.TransportConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import uk.co.thebadgerset.junit.concurrency.TestRunnable;
import uk.co.thebadgerset.junit.concurrency.ThreadTestCoordinator;
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
/**
* This test forces the situation where a session is closed whilst a message consumer is still in its onMessage method.
* Running in AUTO_ACK mode, the close call ought to wait until the onMessage method completes, and the ack is sent
@@ -46,7 +47,7 @@ import uk.co.thebadgerset.junit.concurrency.ThreadTestCoordinator;
*/
public class CloseBeforeAckTest extends TestCase
{
- private static final Logger log = Logger.getLogger(CloseBeforeAckTest.class);
+ private static final Logger log = LoggerFactory.getLogger(CloseBeforeAckTest.class);
Connection connection;
Session session;
@@ -64,34 +65,34 @@ public class CloseBeforeAckTest extends TestCase
public void onMessage(Message message)
{
// Give thread 2 permission to close the session.
- allow(new int[]{1});
+ allow(new int[] { 1 });
// Wait until thread 2 has closed the connection, or is blocked waiting for this to complete.
- waitFor(new int[]{1}, true);
+ waitFor(new int[] { 1 }, true);
}
}
TestThread1 testThread1 = new TestThread1();
TestRunnable testThread2 =
- new TestRunnable()
+ new TestRunnable()
+ {
+ public void runWithExceptions() throws Exception
{
- public void runWithExceptions() throws Exception
- {
- // Send a message to be picked up by thread 1.
- session.createProducer(null).send(session.createQueue(TEST_QUEUE_NAME),
- session.createTextMessage("Hi there thread 1!"));
-
- // Wait for thread 1 to pick up the message and give permission to continue.
- waitFor(new int[]{0}, false);
-
- // Close the connection.
- session.close();
-
- // Allow thread 1 to continue to completion, if it is erronously still waiting.
- allow(new int[]{1});
- }
- };
+ // Send a message to be picked up by thread 1.
+ session.createProducer(null).send(session.createQueue(TEST_QUEUE_NAME),
+ session.createTextMessage("Hi there thread 1!"));
+
+ // Wait for thread 1 to pick up the message and give permission to continue.
+ waitFor(new int[] { 0 }, false);
+
+ // Close the connection.
+ session.close();
+
+ // Allow thread 1 to continue to completion, if it is erronously still waiting.
+ allow(new int[] { 1 });
+ }
+ };
public void testCloseBeforeAutoAck_QPID_397() throws Exception
{
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
index d52707d965..a297011acd 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
@@ -22,34 +22,28 @@ package org.apache.qpid.test.unit.close;
import junit.framework.TestCase;
-import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.message.AbstractJMSMessage;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.testutil.QpidClientConnection;
+import org.apache.qpid.url.URLSyntaxException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.jms.ExceptionListener;
-import javax.jms.Session;
import javax.jms.Connection;
import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.MessageProducer;
import javax.jms.Message;
-import javax.jms.TextMessage;
import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.message.AbstractJMSMessage;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.testutil.QpidClientConnection;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Level;
+import java.util.concurrent.atomic.AtomicInteger;
public class MessageRequeueTest extends TestCase
{
-
- private static final Logger _logger = Logger.getLogger(MessageRequeueTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(MessageRequeueTest.class);
protected static AtomicInteger consumerIds = new AtomicInteger(0);
protected final Integer numTestMessages = 150;
@@ -86,7 +80,7 @@ public class MessageRequeueTest extends TestCase
{
super.tearDown();
- if (!passed) // clean up
+ if (!passed) // clean up
{
QpidClientConnection conn = new QpidClientConnection(BROKER);
@@ -96,6 +90,7 @@ public class MessageRequeueTest extends TestCase
conn.disconnect();
}
+
TransportConnection.killVMBroker(1);
}
@@ -117,7 +112,7 @@ public class MessageRequeueTest extends TestCase
final MessageConsumer consumer = conn.getSession().createConsumer(q);
int messagesReceived = 0;
- long messageLog[] = new long[numTestMessages + 1];
+ long[] messageLog = new long[numTestMessages + 1];
_logger.info("consuming...");
Message msg = consumer.receive(1000);
@@ -130,15 +125,13 @@ public class MessageRequeueTest extends TestCase
int msgindex = msg.getIntProperty("index");
if (messageLog[msgindex] != 0)
{
- _logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) msg).getDeliveryTag() +
- ") more than once.");
+ _logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) msg).getDeliveryTag()
+ + ") more than once.");
}
if (_logger.isInfoEnabled())
{
- _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " +
- "DT:" + dt +
- "IN:" + msgindex);
+ _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt + "IN:" + msgindex);
}
if (dt == 0)
@@ -148,7 +141,7 @@ public class MessageRequeueTest extends TestCase
messageLog[msgindex] = dt;
- //get Next message
+ // get Next message
msg = consumer.receive(1000);
}
@@ -163,7 +156,7 @@ public class MessageRequeueTest extends TestCase
for (long b : messageLog)
{
- if (b == 0 && index != 0) //delivery tag of zero shouldn't exist
+ if ((b == 0) && (index != 0)) // delivery tag of zero shouldn't exist
{
_logger.error("Index: " + index + " was not received.");
list.append(" ");
@@ -175,6 +168,7 @@ public class MessageRequeueTest extends TestCase
index++;
}
+
assertEquals(list.toString(), 0, failed);
_logger.info("consumed: " + messagesReceived);
conn.disconnect();
@@ -199,7 +193,7 @@ public class MessageRequeueTest extends TestCase
t1.start();
t2.start();
t3.start();
-// t4.start();
+ // t4.start();
try
{
@@ -228,7 +222,7 @@ public class MessageRequeueTest extends TestCase
for (long b : receieved)
{
- if (b == 0 && index != 0) //delivery tag of zero shouldn't exist (and we don't have msg 0)
+ if ((b == 0) && (index != 0)) // delivery tag of zero shouldn't exist (and we don't have msg 0)
{
_logger.error("Index: " + index + " was not received.");
list.append(" ");
@@ -237,8 +231,10 @@ public class MessageRequeueTest extends TestCase
list.append(b);
failed++;
}
+
index++;
}
+
assertEquals(list.toString() + "-" + numTestMessages + "-" + totalConsumed, 0, failed);
assertEquals("number of consumed messages does not match initial data", numTestMessages, totalConsumed);
passed = true;
@@ -278,15 +274,14 @@ public class MessageRequeueTest extends TestCase
int msgindex = result.getIntProperty("index");
if (receieved[msgindex] != 0)
{
- _logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) result).getDeliveryTag() +
- ") more than once.");
+ _logger.error("Received Message(" + msgindex + ":"
+ + ((AbstractJMSMessage) result).getDeliveryTag() + ") more than once.");
}
if (_logger.isInfoEnabled())
{
- _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " +
- "DT:" + dt +
- "IN:" + msgindex);
+ _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt
+ + "IN:" + msgindex);
}
if (dt == 0)
@@ -297,9 +292,8 @@ public class MessageRequeueTest extends TestCase
receieved[msgindex] = dt;
}
-
count++;
- if (count % 100 == 0)
+ if ((count % 100) == 0)
{
_logger.info("consumer-" + id + ": got " + result + ", new count is " + count);
}
@@ -328,11 +322,10 @@ public class MessageRequeueTest extends TestCase
}
}
-
public void testRequeue() throws JMSException, AMQException, URLSyntaxException
{
int run = 0;
-// while (run < 10)
+ // while (run < 10)
{
run++;
@@ -359,7 +352,6 @@ public class MessageRequeueTest extends TestCase
assertNotNull("Message should not be null", msg);
-
// As we have not ack'd message will be requeued.
_logger.debug("Close Consumer");
consumer.close();
@@ -369,4 +361,4 @@ public class MessageRequeueTest extends TestCase
}
}
-} \ No newline at end of file
+}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java
index a2cd2e4da3..66e0cad1a9 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java
@@ -1,28 +1,29 @@
package org.apache.qpid.test.unit.message;
-import javax.jms.Connection;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.framing.AMQShortString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
/**
* @author Apache Software Foundation
*/
public class JMSDestinationTest extends TestCase
{
-
- private static final Logger _logger = Logger.getLogger(JMSDestinationTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(JMSDestinationTest.class);
public String _connectionString = "vm://:1";
@@ -32,7 +33,6 @@ public class JMSDestinationTest extends TestCase
TransportConnection.createVMBroker(1);
}
-
protected void tearDown() throws Exception
{
super.tearDown();
@@ -43,7 +43,9 @@ public class JMSDestinationTest extends TestCase
{
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue queue = new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false, true);
+ Queue queue =
+ new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false,
+ true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
@@ -64,7 +66,7 @@ public class JMSDestinationTest extends TestCase
TextMessage rm = (TextMessage) consumer.receive();
assertNotNull(rm);
- assertEquals(rm.getJMSDestination(),queue);
+ assertEquals(rm.getJMSDestination(), queue);
con.close();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
index dad1666299..3012909daa 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,17 +20,8 @@
*/
package org.apache.qpid.test.unit.message;
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.Session;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
@@ -38,13 +29,23 @@ import org.apache.qpid.client.message.NonQpidObjectMessage;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.framing.AMQShortString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.Session;
+
/**
* @author Apache Software Foundation
*/
public class JMSPropertiesTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(JMSPropertiesTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(JMSPropertiesTest.class);
public String _connectionString = "vm://:1";
@@ -52,14 +53,12 @@ public class JMSPropertiesTest extends TestCase
public static final int JMS_DELIV_MODE = 1;
public static final String JMS_TYPE = "test.jms.type";
-
protected void setUp() throws Exception
{
super.setUp();
TransportConnection.createVMBroker(1);
}
-
protected void tearDown() throws Exception
{
super.tearDown();
@@ -70,36 +69,38 @@ public class JMSPropertiesTest extends TestCase
{
AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue queue = new AMQQueue(con.getDefaultQueueExchangeName(),new AMQShortString("someQ"), new AMQShortString("someQ"), false, true);
+ Queue queue =
+ new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false,
+ true);
MessageConsumer consumer = consumerSession.createConsumer(queue);
AMQConnection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = producerSession.createProducer(queue);
- Destination JMS_REPLY_TO = new AMQQueue(con2,"my.replyto");
- //create a test message to send
+ Destination JMS_REPLY_TO = new AMQQueue(con2, "my.replyto");
+ // create a test message to send
ObjectMessage sentMsg = new NonQpidObjectMessage();
sentMsg.setJMSCorrelationID(JMS_CORR_ID);
sentMsg.setJMSDeliveryMode(JMS_DELIV_MODE);
sentMsg.setJMSType(JMS_TYPE);
sentMsg.setJMSReplyTo(JMS_REPLY_TO);
- //send it
+ // send it
producer.send(sentMsg);
con2.close();
con.start();
- //get message and check JMS properties
+ // get message and check JMS properties
ObjectMessage rm = (ObjectMessage) consumer.receive();
assertNotNull(rm);
- assertEquals("JMS Correlation ID mismatch",sentMsg.getJMSCorrelationID(),rm.getJMSCorrelationID());
- //TODO: Commented out as always overwritten by send delivery mode value - prob should not set in conversion
- //assertEquals("JMS Delivery Mode mismatch",sentMsg.getJMSDeliveryMode(),rm.getJMSDeliveryMode());
- assertEquals("JMS Type mismatch",sentMsg.getJMSType(),rm.getJMSType());
- assertEquals("JMS Reply To mismatch",sentMsg.getJMSReplyTo(),rm.getJMSReplyTo());
+ assertEquals("JMS Correlation ID mismatch", sentMsg.getJMSCorrelationID(), rm.getJMSCorrelationID());
+ // TODO: Commented out as always overwritten by send delivery mode value - prob should not set in conversion
+ // assertEquals("JMS Delivery Mode mismatch",sentMsg.getJMSDeliveryMode(),rm.getJMSDeliveryMode());
+ assertEquals("JMS Type mismatch", sentMsg.getJMSType(), rm.getJMSType());
+ assertEquals("JMS Reply To mismatch", sentMsg.getJMSReplyTo(), rm.getJMSReplyTo());
con.close();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/message/StreamMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/message/StreamMessageTest.java
index fb5ea58174..9c4f2af107 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/message/StreamMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/message/StreamMessageTest.java
@@ -20,37 +20,39 @@
*/
package org.apache.qpid.test.unit.message;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageEOFException;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.StreamMessage;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQHeadersExchange;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.url.AMQBindingURL;
import org.apache.qpid.url.BindingURL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageEOFException;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+
/**
* @author Apache Software Foundation
*/
public class StreamMessageTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(StreamMessageTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(StreamMessageTest.class);
public String _connectionString = "vm://:1";
@@ -60,7 +62,6 @@ public class StreamMessageTest extends TestCase
TransportConnection.createVMBroker(1);
}
-
protected void tearDown() throws Exception
{
super.tearDown();
@@ -72,15 +73,18 @@ public class StreamMessageTest extends TestCase
Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- AMQHeadersExchange queue = new AMQHeadersExchange(new AMQBindingURL(ExchangeDefaults.HEADERS_EXCHANGE_CLASS+"://"+ExchangeDefaults.HEADERS_EXCHANGE_NAME+"/test/queue1?"+ BindingURL.OPTION_ROUTING_KEY+"='F0000=1'"));
+ AMQHeadersExchange queue =
+ new AMQHeadersExchange(new AMQBindingURL(
+ ExchangeDefaults.HEADERS_EXCHANGE_CLASS + "://" + ExchangeDefaults.HEADERS_EXCHANGE_NAME
+ + "/test/queue1?" + BindingURL.OPTION_ROUTING_KEY + "='F0000=1'"));
FieldTable ft = new FieldTable();
- ft.setString("F1000","1");
- MessageConsumer consumer = consumerSession.createConsumer(queue, AMQSession.DEFAULT_PREFETCH_LOW_MARK, AMQSession.DEFAULT_PREFETCH_HIGH_MARK, false, false, (String)null, ft);
+ ft.setString("F1000", "1");
+ MessageConsumer consumer =
+ consumerSession.createConsumer(queue, AMQSession.DEFAULT_PREFETCH_LOW_MARK,
+ AMQSession.DEFAULT_PREFETCH_HIGH_MARK, false, false, (String) null, ft);
-
- //force synch to ensure the consumer has resulted in a bound queue
- //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
+ // force synch to ensure the consumer has resulted in a bound queue
+ // ((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
// This is the default now
Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
@@ -91,21 +95,18 @@ public class StreamMessageTest extends TestCase
_logger.info("Starting producer connection");
con2.start();
-
MessageProducer mandatoryProducer = producerSession.createProducer(queue);
// Third test - should be routed
_logger.info("Sending isBound message");
- StreamMessage msg = producerSession.createStreamMessage();
+ StreamMessage msg = producerSession.createStreamMessage();
- msg.setStringProperty("F1000","1");
+ msg.setStringProperty("F1000", "1");
- msg.writeByte((byte)42);
+ msg.writeByte((byte) 42);
mandatoryProducer.send(msg);
-
-
_logger.info("Starting consumer connection");
con.start();
@@ -129,23 +130,24 @@ public class StreamMessageTest extends TestCase
AMQQueue queue = new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("testQ"));
MessageConsumer consumer = consumerSession.createConsumer(queue);
consumer.setMessageListener(new MessageListener()
- {
-
- public void onMessage(Message message)
{
- StreamMessage sm = (StreamMessage) message;
- try
- {
- sm.clearBody();
- sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
- }
- catch (JMSException e)
+
+ public void onMessage(Message message)
{
- _logger.error("Error when writing large string to received msg: " + e, e);
- fail("Error when writing large string to received msg" + e);
+ StreamMessage sm = (StreamMessage) message;
+ try
+ {
+ sm.clearBody();
+ sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
+ }
+ catch (JMSException e)
+ {
+ _logger.error("Error when writing large string to received msg: " + e, e);
+ fail("Error when writing large string to received msg" + e);
+ }
}
- }
- });
+ });
+
Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "test");
AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer mandatoryProducer = producerSession.createProducer(queue);
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
index 15cb9678e4..c8d43a47a5 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,14 +20,6 @@
*/
package org.apache.qpid.test.unit.topic;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.TopicSubscriber;
-
import junit.framework.TestCase;
import org.apache.qpid.AMQException;
@@ -36,11 +28,21 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQTopic;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.url.URLSyntaxException;
-import org.apache.log4j.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.TopicSubscriber;
public class DurableSubscriptionTest extends TestCase
{
- private static final Logger _logger = Logger.getLogger(DurableSubscriptionTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(DurableSubscriptionTest.class);
protected void setUp() throws Exception
{
@@ -84,7 +86,6 @@ public class DurableSubscriptionTest extends TestCase
msg = consumer1.receive(1000);
assertEquals(null, msg);
-
_logger.info("Receive message on consumer 1:expecting A");
msg = consumer2.receive();
assertEquals("A", ((TextMessage) msg).getText());
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/CommitRollbackTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/CommitRollbackTest.java
index 0e718da19b..df2a38d0fc 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/CommitRollbackTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/CommitRollbackTest.java
@@ -21,18 +21,21 @@
package org.apache.qpid.test.unit.transacted;
import junit.framework.TestCase;
+
+import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.AMQException;
import org.apache.qpid.url.URLSyntaxException;
-import org.apache.log4j.Logger;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
-import javax.jms.MessageConsumer;
-import javax.jms.Queue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.jms.JMSException;
import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
import javax.jms.TextMessage;
/**
@@ -52,7 +55,7 @@ public class CommitRollbackTest extends TestCase
private MessageConsumer _consumer;
Queue _jmsQueue;
- private static final Logger _logger = Logger.getLogger(CommitRollbackTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(CommitRollbackTest.class);
private static final String BROKER = "vm://:1";
protected void setUp() throws Exception
@@ -62,10 +65,10 @@ public class CommitRollbackTest extends TestCase
{
TransportConnection.createVMBroker(1);
}
+
testMethod++;
queue += testMethod;
-
newConnection();
}
@@ -106,7 +109,6 @@ public class CommitRollbackTest extends TestCase
assertTrue("session is not transacted", _session.getTransacted());
assertTrue("session is not transacted", _pubSession.getTransacted());
-
_logger.info("sending test message");
String MESSAGE_TEXT = "testPutThenDisconnect";
_publisher.send(_pubSession.createTextMessage(MESSAGE_TEXT));
@@ -119,7 +121,7 @@ public class CommitRollbackTest extends TestCase
_logger.info("receiving result");
Message result = _consumer.receive(1000);
- //commit to ensure message is removed from queue
+ // commit to ensure message is removed from queue
_session.commit();
assertNull("test message was put and disconnected before commit, but is still present", result);
@@ -135,7 +137,6 @@ public class CommitRollbackTest extends TestCase
assertTrue("session is not transacted", _session.getTransacted());
assertTrue("session is not transacted", _pubSession.getTransacted());
-
_logger.info("sending test message");
String MESSAGE_TEXT = "testPutThenDisconnect";
_publisher.send(_pubSession.createTextMessage(MESSAGE_TEXT));
@@ -151,7 +152,7 @@ public class CommitRollbackTest extends TestCase
_logger.info("receiving result");
Message result = _consumer.receive(1000);
- //commit to ensure message is removed from queue
+ // commit to ensure message is removed from queue
_session.commit();
assertNull("test message was put and disconnected before commit, but is still present", result);
@@ -168,7 +169,6 @@ public class CommitRollbackTest extends TestCase
assertTrue("session is not transacted", _session.getTransacted());
assertTrue("session is not transacted", _pubSession.getTransacted());
-
_logger.info("sending test message");
String MESSAGE_TEXT = "testPutThenRollback";
_publisher.send(_pubSession.createTextMessage(MESSAGE_TEXT));
@@ -335,13 +335,12 @@ public class CommitRollbackTest extends TestCase
assertTrue("Messasge is not marked as redelivered", result.getJMSRedelivered());
}
-
/**
* Test that rolling back a session purges the dispatcher queue, and the messages arrive in the correct order
*
* @throws Exception On error
*/
- public void testSend2ThenRollback() throws Exception
+ /*public void testSend2ThenRollback() throws Exception
{
assertTrue("session is not transacted", _session.getTransacted());
assertTrue("session is not transacted", _pubSession.getTransacted());
@@ -391,7 +390,7 @@ public class CommitRollbackTest extends TestCase
}
assertNull("test message should be null", result);
- }
+ }*/
public void testSend2ThenCloseAfter1andTryAgain() throws Exception
{
@@ -428,7 +427,7 @@ public class CommitRollbackTest extends TestCase
{
assertTrue("Messasge is not marked as redelivered" + result, result.getJMSRedelivered());
}
- else // or it will be msg 2 arriving the first time due to latency.
+ else // or it will be msg 2 arriving the first time due to latency.
{
_logger.info("Message 2 wasn't prefetched so wasn't rejected");
assertEquals("2", ((TextMessage) result).getText());
@@ -445,7 +444,6 @@ public class CommitRollbackTest extends TestCase
}
-
public void testPutThenRollbackThenGet() throws Exception
{
assertTrue("session is not transacted", _session.getTransacted());
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
index d994d4c141..929621c496 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,24 +20,24 @@
*/
package org.apache.qpid.test.unit.transacted;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.TextMessage;
-
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.TextMessage;
+
public class TransactedTest extends TestCase
{
private AMQQueue queue1;
@@ -56,7 +56,7 @@ public class TransactedTest extends TestCase
private Session testSession;
private MessageConsumer testConsumer1;
private MessageConsumer testConsumer2;
- private static final Logger _logger = Logger.getLogger(TransactedTest.class);
+ private static final Logger _logger = LoggerFactory.getLogger(TransactedTest.class);
protected void setUp() throws Exception
{
@@ -68,13 +68,15 @@ public class TransactedTest extends TestCase
_logger.info("Create Session");
session = con.createSession(true, Session.SESSION_TRANSACTED);
_logger.info("Create Q1");
- queue1 = new AMQQueue(session.getDefaultQueueExchangeName(), new AMQShortString("Q1"), new AMQShortString("Q1"), false, true);
+ queue1 =
+ new AMQQueue(session.getDefaultQueueExchangeName(), new AMQShortString("Q1"), new AMQShortString("Q1"), false,
+ true);
_logger.info("Create Q2");
queue2 = new AMQQueue(session.getDefaultQueueExchangeName(), new AMQShortString("Q2"), false);
_logger.info("Create Consumer of Q1");
consumer1 = session.createConsumer(queue1);
- //Dummy just to create the queue.
+ // Dummy just to create the queue.
_logger.info("Create Consumer of Q2");
MessageConsumer consumer2 = session.createConsumer(queue2);
_logger.info("Close Consumer of Q2");
@@ -98,7 +100,6 @@ public class TransactedTest extends TestCase
_logger.info("Create prep connection start");
prepCon.start();
-
_logger.info("Create test connection");
testCon = new AMQConnection("vm://:1", "guest", "guest", "TestConnection", "test");
_logger.info("Create test session");
@@ -122,7 +123,7 @@ public class TransactedTest extends TestCase
public void testCommit() throws Exception
{
- //add some messages
+ // add some messages
_logger.info("Send prep A");
prepProducer1.send(prepSession.createTextMessage("A"));
_logger.info("Send prep B");
@@ -130,7 +131,7 @@ public class TransactedTest extends TestCase
_logger.info("Send prep C");
prepProducer1.send(prepSession.createTextMessage("C"));
- //send and receive some messages
+ // send and receive some messages
_logger.info("Send X to Q2");
producer2.send(session.createTextMessage("X"));
_logger.info("Send Y to Q2");
@@ -138,7 +139,6 @@ public class TransactedTest extends TestCase
_logger.info("Send Z to Q2");
producer2.send(session.createTextMessage("Z"));
-
_logger.info("Read A from Q1");
expect("A", consumer1.receive(1000));
_logger.info("Read B from Q1");
@@ -146,13 +146,13 @@ public class TransactedTest extends TestCase
_logger.info("Read C from Q1");
expect("C", consumer1.receive(1000));
- //commit
+ // commit
_logger.info("session commit");
session.commit();
_logger.info("Start test Connection");
testCon.start();
- //ensure sent messages can be received and received messages are gone
+ // ensure sent messages can be received and received messages are gone
_logger.info("Read X from Q2");
expect("X", testConsumer2.receive(1000));
_logger.info("Read Y from Q2");
@@ -170,7 +170,7 @@ public class TransactedTest extends TestCase
public void testRollback() throws Exception
{
- //add some messages
+ // add some messages
_logger.info("Send prep A");
prepProducer1.send(prepSession.createTextMessage("A"));
_logger.info("Send prep B");
@@ -178,7 +178,7 @@ public class TransactedTest extends TestCase
_logger.info("Send prep C");
prepProducer1.send(prepSession.createTextMessage("C"));
- //Quick sleep to ensure all three get pre-fetched
+ // Quick sleep to ensure all three get pre-fetched
Thread.sleep(500);
_logger.info("Sending X Y Z");
@@ -188,14 +188,14 @@ public class TransactedTest extends TestCase
_logger.info("Receiving A B");
expect("A", consumer1.receive(1000));
expect("B", consumer1.receive(1000));
- //Don't consume 'C' leave it in the prefetch cache to ensure rollback removes it.
+ // Don't consume 'C' leave it in the prefetch cache to ensure rollback removes it.
- //rollback
+ // rollback
_logger.info("rollback");
session.rollback();
_logger.info("Receiving A B C");
- //ensure sent messages are not visible and received messages are requeued
+ // ensure sent messages are not visible and received messages are requeued
expect("A", consumer1.receive(1000), true);
expect("B", consumer1.receive(1000), true);
expect("C", consumer1.receive(1000), true);
@@ -211,7 +211,7 @@ public class TransactedTest extends TestCase
_logger.info("Testing we have no messages left after commit");
assertTrue(null == testConsumer1.receive(1000));
- assertTrue(null == testConsumer2.receive(1000));
+ assertTrue(null == testConsumer2.receive(1000));
}
public void testResendsMsgsAfterSessionClose() throws Exception
diff --git a/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java b/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
index 195ed79dab..061c1ef7a4 100644
--- a/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
+++ b/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
@@ -1,26 +1,27 @@
package org.apache.qpid.testutil;
+import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.JMSAMQException;
import org.apache.qpid.url.URLSyntaxException;
-import org.apache.log4j.Logger;
-import javax.jms.ExceptionListener;
-import javax.jms.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.jms.Connection;
+import javax.jms.ExceptionListener;
import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.MessageProducer;
import javax.jms.Message;
import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
import javax.jms.TextMessage;
public class QpidClientConnection implements ExceptionListener
{
-
- private static final Logger _logger = Logger.getLogger(QpidClientConnection.class);
+ private static final Logger _logger = LoggerFactory.getLogger(QpidClientConnection.class);
private boolean transacted = true;
private int ackMode = Session.CLIENT_ACKNOWLEDGE;
@@ -40,17 +41,16 @@ public class QpidClientConnection implements ExceptionListener
setPrefetch(5000);
}
-
public void connect() throws JMSException
{
if (!connected)
{
/*
- * amqp://[user:pass@][clientid]/virtualhost?
- * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
- * [&failover='method[?option='value'[&option='value']]']
- * [&option='value']"
- */
+ * amqp://[user:pass@][clientid]/virtualhost?
+ * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
+ * [&failover='method[?option='value'[&option='value']]']
+ * [&option='value']"
+ */
String brokerUrl = "amqp://guest:guest@" + virtualHost + "?brokerlist='" + brokerlist + "'";
try
{
@@ -63,7 +63,6 @@ public class QpidClientConnection implements ExceptionListener
session = ((AMQConnection) connection).createSession(transacted, ackMode, prefetch);
-
_logger.info("starting connection");
connection.start();
@@ -124,7 +123,6 @@ public class QpidClientConnection implements ExceptionListener
this.prefetch = prefetch;
}
-
/** override as necessary */
public void onException(JMSException exception)
{
@@ -266,4 +264,3 @@ public class QpidClientConnection implements ExceptionListener
_logger.info("consumed: " + messagesReceived);
}
}
-
diff --git a/java/common/pom.xml b/java/common/pom.xml
index 80e4229117..aaa9a556e8 100644
--- a/java/common/pom.xml
+++ b/java/common/pom.xml
@@ -98,15 +98,17 @@
<dependencies>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.0</version>
</dependency>
- <!-- This is a mina dependency but it isn't being picked up-->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
</dependency>
<dependency>
diff --git a/java/common/src/main/java/org/apache/qpid/AMQConnectionClosedException.java b/java/common/src/main/java/org/apache/qpid/AMQConnectionClosedException.java
index e95e805e9f..b2ce3c1b32 100644
--- a/java/common/src/main/java/org/apache/qpid/AMQConnectionClosedException.java
+++ b/java/common/src/main/java/org/apache/qpid/AMQConnectionClosedException.java
@@ -23,14 +23,17 @@ package org.apache.qpid;
import org.apache.qpid.protocol.AMQConstant;
/**
- * AMQConnectionClosedException indicates that an operation cannot be performed becauase a connection has been closed.
+ * AMQConnectionClosedException indicates that a connection has been closed.
+ *
+ * <p/>This exception is really used as an event, in order that the method handler that raises it creates an event
+ * which is propagated to the io handler, in order to notify it of the connection closure.
*
* <p/><table id="crc"><caption>CRC Card</caption>
* <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Represents a failed operation on a closed conneciton.
+ * <tr><td> Represents a the closure of a connection.
* </table>
*
- * @todo Does this duplicate AMQConnectionException?
+ * @todo Should review where exceptions-as-events
*/
public class AMQConnectionClosedException extends AMQException
{
diff --git a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java
index 883e13e5e6..a0574efa72 100644
--- a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java
+++ b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java
@@ -14,13 +14,22 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid;
-
+/**
+ * AMQPInvalidClassException indicates an error when trying to store an illegally typed argument in a field table.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Represents illegal argument type for field table values.
+ * </table>
+ *
+ * @todo Could just re-use an exising exception like IllegalArgumentException or ClassCastException.
+ */
public class AMQPInvalidClassException extends RuntimeException
{
public AMQPInvalidClassException(String s)
diff --git a/java/common/src/main/java/org/apache/qpid/codec/AMQCodecFactory.java b/java/common/src/main/java/org/apache/qpid/codec/AMQCodecFactory.java
index 4e3a46eb90..fa890d0ebb 100644
--- a/java/common/src/main/java/org/apache/qpid/codec/AMQCodecFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/codec/AMQCodecFactory.java
@@ -37,10 +37,10 @@ import org.apache.mina.filter.codec.ProtocolEncoder;
public class AMQCodecFactory implements ProtocolCodecFactory
{
/** Holds the protocol encoder. */
- private AMQEncoder _encoder = new AMQEncoder();
+ private final AMQEncoder _encoder = new AMQEncoder();
/** Holds the protocol decoder. */
- private AMQDecoder _frameDecoder;
+ private final AMQDecoder _frameDecoder;
/**
* Creates a new codec factory, specifiying whether it is expected that the first frame of data should be an
diff --git a/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java b/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
index 5a357557ca..2c783aeaa4 100644
--- a/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
@@ -20,13 +20,14 @@
*/
package org.apache.qpid.common;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
-import org.apache.log4j.Logger;
-
/**
* QpidProperties captures the project name, version number, and source code repository revision number from a properties
* file which is generated as part of the build process. Normally, the name and version number are pulled from the module
@@ -50,7 +51,7 @@ import org.apache.log4j.Logger;
public class QpidProperties
{
/** Used for debugging purposes. */
- private static final Logger _logger = Logger.getLogger(QpidProperties.class);
+ private static final Logger _logger = LoggerFactory.getLogger(QpidProperties.class);
/** The name of the version properties file to load from the class path. */
public static final String VERSION_RESOURCE = "qpidversion.properties";
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlock.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlock.java
index 9155c4024f..903b5bfa7a 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlock.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlock.java
@@ -40,4 +40,14 @@ public abstract class AMQDataBlock implements EncodableAMQDataBlock
* @param buffer
*/
public abstract void writePayload(ByteBuffer buffer);
+
+ public ByteBuffer toByteBuffer()
+ {
+ final ByteBuffer buffer = ByteBuffer.allocate((int)getSize());
+
+ writePayload(buffer);
+ buffer.flip();
+ return buffer;
+ }
+
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
index 9f36448986..82ffc60802 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,12 +20,15 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class AMQDataBlockDecoder
{
private static final String SESSION_METHOD_BODY_FACTORY = "QPID_SESSION_METHOD_BODY_FACTORY";
@@ -39,14 +42,10 @@ public class AMQDataBlockDecoder
_bodiesSupported[HeartbeatBody.TYPE] = new HeartbeatBodyFactory();
}
-
- Logger _logger = Logger.getLogger(AMQDataBlockDecoder.class);
-
-
+ Logger _logger = LoggerFactory.getLogger(AMQDataBlockDecoder.class);
public AMQDataBlockDecoder()
- {
- }
+ { }
public boolean decodable(IoSession session, ByteBuffer in) throws AMQFrameDecodingException
{
@@ -56,26 +55,24 @@ public class AMQDataBlockDecoder
{
return false;
}
+
in.skip(1 + 2);
final long bodySize = in.getUnsignedInt();
-
-
return (remainingAfterAttributes >= bodySize);
}
-
protected Object createAndPopulateFrame(IoSession session, ByteBuffer in)
- throws AMQFrameDecodingException, AMQProtocolVersionException
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
final byte type = in.get();
BodyFactory bodyFactory;
- if(type == AMQMethodBody.TYPE)
+ if (type == AMQMethodBody.TYPE)
{
bodyFactory = (BodyFactory) session.getAttribute(SESSION_METHOD_BODY_FACTORY);
- if(bodyFactory == null)
+ if (bodyFactory == null)
{
AMQVersionAwareProtocolSession protocolSession = (AMQVersionAwareProtocolSession) session.getAttachment();
bodyFactory = new AMQMethodBodyFactory(protocolSession);
@@ -89,10 +86,7 @@ public class AMQDataBlockDecoder
bodyFactory = _bodiesSupported[type];
}
-
-
-
- if(bodyFactory == null)
+ if (bodyFactory == null)
{
throw new AMQFrameDecodingException(null, "Unsupported frame type: " + type, null);
}
@@ -101,25 +95,25 @@ public class AMQDataBlockDecoder
final long bodySize = in.getUnsignedInt();
// bodySize can be zero
- if (channel < 0 || bodySize < 0)
+ if ((channel < 0) || (bodySize < 0))
{
- throw new AMQFrameDecodingException(null, "Undecodable frame: type = " + type + " channel = " + channel +
- " bodySize = " + bodySize, null);
+ throw new AMQFrameDecodingException(null, "Undecodable frame: type = " + type + " channel = " + channel
+ + " bodySize = " + bodySize, null);
}
AMQFrame frame = new AMQFrame(in, channel, bodySize, bodyFactory);
-
byte marker = in.get();
if ((marker & 0xFF) != 0xCE)
{
- throw new AMQFrameDecodingException(null, "End of frame marker not found. Read " + marker + " length=" + bodySize + " type=" + type, null);
+ throw new AMQFrameDecodingException(null, "End of frame marker not found. Read " + marker + " length=" + bodySize
+ + " type=" + type, null);
}
+
return frame;
}
- public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
- throws Exception
+ public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception
{
out.write(createAndPopulateFrame(session, in));
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java
index aedea6dd89..05fd2bb480 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,39 +20,37 @@
*/
package org.apache.qpid.framing;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.apache.mina.filter.codec.demux.MessageEncoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Set;
+
public final class AMQDataBlockEncoder implements MessageEncoder
{
- private static final Logger _logger = Logger.getLogger(AMQDataBlockEncoder.class);
+ private static final Logger _logger = LoggerFactory.getLogger(AMQDataBlockEncoder.class);
private final Set _messageTypes = Collections.singleton(EncodableAMQDataBlock.class);
public AMQDataBlockEncoder()
- {
- }
+ { }
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception
{
final AMQDataBlock frame = (AMQDataBlock) message;
- int frameSize = (int)frame.getSize();
- final ByteBuffer buffer = ByteBuffer.allocate(frameSize);
- //buffer.setAutoExpand(true);
- frame.writePayload(buffer);
+
+ final ByteBuffer buffer = frame.toByteBuffer();
if (_logger.isDebugEnabled())
{
_logger.debug("Encoded frame byte-buffer is '" + EncodingUtils.convertToHexString(buffer) + "'");
}
- buffer.flip();
out.write(buffer);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
index 5293c00379..cf85bdab31 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,16 +20,19 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class AMQMethodBodyFactory implements BodyFactory
{
- private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class);
+ private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class);
private final AMQVersionAwareProtocolSession _protocolSession;
-
+
public AMQMethodBodyFactory(AMQVersionAwareProtocolSession protocolSession)
{
_protocolSession = protocolSession;
@@ -37,6 +40,7 @@ public class AMQMethodBodyFactory implements BodyFactory
public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
{
- return _protocolSession.getRegistry().get((short)in.getUnsignedShort(), (short)in.getUnsignedShort(), in, bodySize);
+ return _protocolSession.getRegistry().get((short) in.getUnsignedShort(), (short) in.getUnsignedShort(), in,
+ bodySize);
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
index 3f6ef73781..ee7abd55c0 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
@@ -1,8 +1,10 @@
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A short string is a representation of an AMQ Short String
* Short strings differ from the Java String class by being limited to on ASCII characters (0-127)
@@ -11,11 +13,11 @@ import org.apache.mina.common.ByteBuffer;
*/
public final class AMQShortString implements CharSequence, Comparable<AMQShortString>
{
- private static final Logger _logger = Logger.getLogger(AMQShortString.class);
+ private static final Logger _logger = LoggerFactory.getLogger(AMQShortString.class);
private final ByteBuffer _data;
private int _hashCode;
- final int _length;
+ private final int _length;
private static final char[] EMPTY_CHAR_ARRAY = new char[0];
public AMQShortString(byte[] data)
@@ -25,22 +27,25 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
_length = data.length;
}
-
public AMQShortString(String data)
{
- this(data == null ? EMPTY_CHAR_ARRAY : data.toCharArray());
- if(data != null) _hashCode = data.hashCode();
+ this((data == null) ? EMPTY_CHAR_ARRAY : data.toCharArray());
+ if (data != null)
+ {
+ _hashCode = data.hashCode();
+ }
}
public AMQShortString(char[] data)
{
- if(data == null)
+ if (data == null)
{
throw new NullPointerException("Cannot create AMQShortString with null char[]");
}
+
final int length = data.length;
final byte[] stringBytes = new byte[length];
- for(int i = 0; i < length; i++)
+ for (int i = 0; i < length; i++)
{
stringBytes[i] = (byte) (0xFF & data[i]);
}
@@ -56,12 +61,13 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
final int length = charSequence.length();
final byte[] stringBytes = new byte[length];
int hash = 0;
- for(int i = 0 ; i < length; i++)
+ for (int i = 0; i < length; i++)
{
stringBytes[i] = ((byte) (0xFF & charSequence.charAt(i)));
hash = (31 * hash) + stringBytes[i];
}
+
_data = ByteBuffer.wrap(stringBytes);
_data.rewind();
_hashCode = hash;
@@ -73,9 +79,8 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
{
_data = data;
_length = data.limit();
-
- }
+ }
/**
* Get the length of the short string
@@ -95,17 +100,18 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
public CharSequence subSequence(int start, int end)
{
- return new CharSubSequence(start,end);
+ return new CharSubSequence(start, end);
}
public int writeToByteArray(byte[] encoding, int pos)
{
final int size = length();
encoding[pos++] = (byte) length();
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
encoding[pos++] = _data.get(i);
}
+
return pos;
}
@@ -113,12 +119,12 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
{
final byte len = byteEncodedDestination[pos];
- if(len == 0)
+ if (len == 0)
{
return null;
}
- ByteBuffer data = ByteBuffer.wrap(byteEncodedDestination,pos+1,len).slice();
-
+
+ ByteBuffer data = ByteBuffer.wrap(byteEncodedDestination, pos + 1, len).slice();
return new AMQShortString(data);
}
@@ -141,11 +147,10 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
}
}
-
public byte[] getBytes()
{
- if(_data.buf().hasArray() && _data.arrayOffset() == 0)
+ if (_data.buf().hasArray() && (_data.arrayOffset() == 0))
{
return _data.array();
}
@@ -157,30 +162,27 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
buf.rewind();
buf.get(b);
-
return b;
}
-
}
public void writeToBuffer(ByteBuffer buffer)
{
-
final int size = length();
if (size != 0)
{
- buffer.put((byte)size);
- if(_data.buf().hasArray())
+ buffer.put((byte) size);
+ if (_data.buf().hasArray())
{
- buffer.put(_data.array(),_data.arrayOffset(),length());
+ buffer.put(_data.array(), _data.arrayOffset(), length());
}
else
{
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
buffer.put(_data.get(i));
@@ -200,14 +202,12 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
private final int _offset;
private final int _end;
-
public CharSubSequence(final int offset, final int end)
{
_offset = offset;
_end = end;
}
-
public int length()
{
return _end - _offset;
@@ -220,29 +220,23 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
public CharSequence subSequence(int start, int end)
{
- return new CharSubSequence(start+_offset,end+_offset);
+ return new CharSubSequence(start + _offset, end + _offset);
}
}
-
-
public char[] asChars()
{
final int size = length();
final char[] chars = new char[size];
-
-
-
- for(int i = 0 ; i < size; i++)
+ for (int i = 0; i < size; i++)
{
chars[i] = (char) _data.get(i);
}
+
return chars;
}
-
-
public String asString()
{
return new String(asChars());
@@ -250,66 +244,69 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
public boolean equals(Object o)
{
- if(o == null)
+ if (o == null)
{
return false;
}
- if(o == this)
+
+ if (o == this)
{
return true;
}
- if(o instanceof AMQShortString)
+
+ if (o instanceof AMQShortString)
{
final AMQShortString otherString = (AMQShortString) o;
- if((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
+ if ((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
{
return false;
}
return _data.equals(otherString._data);
-
-
-
}
- return (o instanceof CharSequence) && equals((CharSequence)o);
+
+ return (o instanceof CharSequence) && equals((CharSequence) o);
}
public boolean equals(CharSequence s)
{
- if(s == null)
+ if (s == null)
{
return false;
}
- if(s.length() != length())
+
+ if (s.length() != length())
{
return false;
}
- for(int i = 0; i < length(); i++)
+
+ for (int i = 0; i < length(); i++)
{
- if(charAt(i)!= s.charAt(i))
+ if (charAt(i) != s.charAt(i))
{
return false;
}
}
+
return true;
}
public int hashCode()
{
int hash = _hashCode;
- if(hash == 0)
+ if (hash == 0)
{
final int size = length();
-
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
hash = (31 * hash) + _data.get(i);
}
+
_hashCode = hash;
}
@@ -320,38 +317,42 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
{
_hashCode = 0;
}
-
+
public String toString()
{
return asString();
}
-
public int compareTo(AMQShortString name)
{
- if(name == null)
+ if (name == null)
{
return 1;
}
else
{
- if(name.length() < length())
+ if (name.length() < length())
{
- return - name.compareTo(this);
+ return -name.compareTo(this);
}
-
-
- for(int i = 0; i < length() ; i++)
+ for (int i = 0; i < length(); i++)
{
final byte d = _data.get(i);
final byte n = name._data.get(i);
- if(d < n) return -1;
- if(d > n) return 1;
+ if (d < n)
+ {
+ return -1;
+ }
+
+ if (d > n)
+ {
+ return 1;
+ }
}
- return length() == name.length() ? 0 : -1;
+ return (length() == name.length()) ? 0 : -1;
}
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
index 4424fc1def..61f2f891e5 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,13 +20,14 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class BasicContentHeaderProperties implements CommonContentHeaderProperties
{
- private static final Logger _logger = Logger.getLogger(BasicContentHeaderProperties.class);
+ private static final Logger _logger = LoggerFactory.getLogger(BasicContentHeaderProperties.class);
private static final AMQShortString ZERO_STRING = null;
@@ -96,8 +97,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
private static final int CLUSTER_ID_MASK = 1 << 2;
public BasicContentHeaderProperties()
- {
- }
+ { }
public int getPropertyListSize()
{
@@ -113,30 +113,37 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
size += EncodingUtils.encodedShortStringLength(_contentType);
}
+
if ((_propertyFlags & ENCONDING_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_encoding);
}
+
if ((_propertyFlags & HEADERS_MASK) > 0)
{
size += EncodingUtils.encodedFieldTableLength(_headers);
}
+
if ((_propertyFlags & DELIVERY_MODE_MASK) > 0)
{
size += 1;
}
+
if ((_propertyFlags & PROPRITY_MASK) > 0)
{
size += 1;
}
+
if ((_propertyFlags & CORRELATION_ID_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_correlationId);
}
+
if ((_propertyFlags & REPLY_TO_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_replyTo);
}
+
if ((_propertyFlags & EXPIRATION_MASK) > 0)
{
if (_expiration == 0L)
@@ -148,40 +155,48 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
size += EncodingUtils.encodedShortStringLength(_expiration);
}
}
+
if ((_propertyFlags & MESSAGE_ID_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_messageId);
}
+
if ((_propertyFlags & TIMESTAMP_MASK) > 0)
{
size += 8;
}
+
if ((_propertyFlags & TYPE_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_type);
}
+
if ((_propertyFlags & USER_ID_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_userId);
}
+
if ((_propertyFlags & APPLICATION_ID_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_appId);
}
+
if ((_propertyFlags & CLUSTER_ID_MASK) > 0)
{
size += EncodingUtils.encodedShortStringLength(_clusterId);
}
+
return size;
}
}
private void clearEncodedForm()
{
- if (!_decoded && _encodedForm != null)
+ if (!_decoded && (_encodedForm != null))
{
- //decode();
+ // decode();
}
+
_encodedForm = null;
}
@@ -208,30 +223,37 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
EncodingUtils.writeShortStringBytes(buffer, _contentType);
}
+
if ((_propertyFlags & ENCONDING_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _encoding);
}
+
if ((_propertyFlags & HEADERS_MASK) != 0)
{
EncodingUtils.writeFieldTableBytes(buffer, _headers);
}
+
if ((_propertyFlags & DELIVERY_MODE_MASK) != 0)
{
buffer.put(_deliveryMode);
}
+
if ((_propertyFlags & PROPRITY_MASK) != 0)
{
buffer.put(_priority);
}
+
if ((_propertyFlags & CORRELATION_ID_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _correlationId);
}
+
if ((_propertyFlags & REPLY_TO_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _replyTo);
}
+
if ((_propertyFlags & EXPIRATION_MASK) != 0)
{
if (_expiration == 0L)
@@ -243,26 +265,32 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
EncodingUtils.writeShortStringBytes(buffer, String.valueOf(_expiration));
}
}
+
if ((_propertyFlags & MESSAGE_ID_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _messageId);
}
+
if ((_propertyFlags & TIMESTAMP_MASK) != 0)
{
EncodingUtils.writeTimestamp(buffer, _timestamp);
}
+
if ((_propertyFlags & TYPE_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _type);
}
+
if ((_propertyFlags & USER_ID_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _userId);
}
+
if ((_propertyFlags & APPLICATION_ID_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _appId);
}
+
if ((_propertyFlags & CLUSTER_ID_MASK) != 0)
{
EncodingUtils.writeShortStringBytes(buffer, _clusterId);
@@ -270,8 +298,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
}
}
- public void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size)
- throws AMQFrameDecodingException
+ public void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size) throws AMQFrameDecodingException
{
_propertyFlags = propertyFlags;
@@ -279,6 +306,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
_logger.debug("Property flags: " + _propertyFlags);
}
+
decode(buffer);
/*_encodedForm = new byte[size];
buffer.get(_encodedForm, 0, size);
@@ -289,7 +317,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
private void decode(ByteBuffer buffer)
{
- //ByteBuffer buffer = ByteBuffer.wrap(_encodedForm);
+ // ByteBuffer buffer = ByteBuffer.wrap(_encodedForm);
int pos = buffer.position();
try
{
@@ -297,54 +325,67 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
_contentType = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & ENCONDING_MASK) != 0)
{
_encoding = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & HEADERS_MASK) != 0)
{
_headers = EncodingUtils.readFieldTable(buffer);
}
+
if ((_propertyFlags & DELIVERY_MODE_MASK) != 0)
{
_deliveryMode = buffer.get();
}
+
if ((_propertyFlags & PROPRITY_MASK) != 0)
{
_priority = buffer.get();
}
+
if ((_propertyFlags & CORRELATION_ID_MASK) != 0)
{
_correlationId = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & REPLY_TO_MASK) != 0)
{
_replyTo = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & EXPIRATION_MASK) != 0)
{
_expiration = EncodingUtils.readLongAsShortString(buffer);
}
+
if ((_propertyFlags & MESSAGE_ID_MASK) != 0)
{
_messageId = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & TIMESTAMP_MASK) != 0)
{
_timestamp = EncodingUtils.readTimestamp(buffer);
}
+
if ((_propertyFlags & TYPE_MASK) != 0)
{
_type = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & USER_ID_MASK) != 0)
{
_userId = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & APPLICATION_ID_MASK) != 0)
{
_appId = EncodingUtils.readAMQShortString(buffer);
}
+
if ((_propertyFlags & CLUSTER_ID_MASK) != 0)
{
_clusterId = EncodingUtils.readAMQShortString(buffer);
@@ -367,7 +408,6 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_decoded = true;
}
-
private void decodeUpToHeaders()
{
ByteBuffer buffer = ByteBuffer.wrap(_encodedForm);
@@ -378,16 +418,19 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
byte length = buffer.get();
buffer.skip(length);
}
+
if ((_propertyFlags & ENCONDING_MASK) != 0)
{
byte length = buffer.get();
buffer.skip(length);
}
+
if ((_propertyFlags & HEADERS_MASK) != 0)
{
_headers = EncodingUtils.readFieldTable(buffer);
}
+
_decodedHeaders = true;
}
catch (AMQFrameDecodingException e)
@@ -412,7 +455,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
if (!_decoded)
{
- //decode();
+ // decode();
}
}
@@ -435,14 +478,15 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public AMQShortString getContentType()
{
decodeContentTypeIfNecessary();
+
return _contentType;
}
-
public String getContentTypeAsString()
{
decodeContentTypeIfNecessary();
- return _contentType == null ? null : _contentType.toString();
+
+ return (_contentType == null) ? null : _contentType.toString();
}
public void setContentType(AMQShortString contentType)
@@ -452,21 +496,21 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_contentType = contentType;
}
-
public void setContentType(String contentType)
{
- setContentType(contentType == null ? null : new AMQShortString(contentType));
+ setContentType((contentType == null) ? null : new AMQShortString(contentType));
}
public String getEncodingAsString()
{
- return getEncoding() == null ? null : getEncoding().toString();
+ return (getEncoding() == null) ? null : getEncoding().toString();
}
public AMQShortString getEncoding()
{
decodeIfNecessary();
+
return _encoding;
}
@@ -474,7 +518,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
{
clearEncodedForm();
_propertyFlags |= ENCONDING_MASK;
- _encoding = encoding == null ? null : new AMQShortString(encoding);
+ _encoding = (encoding == null) ? null : new AMQShortString(encoding);
}
public void setEncoding(AMQShortString encoding)
@@ -484,7 +528,6 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_encoding = encoding;
}
-
public FieldTable getHeaders()
{
decodeHeadersIfNecessary();
@@ -504,10 +547,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_headers = headers;
}
-
public byte getDeliveryMode()
{
decodeIfNecessary();
+
return _deliveryMode;
}
@@ -521,6 +564,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public byte getPriority()
{
decodeIfNecessary();
+
return _priority;
}
@@ -534,18 +578,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public AMQShortString getCorrelationId()
{
decodeIfNecessary();
+
return _correlationId;
}
public String getCorrelationIdAsString()
{
decodeIfNecessary();
- return _correlationId == null ? null : _correlationId.toString();
+
+ return (_correlationId == null) ? null : _correlationId.toString();
}
public void setCorrelationId(String correlationId)
{
- setCorrelationId(correlationId == null ? null : new AMQShortString(correlationId));
+ setCorrelationId((correlationId == null) ? null : new AMQShortString(correlationId));
}
public void setCorrelationId(AMQShortString correlationId)
@@ -558,19 +604,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String getReplyToAsString()
{
decodeIfNecessary();
- return _replyTo == null ? null : _replyTo.toString();
+
+ return (_replyTo == null) ? null : _replyTo.toString();
}
public AMQShortString getReplyTo()
{
decodeIfNecessary();
+
return _replyTo;
}
-
public void setReplyTo(String replyTo)
{
- setReplyTo(replyTo == null ? null : new AMQShortString(replyTo));
+ setReplyTo((replyTo == null) ? null : new AMQShortString(replyTo));
}
public void setReplyTo(AMQShortString replyTo)
@@ -584,6 +631,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public long getExpiration()
{
decodeIfNecessary();
+
return _expiration;
}
@@ -594,24 +642,25 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_expiration = expiration;
}
-
public AMQShortString getMessageId()
{
decodeIfNecessary();
+
return _messageId;
}
public String getMessageIdAsString()
{
decodeIfNecessary();
- return _messageId == null ? null : _messageId.toString();
+
+ return (_messageId == null) ? null : _messageId.toString();
}
public void setMessageId(String messageId)
{
clearEncodedForm();
_propertyFlags |= MESSAGE_ID_MASK;
- _messageId = messageId == null ? null : new AMQShortString(messageId);
+ _messageId = (messageId == null) ? null : new AMQShortString(messageId);
}
public void setMessageId(AMQShortString messageId)
@@ -621,10 +670,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
_messageId = messageId;
}
-
public long getTimestamp()
{
decodeIfNecessary();
+
return _timestamp;
}
@@ -638,20 +687,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String getTypeAsString()
{
decodeIfNecessary();
- return _type == null ? null : _type.toString();
- }
+ return (_type == null) ? null : _type.toString();
+ }
public AMQShortString getType()
{
decodeIfNecessary();
+
return _type;
}
-
public void setType(String type)
{
- setType(type == null ? null : new AMQShortString(type));
+ setType((type == null) ? null : new AMQShortString(type));
}
public void setType(AMQShortString type)
@@ -664,18 +713,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String getUserIdAsString()
{
decodeIfNecessary();
- return _userId == null ? null : _userId.toString();
+
+ return (_userId == null) ? null : _userId.toString();
}
public AMQShortString getUserId()
{
decodeIfNecessary();
+
return _userId;
}
public void setUserId(String userId)
{
- setUserId(userId == null ? null : new AMQShortString(userId));
+ setUserId((userId == null) ? null : new AMQShortString(userId));
}
public void setUserId(AMQShortString userId)
@@ -688,18 +739,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String getAppIdAsString()
{
decodeIfNecessary();
- return _appId == null ? null : _appId.toString();
+
+ return (_appId == null) ? null : _appId.toString();
}
public AMQShortString getAppId()
{
decodeIfNecessary();
+
return _appId;
}
public void setAppId(String appId)
{
- setAppId(appId == null ? null : new AMQShortString(appId));
+ setAppId((appId == null) ? null : new AMQShortString(appId));
}
public void setAppId(AMQShortString appId)
@@ -712,18 +765,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String getClusterIdAsString()
{
decodeIfNecessary();
- return _clusterId == null ? null : _clusterId.toString();
+
+ return (_clusterId == null) ? null : _clusterId.toString();
}
public AMQShortString getClusterId()
{
decodeIfNecessary();
+
return _clusterId;
}
public void setClusterId(String clusterId)
{
- setClusterId(clusterId == null ? null : new AMQShortString(clusterId));
+ setClusterId((clusterId == null) ? null : new AMQShortString(clusterId));
}
public void setClusterId(AMQShortString clusterId)
@@ -735,19 +790,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti
public String toString()
{
- return "reply-to = " + _replyTo +
- ",propertyFlags = " + _propertyFlags +
- ",ApplicationID = " + _appId +
- ",ClusterID = " + _clusterId +
- ",UserId = " + _userId +
- ",JMSMessageID = " + _messageId +
- ",JMSCorrelationID = " + _correlationId +
- ",JMSDeliveryMode = " + _deliveryMode +
- ",JMSExpiration = " + _expiration +
- ",JMSPriority = " + _priority +
- ",JMSTimestamp = " + _timestamp +
- ",JMSType = " + _type;
+ return "reply-to = " + _replyTo + ",propertyFlags = " + _propertyFlags + ",ApplicationID = " + _appId
+ + ",ClusterID = " + _clusterId + ",UserId = " + _userId + ",JMSMessageID = " + _messageId
+ + ",JMSCorrelationID = " + _correlationId + ",JMSDeliveryMode = " + _deliveryMode + ",JMSExpiration = "
+ + _expiration + ",JMSPriority = " + _priority + ",JMSTimestamp = " + _timestamp + ",JMSType = " + _type;
}
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java
index 1641cbf4e8..66c5e19633 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java
@@ -1,12 +1,7 @@
package org.apache.qpid.framing;
-import org.apache.mina.common.ByteBuffer;
-
-import org.apache.log4j.Logger;
-
public interface CommonContentHeaderProperties extends ContentHeaderProperties
{
-
AMQShortString getContentType();
void setContentType(AMQShortString contentType);
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
index 5636229d53..c42995d148 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,12 +20,14 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ContentBodyFactory implements BodyFactory
{
- private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class);
+ private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class);
private static final ContentBodyFactory _instance = new ContentBodyFactory();
@@ -44,4 +46,3 @@ public class ContentBodyFactory implements BodyFactory
return new ContentBody(in, bodySize);
}
}
-
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
index 818fc9cf0c..8d5e2f9fb4 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,12 +20,14 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ContentHeaderBodyFactory implements BodyFactory
{
- private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class);
+ private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class);
private static final ContentHeaderBodyFactory _instance = new ContentHeaderBodyFactory();
@@ -43,8 +45,6 @@ public class ContentHeaderBodyFactory implements BodyFactory
{
// all content headers are the same - it is only the properties that differ.
// the content header body further delegates construction of properties
- return new ContentHeaderBody(in,bodySize);
+ return new ContentHeaderBody(in, bodySize);
}
-
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
index 62fefdc2fc..ccba8bd41e 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
@@ -20,15 +20,16 @@
*/
package org.apache.qpid.framing;
-import java.nio.charset.Charset;
+import org.apache.mina.common.ByteBuffer;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import org.apache.mina.common.ByteBuffer;
+import java.nio.charset.Charset;
public class EncodingUtils
{
- private static final Logger _logger = Logger.getLogger(EncodingUtils.class);
+ private static final Logger _logger = LoggerFactory.getLogger(EncodingUtils.class);
private static final String STRING_ENCODING = "iso8859-15";
@@ -1024,6 +1025,4 @@ public class EncodingUtils
return l;
}
-
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
index 631a3ae149..2fe96b722b 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
@@ -20,6 +20,14 @@
*/
package org.apache.qpid.framing;
+import org.apache.mina.common.ByteBuffer;
+
+import org.apache.qpid.AMQPInvalidClassException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigDecimal;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
@@ -27,16 +35,13 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-import java.math.BigDecimal;
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.AMQPInvalidClassException;
-
-//extends FieldTable
+// extends FieldTable
public class FieldTable
{
- private static final Logger _logger = Logger.getLogger(FieldTable.class);
+ private static final Logger _logger = LoggerFactory.getLogger(FieldTable.class);
+ private static final String STRICT_AMQP = "STRICT_AMQP";
+ private final boolean _strictAMQP = Boolean.valueOf(System.getProperty(STRICT_AMQP, "false"));
private ByteBuffer _encodedForm;
private LinkedHashMap<AMQShortString, AMQTypedValue> _properties;
@@ -47,9 +52,9 @@ public class FieldTable
public FieldTable()
{
super();
-// _encodedForm = ByteBuffer.allocate(INITIAL_ENCODED_FORM_SIZE);
-// _encodedForm.setAutoExpand(true);
-// _encodedForm.limit(0);
+ // _encodedForm = ByteBuffer.allocate(INITIAL_ENCODED_FORM_SIZE);
+ // _encodedForm.setAutoExpand(true);
+ // _encodedForm.limit(0);
}
/**
@@ -69,7 +74,6 @@ public class FieldTable
buffer.skip((int) length);
}
-
private AMQTypedValue getProperty(AMQShortString string)
{
checkPropertyName(string);
@@ -112,7 +116,6 @@ public class FieldTable
}
}
-
private AMQTypedValue setProperty(AMQShortString key, AMQTypedValue val)
{
checkPropertyName(key);
@@ -126,7 +129,7 @@ public class FieldTable
return removeKey(key);
}
}
- else if (_encodedForm != null && val != null)
+ else if ((_encodedForm != null) && (val != null))
{
EncodingUtils.writeShortStringBytes(_encodedForm, key);
val.writeToBuffer(_encodedForm);
@@ -137,7 +140,6 @@ public class FieldTable
return null;
}
-
AMQTypedValue oldVal = _properties.put(key, val);
if (oldVal != null)
{
@@ -147,6 +149,7 @@ public class FieldTable
{
_encodedSize += EncodingUtils.encodedShortStringLength(key) + 1;
}
+
_encodedSize += val.getEncodingSize();
return oldVal;
@@ -158,7 +161,7 @@ public class FieldTable
{
if (_properties == null)
{
- if (_encodedForm == null || _encodedSize == 0)
+ if ((_encodedForm == null) || (_encodedSize == 0))
{
_properties = new LinkedHashMap<AMQShortString, AMQTypedValue>();
}
@@ -171,7 +174,6 @@ public class FieldTable
}
}
-
public Boolean getBoolean(String string)
{
return getBoolean(new AMQShortString(string));
@@ -180,7 +182,7 @@ public class FieldTable
public Boolean getBoolean(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.BOOLEAN))
+ if ((value != null) && (value.getType() == AMQType.BOOLEAN))
{
return (Boolean) value.getValue();
}
@@ -190,7 +192,6 @@ public class FieldTable
}
}
-
public Byte getByte(String string)
{
return getByte(new AMQShortString(string));
@@ -199,7 +200,7 @@ public class FieldTable
public Byte getByte(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.BYTE))
+ if ((value != null) && (value.getType() == AMQType.BYTE))
{
return (Byte) value.getValue();
}
@@ -217,7 +218,7 @@ public class FieldTable
public Short getShort(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.SHORT))
+ if ((value != null) && (value.getType() == AMQType.SHORT))
{
return (Short) value.getValue();
}
@@ -235,7 +236,7 @@ public class FieldTable
public Integer getInteger(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.INT))
+ if ((value != null) && (value.getType() == AMQType.INT))
{
return (Integer) value.getValue();
}
@@ -253,7 +254,7 @@ public class FieldTable
public Long getLong(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.LONG))
+ if ((value != null) && (value.getType() == AMQType.LONG))
{
return (Long) value.getValue();
}
@@ -271,7 +272,7 @@ public class FieldTable
public Float getFloat(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.FLOAT))
+ if ((value != null) && (value.getType() == AMQType.FLOAT))
{
return (Float) value.getValue();
}
@@ -289,7 +290,7 @@ public class FieldTable
public Double getDouble(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.DOUBLE))
+ if ((value != null) && (value.getType() == AMQType.DOUBLE))
{
return (Double) value.getValue();
}
@@ -307,12 +308,10 @@ public class FieldTable
public String getString(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) ||
- (value.getType() == AMQType.ASCII_STRING)))
+ if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) || (value.getType() == AMQType.ASCII_STRING)))
{
return (String) value.getValue();
}
-
else if ((value != null) && (value.getValue() != null) && !(value.getValue() instanceof byte[]))
{
return String.valueOf(value.getValue());
@@ -332,7 +331,7 @@ public class FieldTable
public Character getCharacter(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.ASCII_CHARACTER))
+ if ((value != null) && (value.getType() == AMQType.ASCII_CHARACTER))
{
return (Character) value.getValue();
}
@@ -350,7 +349,7 @@ public class FieldTable
public byte[] getBytes(AMQShortString string)
{
AMQTypedValue value = getProperty(string);
- if (value != null && (value.getType() == AMQType.BINARY))
+ if ((value != null) && (value.getType() == AMQType.BINARY))
{
return (byte[]) value.getValue();
}
@@ -382,7 +381,7 @@ public class FieldTable
public Long getTimestamp(AMQShortString name)
{
AMQTypedValue value = getProperty(name);
- if ((value != null) && ((value.getType() == AMQType.TIMESTAMP)))
+ if ((value != null) && (value.getType() == AMQType.TIMESTAMP))
{
return (Long) value.getValue();
}
@@ -395,7 +394,7 @@ public class FieldTable
public BigDecimal getDecimal(AMQShortString propertyName)
{
AMQTypedValue value = getProperty(propertyName);
- if ((value != null) && ((value.getType() == AMQType.DECIMAL)))
+ if ((value != null) && (value.getType() == AMQType.DECIMAL))
{
return (BigDecimal) value.getValue();
}
@@ -405,76 +404,73 @@ public class FieldTable
}
}
-
// ************ Setters
- public Object setBoolean(String string, boolean b)
+ public Object setBoolean(String string, Boolean b)
{
return setBoolean(new AMQShortString(string), b);
}
- public Object setBoolean(AMQShortString string, boolean b)
+ public Object setBoolean(AMQShortString string, Boolean b)
{
return setProperty(string, AMQType.BOOLEAN.asTypedValue(b));
}
- public Object setByte(String string, byte b)
+ public Object setByte(String string, Byte b)
{
return setByte(new AMQShortString(string), b);
}
- public Object setByte(AMQShortString string, byte b)
+ public Object setByte(AMQShortString string, Byte b)
{
return setProperty(string, AMQType.BYTE.asTypedValue(b));
}
- public Object setShort(String string, short i)
+ public Object setShort(String string, Short i)
{
return setShort(new AMQShortString(string), i);
}
- public Object setShort(AMQShortString string, short i)
+ public Object setShort(AMQShortString string, Short i)
{
return setProperty(string, AMQType.SHORT.asTypedValue(i));
}
-
- public Object setInteger(String string, int i)
+ public Object setInteger(String string, Integer i)
{
return setInteger(new AMQShortString(string), i);
}
- public Object setInteger(AMQShortString string, int i)
+ public Object setInteger(AMQShortString string, Integer i)
{
return setProperty(string, AMQType.INT.asTypedValue(i));
}
-
- public Object setLong(String string, long l)
+ public Object setLong(String string, Long l)
{
return setLong(new AMQShortString(string), l);
}
- public Object setLong(AMQShortString string, long l)
+ public Object setLong(AMQShortString string, Long l)
{
return setProperty(string, AMQType.LONG.asTypedValue(l));
}
- public Object setFloat(String string, float f)
+ public Object setFloat(String string, Float f)
{
return setFloat(new AMQShortString(string), f);
}
- public Object setFloat(AMQShortString string, float v)
+ public Object setFloat(AMQShortString string, Float v)
{
return setProperty(string, AMQType.FLOAT.asTypedValue(v));
}
- public Object setDouble(String string, double d)
+ public Object setDouble(String string, Double d)
{
return setDouble(new AMQShortString(string), d);
}
- public Object setDouble(AMQShortString string, double v)
+ public Object setDouble(AMQShortString string, Double v)
{
return setProperty(string, AMQType.DOUBLE.asTypedValue(v));
}
@@ -537,6 +533,7 @@ public class FieldTable
{
byte[] newBytes = new byte[length];
System.arraycopy(bytes, start, newBytes, 0, length);
+
return setBytes(string, bytes);
}
@@ -560,7 +557,7 @@ public class FieldTable
if (decimal.scale() > Byte.MAX_VALUE)
{
throw new UnsupportedOperationException("AMQP doesnot support decimal scales larger than " + Byte.MAX_VALUE);
- }
+ }
return setProperty(string, AMQType.DECIMAL.asTypedValue(decimal));
}
@@ -619,6 +616,7 @@ public class FieldTable
public boolean isNullStringValue(String name)
{
AMQTypedValue value = getProperty(new AMQShortString(name));
+
return (value != null) && (value.getType() == AMQType.VOID);
}
@@ -643,6 +641,7 @@ public class FieldTable
{
checkPropertyName(propertyName);
initMapIfNecessary();
+
return _properties.containsKey(propertyName);
}
@@ -654,6 +653,7 @@ public class FieldTable
public String toString()
{
initMapIfNecessary();
+
return _properties.toString();
}
@@ -668,20 +668,23 @@ public class FieldTable
throw new IllegalArgumentException("Property name must not be the empty string");
}
- checkIdentiferFormat(propertyName);
+ if (_strictAMQP)
+ {
+ checkIdentiferFormat(propertyName);
+ }
}
protected static void checkIdentiferFormat(AMQShortString propertyName)
{
-// AMQP Spec: 4.2.5.5 Field Tables
-// Guidelines for implementers:
-// * Field names MUST start with a letter, '$' or '#' and may continue with
-// letters, '$' or '#', digits, or underlines, to a maximum length of 128
-// characters.
-// * The server SHOULD validate field names and upon receiving an invalid
-// field name, it SHOULD signal a connection exception with reply code
-// 503 (syntax error). Conformance test: amq_wlp_table_01.
-// * A peer MUST handle duplicate fields by using only the first instance.
+ // AMQP Spec: 4.2.5.5 Field Tables
+ // Guidelines for implementers:
+ // * Field names MUST start with a letter, '$' or '#' and may continue with
+ // letters, '$' or '#', digits, or underlines, to a maximum length of 128
+ // characters.
+ // * The server SHOULD validate field names and upon receiving an invalid
+ // field name, it SHOULD signal a connection exception with reply code
+ // 503 (syntax error). Conformance test: amq_wlp_table_01.
+ // * A peer MUST handle duplicate fields by using only the first instance.
// AMQP length limit
if (propertyName.length() > 128)
@@ -690,12 +693,11 @@ public class FieldTable
}
// AMQ start character
- if (!(Character.isLetter(propertyName.charAt(0))
- || propertyName.charAt(0) == '$'
- || propertyName.charAt(0) == '#'
- || propertyName.charAt(0) == '_')) // Not official AMQP added for JMS.
+ if (!(Character.isLetter(propertyName.charAt(0)) || (propertyName.charAt(0) == '$')
+ || (propertyName.charAt(0) == '#') || (propertyName.charAt(0) == '_'))) // Not official AMQP added for JMS.
{
- throw new IllegalArgumentException("Identifier '" + propertyName + "' does not start with a valid AMQP start character");
+ throw new IllegalArgumentException("Identifier '" + propertyName
+ + "' does not start with a valid AMQP start character");
}
}
@@ -708,7 +710,7 @@ public class FieldTable
if (trace)
{
_logger.trace("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "...");
- _logger.trace(_properties);
+ _logger.trace(_properties.toString());
}
EncodingUtils.writeUnsignedInteger(buffer, getEncodedSize());
@@ -727,6 +729,7 @@ public class FieldTable
buffer.flip();
buffer.get(result);
buffer.release();
+
return result;
}
@@ -749,6 +752,7 @@ public class FieldTable
}
}
+
_encodedSize = encodedSize;
}
@@ -760,7 +764,6 @@ public class FieldTable
recalculateEncodedSize();
}
-
public static interface FieldTableElementProcessor
{
public boolean processElement(String propertyName, AMQTypedValue value);
@@ -782,15 +785,15 @@ public class FieldTable
}
}
}
- return processor.getResult();
+ return processor.getResult();
}
-
public int size()
{
initMapIfNecessary();
+
return _properties.size();
}
@@ -803,6 +806,7 @@ public class FieldTable
public boolean containsKey(AMQShortString key)
{
initMapIfNecessary();
+
return _properties.containsKey(key);
}
@@ -819,23 +823,21 @@ public class FieldTable
{
keys.add(key.toString());
}
+
return keys;
}
-
public Object get(AMQShortString key)
{
return getObject(key);
}
-
public Object put(AMQShortString key, Object value)
{
return setObject(key, value);
}
-
public Object remove(String key)
{
@@ -846,10 +848,10 @@ public class FieldTable
public Object remove(AMQShortString key)
{
AMQTypedValue val = removeKey(key);
- return val == null ? null : val.getValue();
- }
+ return (val == null) ? null : val.getValue();
+ }
public AMQTypedValue removeKey(AMQShortString key)
{
@@ -865,12 +867,12 @@ public class FieldTable
_encodedSize -= EncodingUtils.encodedShortStringLength(key);
_encodedSize--;
_encodedSize -= value.getEncodingSize();
+
return value;
}
}
-
public void clear()
{
initMapIfNecessary();
@@ -882,6 +884,7 @@ public class FieldTable
public Set<AMQShortString> keySet()
{
initMapIfNecessary();
+
return _properties.keySet();
}
@@ -895,17 +898,17 @@ public class FieldTable
{
_encodedForm.flip();
}
-// _encodedForm.limit((int)getEncodedSize());
+ // _encodedForm.limit((int)getEncodedSize());
+
buffer.put(_encodedForm);
}
else if (_properties != null)
{
final Iterator<Map.Entry<AMQShortString, AMQTypedValue>> it = _properties.entrySet().iterator();
- //If there are values then write out the encoded Size... could check _encodedSize != 0
+ // If there are values then write out the encoded Size... could check _encodedSize != 0
// write out the total length, which we have kept up to date as data is added
-
while (it.hasNext())
{
final Map.Entry<AMQShortString, AMQTypedValue> me = it.next();
@@ -913,14 +916,12 @@ public class FieldTable
{
if (_logger.isTraceEnabled())
{
- _logger.trace("Writing Property:" + me.getKey() +
- " Type:" + me.getValue().getType() +
- " Value:" + me.getValue().getValue());
- _logger.trace("Buffer Position:" + buffer.position() +
- " Remaining:" + buffer.remaining());
+ _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
+ + me.getValue().getValue());
+ _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
}
- //Write the actual parameter name
+ // Write the actual parameter name
EncodingUtils.writeShortStringBytes(buffer, me.getKey());
me.getValue().writeToBuffer(buffer);
}
@@ -929,19 +930,17 @@ public class FieldTable
if (_logger.isTraceEnabled())
{
_logger.trace("Exception thrown:" + e);
- _logger.trace("Writing Property:" + me.getKey() +
- " Type:" + me.getValue().getType() +
- " Value:" + me.getValue().getValue());
- _logger.trace("Buffer Position:" + buffer.position() +
- " Remaining:" + buffer.remaining());
+ _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
+ + me.getValue().getValue());
+ _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
}
+
throw new RuntimeException(e);
}
}
}
}
-
private void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
{
@@ -961,17 +960,17 @@ public class FieldTable
if (trace)
{
- _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + "', key '" + key + "', value '" + value.getValue() + "'");
+ _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType()
+ + "', key '" + key + "', value '" + value.getValue() + "'");
}
-
_properties.put(key, value);
-
}
while (buffer.remaining() > expectedRemaining);
}
+
_encodedSize = length;
if (trace)
@@ -983,20 +982,22 @@ public class FieldTable
public int hashCode()
{
initMapIfNecessary();
+
return _properties.hashCode();
}
-
public boolean equals(Object o)
{
if (o == this)
{
return true;
}
+
if (o == null)
{
return false;
}
+
if (!(o instanceof FieldTable))
{
return false;
diff --git a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
index 916b476185..6006e9793c 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
@@ -20,15 +20,16 @@
*/
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
-
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class VersionSpecificRegistry
{
- private static final Logger _log = Logger.getLogger(VersionSpecificRegistry.class);
+ private static final Logger _log = LoggerFactory.getLogger(VersionSpecificRegistry.class);
private final byte _protocolMajorVersion;
private final byte _protocolMinorVersion;
@@ -152,16 +153,17 @@ public class VersionSpecificRegistry
}
catch (NullPointerException e)
{
- throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID + ".", e);
+ throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", e);
}
catch (IndexOutOfBoundsException e)
{
if (classID >= _registry.length)
{
- throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID
- + ".", e);
+ throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", e);
}
else
@@ -175,8 +177,9 @@ public class VersionSpecificRegistry
if (bodyFactory == null)
{
- throw new AMQFrameDecodingException(null, "Method " + methodID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID + ".", null);
+ throw new AMQFrameDecodingException(null, "Method " + methodID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", null);
}
return bodyFactory.newInstance(_protocolMajorVersion, _protocolMinorVersion, classID, methodID, in, size);
diff --git a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
index 7f6b1d40ac..d0dfb1adcf 100644
--- a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
+++ b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
@@ -22,12 +22,15 @@ package org.apache.qpid.pool;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.apache.log4j.Logger;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoSession;
import org.apache.qpid.pool.Event.CloseEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
/**
* PoolingFilter, is a no-op pass through filter that hands all events down the Mina filter chain by default. As it
* adds no behaviour by default to the filter chain, it is abstract.
@@ -78,7 +81,7 @@ import org.apache.qpid.pool.Event.CloseEvent;
public abstract class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionHandler
{
/** Used for debugging purposes. */
- private static final Logger _logger = Logger.getLogger(PoolingFilter.class);
+ private static final Logger _logger = LoggerFactory.getLogger(PoolingFilter.class);
/** Holds a mapping from Mina sessions to batched jobs for execution. */
private final ConcurrentMap<IoSession, Job> _jobs = new ConcurrentHashMap<IoSession, Job>();
@@ -135,7 +138,7 @@ public abstract class PoolingFilter extends IoFilterAdapter implements Job.JobCo
*/
public void init()
{
- _logger.info("Init called on PoolingFilter " + toString());
+ _logger.debug("Init called on PoolingFilter " + toString());
// Called when the filter is initialised in the chain. If the reference count is
// zero this acquire will initialise the pool.
@@ -147,7 +150,7 @@ public abstract class PoolingFilter extends IoFilterAdapter implements Job.JobCo
*/
public void destroy()
{
- _logger.info("Destroy called on PoolingFilter " + toString());
+ _logger.debug("Destroy called on PoolingFilter " + toString());
// When the reference count gets to zero we release the executor service.
_poolReference.releaseExecutorService();
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
index 808272e9ec..2fbeeda1d4 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
@@ -28,7 +28,7 @@ import org.apache.qpid.framing.AMQMethodBody;
*
* <p/>An event listener may be associated with a particular context, usually an AMQP channel, and in addition to
* receiving method events will be notified of errors on that context. This enables listeners to perform any clean
- * up that they need to do before the context is closed.
+ * up that they need to do before the context is closed or retried.
*
* <p/><table id="crc"><caption>CRC Card</caption>
* <tr><th> Responsibilities
@@ -64,8 +64,6 @@ public interface AMQMethodListener
* any necessary clean-up for the context.
*
* @param e The underlying exception that is the source of the error.
- *
- * @todo Consider narrowing the exception, or wrapping it.
*/
void error(Exception e);
}
diff --git a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
index 353c0d39c2..1774fa1194 100644
--- a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
+++ b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
@@ -20,18 +20,19 @@
*/
package org.apache.qpid.url;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-
public class AMQBindingURL implements BindingURL
{
- private static final Logger _logger = Logger.getLogger(AMQBindingURL.class);
+ private static final Logger _logger = LoggerFactory.getLogger(AMQBindingURL.class);
String _url;
AMQShortString _exchangeClass;
diff --git a/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java b/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java
index 4636f44795..461cf9591d 100644
--- a/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java
+++ b/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java
@@ -14,22 +14,23 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.util;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.Queue;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;
public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQueueAtomicSize<E> implements MessageQueue<E>
{
- private static final Logger _logger = Logger.getLogger(ConcurrentLinkedMessageQueueAtomicSize.class);
+ private static final Logger _logger = LoggerFactory.getLogger(ConcurrentLinkedMessageQueueAtomicSize.class);
protected Queue<E> _messageHead = new ConcurrentLinkedQueueAtomicSize<E>();
@@ -62,7 +63,6 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
_logger.debug("Providing item(" + e + ")from message head");
}
-
if (e != null)
{
_messageHeadSize.decrementAndGet();
@@ -85,6 +85,7 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
if (_messageHead.remove(o))
{
_messageHeadSize.decrementAndGet();
+
return true;
}
@@ -101,26 +102,25 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
}
else
{
- //fixme this is super.removeAll but iterator here doesn't work
+ // fixme this is super.removeAll but iterator here doesn't work
// we need to be able to correctly decrement _messageHeadSize
-// boolean modified = false;
-// Iterator<?> e = iterator();
-// while (e.hasNext())
-// {
-// if (c.contains(e.next()))
-// {
-// e.remove();
-// modified = true;
-// _size.decrementAndGet();
-// }
-// }
-// return modified;
+ // boolean modified = false;
+ // Iterator<?> e = iterator();
+ // while (e.hasNext())
+ // {
+ // if (c.contains(e.next()))
+ // {
+ // e.remove();
+ // modified = true;
+ // _size.decrementAndGet();
+ // }
+ // }
+ // return modified;
throw new RuntimeException("Not implemented");
}
}
-
@Override
public boolean isEmpty()
{
@@ -173,6 +173,7 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
{
_logger.debug("Peeking item (" + o + ") from message head");
}
+
return o;
}
@@ -182,36 +183,40 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
public Iterator<E> iterator()
{
final Iterator<E> mainMessageIterator = super.iterator();
+
return new Iterator<E>()
- {
- final Iterator<E> _headIterator = _messageHead.iterator();
- final Iterator<E> _mainIterator = mainMessageIterator;
+ {
+ final Iterator<E> _headIterator = _messageHead.iterator();
+ final Iterator<E> _mainIterator = mainMessageIterator;
- Iterator<E> last;
+ Iterator<E> last;
- public boolean hasNext()
- {
- return _headIterator.hasNext() || _mainIterator.hasNext();
- }
+ public boolean hasNext()
+ {
+ return _headIterator.hasNext() || _mainIterator.hasNext();
+ }
- public E next()
- {
- if (_headIterator.hasNext())
+ public E next()
{
- last = _headIterator;
- return _headIterator.next();
+ if (_headIterator.hasNext())
+ {
+ last = _headIterator;
+
+ return _headIterator.next();
+ }
+ else
+ {
+ last = _mainIterator;
+
+ return _mainIterator.next();
+ }
}
- else
+
+ public void remove()
{
- last = _mainIterator;
- return _mainIterator.next();
+ last.remove();
}
- }
- public void remove()
- {
- last.remove();
- }
- };
+ };
}
@Override
@@ -232,11 +237,14 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ
{
_logger.debug("Adding item(" + o + ") to head of queue");
}
+
if (_messageHead.offer(o))
{
_messageHeadSize.incrementAndGet();
+
return true;
}
+
return false;
}
-} \ No newline at end of file
+}
diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
index 3c8d3f916b..3b8ebc1666 100644
--- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
@@ -22,8 +22,6 @@ package org.apache.qpid.util;
import java.io.*;
-import org.apache.log4j.Logger;
-
/**
* FileUtils provides some simple helper methods for working with files. It follows the convention of wrapping all
* checked exceptions as runtimes, so code using these methods is free of try-catch blocks but does not expect to
diff --git a/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java b/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java
index faeb9d7167..10f6a27293 100644
--- a/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java
@@ -26,6 +26,8 @@ package org.apache.qpid.util;
* <p><table id="crc"><caption>CRC Card</caption>
* <tr><th> Responsibilities <th> Collaborations
* </table>
+ *
+ * @todo Drop this. There are already array pretty printing methods it java.utils.Arrays.
*/
public class PrettyPrintingUtils
{
diff --git a/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java b/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
index aa21841256..63cf6f252b 100644
--- a/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
@@ -20,6 +20,9 @@
*/
package org.apache.qpid.util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -28,8 +31,6 @@ import java.net.URL;
import java.util.Iterator;
import java.util.Properties;
-import org.apache.log4j.Logger;
-
/**
* PropertiesHelper defines some static methods which are useful when working with properties
* files.
@@ -46,7 +47,7 @@ import org.apache.log4j.Logger;
public class PropertiesUtils
{
/** Used for logging. */
- private static final Logger log = Logger.getLogger(PropertiesUtils.class);
+ private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class);
/**
* Get properties from an input stream.
diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
index 6160dc1843..e63b0df770 100644
--- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
+++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
@@ -14,27 +14,25 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.framing;
import junit.framework.Assert;
import junit.framework.TestCase;
-import java.util.Enumeration;
-import java.util.Iterator;
-
import org.apache.mina.common.ByteBuffer;
-import org.apache.log4j.Logger;
+
import org.apache.qpid.AMQPInvalidClassException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class PropertyFieldTableTest extends TestCase
{
-
- private static final Logger _logger = Logger.getLogger(PropertyFieldTableTest.class);
-
+ private static final Logger _logger = LoggerFactory.getLogger(PropertyFieldTableTest.class);
/**
* Test that setting a similar named value replaces any previous value set on that name
@@ -42,9 +40,9 @@ public class PropertyFieldTableTest extends TestCase
public void testReplacement()
{
FieldTable table1 = new FieldTable();
- //Set a boolean value
+ // Set a boolean value
table1.setBoolean("value", true);
- //Check length of table is correct (<Value length> + <type> + <Boolean length>)
+ // Check length of table is correct (<Value length> + <type> + <Boolean length>)
int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength();
Assert.assertEquals(size, table1.getEncodedSize());
@@ -55,13 +53,12 @@ public class PropertyFieldTableTest extends TestCase
size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength();
Assert.assertEquals(size, table1.getEncodedSize());
- //Check boolean value is null
+ // Check boolean value is null
Assert.assertEquals(null, table1.getBoolean("value"));
// ... and integer value is good
Assert.assertEquals((Integer) Integer.MAX_VALUE, table1.getInteger("value"));
}
-
/**
* Set a boolean and check that we can only get it back as a boolean and a string
* Check that attempting to lookup a non existent value returns null
@@ -72,10 +69,10 @@ public class PropertyFieldTableTest extends TestCase
table1.setBoolean("value", true);
Assert.assertTrue(table1.propertyExists("value"));
- //Test Getting right value back
+ // Test Getting right value back
Assert.assertEquals((Boolean) true, table1.getBoolean("value"));
- //Check we don't get anything back for other gets
+ // Check we don't get anything back for other gets
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -86,7 +83,7 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //except value as a string
+ // except value as a string
Assert.assertEquals("true", table1.getString("value"));
table1.remove("value");
@@ -94,7 +91,7 @@ public class PropertyFieldTableTest extends TestCase
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getBoolean("Rubbish"));
}
@@ -108,8 +105,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setByte("value", Byte.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(Byte.MAX_VALUE, (byte) table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -120,14 +117,14 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value"));
table1.remove("value");
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getByte("Rubbish"));
}
@@ -141,8 +138,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setShort("value", Short.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(Short.MAX_VALUE, (short) table1.getShort("value"));
@@ -153,18 +150,17 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value"));
table1.remove("value");
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getShort("Rubbish"));
}
-
/**
* Set a char and check that we can only get it back as a char
* Check that attempting to lookup a non existent value returns null
@@ -175,8 +171,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setChar("value", 'c');
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -187,7 +183,7 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("c", table1.getString("value"));
table1.remove("value");
@@ -195,11 +191,10 @@ public class PropertyFieldTableTest extends TestCase
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getCharacter("Rubbish"));
}
-
/**
* Set a double and check that we can only get it back as a double
* Check that attempting to lookup a non existent value returns null
@@ -210,8 +205,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setDouble("value", Double.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -222,20 +217,19 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value"));
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getDouble("Rubbish"));
}
-
/**
* Set a float and check that we can only get it back as a float
* Check that attempting to lookup a non existent value returns null
@@ -246,8 +240,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setFloat("value", Float.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -258,22 +252,20 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value"));
-
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getFloat("Rubbish"));
}
-
/**
* Set an int and check that we can only get it back as an int
* Check that attempting to lookup a non existent value returns null
@@ -284,8 +276,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setInteger("value", Integer.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -296,22 +288,20 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value"));
-
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getInteger("Rubbish"));
}
-
/**
* Set a long and check that we can only get it back as a long
* Check that attempting to lookup a non existent value returns null
@@ -322,8 +312,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setLong("value", Long.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -334,36 +324,34 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(Long.MAX_VALUE, (long) table1.getLong("value"));
Assert.assertEquals(null, table1.getBytes("value"));
- //... and a the string value of it.
+ // ... and a the string value of it.
Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value"));
-
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getLong("Rubbish"));
}
-
/**
* Set a double and check that we can only get it back as a double
* Check that attempting to lookup a non existent value returns null
*/
public void testBytes()
{
- byte[] bytes = {99, 98, 97, 96, 95};
+ byte[] bytes = { 99, 98, 97, 96, 95 };
FieldTable table1 = new FieldTable();
table1.setBytes("value", bytes);
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -374,17 +362,17 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getLong("value"));
assertBytesEqual(bytes, table1.getBytes("value"));
- //... and a the string value of it is null
+ // ... and a the string value of it is null
Assert.assertEquals(null, table1.getString("value"));
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
// Table should now have zero length for encoding
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getBytes("Rubbish"));
}
@@ -405,7 +393,6 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(0, table.keySet().size());
}
-
/**
* Set a String and check that we can only get it back as a String
* Check that attempting to lookup a non existent value returns null
@@ -416,8 +403,8 @@ public class PropertyFieldTableTest extends TestCase
table1.setString("value", "Hello");
Assert.assertTrue(table1.propertyExists("value"));
- //Tets lookups we shouldn't get anything back for other gets
- //we should get right value back for this type ....
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
Assert.assertEquals(null, table1.getBoolean("value"));
Assert.assertEquals(null, table1.getByte("value"));
Assert.assertEquals(null, table1.getShort("value"));
@@ -429,40 +416,35 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(null, table1.getBytes("value"));
Assert.assertEquals("Hello", table1.getString("value"));
- //Try setting a null value and read it back
+ // Try setting a null value and read it back
table1.setString("value", null);
Assert.assertEquals(null, table1.getString("value"));
- //but still contains the value
+ // but still contains the value
Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
- //but after a removeKey it doesn't
+ // but after a removeKey it doesn't
Assert.assertFalse(table1.containsKey("value"));
checkEmpty(table1);
- //Looking up an invalid value returns null
+ // Looking up an invalid value returns null
Assert.assertEquals(null, table1.getString("Rubbish"));
- //Additional Test that haven't been covered for string
+ // Additional Test that haven't been covered for string
table1.setObject("value", "Hello");
- //Check that it was set correctly
+ // Check that it was set correctly
Assert.assertEquals("Hello", table1.getString("value"));
}
-
-
-
-
-
public void testValues()
{
FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
- byte[] bytes = {99, 98, 97, 96, 95};
+ byte[] bytes = { 99, 98, 97, 96, 95 };
table.setBytes("bytes", bytes);
table.setChar("char", 'c');
table.setDouble("double", Double.MAX_VALUE);
@@ -484,7 +466,6 @@ public class PropertyFieldTableTest extends TestCase
table.setObject("object-short", Short.MAX_VALUE);
table.setObject("object-string", "Hello");
-
Assert.assertEquals((Boolean) true, table.getBoolean("bool"));
Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte"));
assertBytesEqual(bytes, table.getBytes("bytes"));
@@ -509,10 +490,9 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals("Hello", table.getObject("object-string"));
}
-
public void testwriteBuffer()
{
- byte[] bytes = {99, 98, 97, 96, 95};
+ byte[] bytes = { 99, 98, 97, 96, 95 };
FieldTable table = new FieldTable();
table.setBoolean("bool", true);
@@ -569,13 +549,11 @@ public class PropertyFieldTableTest extends TestCase
size += 1 + EncodingUtils.encodedShortStringLength("boolean") + EncodingUtils.encodedBooleanLength();
Assert.assertEquals(size, result.getEncodedSize());
-
result.setByte("byte", (byte) Byte.MAX_VALUE);
size += 1 + EncodingUtils.encodedShortStringLength("byte") + EncodingUtils.encodedByteLength();
Assert.assertEquals(size, result.getEncodedSize());
-
- byte[] _bytes = {99, 98, 97, 96, 95};
+ byte[] _bytes = { 99, 98, 97, 96, 95 };
result.setBytes("bytes", _bytes);
size += 1 + EncodingUtils.encodedShortStringLength("bytes") + 4 + _bytes.length;
@@ -597,7 +575,6 @@ public class PropertyFieldTableTest extends TestCase
size += 1 + EncodingUtils.encodedShortStringLength("int") + EncodingUtils.encodedIntegerLength();
Assert.assertEquals(size, result.getEncodedSize());
-
result.setLong("long", (long) Long.MAX_VALUE);
size += 1 + EncodingUtils.encodedShortStringLength("long") + EncodingUtils.encodedLongLength();
Assert.assertEquals(size, result.getEncodedSize());
@@ -610,7 +587,6 @@ public class PropertyFieldTableTest extends TestCase
size += 1 + EncodingUtils.encodedShortStringLength("result") + EncodingUtils.encodedLongStringLength("Hello");
Assert.assertEquals(size, result.getEncodedSize());
-
result.setObject("object-bool", true);
size += 1 + EncodingUtils.encodedShortStringLength("object-bool") + EncodingUtils.encodedBooleanLength();
Assert.assertEquals(size, result.getEncodedSize());
@@ -639,7 +615,6 @@ public class PropertyFieldTableTest extends TestCase
size += 1 + EncodingUtils.encodedShortStringLength("object-int") + EncodingUtils.encodedIntegerLength();
Assert.assertEquals(size, result.getEncodedSize());
-
result.setObject("object-long", Long.MAX_VALUE);
size += 1 + EncodingUtils.encodedShortStringLength("object-long") + EncodingUtils.encodedLongLength();
Assert.assertEquals(size, result.getEncodedSize());
@@ -650,63 +625,62 @@ public class PropertyFieldTableTest extends TestCase
}
-// public void testEncodingSize1()
-// {
-// PropertyFieldTable table = new PropertyFieldTable();
-// int length = 0;
-// result.put("one", 1L);
-// length = EncodingUtils.encodedShortStringLength("one");
-// length += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(length, result.getEncodedSize());
-//
-// result.put("two", 2L);
-// length += EncodingUtils.encodedShortStringLength("two");
-// length += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(length, result.getEncodedSize());
-//
-// result.put("three", 3L);
-// length += EncodingUtils.encodedShortStringLength("three");
-// length += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(length, result.getEncodedSize());
-//
-// result.put("four", 4L);
-// length += EncodingUtils.encodedShortStringLength("four");
-// length += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(length, result.getEncodedSize());
-//
-// result.put("five", 5L);
-// length += EncodingUtils.encodedShortStringLength("five");
-// length += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(length, result.getEncodedSize());
-//
-// //fixme should perhaps be expanded to incorporate all types.
-//
-// final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem?
-//
-// result.writeToBuffer(buffer);
-//
-// buffer.flip();
-//
-// long length = buffer.getUnsignedInt();
-//
-// try
-// {
-// PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
-//
-// Assert.assertEquals((Long) 1L, table2.getLong("one"));
-// Assert.assertEquals((Long) 2L, table2.getLong("two"));
-// Assert.assertEquals((Long) 3L, table2.getLong("three"));
-// Assert.assertEquals((Long) 4L, table2.getLong("four"));
-// Assert.assertEquals((Long) 5L, table2.getLong("five"));
-// }
-// catch (AMQFrameDecodingException e)
-// {
-// e.printStackTrace();
-// fail("PFT should be instantiated from bytes." + e.getCause());
-// }
-//
-// }
-
+ // public void testEncodingSize1()
+ // {
+ // PropertyFieldTable table = new PropertyFieldTable();
+ // int length = 0;
+ // result.put("one", 1L);
+ // length = EncodingUtils.encodedShortStringLength("one");
+ // length += 1 + EncodingUtils.encodedLongLength();
+ // assertEquals(length, result.getEncodedSize());
+ //
+ // result.put("two", 2L);
+ // length += EncodingUtils.encodedShortStringLength("two");
+ // length += 1 + EncodingUtils.encodedLongLength();
+ // assertEquals(length, result.getEncodedSize());
+ //
+ // result.put("three", 3L);
+ // length += EncodingUtils.encodedShortStringLength("three");
+ // length += 1 + EncodingUtils.encodedLongLength();
+ // assertEquals(length, result.getEncodedSize());
+ //
+ // result.put("four", 4L);
+ // length += EncodingUtils.encodedShortStringLength("four");
+ // length += 1 + EncodingUtils.encodedLongLength();
+ // assertEquals(length, result.getEncodedSize());
+ //
+ // result.put("five", 5L);
+ // length += EncodingUtils.encodedShortStringLength("five");
+ // length += 1 + EncodingUtils.encodedLongLength();
+ // assertEquals(length, result.getEncodedSize());
+ //
+ // //fixme should perhaps be expanded to incorporate all types.
+ //
+ // final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem?
+ //
+ // result.writeToBuffer(buffer);
+ //
+ // buffer.flip();
+ //
+ // long length = buffer.getUnsignedInt();
+ //
+ // try
+ // {
+ // PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
+ //
+ // Assert.assertEquals((Long) 1L, table2.getLong("one"));
+ // Assert.assertEquals((Long) 2L, table2.getLong("two"));
+ // Assert.assertEquals((Long) 3L, table2.getLong("three"));
+ // Assert.assertEquals((Long) 4L, table2.getLong("four"));
+ // Assert.assertEquals((Long) 5L, table2.getLong("five"));
+ // }
+ // catch (AMQFrameDecodingException e)
+ // {
+ // e.printStackTrace();
+ // fail("PFT should be instantiated from bytes." + e.getCause());
+ // }
+ //
+ // }
/**
* Additional test for setObject
@@ -715,7 +689,7 @@ public class PropertyFieldTableTest extends TestCase
{
FieldTable table = new FieldTable();
- //Try setting a non primative object
+ // Try setting a non primative object
try
{
@@ -724,7 +698,7 @@ public class PropertyFieldTableTest extends TestCase
}
catch (AMQPInvalidClassException iae)
{
- //normal path
+ // normal path
}
// so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
@@ -739,18 +713,17 @@ public class PropertyFieldTableTest extends TestCase
try
{
- table.setObject((String)null, "String");
+ table.setObject((String) null, "String");
fail("Null property name is not allowed");
}
catch (IllegalArgumentException iae)
{
- //normal path
+ // normal path
}
// so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
-
/**
* Additional test checkPropertyName doesn't accept an empty String
*/
@@ -765,18 +738,19 @@ public class PropertyFieldTableTest extends TestCase
}
catch (IllegalArgumentException iae)
{
- //normal path
+ // normal path
}
// so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
-
/**
* Additional test checkPropertyName doesn't accept an empty String
*/
public void testCheckPropertyNamehasMaxLength()
{
+ String oldVal = System.getProperty("STRICT_AMQP");
+ System.setProperty("STRICT_AMQP", "true");
FieldTable table = new FieldTable();
StringBuffer longPropertyName = new StringBuffer(129);
@@ -793,21 +767,30 @@ public class PropertyFieldTableTest extends TestCase
}
catch (IllegalArgumentException iae)
{
- //normal path
+ // normal path
}
// so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
+ if (oldVal != null)
+ {
+ System.setProperty("STRICT_AMQP", oldVal);
+ }
+ else
+ {
+ System.clearProperty("STRICT_AMQP");
+ }
}
-
/**
* Additional test checkPropertyName starts with a letter
*/
public void testCheckPropertyNameStartCharacterIsLetter()
{
+ String oldVal = System.getProperty("STRICT_AMQP");
+ System.setProperty("STRICT_AMQP", "true");
FieldTable table = new FieldTable();
- //Try a name that starts with a number
+ // Try a name that starts with a number
try
{
table.setObject("1", "String");
@@ -815,21 +798,30 @@ public class PropertyFieldTableTest extends TestCase
}
catch (IllegalArgumentException iae)
{
- //normal path
+ // normal path
}
// so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
+ if (oldVal != null)
+ {
+ System.setProperty("STRICT_AMQP", oldVal);
+ }
+ else
+ {
+ System.clearProperty("STRICT_AMQP");
+ }
}
-
/**
* Additional test checkPropertyName starts with a hash or a dollar
*/
public void testCheckPropertyNameStartCharacterIsHashorDollar()
{
+ String oldVal = System.getProperty("STRICT_AMQP");
+ System.setProperty("STRICT_AMQP", "true");
FieldTable table = new FieldTable();
- //Try a name that starts with a number
+ // Try a name that starts with a number
try
{
table.setObject("#", "String");
@@ -839,8 +831,16 @@ public class PropertyFieldTableTest extends TestCase
{
fail("property name are allowed to start with # and $s");
}
- }
+ if (oldVal != null)
+ {
+ System.setProperty("STRICT_AMQP", oldVal);
+ }
+ else
+ {
+ System.clearProperty("STRICT_AMQP");
+ }
+ }
/**
* Additional test to test the contents of the table
@@ -853,7 +853,7 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals("String", table.getString("StringProperty"));
- //Test Clear
+ // Test Clear
table.clear();
@@ -872,18 +872,12 @@ public class PropertyFieldTableTest extends TestCase
table.setObject("n2", "2");
table.setObject("n3", "3");
-
Assert.assertEquals("1", table.getObject("n1"));
Assert.assertEquals("2", table.getObject("n2"));
Assert.assertEquals("3", table.getObject("n3"));
-
-
-
}
-
-
private void assertBytesEqual(byte[] expected, byte[] actual)
{
Assert.assertEquals(expected.length, actual.length);
diff --git a/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java b/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java
index c480ce3944..815b61d293 100644
--- a/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java
+++ b/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java
@@ -1,10 +1,11 @@
package org.apache.qpid.util;
-import java.util.Properties;
-
import junit.framework.*;
-import org.apache.log4j.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Properties;
/**
* Unit tests the {@link CommandLineParser} class.
@@ -37,7 +38,7 @@ import org.apache.log4j.*;
*/
public class CommandLineParserTest extends TestCase
{
- private static final Logger log = Logger.getLogger(CommandLineParserTest.class);
+ private static final Logger log = LoggerFactory.getLogger(CommandLineParserTest.class);
public CommandLineParserTest(String name)
{
@@ -58,11 +59,6 @@ public class CommandLineParserTest extends TestCase
return suite;
}
- public void setUp()
- {
- NDC.push(getName());
- }
-
/** Check that get errors returns an empty string on no errors. */
public void testGetErrorsReturnsEmptyStringOnNoErrors() throws Exception
{
@@ -534,9 +530,4 @@ public class CommandLineParserTest extends TestCase
assertTrue("IllegalArgumentException not thrown for an unknown option when errors on unknowns mode is on.",
testPassed);
}
-
- protected void tearDown() throws Exception
- {
- NDC.pop();
- }
}
diff --git a/java/integrationtests/docs/RunningSustainedTests.txt b/java/integrationtests/docs/RunningSustainedTests.txt
new file mode 100644
index 0000000000..2b37f4c5a7
--- /dev/null
+++ b/java/integrationtests/docs/RunningSustainedTests.txt
@@ -0,0 +1,15 @@
+In addition to the integration tests the framework provided by this package also allows for
+sustained tests to be run. Currently avaible tests:
+- org.apache.qpid.sustained.SustainedTestClient : Pub Sub test to determine steady state throughput.
+
+
+Running Tests.
+
+Run the tests as per the integration tests.
+ - Start a broker
+ - Start at least one Client [java org.apache.qpid.sustained.TestClient], ensuring unique naming
+ - Start Test Controller [java org.apache.qpid.sustained.TestCoordinator]
+ - Additional Test clients can be started:
+ [java org.apache.qpid.sustained.TestClient -j org.apache.qpid.sustained.SustainedTestClient]
+
+
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java
index 3003c00ca5..31de84e630 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java
@@ -21,10 +21,7 @@
*/
package org.apache.qpid.interop.coordinator;
-import java.util.Collection;
import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.LinkedBlockingQueue;
import javax.jms.*;
@@ -74,13 +71,13 @@ public abstract class CoordinatingTestCase extends TestCase
private static final Logger log = Logger.getLogger(CoordinatingTestCase.class);
/** Holds the contact details for the sending test client. */
- TestClientDetails sender;
+ protected TestClientDetails sender;
/** Holds the contact details for the receving test client. */
- TestClientDetails receiver;
+ protected TestClientDetails receiver;
/** Holds the conversation factory over which to coordinate the test. */
- ConversationFactory conversationFactory;
+ protected ConversationFactory conversationFactory;
/**
* Creates a new coordinating test case with the specified name.
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
index 7c5079327e..6eec20769a 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
@@ -60,28 +60,28 @@ public class Coordinator extends TKTestRunner
public static final String DEFAULT_CONNECTION_PROPS_RESOURCE = "org/apache/qpid/interop/connection.properties";
/** Holds the URL of the broker to coordinate the tests on. */
- String brokerUrl;
+ protected String brokerUrl;
/** Holds the virtual host to coordinate the tests on. If <tt>null</tt>, then the default virtual host is used. */
- String virtualHost;
+ protected String virtualHost;
/** Holds the list of all clients that enlisted, when the compulsory invite was issued. */
- Set<TestClientDetails> enlistedClients = new HashSet<TestClientDetails>();
+ protected Set<TestClientDetails> enlistedClients = new HashSet<TestClientDetails>();
/** Holds the conversation helper for the control conversation. */
- private ConversationFactory conversationFactory;
+ protected ConversationFactory conversationFactory;
/** Holds the connection that the coordinating messages are sent over. */
- private Connection connection;
+ protected Connection connection;
/**
* Holds the name of the class of the test currently being run. Ideally passed into the {@link #createTestResult}
* method, but as the signature is already fixed for this, the current value gets pushed here as a member variable.
*/
- private String currentTestClassName;
+ protected String currentTestClassName;
/** Holds the path of the directory to output test results too, if one is defined. */
- private static String reportDir;
+ protected static String _reportDir;
/**
* Creates an interop test coordinator on the specified broker and virtual host.
@@ -89,7 +89,7 @@ public class Coordinator extends TKTestRunner
* @param brokerUrl The URL of the broker to connect to.
* @param virtualHost The virtual host to run all tests on. Optional, may be <tt>null</tt>.
*/
- Coordinator(String brokerUrl, String virtualHost)
+ public Coordinator(String brokerUrl, String virtualHost)
{
log.debug("Coordinator(String brokerUrl = " + brokerUrl + ", String virtualHost = " + virtualHost + "): called");
@@ -116,38 +116,36 @@ public class Coordinator extends TKTestRunner
// Use the command line parser to evaluate the command line with standard handling behaviour (print errors
// and usage then exit if there are errors).
Properties options =
- CommandLineParser.processCommandLine(args,
- new CommandLineParser(
- new String[][]
- {
- { "b", "The broker URL.", "broker", "false" },
- { "h", "The virtual host to use.", "virtual host", "false" },
- { "o", "The name of the directory to output test timings to.", "dir", "false" }
- }));
+ CommandLineParser.processCommandLine(args,
+ new CommandLineParser(
+ new String[][]
+ {
+ {"b", "The broker URL.", "broker", "false"},
+ {"h", "The virtual host to use.", "virtual host", "false"},
+ {"o", "The name of the directory to output test timings to.", "dir", "false"}
+ }));
// Extract the command line options.
String brokerUrl = options.getProperty("b");
String virtualHost = options.getProperty("h");
- reportDir = options.getProperty("o");
- reportDir = (reportDir == null) ? "." : reportDir;
+ _reportDir = options.getProperty("o");
+ _reportDir = (_reportDir == null) ? "." : _reportDir;
// Scan for available test cases using a classpath scanner.
Collection<Class<? extends CoordinatingTestCase>> testCaseClasses =
- new ArrayList<Class<? extends CoordinatingTestCase>>();
+ new ArrayList<Class<? extends CoordinatingTestCase>>();
// ClasspathScanner.getMatches(CoordinatingTestCase.class, "^Test.*", true);
// Hard code the test classes till the classpath scanner is fixed.
Collections.addAll(testCaseClasses,
- new Class[]
- {
- CoordinatingTestCase1DummyRun.class, CoordinatingTestCase2BasicP2P.class,
- CoordinatingTestCase3BasicPubSub.class
- });
+ CoordinatingTestCase1DummyRun.class,
+ CoordinatingTestCase2BasicP2P.class,
+ CoordinatingTestCase3BasicPubSub.class);
// Check that some test classes were actually found.
- if ((testCaseClasses == null) || testCaseClasses.isEmpty())
+ if (testCaseClasses.isEmpty())
{
throw new RuntimeException(
- "No test classes implementing CoordinatingTestCase were found on the class path.");
+ "No test classes implementing CoordinatingTestCase were found on the class path.");
}
int i = 0;
@@ -194,7 +192,7 @@ public class Coordinator extends TKTestRunner
public TestResult start(String[] testClassNames) throws Exception
{
log.debug("public TestResult start(String[] testClassNames = " + PrettyPrintingUtils.printArray(testClassNames)
- + ": called");
+ + ": called");
// Connect to the broker.
connection = TestClient.createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl, virtualHost);
@@ -228,7 +226,7 @@ public class Coordinator extends TKTestRunner
// Record the current test class, so that the test results can be output to a file incorporating this name.
this.currentTestClassName = testClassName;
- result = super.start(new String[] { testClassName });
+ result = super.start(new String[]{testClassName});
}
// At this point in time, all tests have completed. Broadcast the shutdown message.
@@ -252,7 +250,7 @@ public class Coordinator extends TKTestRunner
public static Set<TestClientDetails> extractEnlists(Collection<Message> enlists) throws JMSException
{
log.debug("public static Set<TestClientDetails> extractEnlists(Collection<Message> enlists = " + enlists
- + "): called");
+ + "): called");
Set<TestClientDetails> enlistedClients = new HashSet<TestClientDetails>();
@@ -310,9 +308,9 @@ public class Coordinator extends TKTestRunner
targetTest = new WrappedSuiteTestDecorator(suite);
log.debug("Wrapped with a WrappedSuiteTestDecorator.");
}
-
// Wrap the tests in an inviting test decorator, to perform the invite/test cycle.
- targetTest = new InvitingTestDecorator(targetTest, enlistedClients, conversationFactory, connection);
+
+ targetTest = newTestDecorator(targetTest, enlistedClients, conversationFactory, connection);
TestSuite suite = new TestSuite();
suite.addTest(targetTest);
@@ -323,6 +321,11 @@ public class Coordinator extends TKTestRunner
return super.doRun(suite, wait);
}
+ protected WrappedSuiteTestDecorator newTestDecorator(WrappedSuiteTestDecorator targetTest, Set<TestClientDetails> enlistedClients, ConversationFactory conversationFactory, Connection connection)
+ {
+ return new InvitingTestDecorator(targetTest, enlistedClients, conversationFactory, connection);
+ }
+
/**
* Creates the TestResult object to be used for test runs.
*
@@ -335,10 +338,10 @@ public class Coordinator extends TKTestRunner
TKTestResult result = new TKTestResult(fPrinter.getWriter(), delay, verbose, testCaseName);
// Check if a directory to output reports to has been specified and attach test listeners if so.
- if (reportDir != null)
+ if (_reportDir != null)
{
// Create the report directory if it does not already exist.
- File reportDirFile = new File(reportDir);
+ File reportDirFile = new File(_reportDir);
if (!reportDirFile.exists())
{
@@ -377,4 +380,9 @@ public class Coordinator extends TKTestRunner
return result;
}
+
+ public void setReportDir(String reportDir)
+ {
+ _reportDir = reportDir;
+ }
}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java
index 858ed1a589..8695f7f66f 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java
@@ -21,7 +21,6 @@
package org.apache.qpid.interop.coordinator;
import java.util.*;
-import java.util.concurrent.LinkedBlockingQueue;
import javax.jms.Connection;
import javax.jms.Destination;
@@ -30,7 +29,6 @@ import javax.jms.Message;
import junit.framework.Test;
import junit.framework.TestResult;
-import junit.framework.TestSuite;
import org.apache.log4j.Logger;
@@ -107,7 +105,7 @@ public class InvitingTestDecorator extends WrappedSuiteTestDecorator
CoordinatingTestCase coordTest = (CoordinatingTestCase) test;
// Broadcast the invitation to find out what clients are available to test.
- Set<TestClientDetails> enlists = null;
+ Set<TestClientDetails> enlists;
try
{
Message invite = conversationFactory.getSession().createMessage();
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningCoordinatorTest.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningCoordinatorTest.java
new file mode 100644
index 0000000000..1b4461f8c2
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningCoordinatorTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *
+ */
+package org.apache.qpid.interop.coordinator;
+
+import javax.jms.Message;
+
+public interface ListeningCoordinatorTest
+{
+ public void latejoin(Message message);
+}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningTestDecorator.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningTestDecorator.java
new file mode 100644
index 0000000000..4312dfbcc6
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/ListeningTestDecorator.java
@@ -0,0 +1,200 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.interop.coordinator;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+import org.apache.log4j.Logger;
+import org.apache.qpid.util.ConversationFactory;
+import uk.co.thebadgerset.junit.extensions.WrappedSuiteTestDecorator;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * <p><table id="crc"><caption>CRC Card</caption> <tr><th> Responsibilities <th> Collaborations <tr><td> Broadcast test
+ * invitations and collect enlists. <td> {@link ConversationFactory}. <tr><td> Output test failures for clients
+ * unwilling to run the test case. <td> {@link Coordinator} <tr><td> Execute coordinated test cases. <td> {@link
+ * CoordinatingTestCase} </table>
+ */
+public class ListeningTestDecorator extends WrappedSuiteTestDecorator implements MessageListener
+{
+ private static final Logger log = Logger.getLogger(ListeningTestDecorator.class);
+
+ /** Holds the contact information for all test clients that are available and that may take part in the test. */
+ Set<TestClientDetails> allClients;
+
+ /** Holds the conversation helper for the control level conversation for coordinating the test through. */
+ ConversationFactory conversationFactory;
+
+ /** Holds the connection that the control conversation is held over. */
+ Connection connection;
+
+ /** Holds the underlying {@link CoordinatingTestCase}s that this decorator wraps. */
+ WrappedSuiteTestDecorator testSuite;
+
+ /** Hold the current running test case. */
+ CoordinatingTestCase _currentTest = null;
+
+ /**
+ * Creates a wrapped suite test decorator from another one.
+ *
+ * @param suite The test suite.
+ * @param availableClients The list of all clients that responded to the compulsory invite.
+ * @param controlConversation The conversation helper for the control level, test coordination conversation.
+ * @param controlConnection The connection that the coordination messages are sent over.
+ */
+ public ListeningTestDecorator(WrappedSuiteTestDecorator suite, Set<TestClientDetails> availableClients,
+ ConversationFactory controlConversation, Connection controlConnection)
+ {
+ super(suite);
+
+ log.debug("public InvitingTestDecorator(WrappedSuiteTestDecorator suite, Set<TestClientDetails> allClients = "
+ + availableClients + ", ConversationHelper controlConversation = " + controlConversation + "): called");
+
+ testSuite = suite;
+ allClients = availableClients;
+ conversationFactory = controlConversation;
+ connection = controlConnection;
+ }
+
+ /**
+ * Broadcasts a test invitation and accetps enlisting from participating clients. The wrapped test case is then
+ * repeated for every combination of test clients (provided the wrapped test case extends {@link
+ * CoordinatingTestCase}.
+ *
+ * <p/>Any JMSExceptions during the invite/enlist conversation will be allowed to fall through as runtime
+ * exceptions, resulting in the non-completion of the test run.
+ *
+ * @param testResult The the results object to monitor the test results with.
+ *
+ * @todo Better error recovery for failure of the invite/enlist conversation could be added.
+ */
+ public void run(TestResult testResult)
+ {
+ log.debug("public void run(TestResult testResult): called");
+
+ Collection<Test> tests = testSuite.getAllUnderlyingTests();
+
+ for (Test test : tests)
+ {
+ CoordinatingTestCase coordTest = (CoordinatingTestCase) test;
+
+ Set<TestClientDetails> enlists = signupClients(coordTest);
+
+ if (enlists.size() == 0)
+ {
+ throw new RuntimeException("No clients to test with");
+ }
+
+ Iterator<TestClientDetails> clients = enlists.iterator();
+ coordTest.setSender(clients.next());
+
+ while (clients.hasNext())
+ {
+ // Set the sending and receiving client details on the test case.
+ coordTest.setReceiver(clients.next());
+ }
+
+ // Pass down the connection to hold the coordination conversation over.
+ coordTest.setConversationFactory(conversationFactory);
+
+
+ if (coordTest instanceof ListeningCoordinatorTest)
+ {
+ _currentTest = coordTest;
+ }
+ // Execute the test case.
+ coordTest.run(testResult);
+
+ _currentTest = null;
+ }
+ }
+
+ private Set<TestClientDetails> signupClients(CoordinatingTestCase coordTest)
+ {
+ // Broadcast the invitation to find out what clients are available to test.
+ Set<TestClientDetails> enlists;
+ try
+ {
+ Message invite = conversationFactory.getSession().createMessage();
+ Destination controlTopic = conversationFactory.getSession().createTopic("iop.control");
+ ConversationFactory.Conversation conversation = conversationFactory.startConversation();
+
+ invite.setStringProperty("CONTROL_TYPE", "INVITE");
+ invite.setStringProperty("TEST_NAME", coordTest.getTestCaseNameForTestMethod(coordTest.getName()));
+
+ conversation.send(controlTopic, invite);
+
+ // Wait for a short time, to give test clients an opportunity to reply to the invitation.
+ Collection<Message> replies = conversation.receiveAll(allClients.size(), 5000);
+
+ log.debug("Received " + replies.size() + " enlist replies");
+
+ enlists = Coordinator.extractEnlists(replies);
+
+ //Create topic to listen on for latejoiners
+ Destination listenTopic = conversationFactory.getSession().createTopic("iop.control.test." + coordTest.getTestCaseNameForTestMethod(coordTest.getName()));
+
+ //Listen for joiners
+ conversationFactory.getSession().createConsumer(listenTopic).setMessageListener(this);
+ log.debug("Created consumer on :" + listenTopic);
+ }
+ catch (JMSException e)
+ {
+ throw new RuntimeException("There was a JMSException during the invite/enlist conversation.", e);
+ }
+
+ return enlists;
+ }
+
+ /**
+ * Prints a string summarizing this test decorator, mainly for debugging purposes.
+ *
+ * @return String representation for debugging purposes.
+ */
+ public String toString()
+ {
+ return "ListeningTestDecorator: [ testSuite = " + testSuite + " ]";
+ }
+
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ if (message.getStringProperty("CONTROL_TYPE").equals("LATEJOIN"))
+ {
+ ((ListeningCoordinatorTest) _currentTest).latejoin(message);
+ }
+ }
+ catch (JMSException e)
+ {
+ log.debug("Unable to process message:" + message);
+ }
+ }
+}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
index 0b9c72e1b6..6cca23446f 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
@@ -75,16 +75,17 @@ public class TestClient implements MessageListener
/** Holds all the test cases loaded from the classpath. */
Map<String, InteropClientTestCase> testCases = new HashMap<String, InteropClientTestCase>();
- InteropClientTestCase currentTestCase;
+ protected InteropClientTestCase currentTestCase;
- private MessageProducer producer;
- private Session session;
+ protected Connection _connection;
+ protected MessageProducer producer;
+ protected Session session;
- private String clientName = CLIENT_NAME;
+ protected String clientName = CLIENT_NAME;
/**
- * Creates a new interop test client, listenting to the specified broker and virtual host, with the specified
- * client identifying name.
+ * Creates a new interop test client, listenting to the specified broker and virtual host, with the specified client
+ * identifying name.
*
* @param brokerUrl The url of the broker to connect to.
* @param virtualHost The virtual host to conect to.
@@ -93,7 +94,7 @@ public class TestClient implements MessageListener
public TestClient(String brokerUrl, String virtualHost, String clientName)
{
log.debug("public TestClient(String brokerUrl = " + brokerUrl + ", String virtualHost = " + virtualHost
- + ", String clientName = " + clientName + "): called");
+ + ", String clientName = " + clientName + "): called");
// Retain the connection parameters.
this.brokerUrl = brokerUrl;
@@ -117,13 +118,13 @@ public class TestClient implements MessageListener
{
// Use the command line parser to evaluate the command line.
CommandLineParser commandLine =
- new CommandLineParser(
- new String[][]
- {
- { "b", "The broker URL.", "broker", "false" },
- { "h", "The virtual host to use.", "virtual host", "false" },
- { "n", "The test client name.", "name", "false" }
- });
+ new CommandLineParser(
+ new String[][]
+ {
+ {"b", "The broker URL.", "broker", "false"},
+ {"h", "The virtual host to use.", "virtual host", "false"},
+ {"n", "The test client name.", "name", "false"}
+ });
// Capture the command line arguments or display errors and correct usage and then exit.
Properties options = null;
@@ -151,9 +152,17 @@ public class TestClient implements MessageListener
// Create a test client and start it running.
TestClient client = new TestClient(brokerUrl, virtualHost, (clientName == null) ? CLIENT_NAME : clientName);
+ // Use a class path scanner to find all the interop test case implementations.
+ Collection<Class<? extends InteropClientTestCase>> testCaseClasses =
+ new ArrayList<Class<? extends InteropClientTestCase>>();
+ // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true);
+ // Hard code the test classes till the classpath scanner is fixed.
+ Collections.addAll(testCaseClasses,
+ new Class[]{TestCase1DummyRun.class, TestCase2BasicP2P.class, TestClient.class});
+
try
{
- client.start();
+ client.start(testCaseClasses);
}
catch (Exception e)
{
@@ -165,20 +174,12 @@ public class TestClient implements MessageListener
/**
* Starts the interop test client running. This causes it to start listening for incoming test invites.
*
- * @throws JMSException Any underlying JMSExceptions are allowed to fall through.
+ * @throws JMSException Any underlying JMSExceptions are allowed to fall through. @param testCaseClasses
*/
- private void start() throws JMSException
+ protected void start(Collection<Class<? extends InteropClientTestCase>> testCaseClasses) throws JMSException
{
log.debug("private void start(): called");
- // Use a class path scanner to find all the interop test case implementations.
- Collection<Class<? extends InteropClientTestCase>> testCaseClasses =
- new ArrayList<Class<? extends InteropClientTestCase>>();
- // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true);
- // Hard code the test classes till the classpath scanner is fixed.
- Collections.addAll(testCaseClasses,
- new Class[] { TestCase1DummyRun.class, TestCase2BasicP2P.class, TestCase3BasicPubSub.class });
-
// Create all the test case implementations and index them by the test names.
for (Class<? extends InteropClientTestCase> nextClass : testCaseClasses)
{
@@ -200,9 +201,9 @@ public class TestClient implements MessageListener
}
// Open a connection to communicate with the coordinator on.
- Connection connection = createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl, virtualHost);
+ _connection = createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl, virtualHost);
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Set this up to listen for control messages.
MessageConsumer consumer = session.createConsumer(session.createTopic("iop.control." + clientName));
@@ -215,7 +216,7 @@ public class TestClient implements MessageListener
producer = session.createProducer(null);
// Start listening for incoming control messages.
- connection.start();
+ _connection.start();
}
/**
@@ -232,22 +233,25 @@ public class TestClient implements MessageListener
* @param virtualHost The virtual host to connectio to, <tt>null</tt> to use the default.
*
* @return A JMS conneciton.
+ *
+ * @todo Make username/password configurable. Allow multiple urls for fail over. Once it feels right, move it to a
+ * Utils library class.
*/
public static Connection createConnection(String connectionPropsResource, String brokerUrl, String virtualHost)
{
log.debug("public static Connection createConnection(String connectionPropsResource = " + connectionPropsResource
- + ", String brokerUrl = " + brokerUrl + ", String virtualHost = " + virtualHost + "): called");
+ + ", String brokerUrl = " + brokerUrl + ", String virtualHost = " + virtualHost + "): called");
try
{
Properties connectionProps =
- PropertiesUtils.getProperties(TestClient.class.getClassLoader().getResourceAsStream(
- connectionPropsResource));
+ PropertiesUtils.getProperties(TestClient.class.getClassLoader().getResourceAsStream(
+ connectionPropsResource));
if (brokerUrl != null)
{
String connectionString =
- "amqp://guest:guest/" + ((virtualHost != null) ? virtualHost : "") + "?brokerlist='" + brokerUrl + "'";
+ "amqp://guest:guest/" + ((virtualHost != null) ? virtualHost : "") + "?brokerlist='" + brokerUrl + "'";
connectionProps.setProperty(CONNECTION_PROPERTY, connectionString);
}
@@ -286,21 +290,21 @@ public class TestClient implements MessageListener
String controlType = message.getStringProperty("CONTROL_TYPE");
String testName = message.getStringProperty("TEST_NAME");
+ log.info("onMessage(Message message = " + message + "): for '" + controlType + "' to '" + testName + "'");
+
// Check if the message is a test invite.
if ("INVITE".equals(controlType))
{
- String testCaseName = message.getStringProperty("TEST_NAME");
-
// Flag used to indicate that an enlist should be sent. Only enlist to compulsory invites or invites
// for which test cases exist.
boolean enlist = false;
- if (testCaseName != null)
+ if (testName != null)
{
- log.debug("Got an invite to test: " + testCaseName);
+ log.debug("Got an invite to test: " + testName);
// Check if the requested test case is available.
- InteropClientTestCase testCase = testCases.get(testCaseName);
+ InteropClientTestCase testCase = testCases.get(testName);
if (testCase != null)
{
@@ -308,6 +312,10 @@ public class TestClient implements MessageListener
currentTestCase = testCase;
enlist = true;
}
+ else
+ {
+ log.warn("'" + testName + "' not part of this clients tests.");
+ }
}
else
{
@@ -325,6 +333,8 @@ public class TestClient implements MessageListener
enlistMessage.setStringProperty("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName);
enlistMessage.setJMSCorrelationID(message.getJMSCorrelationID());
+ log.info("Sending Message '" + enlistMessage + "'. to " + message.getJMSReplyTo());
+
producer.send(message.getJMSReplyTo(), enlistMessage);
}
}
@@ -369,9 +379,10 @@ public class TestClient implements MessageListener
}
else if ("TERMINATE".equals(controlType))
{
- System.out.println("Received termination instruction from coordinator.");
+ log.info("Received termination instruction from coordinator.");
// Is a cleaner shutdown needed?
+ _connection.close();
System.exit(0);
}
else
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase1DummyRun.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase1DummyRun.java
index 874f86daa9..85b89172bb 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase1DummyRun.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase1DummyRun.java
@@ -20,14 +20,14 @@
*/
package org.apache.qpid.interop.testclient.testcases;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.Session;
-
import org.apache.log4j.Logger;
import org.apache.qpid.interop.testclient.InteropClientTestCase;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
/**
* Implements tet case 1, dummy run. This test case sends no test messages, it exists to confirm that the test harness
* is interacting with the coordinator correctly.
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
index 2773cad3f3..ec8c72afa9 100644
--- a/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
+++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
@@ -5,7 +5,6 @@ import javax.jms.*;
import org.apache.log4j.Logger;
import org.apache.qpid.interop.testclient.InteropClientTestCase;
-import org.apache.qpid.interop.testclient.TestClient;
/**
* Implements test case 3, basic pub/sub. Sends/received a specified number of messages to a specified route on the
@@ -120,8 +119,8 @@ public class TestCase3BasicPubSub implements InteropClientTestCase
session = new Session[1];
connection[0] =
- TestClient.createConnection(TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE, TestClient.brokerUrl,
- TestClient.virtualHost);
+ org.apache.qpid.interop.testclient.TestClient.createConnection(org.apache.qpid.interop.testclient.TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE, org.apache.qpid.interop.testclient.TestClient.brokerUrl,
+ org.apache.qpid.interop.testclient.TestClient.virtualHost);
session[0] = connection[0].createSession(false, Session.AUTO_ACKNOWLEDGE);
// Extract and retain the test parameters.
@@ -140,8 +139,8 @@ public class TestCase3BasicPubSub implements InteropClientTestCase
for (int i = 0; i < numReceivers; i++)
{
connection[i] =
- TestClient.createConnection(TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE, TestClient.brokerUrl,
- TestClient.virtualHost);
+ org.apache.qpid.interop.testclient.TestClient.createConnection(org.apache.qpid.interop.testclient.TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE, org.apache.qpid.interop.testclient.TestClient.brokerUrl,
+ org.apache.qpid.interop.testclient.TestClient.virtualHost);
session[i] = connection[i].createSession(false, Session.AUTO_ACKNOWLEDGE);
sendDestination = session[i].createTopic(sendKey);
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestClient.java b/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestClient.java
new file mode 100644
index 0000000000..3a0d587d44
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestClient.java
@@ -0,0 +1,567 @@
+package org.apache.qpid.sustained;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.client.AMQNoConsumersException;
+import org.apache.qpid.client.AMQNoRouteException;
+import org.apache.qpid.interop.testclient.testcases.TestCase3BasicPubSub;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Implements test case 3, basic pub/sub. Sends/received a specified number of messages to a specified route on the
+ * default topic exchange, using the specified number of receiver connections. Produces reports on the actual number of
+ * messages sent/received.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption> <tr><th> Responsibilities <th> Collaborations <tr><td> Supply the name
+ * of the test case that this implements. <tr><td> Accept/Reject invites based on test parameters. <tr><td> Adapt to
+ * assigned roles. <tr><td> Send required number of test messages using pub/sub. <tr><td> Generate test reports.
+ * </table>
+ */
+public class SustainedTestClient extends TestCase3BasicPubSub implements ExceptionListener
+{
+ /** Used for debugging. */
+ private static final Logger log = Logger.getLogger(SustainedTestClient.class);
+
+ /** The role to be played by the test. */
+ private Roles role;
+
+ /** The number of test messages to send. */
+// private int numMessages;
+
+ /** The number of receiver connection to use. */
+ private int numReceivers;
+
+ /** The routing key to send them to on the default direct exchange. */
+ private Destination sendDestination;
+
+ /** The routing key to send updates to on the default direct exchange. */
+ private Destination sendUpdateDestination;
+
+
+ /** The connections to send/receive the test messages on. */
+ private Connection[] connection;
+
+ /** The sessions to send/receive the test messages on. */
+ private Session[] session;
+
+ /** The producer to send the test messages with. */
+ MessageProducer producer;
+
+ /** Adapter that adjusts the send rate based on the updates from clients. */
+ SustainedRateAdapter _rateAdapter;
+
+ /** */
+ int updateInterval;
+
+ private boolean _running = true;
+
+ /**
+ * Should provide the name of the test case that this class implements. The exact names are defined in the interop
+ * testing spec.
+ *
+ * @return The name of the test case that this implements.
+ */
+ public String getName()
+ {
+ log.debug("public String getName(): called");
+
+ return "Perf_SustainedPubSub";
+ }
+
+ /**
+ * Assigns the role to be played by this test case. The test parameters are fully specified in the assignment
+ * message. When this method return the test case will be ready to execute.
+ *
+ * @param role The role to be played; sender or receiver.
+ * @param assignRoleMessage The role assingment message, contains the full test parameters.
+ *
+ * @throws JMSException Any JMSException resulting from reading the message are allowed to fall through.
+ */
+ public void assignRole(Roles role, Message assignRoleMessage) throws JMSException
+ {
+ log.debug("public void assignRole(Roles role = " + role + ", Message assignRoleMessage = " + assignRoleMessage
+ + "): called");
+
+ // Take note of the role to be played.
+ this.role = role;
+
+ // Extract and retain the test parameters.
+ numReceivers = assignRoleMessage.getIntProperty("SUSTAINED_NUM_RECEIVERS");
+ updateInterval = assignRoleMessage.getIntProperty("SUSTAINED_UPDATE_INTERVAL");
+ String sendKey = assignRoleMessage.getStringProperty("SUSTAINED_KEY");
+ String sendUpdateKey = assignRoleMessage.getStringProperty("SUSTAINED_UPDATE_KEY");
+ int ackMode = assignRoleMessage.getIntProperty("ACKNOWLEDGE_MODE");
+
+ log.debug("numReceivers = " + numReceivers);
+ log.debug("updateInterval = " + updateInterval);
+ log.debug("ackMode = " + ackMode);
+ log.debug("sendKey = " + sendKey);
+ log.debug("sendUpdateKey = " + sendUpdateKey);
+ log.debug("role = " + role);
+
+ switch (role)
+ {
+ // Check if the sender role is being assigned, and set up a single message producer if so.
+ case SENDER:
+ log.info("*********** Creating SENDER");
+ // Create a new connection to pass the test messages on.
+ connection = new Connection[1];
+ session = new Session[1];
+
+ connection[0] =
+ org.apache.qpid.interop.testclient.TestClient.createConnection(org.apache.qpid.interop.testclient.TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE, org.apache.qpid.interop.testclient.TestClient.brokerUrl,
+ org.apache.qpid.interop.testclient.TestClient.virtualHost);
+ session[0] = connection[0].createSession(false, ackMode);
+
+ // Extract and retain the test parameters.
+ sendDestination = session[0].createTopic(sendKey);
+
+ connection[0].setExceptionListener(this);
+
+ producer = session[0].createProducer(sendDestination);
+
+ sendUpdateDestination = session[0].createTopic(sendUpdateKey);
+ MessageConsumer updateConsumer = session[0].createConsumer(sendUpdateDestination);
+
+ _rateAdapter = new SustainedRateAdapter(this);
+ updateConsumer.setMessageListener(_rateAdapter);
+
+
+ break;
+
+ // Otherwise the receiver role is being assigned, so set this up to listen for messages on the required number
+ // of receiver connections.
+ case RECEIVER:
+ log.info("*********** Creating RECEIVER");
+ // Create the required number of receiver connections.
+ connection = new Connection[numReceivers];
+ session = new Session[numReceivers];
+
+ for (int i = 0; i < numReceivers; i++)
+ {
+ connection[i] =
+ org.apache.qpid.interop.testclient.TestClient.createConnection(org.apache.qpid.interop.testclient.TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE,
+ org.apache.qpid.interop.testclient.TestClient.brokerUrl,
+ org.apache.qpid.interop.testclient.TestClient.virtualHost);
+ session[i] = connection[i].createSession(false, ackMode);
+
+ sendDestination = session[i].createTopic(sendKey);
+
+ sendUpdateDestination = session[i].createTopic(sendUpdateKey);
+
+ MessageConsumer consumer = session[i].createConsumer(sendDestination);
+
+ consumer.setMessageListener(new SustainedListener(TestClient.CLIENT_NAME + "-" + i, updateInterval, session[i], sendUpdateDestination));
+ }
+
+ break;
+ }
+
+ // Start all the connection dispatcher threads running.
+ for (int i = 0; i < connection.length; i++)
+ {
+ connection[i].start();
+ }
+ }
+
+ /** Performs the test case actions. */
+ public void start() throws JMSException
+ {
+ log.debug("public void start(): called");
+
+ // Check that the sender role is being performed.
+ switch (role)
+ {
+ // Check if the sender role is being assigned, and set up a single message producer if so.
+ case SENDER:
+ Message testMessage = session[0].createTextMessage("test");
+
+// for (int i = 0; i < numMessages; i++)
+ while (_running)
+ {
+ producer.send(testMessage);
+
+ _rateAdapter.sentMessage();
+ }
+ break;
+ case RECEIVER:
+
+ }
+ }
+
+ /**
+ * Gets a report on the actions performed by the test case in its assigned role.
+ *
+ * @param session The session to create the report message in.
+ *
+ * @return The report message.
+ *
+ * @throws JMSException Any JMSExceptions resulting from creating the report are allowed to fall through.
+ */
+ public Message getReport(Session session) throws JMSException
+ {
+ log.debug("public Message getReport(Session session): called");
+
+ // Close the test connections.
+ for (int i = 0; i < connection.length; i++)
+ {
+ connection[i].close();
+ }
+
+ Message report = session.createMessage();
+ report.setStringProperty("CONTROL_TYPE", "REPORT");
+
+ return report;
+ }
+
+ public void onException(JMSException jmsException)
+ {
+ Exception linked = jmsException.getLinkedException();
+
+ if (linked != null)
+ {
+ if (linked instanceof AMQNoRouteException)
+ {
+ log.warn("No route .");
+ }
+ else if (linked instanceof AMQNoConsumersException)
+ {
+ log.warn("No clients currently available for message:" + ((AMQNoConsumersException) linked).getUndeliveredMessage());
+ }
+ else
+ {
+
+ log.warn("LinkedException:" + linked);
+ }
+
+ _rateAdapter.NO_CLIENTS = true;
+ }
+ else
+ {
+ log.warn("Exception:" + linked);
+ }
+ }
+
+ class SustainedListener implements MessageListener
+ {
+ private int _received = 0;
+ private int _updateInterval = 0;
+ private Long _time;
+ MessageProducer _updater;
+ Session _session;
+ String _client;
+
+
+ public SustainedListener(String clientname, int updateInterval, Session session, Destination sendDestination) throws JMSException
+ {
+ _updateInterval = updateInterval;
+ _client = clientname;
+ _session = session;
+ _updater = session.createProducer(sendDestination);
+ }
+
+ public void setReportInterval(int reportInterval)
+ {
+ _updateInterval = reportInterval;
+ _received = 0;
+ }
+
+ public void onMessage(Message message)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Message " + _received + "received in listener");
+ }
+
+ if (message instanceof TextMessage)
+ {
+
+ try
+ {
+ if (((TextMessage) message).getText().equals("test"))
+ {
+ if (_received == 0)
+ {
+ _time = System.nanoTime();
+ sendStatus(0, _received);
+ }
+
+ _received++;
+
+ if (_received % _updateInterval == 0)
+ {
+ Long currentTime = System.nanoTime();
+
+ try
+ {
+ sendStatus(currentTime - _time, _received);
+ _time = currentTime;
+ }
+ catch (JMSException e)
+ {
+ log.error("Unable to send update.");
+ }
+ }
+
+ }
+ }
+ catch (JMSException e)
+ {
+ //ignore error
+ }
+ }
+ }
+
+ private void sendStatus(long time, int received) throws JMSException
+ {
+ Message updateMessage = _session.createTextMessage("update");
+ updateMessage.setStringProperty("CLIENT_ID", _client);
+ updateMessage.setStringProperty("CONTROL_TYPE", "UPDATE");
+ updateMessage.setLongProperty("RECEIVED", received);
+ updateMessage.setLongProperty("DURATION", time);
+
+ log.info("**** SENDING **** CLIENT_ID:" + _client + " RECEIVED:" + received + " DURATION:" + time);
+
+ _updater.send(updateMessage);
+ }
+
+ }
+
+ class SustainedRateAdapter implements MessageListener
+ {
+ private SustainedTestClient _client;
+ private long _variance = 250; //no. messages to allow drifting
+ private volatile long _delay; //in nanos
+ private long _sent;
+ private Map<String, Long> _slowClients = new HashMap<String, Long>();
+ private static final long PAUSE_SLEEP = 10; // 10 ms
+ private static final long NO_CLIENT_SLEEP = 1000; // 1s
+ private static final long MAX_MESSAGE_DRIFT = 1000; // no messages drifted from producer
+ private volatile boolean NO_CLIENTS = true;
+ private int _delayShifting;
+ private static final int REPORTS_WITHOUT_CHANGE = 10;
+ private static final double MAXIMUM_DELAY_SHIFT = .02; //2%
+
+ SustainedRateAdapter(SustainedTestClient client)
+ {
+ _client = client;
+ }
+
+ public void onMessage(Message message)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("SustainedRateAdapter onMessage(Message message = " + message + "): called");
+ }
+
+ try
+ {
+ String controlType = message.getStringProperty("CONTROL_TYPE");
+
+ // Check if the message is a test invite.
+ if ("UPDATE".equals(controlType))
+ {
+ NO_CLIENTS = false;
+ long duration = message.getLongProperty("DURATION");
+ long received = message.getLongProperty("RECEIVED");
+ String client = message.getStringProperty("CLIENT_ID");
+
+ log.info("**** SENDING **** CLIENT_ID:" + client + " RECEIVED:" + received + " DURATION:" + duration);
+
+
+ recordSlow(client, received);
+
+ adjustDelay(client, received, duration);
+ }
+ }
+ catch (JMSException e)
+ {
+ //
+ }
+ }
+
+ class Pair<X, Y>
+ {
+ X item1;
+ Y item2;
+
+ Pair(X i1, Y i2)
+ {
+ item1 = i1;
+ item2 = i2;
+ }
+
+ X getItem1()
+ {
+ return item1;
+ }
+
+ Y getItem2()
+ {
+ return item2;
+ }
+ }
+
+ Map<String, Pair<Long, Long>> delays = new HashMap<String, Pair<Long, Long>>();
+ Long totalReceived = 0L;
+ Long totalDuration = 0L;
+
+ private void adjustDelay(String client, long received, long duration)
+ {
+ Pair<Long, Long> current = delays.get(client);
+
+ if (current == null)
+ {
+ delays.put(client, new Pair<Long, Long>(received, duration));
+ }
+ else
+ {
+ //reduce totals
+ totalReceived -= current.getItem1();
+ totalDuration -= current.getItem2();
+ }
+
+ totalReceived += received;
+ totalDuration += duration;
+
+ long averageDuration = totalDuration / delays.size();
+
+ long diff = Math.abs(_delay - averageDuration);
+
+ //if the averageDuration differs from the current by more than the specified variane then adjust delay.
+ if (diff > _variance)
+ {
+ if (averageDuration > _delay)
+ {
+ // we can go faster
+ _delay -= diff;
+ if (_delay < 0)
+ {
+ _delay = 0;
+ }
+ }
+ else
+ {
+ // we need to slow down
+ _delay += diff;
+ }
+ delayChanged();
+ }
+ else
+ {
+ delayStable();
+ }
+
+ }
+
+ private void delayChanged()
+ {
+ _delayShifting = REPORTS_WITHOUT_CHANGE;
+ }
+
+ private void delayStable()
+ {
+ _delayShifting--;
+
+ if (_delayShifting < 0)
+ {
+ _delayShifting = 0;
+ log.info("Delay stabilised:" + _delay);
+ }
+ }
+
+ // Record Slow clients
+ private void recordSlow(String client, long received)
+ {
+ if (received < (_sent - _variance))
+ {
+ _slowClients.put(client, received);
+ }
+ else
+ {
+ _slowClients.remove(client);
+ }
+ }
+
+ public void sentMessage()
+ {
+ if (_sent % updateInterval == 0)
+ {
+
+ // Cause test to pause when we have slow
+ if (!_slowClients.isEmpty() || NO_CLIENTS)
+ {
+ log.info("Pausing for slow clients");
+
+ //_delay <<= 1;
+
+ while (!_slowClients.isEmpty())
+ {
+ sleep(PAUSE_SLEEP);
+ }
+
+ if (NO_CLIENTS)
+ {
+ sleep(NO_CLIENT_SLEEP);
+ }
+
+ log.debug("Continuing");
+ return;
+ }
+ else
+ {
+ log.info("Delay:" + _delay);
+ }
+ }
+
+ _sent++;
+
+ if (_delay > 0)
+ {
+ // less than 10ms sleep doesn't work.
+ // _delay is in nano seconds
+ if (_delay < 1000000)
+ {
+ sleep(0, (int) _delay);
+ }
+ else
+ {
+ if (_delay < 30000000000L)
+ {
+ sleep(_delay / 1000000, (int) (_delay % 1000000));
+ }
+ }
+ }
+ }
+
+ private void sleep(long sleep)
+ {
+ sleep(sleep, 0);
+ }
+
+ private void sleep(long milli, int nano)
+ {
+ try
+ {
+ log.debug("Sleep:" + milli + ":" + nano);
+ Thread.sleep(milli, nano);
+ }
+ catch (InterruptedException e)
+ {
+ //
+ }
+ }
+ }
+
+}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestCoordinator.java b/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestCoordinator.java
new file mode 100644
index 0000000000..4081d87192
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/sustained/SustainedTestCoordinator.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *
+ */
+package org.apache.qpid.sustained;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.interop.coordinator.ListeningCoordinatorTest;
+import org.apache.qpid.interop.coordinator.TestClientDetails;
+import org.apache.qpid.interop.coordinator.testcases.CoordinatingTestCase3BasicPubSub;
+import org.apache.qpid.util.ConversationFactory;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public class SustainedTestCoordinator extends CoordinatingTestCase3BasicPubSub implements ListeningCoordinatorTest
+{
+ /** Used for debugging. */
+ private static final Logger log = Logger.getLogger(SustainedTestCoordinator.class);
+ private List<TestClientDetails> _receivers;
+ private static final String SUSTAINED_KEY = "Perf_SustainedPubSub";
+ Map<String, Object> _testProperties;
+
+ /**
+ * Creates a new coordinating test case with the specified name.
+ *
+ * @param name The test case name.
+ */
+ public SustainedTestCoordinator(String name)
+ {
+ super(name);
+ _receivers = new LinkedList();
+ }
+
+ /**
+ * Adds a receiver to this test.
+ *
+ * @param receiver The contact details of the sending client in the test.
+ */
+ public void setReceiver(TestClientDetails receiver)
+ {
+ _receivers.add(receiver);
+ }
+
+
+ /**
+ * Performs the a single test run
+ *
+ * @throws Exception if there was a problem running the test.
+ */
+ public void testBasicPubSub() throws Exception
+ {
+ log.debug("public void testSinglePubSubCycle(): called");
+
+ Map<String, Object> testConfig = new HashMap<String, Object>();
+ testConfig.put("TEST_NAME", "Perf_SustainedPubSub");
+ testConfig.put("SUSTAINED_KEY", SUSTAINED_KEY);
+ //testConfig.put("SUSTAINED_MSG_RATE", 10);
+ testConfig.put("SUSTAINED_NUM_RECEIVERS", 2);
+ testConfig.put("SUSTAINED_UPDATE_INTERVAL", 25);
+ testConfig.put("SUSTAINED_UPDATE_KEY", SUSTAINED_KEY + ".UPDATE");
+ testConfig.put("ACKNOWLEDGE_MODE", AMQSession.NO_ACKNOWLEDGE);
+
+ sequenceTest(testConfig);
+ }
+
+ /**
+ * Holds a test coordinating conversation with the test clients. This is the basic implementation of the inner loop
+ * of Use Case 5. It consists of assigning the test roles, begining the test and gathering the test reports from the
+ * participants.
+ *
+ * @param testProperties The test case definition.
+ *
+ * @return The test results from the senders and receivers.
+ *
+ * @throws javax.jms.JMSException All underlying JMSExceptions are allowed to fall through.
+ */
+ protected Message[] sequenceTest(Map<String, Object> testProperties) throws JMSException
+ {
+ log.debug("protected Message[] sequenceTest(Object... testProperties = " + testProperties + "): called");
+
+ Session session = conversationFactory.getSession();
+ Destination senderControlTopic = session.createTopic(sender.privateControlKey);
+
+ ConversationFactory.Conversation senderConversation = conversationFactory.startConversation();
+
+ // Assign the sender role to the sending test client.
+ Message assignSender = conversationFactory.getSession().createMessage();
+ setPropertiesOnMessage(assignSender, testProperties);
+ assignSender.setStringProperty("CONTROL_TYPE", "ASSIGN_ROLE");
+ assignSender.setStringProperty("ROLE", "SENDER");
+
+ senderConversation.send(senderControlTopic, assignSender);
+
+ //Assign and wait for the receiver ckuebts to be ready.
+ _testProperties = testProperties;
+
+ // Wait for the senders to confirm their roles.
+ senderConversation.receive();
+
+ assignReceivers();
+
+ // Start the test.
+ Message start = session.createMessage();
+ start.setStringProperty("CONTROL_TYPE", "START");
+
+ senderConversation.send(senderControlTopic, start);
+
+ // Wait for the test sender to return its report.
+ Message senderReport = senderConversation.receive();
+
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ // Ask the receiver for its report.
+ Message statusRequest = session.createMessage();
+ statusRequest.setStringProperty("CONTROL_TYPE", "STATUS_REQUEST");
+
+
+ return new Message[]{senderReport};
+ }
+
+ private void assignReceivers()
+ {
+ for (TestClientDetails receiver : _receivers)
+ {
+ registerReceiver(receiver);
+ }
+ }
+
+ private void registerReceiver(TestClientDetails receiver)
+ {
+ log.info("registerReceiver called for receiver:" + receiver);
+ try
+ {
+ Session session = conversationFactory.getSession();
+ Destination receiverControlTopic = session.createTopic(receiver.privateControlKey);
+ ConversationFactory.Conversation receiverConversation = conversationFactory.startConversation();
+ // Assign the receiver role the receiving client.
+ Message assignReceiver = session.createMessage();
+ setPropertiesOnMessage(assignReceiver, _testProperties);
+ assignReceiver.setStringProperty("CONTROL_TYPE", "ASSIGN_ROLE");
+ assignReceiver.setStringProperty("ROLE", "RECEIVER");
+
+ receiverConversation.send(receiverControlTopic, assignReceiver);
+
+ //Don't wait for receiver to be ready.... we can't this is being done in
+ // the dispatcher thread, and most likely the acceptance message we
+ // want is sitting in the Dispatcher._queue waiting its turn for being
+ // dispatched so if we block here we won't can't get the message.
+ // So assume consumer is ready for action.
+ //receiverConversation.receive();
+ }
+ catch (JMSException e)
+ {
+ log.warn("Unable to assign receiver:" + receiver + ". Due to:" + e.getMessage());
+ }
+ }
+
+ public void latejoin(Message message)
+ {
+ try
+ {
+
+ TestClientDetails clientDetails = new TestClientDetails();
+ clientDetails.clientName = message.getStringProperty("CLIENT_NAME");
+ clientDetails.privateControlKey = message.getStringProperty("CLIENT_PRIVATE_CONTROL_KEY");
+
+
+ registerReceiver(clientDetails);
+ }
+ catch (JMSException e)
+ {
+ //swallow
+ }
+ }
+
+ /**
+ * Should provide a translation from the junit method name of a test to its test case name as defined in the interop
+ * testing specification. For example the method "testP2P" might map onto the interop test case name
+ * "TC2_BasicP2P".
+ *
+ * @param methodName The name of the JUnit test method.
+ *
+ * @return The name of the corresponding interop test case.
+ */
+ public String getTestCaseNameForTestMethod(String methodName)
+ {
+ return "Perf_SustainedPubSub";
+ }
+}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestClient.java b/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestClient.java
new file mode 100644
index 0000000000..44fc090410
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestClient.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *
+ */
+package org.apache.qpid.sustained;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.interop.testclient.InteropClientTestCase;
+import org.apache.qpid.util.CommandLineParser;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+
+public class TestClient extends org.apache.qpid.interop.testclient.TestClient
+{
+ private static Logger log = Logger.getLogger(TestClient.class);
+
+ /**
+ * Creates a new interop test client, listenting to the specified broker and virtual host, with the specified client
+ * identifying name.
+ *
+ * @param brokerUrl The url of the broker to connect to.
+ * @param virtualHost The virtual host to conect to.
+ * @param clientName The client name to use.
+ */
+ public TestClient(String brokerUrl, String virtualHost, String clientName)
+ {
+ super(brokerUrl, virtualHost, clientName);
+ }
+
+ /**
+ * The entry point for the interop test coordinator. This client accepts the following command line arguments:
+ *
+ * <p/><table> <tr><td> -b <td> The broker URL. <td> Optional. <tr><td> -h <td> The virtual
+ * host. <td> Optional. <tr><td> -n <td> The test client name. <td> Optional. <tr><td> name=value <td>
+ * Trailing argument define name/value pairs. Added to system properties. <td> Optional. </table>
+ *
+ * @param args The command line arguments.
+ */
+ public static void main(String[] args)
+ {
+ // Use the command line parser to evaluate the command line.
+ CommandLineParser commandLine =
+ new CommandLineParser(
+ new String[][]
+ {
+ {"b", "The broker URL.", "broker", "false"},
+ {"h", "The virtual host to use.", "virtual host", "false"},
+ {"n", "The test client name.", "name", "false"},
+ {"j", "Join this test client to running test.", "join", ""}
+ });
+
+ // Capture the command line arguments or display errors and correct usage and then exit.
+ Properties options = null;
+
+ try
+ {
+ options = commandLine.parseCommandLine(args);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(commandLine.getErrors());
+ System.out.println(commandLine.getUsage());
+ System.exit(1);
+ }
+
+ // Extract the command line options.
+ String brokerUrl = options.getProperty("b");
+ String virtualHost = options.getProperty("h");
+ String clientName = options.getProperty("n");
+ String join = options.getProperty("j");
+
+ // Add all the trailing command line options (name=value pairs) to system properties. Tests may pick up
+ // overridden values from there.
+ commandLine.addCommandLineToSysProperties();
+
+ // Create a test client and start it running.
+ TestClient client = new TestClient(brokerUrl, virtualHost, (clientName == null) ? CLIENT_NAME : clientName);
+
+ // Use a class path scanner to find all the interop test case implementations.
+ Collection<Class<? extends InteropClientTestCase>> testCaseClasses =
+ new ArrayList<Class<? extends InteropClientTestCase>>();
+ // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true);
+ // Hard code the test classes till the classpath scanner is fixed.
+ Collections.addAll(testCaseClasses,
+ SustainedTestClient.class);
+
+
+ try
+ {
+ client.start(testCaseClasses, join);
+ }
+ catch (Exception e)
+ {
+ log.error("The test client was unable to start.", e);
+ System.exit(1);
+ }
+ }
+
+ protected void start(Collection<Class<? extends InteropClientTestCase>> testCaseClasses, String join) throws JMSException, ClassNotFoundException
+ {
+ super.start(testCaseClasses);
+ log.debug("private void start(): called");
+
+ if (join != null && !join.equals(""))
+ {
+ Message latejoin = session.createMessage();
+
+ try
+ {
+ Object test = Class.forName(join).newInstance();
+ if (test instanceof InteropClientTestCase)
+ {
+ currentTestCase = (InteropClientTestCase) test;
+ }
+ else
+ {
+ throw new RuntimeException("Requested to join class '" + join + "' but this is not a InteropClientTestCase.");
+ }
+
+ latejoin.setStringProperty("CONTROL_TYPE", "LATEJOIN");
+ latejoin.setStringProperty("CLIENT_NAME", clientName);
+ latejoin.setStringProperty("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName);
+ producer.send(session.createTopic("iop.control.test." + currentTestCase.getName()), latejoin);
+ }
+ catch (InstantiationException e)
+ {
+ log.warn("Unable to request latejoining of test:" + currentTestCase);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.warn("Unable to request latejoining of test:" + currentTestCase);
+ }
+ }
+ }
+
+}
diff --git a/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestCoordinator.java b/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestCoordinator.java
new file mode 100644
index 0000000000..7e12fe39fb
--- /dev/null
+++ b/java/integrationtests/src/main/java/org/apache/qpid/sustained/TestCoordinator.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *
+ */
+package org.apache.qpid.sustained;
+
+import org.apache.qpid.interop.coordinator.Coordinator;
+import org.apache.qpid.interop.coordinator.ListeningTestDecorator;
+import org.apache.qpid.interop.coordinator.TestClientDetails;
+import org.apache.qpid.util.CommandLineParser;
+import org.apache.qpid.util.ConversationFactory;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestResult;
+import uk.co.thebadgerset.junit.extensions.WrappedSuiteTestDecorator;
+
+import javax.jms.Connection;
+
+public class TestCoordinator extends Coordinator
+{
+
+ private static final Logger log = Logger.getLogger(TestCoordinator.class);
+
+ /**
+ * Creates an interop test coordinator on the specified broker and virtual host.
+ *
+ * @param brokerUrl The URL of the broker to connect to.
+ * @param virtualHost The virtual host to run all tests on. Optional, may be <tt>null</tt>.
+ */
+ TestCoordinator(String brokerUrl, String virtualHost)
+ {
+ super(brokerUrl, virtualHost);
+ }
+
+ protected WrappedSuiteTestDecorator newTestDecorator(WrappedSuiteTestDecorator targetTest, Set<TestClientDetails> enlistedClients, ConversationFactory conversationFactory, Connection connection)
+ {
+ return new ListeningTestDecorator(targetTest, enlistedClients, conversationFactory, connection);
+ }
+
+
+ /**
+ * The entry point for the interop test coordinator. This client accepts the following command line arguments:
+ *
+ * <p/><table> <tr><td> -b <td> The broker URL. <td> Mandatory. <tr><td> -h <td> The virtual host.
+ * <td> Optional. <tr><td> name=value <td> Trailing argument define name/value pairs. Added to system properties.
+ * <td> Optional. </table>
+ *
+ * @param args The command line arguments.
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ // Use the command line parser to evaluate the command line with standard handling behaviour (print errors
+ // and usage then exist if there are errors).
+ Properties options =
+ CommandLineParser.processCommandLine(args,
+ new CommandLineParser(
+ new String[][]
+ {
+ {"b", "The broker URL.", "broker", "false"},
+ {"h", "The virtual host to use.", "virtual host", "false"},
+ {"o", "The name of the directory to output test timings to.", "dir", "false"}
+ }));
+
+ // Extract the command line options.
+ String brokerUrl = options.getProperty("b");
+ String virtualHost = options.getProperty("h");
+ String reportDir = options.getProperty("o");
+ reportDir = (reportDir == null) ? "." : reportDir;
+
+
+ String[] testClassNames = {SustainedTestCoordinator.class.getName()};
+
+ // Create a coordinator and begin its test procedure.
+ Coordinator coordinator = new TestCoordinator(brokerUrl, virtualHost);
+
+ coordinator.setReportDir(reportDir);
+
+ TestResult testResult = coordinator.start(testClassNames);
+
+ if (testResult.failureCount() > 0)
+ {
+ System.exit(FAILURE_EXIT);
+ }
+ else
+ {
+ System.exit(SUCCESS_EXIT);
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println(e.getMessage());
+ log.error("Top level handler caught execption.", e);
+ System.exit(EXCEPTION_EXIT);
+ }
+ }
+}
diff --git a/java/management/eclipse-plugin/pom.xml b/java/management/eclipse-plugin/pom.xml
index 152b5e9b1a..4fbc8a0e3f 100644
--- a/java/management/eclipse-plugin/pom.xml
+++ b/java/management/eclipse-plugin/pom.xml
@@ -167,16 +167,27 @@
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-broker</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+
</dependencies>
<build>
diff --git a/java/perftests/RunningPerformanceTests.txt b/java/perftests/RunningPerformanceTests.txt
index 95051c088e..54291483bf 100644
--- a/java/perftests/RunningPerformanceTests.txt
+++ b/java/perftests/RunningPerformanceTests.txt
@@ -116,7 +116,7 @@ The specific performance test cases for QPid are implemented as extensions to JU
The most common test case to run is implemented in the class PingAsyncTestPerf, which sends and recieves messages simultaneously. This class uses a PingPongProdicer to do its sending and receiving, and wraps it in a suitable way to make it callable through the extended JUnit test runner. This class also accpets another parameter "batchSize" with a default of "1000". This tells the test how many messages to send before stopping sending and waiting for them all to come back. The actual value entered does not matter too much, but typically values larger than 1000 are used to ensure that there is a reasonable opportunity for simultaneous sending and receiving, and less than 10000 to ensure that each test method invocation does not go on for too long.
-The test script parameters can all be seen in the pom.xml file. A three letter code is used on the test scripts, first letter P or T for persistent or transient, second letter Q or T for queue (p2p) or topic (pub/sub), third letter R for reliability tests, C for client scaling tests, M for message size tests.Typically tests run and sample their results for 10 minutes, to get a reasonable measurement of a broker running under a steady load. The tests as configured do not measure peak performance.
+The test script parameters can all be seen in the pom.xml file. A three letter code is used on the test scripts, first letter P or T for persistent or transient, second letter Q or T for queue (p2p) or topic (pub/sub), third letter R for reliability tests, C for client scaling tests, M for message size tests.Typically tests run and sample their results for 10 minutes, to get a reasonable measurement of a broker running under a steady load. The tests as configured do not measure 'burst' performance.
The reliability/burn in tests, test the broker running at slightly below its maximum throughput for a period of 24 hours. Their purpose is to check that the broker remains stable under load for a reasonable duration, in order to provide some confidence in the long-term stability of its process. These tests are intended to be run as a two step process. The first two tests run for 10 minutes and are used to asses the broker throughput for the test. The output from these tests are to be fed into the rate limiter for the second set of tests, so that the broker may be set up to run at slightly below its maximum throughput for the 24 hour duration. It is suggested that 90% of the rate achieved by the first two tests should be used for this.
diff --git a/java/perftests/pom.xml b/java/perftests/pom.xml
index 17cc4a3be9..8d03755efc 100644
--- a/java/perftests/pom.xml
+++ b/java/perftests/pom.xml
@@ -305,16 +305,16 @@
<PTM-Qpid-2-1M>-n PTM-Qpid-2-1M -d10M -s[1000] -c[1] -o $QPID_WORK/results -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true pubsub=true transacted=false commitBatchSize=10 batchSize=1000 messageSize=1048476 destinationsCount=1 rate=0 maxPending=20000000</PTM-Qpid-2-1M>
<!-- Failover Tests. -->
- <FT-Qpid-1>-n FT-Qpid-1 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-1>
- <FT-Qpid-2>-n FT-Qpid-2 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failAfterSend=true -o $QPID_WORK/results</FT-Qpid-2>
- <FT-Qpid-3>-n FT-Qpid-3 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failAfterCommit=true -o $QPID_WORK/results</FT-Qpid-3>
- <FT-Qpid-4>-n FT-Qpid-4 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" transacted=false failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-4>
- <FT-Qpid-5>-n FT-Qpid-5 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" transacted=false failAfterSend=true -o $QPID_WORK/results</FT-Qpid-5>
- <FT-Qpid-1-P>-n FT-Qpid-1-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-1-P>
- <FT-Qpid-2-P>-n FT-Qpid-2-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failAfterSend=true -o $QPID_WORK/results</FT-Qpid-2-P>
- <FT-Qpid-3-P>-n FT-Qpid-3-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" failAfterCommit=true -o $QPID_WORK/results</FT-Qpid-3-P>
- <FT-Qpid-4-P>-n FT-Qpid-4-P -s [250] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" transacted=false failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-4-P>
- <FT-Qpid-5-P>-n FT-Qpid-5-P -s [250] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 broker="tcp://10.0.0.1:5001;tcp://10.0.0.2:5002" transacted=false failAfterSend=true -o $QPID_WORK/results</FT-Qpid-5-P>
+ <FT-Qpid-1>-n FT-Qpid-1 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-1>
+ <FT-Qpid-2>-n FT-Qpid-2 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failAfterSend=true -o $QPID_WORK/results</FT-Qpid-2>
+ <FT-Qpid-3>-n FT-Qpid-3 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failAfterCommit=true -o $QPID_WORK/results</FT-Qpid-3>
+ <FT-Qpid-4>-n FT-Qpid-4 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" transacted=false failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-4>
+ <FT-Qpid-5>-n FT-Qpid-5 -s [250000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf messageSize=256 batchSize=10000 broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" transacted=false failAfterSend=true -o $QPID_WORK/results</FT-Qpid-5>
+ <FT-Qpid-1-P>-n FT-Qpid-1-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-1-P>
+ <FT-Qpid-2-P>-n FT-Qpid-2-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failAfterSend=true -o $QPID_WORK/results</FT-Qpid-2-P>
+ <FT-Qpid-3-P>-n FT-Qpid-3-P -s [25000] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 batchSize=10000 transacted=true broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" failAfterCommit=true -o $QPID_WORK/results</FT-Qpid-3-P>
+ <FT-Qpid-4-P>-n FT-Qpid-4-P -s [250] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" transacted=false failBeforeSend=true -o $QPID_WORK/results</FT-Qpid-4-P>
+ <FT-Qpid-5-P>-n FT-Qpid-5-P -s [250] -t testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf persistent=true messageSize=256 broker="tcp://127.0.0.1:5001;tcp://127.0.0.1:5002" transacted=false failAfterSend=true -o $QPID_WORK/results</FT-Qpid-5-P>
</commands>
</configuration>
diff --git a/java/pom.xml b/java/pom.xml
index 23b707682a..a8dbce30a1 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -41,12 +41,23 @@ under the License.
</prerequisites>
<distributionManagement>
+
<snapshotRepository>
<id>apache.snapshots</id>
<name>Apache SNAPSHOT Repository</name>
<url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
</snapshotRepository>
+ <!--
+ <snapshotRepository>
+ <uniqueVersion>true</uniqueVersion>
+ <id>snapshot-repo</id>
+ <name>Local Snapshot Repository</name>
+ <url>file://${basedir}/${topDirectoryLocation}/snapshots</url>
+ <layout>default</layout>
+ </snapshotRepository>
+ -->
+
<!-- Qpid has a Wiki site, maven generated site not used. This is just so that it can be created locally for viewing the reports. -->
<site>
<id>Qpid_Site</id>
@@ -414,7 +425,7 @@ under the License.
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
- <version>3.1</version>
+ <version>3.2</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
@@ -591,7 +602,17 @@ under the License.
<enabled>true</enabled>
</snapshots>
</repository>
- </repositories>
+ <repository>
+ <id>Codehaus Snapshots</id>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+</repositories>
<pluginRepositories>
<pluginRepository>
@@ -619,8 +640,10 @@ under the License.
<id>fastinstall</id>
<properties>
<maven.test.skip>true</maven.test.skip>
+ <skip.python.tests>true</skip.python.tests>
</properties>
</profile>
+
<profile>
<id>nochecks</id>
</profile>
diff --git a/java/systests/pom.xml b/java/systests/pom.xml
index d9d07ed6f9..8a245b73a9 100644
--- a/java/systests/pom.xml
+++ b/java/systests/pom.xml
@@ -54,6 +54,15 @@
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
diff --git a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
index 0da18ea87f..976f58ec3d 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
@@ -1,13 +1,14 @@
package org.apache.qpid.server.failure;
import junit.framework.TestCase;
-import org.apache.qpid.testutil.QpidClientConnection;
+import org.apache.qpid.testutil.QpidClientConnectionHelper;
import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.AMQException;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.log4j.Logger;
import javax.jms.JMSException;
+import javax.jms.DeliveryMode;
import java.io.IOException;
@@ -16,7 +17,7 @@ public class HeapExhaustion extends TestCase
{
private static final Logger _logger = Logger.getLogger(HeapExhaustion.class);
- protected QpidClientConnection conn;
+ protected QpidClientConnectionHelper conn;
protected final String BROKER = "localhost";
protected final String vhost = "/test";
protected final String queue = "direct://amq.direct//queue";
@@ -31,7 +32,7 @@ public class HeapExhaustion extends TestCase
protected void setUp() throws Exception
{
- conn = new QpidClientConnection(BROKER);
+ conn = new QpidClientConnectionHelper(BROKER);
conn.setVirtualHost(vhost);
try
@@ -68,7 +69,7 @@ public class HeapExhaustion extends TestCase
int size = payload.getBytes().length;
while (true)
{
- conn.put(queue, payload, 1);
+ conn.put(queue, payload, 1, DeliveryMode.NON_PERSISTENT);
copies++;
total += size;
System.out.println("put copy " + copies + " OK for total bytes: " + total);
@@ -88,7 +89,7 @@ public class HeapExhaustion extends TestCase
int size = payload.getBytes().length;
while (true)
{
- conn.put(queue, payload, 1);
+ conn.put(queue, payload, 1, DeliveryMode.NON_PERSISTENT);
copies++;
total += size;
System.out.println("put copy " + copies + " OK for total bytes: " + total);
diff --git a/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnection.java b/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
index 6f955ebdab..fcc3adee13 100644
--- a/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnection.java
+++ b/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
@@ -1,284 +1,275 @@
-package org.apache.qpid.testutil;
-
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.JMSAMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.log4j.Logger;
-
-import javax.jms.ExceptionListener;
-import javax.jms.Session;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.MessageProducer;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.TextMessage;
-
-public class QpidClientConnection implements ExceptionListener
-{
-
- private static final Logger _logger = Logger.getLogger(QpidClientConnection.class);
-
- private boolean transacted = true;
- private int ackMode = Session.CLIENT_ACKNOWLEDGE;
- private Connection connection;
-
- private String virtualHost;
- private String brokerlist;
- private int prefetch;
- protected Session session;
- protected boolean connected;
-
- public QpidClientConnection(String broker)
- {
- super();
- setVirtualHost("/test");
- setBrokerList(broker);
- setPrefetch(5000);
- }
-
-
- public void connect()
- throws
- JMSException
- {
- if (!connected)
- {
- /*
- * amqp://[user:pass@][clientid]/virtualhost?
- * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
- * [&failover='method[?option='value'[&option='value']]']
- * [&option='value']"
- */
- String brokerUrl = "amqp://guest:guest@" + virtualHost + "?brokerlist='" + brokerlist + "'";
- try
- {
- AMQConnectionFactory factory = new AMQConnectionFactory(new AMQConnectionURL(brokerUrl));
- _logger.info("connecting to Qpid :" + brokerUrl);
- connection = factory.createConnection();
-
- // register exception listener
- connection.setExceptionListener(this);
-
- session = ((AMQConnection) connection).createSession(transacted, ackMode, prefetch);
-
-
- _logger.info("starting connection");
- connection.start();
-
- connected = true;
- }
- catch (URLSyntaxException e)
- {
- throw new JMSAMQException("URL syntax error in [" + brokerUrl + "]: " + e.getMessage(), e);
- }
- }
- }
-
- public void disconnect()
- throws
- JMSException
- {
- if (connected)
- {
- session.commit();
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected");
- }
- }
-
- public void disconnectWithoutCommit()
- throws
- JMSException
- {
- if (connected)
- {
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected without commit");
- }
- }
-
- public String getBrokerList()
- {
- return brokerlist;
- }
-
- public void setBrokerList(String brokerlist)
- {
- this.brokerlist = brokerlist;
- }
-
- public String getVirtualHost()
- {
- return virtualHost;
- }
-
- public void setVirtualHost(String virtualHost)
- {
- this.virtualHost = virtualHost;
- }
-
- public void setPrefetch(int prefetch)
- {
- this.prefetch = prefetch;
- }
-
-
- /**
- * override as necessary
- */
- public void onException(JMSException exception)
- {
- _logger.info("ExceptionListener event: error " + exception.getErrorCode() + ", message: " + exception.getMessage());
- }
-
- public boolean isConnected()
- {
- return connected;
- }
-
- public Session getSession()
- {
- return session;
- }
-
- /**
- * Put a String as a text messages, repeat n times. A null payload will result in a null message.
- *
- * @param queueName The queue name to put to
- * @param payload the content of the payload
- * @param copies the number of messages to put
- * @throws javax.jms.JMSException any exception that occurs
- */
- public void put(String queueName, String payload, int copies)
- throws
- JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("putting to queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageProducer sender = session.createProducer(queue);
-
- for (int i = 0; i < copies; i++)
- {
- Message m = session.createTextMessage(payload + i);
- m.setIntProperty("index", i + 1);
- sender.send(m);
- }
-
- try
- {
- session.commit();
- } catch (JMSException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- sender.close();
- _logger.info("put " + copies + " copies");
- }
-
- /**
- * GET the top message on a queue. Consumes the message. Accepts timeout value.
- *
- * @param queueName The quename to get from
- * @param readTimeout The timeout to use
- * @return the content of the text message if any
- * @throws javax.jms.JMSException any exception that occured
- */
- public Message getNextMessage(String queueName, long readTimeout)
- throws
- JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
-
- Message message = consumer.receive(readTimeout);
- session.commit();
- consumer.close();
-
- Message result;
-
- // all messages we consume should be TextMessages
- if (message instanceof TextMessage)
- {
- result = ((TextMessage) message);
- } else if (null == message)
- {
- result = null;
- } else
- {
- _logger.info("warning: received non-text message");
- result = message;
- }
-
- return result;
- }
-
- /**
- * GET the top message on a queue. Consumes the message.
- *
- * @param queueName The Queuename to get from
- * @return The string content of the text message, if any received
- * @throws javax.jms.JMSException any exception that occurs
- */
- public Message getNextMessage(String queueName)
- throws
- JMSException
- {
- return getNextMessage(queueName, 0);
- }
-
- /**
- * Completely clears a queue. For readTimeout behaviour see Javadocs for javax.jms.MessageConsumer.
- *
- * @param queueName The Queue name to consume from
- * @param readTimeout The timeout for each consume
- * @throws javax.jms.JMSException Any exception that occurs during the consume
- * @throws InterruptedException If the consume thread was interrupted during a consume.
- */
- public void consume(String queueName, int readTimeout)
- throws
- JMSException,
- InterruptedException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("consuming queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
- int messagesReceived = 0;
-
- _logger.info("consuming...");
- while ((consumer.receive(readTimeout)) != null)
- {
- messagesReceived++;
- }
-
- session.commit();
- consumer.close();
-
- _logger.info("consumed: " + messagesReceived);
- }
-}
+package org.apache.qpid.testutil;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.client.JMSAMQException;
+import org.apache.qpid.url.URLSyntaxException;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+/**
+ * @todo This was originally cut and paste from the client module leading to a duplicate class, then altered very
+ * slightly. To avoid the duplicate class the name was altered slightly to have 'Helper' on the end in order
+ * to distinguish it from the original. Delete this class and use the original instead, just upgrade it to
+ * provide the new features needed.
+ */
+public class QpidClientConnectionHelper implements ExceptionListener
+{
+
+ private static final Logger _logger = Logger.getLogger(QpidClientConnectionHelper.class);
+
+ private boolean transacted = true;
+ private int ackMode = Session.CLIENT_ACKNOWLEDGE;
+ private Connection connection;
+
+ private String virtualHost;
+ private String brokerlist;
+ private int prefetch;
+ protected Session session;
+ protected boolean connected;
+
+ public QpidClientConnectionHelper(String broker)
+ {
+ super();
+ setVirtualHost("/test");
+ setBrokerList(broker);
+ setPrefetch(5000);
+ }
+
+ public void connect() throws JMSException
+ {
+ if (!connected)
+ {
+ /*
+ * amqp://[user:pass@][clientid]/virtualhost?
+ * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
+ * [&failover='method[?option='value'[&option='value']]']
+ * [&option='value']"
+ */
+ String brokerUrl = "amqp://guest:guest@" + virtualHost + "?brokerlist='" + brokerlist + "'";
+ try
+ {
+ AMQConnectionFactory factory = new AMQConnectionFactory(new AMQConnectionURL(brokerUrl));
+ _logger.info("connecting to Qpid :" + brokerUrl);
+ connection = factory.createConnection();
+
+ // register exception listener
+ connection.setExceptionListener(this);
+
+ session = ((AMQConnection) connection).createSession(transacted, ackMode, prefetch);
+
+ _logger.info("starting connection");
+ connection.start();
+
+ connected = true;
+ }
+ catch (URLSyntaxException e)
+ {
+ throw new JMSAMQException("URL syntax error in [" + brokerUrl + "]: " + e.getMessage(), e);
+ }
+ }
+ }
+
+ public void disconnect() throws JMSException
+ {
+ if (connected)
+ {
+ session.commit();
+ session.close();
+ connection.close();
+ connected = false;
+ _logger.info("disconnected");
+ }
+ }
+
+ public void disconnectWithoutCommit() throws JMSException
+ {
+ if (connected)
+ {
+ session.close();
+ connection.close();
+ connected = false;
+ _logger.info("disconnected without commit");
+ }
+ }
+
+ public String getBrokerList()
+ {
+ return brokerlist;
+ }
+
+ public void setBrokerList(String brokerlist)
+ {
+ this.brokerlist = brokerlist;
+ }
+
+ public String getVirtualHost()
+ {
+ return virtualHost;
+ }
+
+ public void setVirtualHost(String virtualHost)
+ {
+ this.virtualHost = virtualHost;
+ }
+
+ public void setPrefetch(int prefetch)
+ {
+ this.prefetch = prefetch;
+ }
+
+ /** override as necessary */
+ public void onException(JMSException exception)
+ {
+ _logger.info("ExceptionListener event: error " + exception.getErrorCode() + ", message: " + exception.getMessage());
+ }
+
+ public boolean isConnected()
+ {
+ return connected;
+ }
+
+ public Session getSession()
+ {
+ return session;
+ }
+
+ /**
+ * Put a String as a text messages, repeat n times. A null payload will result in a null message.
+ *
+ * @param queueName The queue name to put to
+ * @param payload the content of the payload
+ * @param copies the number of messages to put
+ *
+ * @throws javax.jms.JMSException any exception that occurs
+ */
+ public void put(String queueName, String payload, int copies, int deliveryMode) throws JMSException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ _logger.info("putting to queue " + queueName);
+ Queue queue = session.createQueue(queueName);
+
+ final MessageProducer sender = session.createProducer(queue);
+
+ sender.setDeliveryMode(deliveryMode);
+
+ for (int i = 0; i < copies; i++)
+ {
+ Message m = session.createTextMessage(payload + i);
+ m.setIntProperty("index", i + 1);
+ sender.send(m);
+ }
+
+ session.commit();
+ sender.close();
+ _logger.info("put " + copies + " copies");
+ }
+
+ /**
+ * GET the top message on a queue. Consumes the message. Accepts timeout value.
+ *
+ * @param queueName The quename to get from
+ * @param readTimeout The timeout to use
+ *
+ * @return the content of the text message if any
+ *
+ * @throws javax.jms.JMSException any exception that occured
+ */
+ public Message getNextMessage(String queueName, long readTimeout) throws JMSException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ Queue queue = session.createQueue(queueName);
+
+ final MessageConsumer consumer = session.createConsumer(queue);
+
+ Message message = consumer.receive(readTimeout);
+ session.commit();
+ consumer.close();
+
+ Message result;
+
+ // all messages we consume should be TextMessages
+ if (message instanceof TextMessage)
+ {
+ result = ((TextMessage) message);
+ }
+ else if (null == message)
+ {
+ result = null;
+ }
+ else
+ {
+ _logger.info("warning: received non-text message");
+ result = message;
+ }
+
+ return result;
+ }
+
+ /**
+ * GET the top message on a queue. Consumes the message.
+ *
+ * @param queueName The Queuename to get from
+ *
+ * @return The string content of the text message, if any received
+ *
+ * @throws javax.jms.JMSException any exception that occurs
+ */
+ public Message getNextMessage(String queueName) throws JMSException
+ {
+ return getNextMessage(queueName, 0);
+ }
+
+ /**
+ * Completely clears a queue. For readTimeout behaviour see Javadocs for javax.jms.MessageConsumer.
+ *
+ * @param queueName The Queue name to consume from
+ * @param readTimeout The timeout for each consume
+ *
+ * @throws javax.jms.JMSException Any exception that occurs during the consume
+ * @throws InterruptedException If the consume thread was interrupted during a consume.
+ */
+ public void consume(String queueName, int readTimeout) throws JMSException, InterruptedException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ _logger.info("consuming queue " + queueName);
+ Queue queue = session.createQueue(queueName);
+
+ final MessageConsumer consumer = session.createConsumer(queue);
+ int messagesReceived = 0;
+
+ _logger.info("consuming...");
+ while ((consumer.receive(readTimeout)) != null)
+ {
+ messagesReceived++;
+ }
+
+ session.commit();
+ consumer.close();
+ _logger.info("consumed: " + messagesReceived);
+ }
+}