Changeset 373974a6fbcec5a328d77ddbfa850b1682f58b0b
- Timestamp:
- 03/17/10 15:21:59
(3 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1268839319 +0000
- git-parent:
[77c2f1d33af8c513f72b1dee14b5dd6d2104df06]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1268839319 +0000
- Message:
allow overriding the listner
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| ra917ef4 |
r373974a |
|
| 8 | 8 | |
|---|
| 9 | 9 | package com.omniti.reconnoiter.broker; |
|---|
| | 10 | |
|---|
| | 11 | import java.lang.reflect.Constructor; |
|---|
| 10 | 12 | |
|---|
| 11 | 13 | import javax.jms.Connection; |
|---|
| … | … | |
| 27 | 29 | private String hostName; |
|---|
| 28 | 30 | private int portNumber; |
|---|
| | 31 | private Class listenerClass; |
|---|
| | 32 | private Constructor<UpdateListener> con; |
|---|
| | 33 | |
|---|
| | 34 | @SuppressWarnings("unchecked") |
|---|
| 29 | 35 | public AMQBroker(StratconConfig config) { |
|---|
| 30 | 36 | this.hostName = config.getBrokerParameter("hostname", "127.0.0.1"); |
|---|
| 31 | 37 | this.portNumber = Integer.parseInt(config.getBrokerParameter("port", "61613")); |
|---|
| | 38 | String className = config.getBrokerParameter("listenerClass", "com.omniti.reconnoiter.broker.AMQListener"); |
|---|
| | 39 | try { |
|---|
| | 40 | this.listenerClass = Class.forName(className); |
|---|
| | 41 | this.con = this.listenerClass.getDeclaredConstructor( |
|---|
| | 42 | new Class[] { EPServiceProvider.class, StratconQuery.class, String.class } |
|---|
| | 43 | ); |
|---|
| | 44 | } |
|---|
| | 45 | catch(java.lang.ClassNotFoundException e) { |
|---|
| | 46 | throw new RuntimeException("Cannot find class: " + className); |
|---|
| | 47 | } |
|---|
| | 48 | catch(java.lang.NoSuchMethodException e) { |
|---|
| | 49 | throw new RuntimeException("Cannot find constructor for class: " + className); |
|---|
| | 50 | } |
|---|
| | 51 | |
|---|
| 32 | 52 | } |
|---|
| 33 | 53 | |
|---|
| … | … | |
| 68 | 88 | |
|---|
| 69 | 89 | public UpdateListener getListener(EPServiceProvider epService, StratconQuery sq) { |
|---|
| 70 | | return new AMQListener(epService, sq, "vm://localhost"); |
|---|
| | 90 | UpdateListener l = null; |
|---|
| | 91 | try { |
|---|
| | 92 | l = con.newInstance(epService, sq, "vm://localhost"); |
|---|
| | 93 | } |
|---|
| | 94 | catch(java.lang.InstantiationException ie) { } |
|---|
| | 95 | catch(java.lang.IllegalAccessException ie) { } |
|---|
| | 96 | catch(java.lang.reflect.InvocationTargetException ie) { } |
|---|
| | 97 | return l; |
|---|
| 71 | 98 | } |
|---|
| 72 | 99 | } |
|---|
| ra917ef4 |
r373974a |
|
| 10 | 10 | |
|---|
| 11 | 11 | import java.io.IOException; |
|---|
| | 12 | import java.lang.reflect.Constructor; |
|---|
| 12 | 13 | |
|---|
| 13 | 14 | import com.espertech.esper.client.EPServiceProvider; |
|---|
| … | … | |
| 37 | 38 | private String alertRoutingKey; |
|---|
| 38 | 39 | private String alertExchangeName; |
|---|
| | 40 | private Class listenerClass; |
|---|
| | 41 | private Constructor<UpdateListener> con; |
|---|
| 39 | 42 | |
|---|
| | 43 | @SuppressWarnings("unchecked") |
|---|
| 40 | 44 | public RabbitBroker(StratconConfig config) { |
|---|
| 41 | 45 | this.userName = config.getBrokerParameter("username", "guest"); |
|---|
| … | … | |
| 45 | 49 | this.portNumber = Integer.parseInt(config.getBrokerParameter("port", "5672")); |
|---|
| 46 | 50 | |
|---|
| | 51 | String className = config.getBrokerParameter("listenerClass", "com.omniti.reconnoiter.broker.RabbitListener"); |
|---|
| | 52 | try { |
|---|
| | 53 | this.listenerClass = Class.forName(className); |
|---|
| | 54 | this.con = this.listenerClass.getDeclaredConstructor( |
|---|
| | 55 | new Class[] { EPServiceProvider.class, StratconQuery.class, Channel.class, |
|---|
| | 56 | String.class, String.class } |
|---|
| | 57 | ); |
|---|
| | 58 | } |
|---|
| | 59 | catch(java.lang.ClassNotFoundException e) { |
|---|
| | 60 | throw new RuntimeException("Cannot find class: " + className); |
|---|
| | 61 | } |
|---|
| | 62 | catch(java.lang.NoSuchMethodException e) { |
|---|
| | 63 | throw new RuntimeException("Cannot find constructor for class: " + className); |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| 47 | 66 | // This is a fanout exchange |
|---|
| 48 | 67 | this.exchangeName = config.getMQParameter("exchange", "noit.firehose"); |
|---|
| … | … | |
| 118 | 137 | } |
|---|
| 119 | 138 | } |
|---|
| 120 | | |
|---|
| | 139 | |
|---|
| 121 | 140 | public UpdateListener getListener(EPServiceProvider epService, StratconQuery sq) { |
|---|
| 122 | | return new RabbitListener(epService, sq, channel, alertExchangeName, alertRoutingKey); |
|---|
| | 141 | UpdateListener l = null; |
|---|
| | 142 | try { |
|---|
| | 143 | l = con.newInstance(epService, sq, channel, alertExchangeName, alertRoutingKey); |
|---|
| | 144 | } |
|---|
| | 145 | catch(java.lang.InstantiationException ie) { } |
|---|
| | 146 | catch(java.lang.IllegalAccessException ie) { } |
|---|
| | 147 | catch(java.lang.reflect.InvocationTargetException ie) { } |
|---|
| | 148 | return l; |
|---|
| 123 | 149 | } |
|---|
| 124 | 150 | } |
|---|