Changeset 373974a6fbcec5a328d77ddbfa850b1682f58b0b

Show
Ignore:
Timestamp:
03/17/10 15:21:59 (4 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
  • src/java/com/omniti/reconnoiter/broker/AMQBroker.java

    ra917ef4 r373974a  
    88 
    99package com.omniti.reconnoiter.broker; 
     10 
     11import java.lang.reflect.Constructor; 
    1012 
    1113import javax.jms.Connection; 
     
    2729  private String hostName; 
    2830  private int portNumber; 
     31  private Class listenerClass; 
     32  private Constructor<UpdateListener> con; 
     33 
     34  @SuppressWarnings("unchecked") 
    2935  public AMQBroker(StratconConfig config) { 
    3036    this.hostName = config.getBrokerParameter("hostname", "127.0.0.1"); 
    3137    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 
    3252  } 
    3353 
     
    6888   
    6989  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; 
    7198  } 
    7299} 
  • src/java/com/omniti/reconnoiter/broker/RabbitBroker.java

    ra917ef4 r373974a  
    1010 
    1111import java.io.IOException; 
     12import java.lang.reflect.Constructor; 
    1213 
    1314import com.espertech.esper.client.EPServiceProvider; 
     
    3738  private String alertRoutingKey; 
    3839  private String alertExchangeName; 
     40  private Class listenerClass; 
     41  private Constructor<UpdateListener> con; 
    3942 
     43  @SuppressWarnings("unchecked")  
    4044  public RabbitBroker(StratconConfig config) { 
    4145    this.userName = config.getBrokerParameter("username", "guest"); 
     
    4549    this.portNumber = Integer.parseInt(config.getBrokerParameter("port", "5672")); 
    4650     
     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 
    4766    // This is a fanout exchange 
    4867    this.exchangeName = config.getMQParameter("exchange", "noit.firehose"); 
     
    118137    } 
    119138  } 
    120    
     139 
    121140  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; 
    123149  } 
    124150}