Changeset 1355 for raptor-client


Ignore:
Timestamp:
01/15/12 21:30:16 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk
Files:
2 added
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/pom.xml

    r1323 r1355  
    1 <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"> 
     1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     2    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    23    <modelVersion>4.0.0</modelVersion> 
    34    <groupId>uk.ac.cardiff.raptor</groupId> 
     
    6364            <groupId>uk.ac.cardiff.raptor</groupId> 
    6465            <artifactId>raptor-information-model</artifactId> 
    65            <version>1.0.2-SNAPSHOT</version> 
     66            <version>1.0.2-SNAPSHOT</version> 
    6667            <exclusions> 
    6768                <exclusion> 
     
    209210 
    210211 
    211  
     212        <dependency> 
     213            <groupId>joda-time</groupId> 
     214            <artifactId>joda-time</artifactId> 
     215            <version>1.6</version> 
     216        </dependency> 
    212217        <dependency> 
    213218            <groupId>ehcache</groupId> 
     
    326331            <plugin> 
    327332                <artifactId>maven-release-plugin</artifactId> 
    328                 
     333 
    329334                <configuration> 
    330                      
     335 
    331336                    <tagBase> 
    332337                        http://iam.cf.ac.uk/repos/RAPTOR/raptor-client/tags 
    333338                    </tagBase> 
    334                      
     339 
    335340                </configuration> 
    336341                <dependencies> 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/DefaultEventStorageEngine.java

    r1306 r1355  
    3737 *  
    3838 */ 
    39 public class EventStorageEngine implements StoreEntriesTaskCallbackInterface { 
     39public class DefaultEventStorageEngine implements EventStorageEngine, StoreEntriesTaskCallbackInterface { 
    4040 
    4141    /** Class logger */ 
    42     private final Logger log = LoggerFactory.getLogger(EventStorageEngine.class); 
     42    private final Logger log = LoggerFactory.getLogger(DefaultEventStorageEngine.class); 
    4343 
    4444    /** Responsible for storing all entries (e.g. events) */ 
     
    5555 
    5656    /** Default Constructor */ 
    57     public EventStorageEngine() { 
     57    public DefaultEventStorageEngine() { 
    5858 
    5959    } 
     
    6565    } 
    6666 
    67     /** 
    68      * Stores the <code>events</code> asynchronously through the configured 
    69      * {@link uk.ac.cardiff.raptor.store.EventHandler} 
    70      *  
    71      * @param transactionId the numerical Id of this transaction 
    72      * @param events the events to store 
    73      */ 
     67    /** {@inheritDoc} */ 
    7468    public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) 
    7569            throws TransactionInProgressException { 
     
    8680    } 
    8781 
     82    /** {@inheritDoc} */ 
    8883    public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) 
    8984            throws TransactionInProgressException { 
     
    106101    } 
    107102 
    108     /** 
    109      * Returns events on or after the input time <code>earliestReleaseTime</code>. 
    110      *  
    111      * @param earliestReleaseTime 
    112      * @return 
    113      */ 
     103    /** {@inheritDoc} */ 
    114104    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
    115105        List<Event> query = 
     
    118108    } 
    119109 
    120     /** 
    121      * Returns events on or after the input time <code>earliestReleaseTime</code>, but with a maximum of 
    122      * <code>maxNoResults</code> results (in chronological order). 
    123      *  
    124      * @param earliestReleaseTime 
    125      * @param maxNoResults 
    126      * @return 
    127      */ 
     110    /** {@inheritDoc} */ 
    128111    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 
    129112        List<Event> query = 
     
    133116    } 
    134117 
    135     /** 
    136      * 
    137      */ 
    138118    public void removeAllEntries() { 
    139119        eventHandler.removeAllEvents(); 
     
    172152 
    173153    /** 
    174      * Returns the possible values that each of the input field names can take 
    175      *  
    176      * @param possibleFieldNameValuesList 
    177      * @return 
     154     * {@inheritDoc} 
    178155     */ 
    179156    public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EventStorageEngine.java

    r1188 r1355  
    1414 * limitations under the License. 
    1515 */ 
    16 /** 
    17  * 
    18  */ 
    1916 
    2017package uk.ac.cardiff.raptor.store; 
    2118 
    22 import java.util.ArrayList; 
    2319import java.util.List; 
    2420 
    2521import org.joda.time.DateTime; 
    26 import org.slf4j.Logger; 
    27 import org.slf4j.LoggerFactory; 
    2822 
    2923import uk.ac.cardiff.model.event.Event; 
    3024import uk.ac.cardiff.model.wsmodel.Suggestion; 
    31 import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
    32 import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 
    33 import uk.ac.cardiff.raptor.store.dao.StorageException; 
    3425 
    35 /** 
    36  * @author philsmart 
    37  *  
    38  */ 
    39 public class EventStorageEngine implements StoreEntriesTaskCallbackInterface { 
    40  
    41     /** Class logger */ 
    42     private final Logger log = LoggerFactory.getLogger(EventStorageEngine.class); 
    43  
    44     /** Responsible for storing all entries (e.g. events) */ 
    45     private QueryableEventHandler eventHandler; 
    46  
    47     /** Engine used to associate attributes to existing events in the MUA */ 
    48     private AttributeAssociationEngine attributeAssociationEngine; 
    49  
    50     /** The ID of the currently executing transaction */ 
    51     private int currentTransactionId; 
    52  
    53     /** Whether a transaction is currently in progress */ 
    54     private boolean transactionInProgress; 
    55  
    56     /** Default Constructor */ 
    57     public EventStorageEngine() { 
    58  
    59     } 
    60  
    61     public void storageResultCallback(Object result) { 
    62         log.debug("Storage task completed {}, for transaction id [{}]", result, currentTransactionId); 
    63         transactionInProgress = false; 
    64  
    65     } 
     26public interface EventStorageEngine { 
    6627 
    6728    /** 
     
    7334     */ 
    7435    public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) 
    75             throws TransactionInProgressException { 
    76         if (transactionInProgress) { 
    77             throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 
    78         } 
    79         log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 
    80         currentTransactionId = transactionId; 
    81         transactionInProgress = true; 
    82         AsynchronousEntryStoragePipeline asyncEntryStorage = 
    83                 new AsynchronousEntryStoragePipeline(transactionId, eventHandler, attributeAssociationEngine); 
    84         asyncEntryStorage.execute(events, this); 
     36            throws TransactionInProgressException; 
    8537 
    86     } 
    87  
     38    /** 
     39     * Stores the <code>events</code> synchronously through the configured 
     40     * {@link uk.ac.cardiff.raptor.store.EventHandler} 
     41     *  
     42     * @param transactionId the numerical Id of this transaction 
     43     * @param events the events to store 
     44     */ 
    8845    public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) 
    89             throws TransactionInProgressException { 
    90         if (transactionInProgress) { 
    91             throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 
    92         } 
    93         log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 
    94         currentTransactionId = transactionId; 
    95         transactionInProgress = true; 
    96         try { 
    97             attributeAssociationEngine.associateAttributes(events); 
    98             eventHandler.addEvents(events); 
    99             log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 
    100         } catch (StorageException e) { 
    101             log.error("Could not store events for transaction id [{}], {}", transactionId); 
    102         } catch (AttributeAssociationException e) { 
    103             log.error("Could not store events for transaction id [{}], {}", transactionId); 
    104         } 
    105         transactionInProgress = false; 
    106     } 
     46            throws TransactionInProgressException; 
    10747 
    10848    /** 
     
    11252     * @return 
    11353     */ 
    114     public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
    115         List<Event> query = 
    116                 (List<Event>) eventHandler.query("from Event where eventTime >= ?", new Object[] {earliestReleaseTime}); 
    117         return query; 
    118     } 
     54    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime); 
    11955 
    12056    /** 
     
    12662     * @return 
    12763     */ 
    128     public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 
    129         List<Event> query = 
    130                 (List<Event>) eventHandler.query("from Event where eventTime >= ? order by eventTime asc", 
    131                         new Object[] {earliestReleaseTime}, maxNoResults); 
    132         return query; 
    133     } 
    134  
    135     /** 
    136      * 
    137      */ 
    138     public void removeAllEntries() { 
    139         eventHandler.removeAllEvents(); 
    140     } 
    141  
    142     /** 
    143      * Sets the configured event handler. Must also then initialise that entry handler 
    144      *  
    145      * @param entryHandler the entryHandler to set 
    146      */ 
    147     public void setEventHandler(QueryableEventHandler entryHandler) { 
    148         this.eventHandler = entryHandler; 
    149         entryHandler.initialise(); 
    150     } 
    151  
    152     /** 
    153      * @return the entryHandler 
    154      */ 
    155     public QueryableEventHandler getEventHandler() { 
    156         return eventHandler; 
    157     } 
    158  
    159     /** 
    160      * @param attributeAssociationEngine the attributeAssociationEngine to set 
    161      */ 
    162     public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 
    163         this.attributeAssociationEngine = attributeAssociationEngine; 
    164     } 
    165  
    166     /** 
    167      * @return the attributeAssociationEngine 
    168      */ 
    169     public AttributeAssociationEngine getAttributeAssociationEngine() { 
    170         return attributeAssociationEngine; 
    171     } 
     64    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults); 
    17265 
    17366    /** 
     
    17770     * @return 
    17871     */ 
    179     public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 
    180         ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 
     72    public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList); 
    18173 
    182         for (String fieldName : possibleFieldNameValuesList) { 
    183             try { 
    184                 String query = "select " + fieldName + " from Event group by (" + fieldName + ")"; 
    185                 List results = eventHandler.query(query, null); 
    186                 log.trace("Looking for possible values for field {} using query [{}]", fieldName, query); 
    187                 int noResults = 0; 
    188                 for (Object result : results) { 
    189                     if (result instanceof String) { 
    190                         Suggestion suggestion = new Suggestion(); 
    191                         suggestion.setBase(fieldName); 
    192                         suggestion.setValue((String) result); 
    193                         suggestions.add(suggestion); 
    194                         noResults++; 
    195                     } 
    196                 } 
    197                 log.debug("Field {} has {} suggestion values", fieldName, noResults); 
    198             } catch (RuntimeException e) { 
    199                 log.warn( 
    200                         "Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about", 
    201                         fieldName); 
    202             } 
    203  
    204         } 
    205  
    206         return suggestions; 
    207     } 
     74    // TODO, should we allow direct access the the event handler in this class. 
     75    public QueryableEventHandler getEventHandler(); 
    20876 
    20977} 
Note: See TracChangeset for help on using the changeset viewer.