Changeset 1043 for raptor-client


Ignore:
Timestamp:
07/15/11 17:57:05 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
9 edited
5 moved

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/Endpoint.java

    r817 r1043  
    2626import uk.ac.cardiff.model.event.Event; 
    2727import uk.ac.cardiff.raptor.attribute.filtering.AttributeFilterPolicy; 
    28 import uk.ac.cardiff.raptor.remoting.policy.PushPolicy; 
     28import uk.ac.cardiff.raptor.remoting.policy.AbstractPushPolicy; 
    2929 
    3030/** 
     
    4949 
    5050        /** A List of the PushPolicies defined for this endpoint */ 
    51         private List<PushPolicy> pushPolicies; 
     51        private List<AbstractPushPolicy> pushPolicies; 
    5252 
    5353        /** The filter policy defined for this endpoint **/ 
     
    9595        } 
    9696 
    97         public void setPushPolicies(List<PushPolicy> pushPolicies) { 
     97        public void setPushPolicies(List<AbstractPushPolicy> pushPolicies) { 
    9898                this.pushPolicies = pushPolicies; 
    9999        } 
    100100 
    101         public List<PushPolicy> getPushPolicies() { 
     101        public List<AbstractPushPolicy> getPushPolicies() { 
    102102                return pushPolicies; 
    103103        } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseEngine.java

    r1025 r1043  
    2828import uk.ac.cardiff.raptor.registry.EndpointRegistry; 
    2929import uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient; 
    30 import uk.ac.cardiff.raptor.remoting.policy.PushPolicy; 
     30import uk.ac.cardiff.raptor.remoting.policy.AbstractPushPolicy; 
    3131 
    3232import org.slf4j.Logger; 
     
    174174    private boolean shouldRelease(Endpoint endpoint, List<Event> events) { 
    175175        boolean shouldRelease = false; 
    176         for (PushPolicy policy : endpoint.getPushPolicies()) { 
     176        for (AbstractPushPolicy policy : endpoint.getPushPolicies()) { 
    177177            if (policy.evaluatePolicy(events)) 
    178178                shouldRelease = true; 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/AbstractPushPolicy.java

    r1037 r1043  
    2727 * 
    2828 */ 
    29 public abstract class PushPolicy { 
     29public abstract class AbstractPushPolicy { 
    3030 
    3131    public abstract boolean evaluatePolicy(List<Event> events); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/ElapsedTimePushPolicy.java

    r796 r1043  
    2424import uk.ac.cardiff.raptor.remoting.client.EventReleaseEngine; 
    2525 
    26 public class ElapsedTimePushPolicy extends PushPolicy{ 
     26public class ElapsedTimePushPolicy extends AbstractPushPolicy{ 
    2727         
    2828        /** Class logger */ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoElapsedTimePushPolicy.java

    r817 r1043  
    2929 * elapses, the <code>lastReleasedTime</code> is updated. In effect, the 
    3030 * <code>pushInterval</code> is only effective if the number of entries does not 
    31  * suppress the threshold in the given time interval. 
     31 * suppress the threshold in the given time interval. However, the elapsed time will 
     32 * only send events if there are more than 0 events to send. 
    3233 * 
    3334 * @author philsmart 
    3435 * 
    3536 */ 
    36 public class EntryNoElapsedTimePushPolicy extends PushPolicy { 
     37public class EntryNoElapsedTimePushPolicy extends AbstractPushPolicy { 
    3738 
    3839        /** Class logger */ 
     
    5657        } 
    5758 
     59        /** 
     60         * Evaluates this push policy based on both time interval since last release, and number of events. 
     61         *  
     62         * @param events the events with which to evaluate the push policy. 
     63         * @return true if the number of <code>events</code> are >= <code>pushOnOrAfterNoEntries</code>, or true if  
     64         *     the time since the last release exceeds <code>pushInterval</code> and the number of <code>events</code 
     65         *     is greater than 0, false otherwise.  
     66         */ 
    5867        public boolean evaluatePolicy(List<Event> events) { 
    5968                long currentTime = System.currentTimeMillis(); 
     
    6372                } else { 
    6473                        long difference = currentTime - lastReleasedTime; 
    65                         //log.debug("ElapsedTime difference {}, pushInterval {}", difference, pushInterval); 
    66                         if (difference >= getPushInterval()) { 
     74                        log.trace("ElapsedTime difference {}, pushInterval {}", difference, pushInterval); 
     75                        if (difference >= getPushInterval() && events.size()>0) { 
     76                                log.trace("Elapsed time passed and {} events to send",events.size()); 
    6777                                lastReleasedTime = currentTime; 
    6878                                return true; 
    6979                        } 
     80                        else if (difference >= getPushInterval() && events.size()==0){ 
     81                            log.trace("Elapsed time passed but no events to send",events.size()); 
     82                            lastReleasedTime = currentTime; 
     83                            return false; 
     84                        } 
    7085                } 
    7186                return false; 
     87                 
    7288        } 
    7389 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoPushPolicy.java

    r672 r1043  
    2020import uk.ac.cardiff.model.event.Event; 
    2121 
    22 public class EntryNoPushPolicy extends PushPolicy{ 
     22public class EntryNoPushPolicy extends AbstractPushPolicy{ 
    2323         
    2424        /** The threshold on the number of events needed before release*/ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/AsynchronousEntryStoragePipeline.java

    r817 r1043  
    2626import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
    2727 
    28  
    2928public class AsynchronousEntryStoragePipeline { 
    3029 
    31         /** class logger */ 
    32         private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStoragePipeline.class); 
     30    /** class logger */ 
     31    private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStoragePipeline.class); 
    3332 
    34         /** An ID used to track the progress of any transaction */ 
    35         private int transactionId; 
     33    /** An ID used to track the progress of any transaction */ 
     34    private int transactionId; 
    3635 
    37         /** entry handler used to store entries (e.g. events)*/ 
    38     private EntryHandler entryHandler; 
     36    /** entry handler used to store entries (e.g. events) */ 
     37    private EventHandler eventHandler; 
    3938 
    4039    /** Attribute association engine, used to attach additional attributes to events */ 
    4140    private AttributeAssociationEngine attributeAssociationEngine; 
    4241 
    43         public AsynchronousEntryStoragePipeline(int transactionId, EntryHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine){ 
    44             this.entryHandler = entryHandler; 
    45             this.attributeAssociationEngine = attributeAssociationEngine; 
    46             this.transactionId=transactionId; 
    47         } 
    48  
    49         /** 
    50          * Starts and shuts down the <code>storeEntryTask</code> immediately, so that when it completes 
    51          * it can be re-used. 
    52          * 
    53          * @param events 
    54          */ 
    55         public void execute(List<Event> events, StoreEntriesTaskCallbackInterface callback){ 
    56             StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(entryHandler, attributeAssociationEngine, events,callback); 
    57             ExecutorService es = Executors.newSingleThreadExecutor(); 
    58             es.submit(storeEntryTask); 
    59             es.shutdown(); 
    60         } 
    61  
     42    public AsynchronousEntryStoragePipeline(int transactionId, EventHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine) { 
     43        this.eventHandler = entryHandler; 
     44        this.attributeAssociationEngine = attributeAssociationEngine; 
     45        this.transactionId = transactionId; 
     46    } 
    6247 
    6348    /** 
    64      * @param transactionId the transactionId to set 
     49     * Starts and shuts down the <code>storeEntryTask</code> immediately, so that when it completes it can be re-used. 
     50     *  
     51     * @param events 
     52     *            the events to store 
     53     */ 
     54    public void execute(List<Event> events, StoreEntriesTaskCallbackInterface callback) { 
     55        StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(eventHandler, attributeAssociationEngine, events, callback); 
     56        ExecutorService es = Executors.newSingleThreadExecutor(); 
     57        es.submit(storeEntryTask); 
     58        es.shutdown(); 
     59    } 
     60 
     61    /** 
     62     * @param transactionId 
     63     *            the transactionId to set 
    6564     */ 
    6665    public void setTransactionId(int transactionId) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EventHandler.java

    r1037 r1043  
    3232 
    3333 
    34 public interface EntryHandler { 
     34public interface EventHandler { 
    3535 
    3636        /** 
     
    3838         * @param entries 
    3939         */ 
    40         public void addEntries(List<Event> entries) throws StorageException; 
     40        public void addEvents(List<Event> entries) throws StorageException; 
    4141 
    4242        /** 
     
    4444         * @param event 
    4545         */ 
    46         public boolean addEntry(Event event); 
     46        public boolean addEvent(Event event); 
    4747 
    4848        /** 
     
    5050         * @return 
    5151         */ 
    52         public DateTime getLatestEntryTime(); 
     52        public DateTime getLatestEventTime(); 
    5353 
    5454        /** 
     
    5656         * @return 
    5757         */ 
    58         public List<Event> getEntries(); 
     58        public List<Event> getEvents(); 
    5959 
    6060        /** 
     
    6262         * @param entries 
    6363         */ 
    64         public void setEntries(Set<Event> entries); 
     64        public void setEvents(Set<Event> entries); 
    6565 
    6666        /** 
    6767         * 
    6868         */ 
    69         public void removeAllEntries(); 
     69        public void removeAllEvents(); 
    7070 
    7171        public void update(String query, Object[] parameters) throws StorageException; 
     
    112112         * @return 
    113113         */ 
    114         public long getNumberOfEntries(); 
     114        public long getNumberOfEvents(); 
    115115 
    116116        /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r1024 r1043  
    3232import uk.ac.cardiff.model.event.Event; 
    3333import uk.ac.cardiff.model.wsmodel.Suggestion; 
    34 import uk.ac.cardiff.raptor.store.EntryHandler; 
     34import uk.ac.cardiff.raptor.store.EventHandler; 
    3535import uk.ac.cardiff.raptor.store.dao.StorageException; 
    3636import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
     
    4747 
    4848        /** Responsible for storing all entries (e.g. events) */ 
    49         private EntryHandler entryHandler; 
     49        private EventHandler entryHandler; 
    5050 
    5151        /** Engine used to associate attributes to existing events in the MUA */ 
     
    9393                try { 
    9494                        attributeAssociationEngine.associateAttributes(events); 
    95                         entryHandler.addEntries(events); 
     95                        entryHandler.addEvents(events); 
    9696                        log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 
    9797                } catch (StorageException e) { 
     
    134134     */ 
    135135        public void removeAllEntries() { 
    136                 entryHandler.removeAllEntries(); 
     136                entryHandler.removeAllEvents(); 
    137137        } 
    138138 
     
    144144         *            the entryHandler to set 
    145145         */ 
    146         public void setEntryHandler(EntryHandler entryHandler) { 
     146        public void setEntryHandler(EventHandler entryHandler) { 
    147147                this.entryHandler = entryHandler; 
    148148                entryHandler.initialise(); 
     
    152152         * @return the entryHandler 
    153153         */ 
    154         public EntryHandler getEntryHandler() { 
     154        public EventHandler getEntryHandler() { 
    155155                return entryHandler; 
    156156        } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEntriesPipelineTask.java

    r817 r1043  
    3030import uk.ac.cardiff.raptor.store.dao.StorageException; 
    3131 
     32/** 
     33 *  
     34 *  
     35 */ 
     36public class StoreEntriesPipelineTask implements Callable<Boolean> { 
    3237 
     38    /** class logger */ 
     39    private final Logger log = LoggerFactory.getLogger(StoreEntriesPipelineTask.class); 
    3340 
    34 /** 
    35  * @author philsmart 
    36  * 
    37  */ 
    38 public class StoreEntriesPipelineTask implements Callable<Boolean>{ 
     41    /** The entry handler used to store entries (e.g. events) */ 
     42    private EventHandler eventHandler; 
    3943 
    40         /** class logger */ 
    41         private final Logger log = LoggerFactory.getLogger(StoreEntriesPipelineTask.class); 
    42  
    43         /** The entry handler used to store entries (e.g. events)*/ 
    44     private EntryHandler entryHandler; 
    45  
    46     /** The callback interface that is called once the <code>call</code> method has completed*/ 
     44    /** The callback interface that is called once the <code>call</code> method has completed */ 
    4745    private StoreEntriesTaskCallbackInterface storeCallback; 
    4846 
     
    5351    private List<Event> events; 
    5452 
    55     public StoreEntriesPipelineTask(EntryHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine,List<Event> events, StoreEntriesTaskCallbackInterface storeCallback){ 
     53    public StoreEntriesPipelineTask(EventHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine, List<Event> events, StoreEntriesTaskCallbackInterface storeCallback) { 
    5654        this.storeCallback = storeCallback; 
    5755        this.attributeAssociationEngine = attributeAssociationEngine; 
    58         this.entryHandler = entryHandler; 
     56        this.eventHandler = entryHandler; 
    5957        this.events = events; 
    6058    } 
    6159 
     60    /** 
     61     * Called to perform both attribute association using the {@link uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine} and then 
     62     * store the <code>events</code> using the {@link  uk.ac.cardiff.raptor.store.EventHandler}. 
     63     */ 
    6264    public Boolean call() throws Exception { 
    63         try{ 
    64  
    65             associate(); 
    66             store(); 
    67  
    68         } 
    69         catch(StorageException e){ 
    70             log.error("Failed to store events asynchronously {}",e.getMessage(),e); 
    71             storeCallback.storageResultCallback(new Boolean("false")); 
    72             return false; 
    73         } 
     65        try { 
     66            associate(); 
     67            store(); 
     68        } catch (StorageException e) { 
     69            log.error("Failed to store events asynchronously", e); 
     70            storeCallback.storageResultCallback(new Boolean("false")); 
     71            return false; 
     72        } 
    7473        storeCallback.storageResultCallback(new Boolean("true")); 
    7574        return true; 
    7675    } 
    7776 
    78     private void store() throws StorageException{ 
    79         entryHandler.addEntries(events); 
     77    /** 
     78     * Stores the <code>events</code> with the configured {@link  uk.ac.cardiff.raptor.store.EventHandler} 
     79     *  
     80     * @throws StorageException 
     81     */ 
     82    private void store() throws StorageException { 
     83        eventHandler.addEvents(events); 
    8084    } 
    8185 
    82     private void associate(){ 
     86    private void associate() { 
    8387        try { 
    8488            attributeAssociationEngine.associateAttributes(events); 
    8589        } catch (AttributeAssociationException e) { 
    86             log.warn("{}",e.getMessage()); 
     90            log.warn("{}", e.getMessage()); 
    8791        } 
    8892    } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java

    r1024 r1043  
    3838public class DefaultDataConnection implements RaptorDataConnection { 
    3939 
    40         /** hibernate template to persist classes */ 
    41         private HibernateTemplate hibernateTemplate; 
     40    /** hibernate template to persist classes */ 
     41    private HibernateTemplate hibernateTemplate; 
    4242 
    43         private SessionFactory sessionFactory; 
     43    private SessionFactory sessionFactory; 
    4444 
    45         /** class logger */ 
    46         private static Logger log = LoggerFactory.getLogger(DefaultDataConnection.class); 
     45    /** class logger */ 
     46    private static Logger log = LoggerFactory.getLogger(DefaultDataConnection.class); 
    4747 
    48         public void save(Object object) throws DataAccessException { 
    49                 hibernateTemplate.saveOrUpdate(object); 
    50         } 
     48    public void save(Object object) throws DataAccessException { 
     49        hibernateTemplate.saveOrUpdate(object); 
     50    } 
    5151 
    52         public void saveAll(Collection collection) throws DataAccessException { 
    53                 hibernateTemplate.saveOrUpdateAll(collection); 
    54         } 
     52    public void saveAll(@SuppressWarnings("rawtypes") Collection collection) throws DataAccessException { 
     53        hibernateTemplate.saveOrUpdateAll(collection); 
     54    } 
    5555 
    56         public List runQuery(String query, Object[] parameters) throws DataAccessException { 
    57                 return hibernateTemplate.find(query, parameters); 
    58         } 
     56    @SuppressWarnings("rawtypes") 
     57    public List runQuery(String query, Object[] parameters) throws DataAccessException { 
     58        return hibernateTemplate.find(query, parameters); 
     59    } 
    5960 
    60         public void runUpdate(String query, Object[] parameters) throws DataAccessException { 
    61                 hibernateTemplate.bulkUpdate(query, parameters); 
    62         } 
     61    public void runUpdate(String query, Object[] parameters) throws DataAccessException { 
     62        hibernateTemplate.bulkUpdate(query, parameters); 
     63    } 
    6364 
    64         public List runQuery(String query, Object[] parameters, int maxResultSize) throws DataAccessException { 
    65                 hibernateTemplate.setMaxResults(maxResultSize); 
    66                 List result = hibernateTemplate.find(query, parameters); 
    67                 hibernateTemplate.setMaxResults(0); 
    68                 return result; 
    69         } 
    70          
    71         /**  
    72          * Not used method. Specific to this implementation for testing. 
    73          *  
    74          * @param query 
    75          * @param pageSize 
    76          * @param pageNumber 
    77          * @return 
    78          * @throws DataAccessException 
    79          */ 
    80         public List runQueryPaged(final String query, final int pageSize, final int pageNumber) throws DataAccessException { 
    81                 HibernateTemplate template = getHibernateTemplate(); 
     65    @SuppressWarnings("rawtypes") 
     66    public List runQuery(String query, Object[] parameters, int maxResultSize) throws DataAccessException { 
     67        hibernateTemplate.setMaxResults(maxResultSize); 
     68        List result = hibernateTemplate.find(query, parameters); 
     69        hibernateTemplate.setMaxResults(0); 
     70        return result; 
     71    } 
     72 
     73    /** 
     74     * Not used method. Specific to this implementation for testing. 
     75     *  
     76     * @param query 
     77     * @param pageSize 
     78     * @param pageNumber 
     79     * @return 
     80     * @throws DataAccessException 
     81     */ 
     82    @SuppressWarnings("rawtypes") 
     83    public List runQueryPaged(final String query, final int pageSize, final int pageNumber) throws DataAccessException { 
     84        HibernateTemplate template = getHibernateTemplate(); 
    8285        return template.executeFind(new HibernateCallback() { 
    8386            public Object doInHibernate(Session session) throws HibernateException, SQLException { 
     
    8891            } 
    8992        }); 
    90         } 
     93    } 
     94     
     95    public Object runQueryUnique(String query, Object[] parameters) throws DataAccessException { 
     96        if (parameters != null) 
     97            log.trace("Query to db, {}, with params [{}]", query, Arrays.asList(parameters)); 
     98        Object object = DataAccessUtils.uniqueResult(getHibernateTemplate().find(query, parameters)); 
     99        return object; 
     100    } 
    91101 
    92         public Object runQueryUnique(String query, Object[] parameters) throws DataAccessException { 
    93                 if (parameters != null) 
    94                         log.trace("Query to db, {}, with params [{}]", query, Arrays.asList(parameters)); 
    95                 Object object = DataAccessUtils.uniqueResult(getHibernateTemplate().find(query, parameters)); 
    96                 return object; 
    97         } 
     102    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { 
     103        this.hibernateTemplate = hibernateTemplate; 
     104    } 
    98105 
    99         public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { 
    100                 this.hibernateTemplate = hibernateTemplate; 
    101         } 
     106    public HibernateTemplate getHibernateTemplate() { 
     107        return hibernateTemplate; 
     108    } 
    102109 
    103         public HibernateTemplate getHibernateTemplate() { 
    104                 return hibernateTemplate; 
    105         } 
     110    public void setSessionFactory(SessionFactory sessionFactory) { 
     111        this.sessionFactory = sessionFactory; 
     112        this.hibernateTemplate = new HibernateTemplate(sessionFactory); 
     113    } 
    106114 
    107         public void setSessionFactory(SessionFactory sessionFactory) { 
    108                 this.sessionFactory = sessionFactory; 
    109                 this.hibernateTemplate = new HibernateTemplate(sessionFactory); 
    110         } 
    111115 
    112         /** 
    113          * <p> 
    114          * import, here we load all entries to bind them in hibernate then we delete 
    115          * them. Not sure if all these entries are loaded then delete if lazy 
    116          * loading is false. 
    117          * </p> 
    118          * (non-Javadoc) 
    119          *  
    120          * @see main.uk.ac.cf.dao.internal.ICADataConnection#deleteAllEntries() 
    121          */ 
    122         @Override 
    123         public void deleteAllEntries(Collection entries) throws DataAccessException { 
    124                 hibernateTemplate.deleteAll(entries); 
     116    @SuppressWarnings("rawtypes") 
     117    @Override 
     118    public void deleteAllEntries(Collection entries) throws DataAccessException { 
     119        hibernateTemplate.deleteAll(entries); 
    125120 
    126         } 
     121    } 
    127122 
    128123} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/LogFileMemoryEventHandler.java

    r1037 r1043  
    3737import org.slf4j.LoggerFactory; 
    3838 
    39 public class LogFileMemoryEntryHandler implements IncrementalEntryHandler { 
     39public class LogFileMemoryEventHandler implements IncrementalEntryHandler { 
    4040 
    4141        /** Class logger */ 
    42         private final Logger log = LoggerFactory.getLogger(MemoryEntryHandler.class); 
     42        private final Logger log = LoggerFactory.getLogger(MemoryEventHandler.class); 
    4343 
    4444        /** Pointer to the last recorded entry, for incremental update. */ 
     
    5656        private Set<Event> latestEqualEntries; 
    5757 
    58         public LogFileMemoryEntryHandler() { 
     58        public LogFileMemoryEventHandler() { 
    5959                entries = new LinkedHashSet<Event>(); 
    6060                latestEqualEntries = new LinkedHashSet<Event>(); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEventHandler.java

    r1037 r1043  
    3434import uk.ac.cardiff.model.event.Event; 
    3535import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    36 import uk.ac.cardiff.raptor.store.EntryHandler; 
     36import uk.ac.cardiff.raptor.store.EventHandler; 
    3737 
    3838import org.joda.time.DateTime; 
     
    4040import org.slf4j.LoggerFactory; 
    4141 
    42 public class MemoryEntryHandler implements EntryHandler { 
     42public class MemoryEventHandler implements EventHandler { 
    4343 
    4444        /** Class logger */ 
    45         private final Logger log = LoggerFactory.getLogger(MemoryEntryHandler.class); 
     45        private final Logger log = LoggerFactory.getLogger(MemoryEventHandler.class); 
    4646 
    4747        /** pointer to the last recorded entry, for incremental update */ 
     
    5454        private Set<Event> entries; 
    5555 
    56         public MemoryEntryHandler() { 
     56        public MemoryEventHandler() { 
    5757                entries = new LinkedHashSet<Event>(); 
    5858        } 
    5959 
    60         public void addEntries(List<Event> entries) { 
     60        public void addEvents(List<Event> entries) { 
    6161                log.debug("Current: " + this.entries.size() + " in: " + entries.size()); 
    6262                int notAdded = 0; 
    6363                for (Event event : entries) { 
    64                         boolean didAdd = addEntry(event); 
     64                        boolean didAdd = addEvent(event); 
    6565                        if (didAdd == false) 
    6666                                notAdded++; 
    6767 
    6868                } 
    69                 log.debug("Total No. of Entries {}, Lastest Entry at: {}, with {} duplicates", new Object[] { this.entries.size(), getLatestEntryTime(), notAdded }); 
     69                log.debug("Total No. of Entries {}, Lastest Entry at: {}, with {} duplicates", new Object[] { this.entries.size(), getLatestEventTime(), notAdded }); 
    7070        } 
    7171 
     
    7777         *            the event to store 
    7878         */ 
    79         public boolean addEntry(Event event) { 
     79        public boolean addEvent(Event event) { 
    8080                addEventIdIfNull(event); 
    8181                if (!entries.contains(event)) { 
     
    107107        private void updateLastEntry(Event event) { 
    108108                DateTime entryTime = event.getEventTime(); 
    109                 if (getLatestEntryTime() == null) 
     109                if (getLatestEventTime() == null) 
    110110                        setLatestEntryTime(entryTime); 
    111                 if (entryTime.isAfter(getLatestEntryTime())) { 
     111                if (entryTime.isAfter(getLatestEventTime())) { 
    112112                        setLatestEntryTime(entryTime); 
    113113 
     
    135135        } 
    136136 
    137         public DateTime getLatestEntryTime() { 
     137        public DateTime getLatestEventTime() { 
    138138                return latestEntryTime; 
    139139        } 
     
    151151         * @return the list of entries currently stored by the entry handler 
    152152         */ 
    153         public List<Event> getEntries() { 
     153        public List<Event> getEvents() { 
    154154                return new ArrayList<Event>(entries); 
    155155 
     
    160160         * so as not to add previously parsed entries. 
    161161         */ 
    162         public void removeAllEntries() { 
     162        public void removeAllEvents() { 
    163163                entries.clear(); 
    164164        } 
     
    179179        } 
    180180 
    181         public long getNumberOfEntries() { 
     181        public long getNumberOfEvents() { 
    182182                return entries.size(); 
    183183        } 
     
    204204        } 
    205205 
    206         public void setEntries(Set<Event> entries) { 
     206        public void setEvents(Set<Event> entries) { 
    207207                this.entries = entries; 
    208208 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java

    r1037 r1043  
    3232 
    3333import uk.ac.cardiff.model.event.Event; 
    34 import uk.ac.cardiff.raptor.store.EntryHandler; 
     34import uk.ac.cardiff.raptor.store.EventHandler; 
    3535import uk.ac.cardiff.raptor.store.dao.RaptorDataConnection; 
    3636import uk.ac.cardiff.raptor.store.dao.StorageException; 
     
    4040 * 
    4141 */ 
    42 public class PersistantEntryHandler implements EntryHandler { 
    43         // TODO can use the spring initialisation callback methods to initials the 
    44         // bean after all properties set etc, rather than initialising on the set 
    45         // method of the engine class 
    46  
     42public class PersistantEventHandler implements EventHandler { 
     43     
    4744        /** class logger. */ 
    48         private final Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 
     45        private final Logger log = LoggerFactory.getLogger(PersistantEventHandler.class); 
    4946 
    5047        /** data connection used to persist entries. */ 
     
    5855        private Set<Event> persistQueue; 
    5956 
    60         public PersistantEntryHandler(RaptorDataConnection dataConnection) { 
     57        public PersistantEventHandler(RaptorDataConnection dataConnection) { 
    6158                this.setDataConnection(dataConnection); 
    6259                persistQueue = new HashSet<Event>(); 
     
    7067        public void initialise() { 
    7168                log.info("Persistant entry handler [{}] initialising", this); 
    72                 log.info("Persistent data store has {} entries for [{}]", this.getNumberOfEntries(),this); 
     69                log.info("Persistent data store has {} entries for [{}]", this.getNumberOfEvents(),this); 
    7370                log.info("Persistant entry handler [{}] started", this); 
    7471        } 
     
    135132         * @throws 
    136133         */ 
    137         public void addEntries(List<Event> entries) throws StorageException{ 
     134        public void addEvents(List<Event> entries) throws StorageException{ 
    138135                log.info("Persistent Entry Handler has {} entries, with {} new entries inputted, and {} exist in the queue", 
    139                                 new Object[]{this.getNumberOfEntries(), entries.size(),persistQueue.size()}); 
     136                                new Object[]{this.getNumberOfEvents(), entries.size(),persistQueue.size()}); 
    140137 
    141138                int duplicates = 0; 
     
    161158                } 
    162159                persistQueue.clear(); 
    163                 log.info("Total No. of Entries after addition = {}, finding {} duplicates", this.getNumberOfEntries(), duplicates); 
    164         } 
    165  
    166         public boolean addEntry(Event event) { 
     160                log.info("Total No. of Entries after addition = {}, finding {} duplicates", this.getNumberOfEvents(), duplicates); 
     161        } 
     162 
     163        public boolean addEvent(Event event) { 
    167164 
    168165                String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and eventId =?"; 
     
    181178        } 
    182179 
    183         public List<Event> getEntries() { 
     180        public List<Event> getEvents() { 
    184181                List<Event> runQuery = dataConnection.runQuery("from Event",null); 
    185182                return runQuery; 
    186183        } 
    187184 
    188         public void removeAllEntries() { 
     185        public void removeAllEvents() { 
    189186                log.error("Method removeAllEntries not yet implemented"); 
    190187        } 
     
    198195        } 
    199196 
    200         public void setEntries(Set<Event> entries) { 
    201  
    202         } 
    203  
    204         public long getNumberOfEntries() { 
     197        public void setEvents(Set<Event> entries) { 
     198 
     199        } 
     200 
     201        public long getNumberOfEvents() { 
    205202                Object result = dataConnection.runQueryUnique("select count(*) from Event", null); 
    206203                return (Long) result; 
    207204        } 
    208205 
    209         public DateTime getLatestEntryTime(){ 
     206        public DateTime getLatestEventTime(){ 
    210207                return (DateTime) dataConnection.runQueryUnique("select max(eventTime) from Event", null); 
    211208        } 
Note: See TracChangeset for help on using the changeset viewer.