Changeset 772


Ignore:
Timestamp:
05/09/11 18:04:03 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
8 edited

Legend:

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

    r767 r772  
    6666                        boolean shouldRelease = shouldRelease(endpoint,applicableEvents); 
    6767                        log.debug("Endpoint {}, should release {}", endpoint.getServiceEndpoint(), shouldRelease); 
    68                         List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
    69                         EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
    70                         if (shouldRelease) {                             
     68                        if (shouldRelease) { 
     69                                List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
     70                                EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
    7171                                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
    7272                                boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage,endpoint); 
     
    7676                                else if (releaseSuccess ==true){ 
    7777                                        releaseCount++; 
    78                                         endpoint.getReleaseInformation().setLastReleasedEventTime(getLatestEvent(events)); 
     78                                        endpoint.getReleaseInformation().releasePerformed(filteredEntries); 
    7979                                        log.debug("Endpoint [{}] has been sent events up to and including {}",endpoint.getServiceEndpoint(), 
    8080                                                        endpoint.getReleaseInformation().getLastReleasedEventTime()); 
     
    9191 
    9292        } 
    93          
     93 
    9494        /** 
    9595         * Filters the input list of events (<code>events</code>) such that only those that are after (chronological) 
    9696         * the <code>latestPublishedEventTime</code> of the input <code>Endpoint</code> remain 
    97          *  
     97         * 
    9898         * @param endpoint the endpoint that is to be filtered on 
    9999         * @param events the list of events that are filtered chronologically 
     
    102102        private List<Event> chronologicalFilter(Endpoint endpoint, List<Event> events){ 
    103103                ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
    104                  
     104 
    105105                for (Event event : events){ 
    106                         if (event.getEventTime().isAfter(endpoint.getReleaseInformation().getLastReleasedEventTime())){ 
     106                    if (endpoint.getReleaseInformation().hasNotBeenReleased(event)){ 
    107107                                applicableEvents.add(event); 
    108108                        } 
     
    159159                return pushMessage; 
    160160        } 
    161          
    162         /** 
    163          * Gets the latest (chronologically) event by <code>eventTime</code> from the  
    164          * <code>events</code> list parameter. 
    165          *  
    166          * @param events the list of events from which to find the latest 
    167          * @return the <code>DateTime</code> of the latest event 
    168          */ 
    169         private DateTime getLatestEvent(List<Event> events){ 
    170                 DateTime latest = null; 
    171                 for (Event event : events){ 
    172                         if (latest==null) 
    173                                 latest=event.getEventTime(); 
    174                         else{ 
    175                                 if (event.getEventTime().isAfter(latest)){ 
    176                                         latest = event.getEventTime(); 
    177                                 } 
    178                         } 
    179                 } 
    180                 return latest; 
    181         } 
     161 
    182162 
    183163        public void setAttributeFilterEngine(AttrributeFilterEngine attributeFilterEngine) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/ReleaseInformation.java

    r767 r772  
    11package uk.ac.cardiff.raptor.registry; 
    22 
     3import java.util.HashSet; 
     4import java.util.List; 
    35import java.util.Set; 
    46 
    57import org.joda.time.DateTime; 
     8import org.slf4j.Logger; 
     9import org.slf4j.LoggerFactory; 
    610 
    711import uk.ac.cardiff.model.event.Event; 
    812 
    913public class ReleaseInformation { 
    10          
     14 
     15    /** Class logger */ 
     16    private final Logger log = LoggerFactory.getLogger(ReleaseInformation.class); 
     17 
    1118        /** The date and time of the last entry sent to this client */ 
    1219        private DateTime lastReleasedEventTime; 
    13          
     20 
    1421        /** 
    1522         * Stores the set of latest unique entries. That is, those with the latest 
     
    1825        private Set<Event> latestEqualEntries; 
    1926 
     27 
     28 
    2029        /** 
    21          * @param lastPublishedEntryTime the lastPublishedEntryTime to set 
     30         * Default constructor. Instantiate <code>latestEqualEntries</code> 
    2231         */ 
    23         public void setLastReleasedEventTime(DateTime lastReleasedEventTime) { 
    24                 this.lastReleasedEventTime = lastReleasedEventTime; 
     32        public ReleaseInformation(){ 
     33            latestEqualEntries = new HashSet<Event>(); 
    2534        } 
    2635 
    27         /** 
    28          * @return the lastPublishedEntryTime if its not null, otherwise a new datetime set 
    29          * to EPOCH is returned (1970-01-01T00:00) 
    30          */ 
    31         public DateTime getLastReleasedEventTime() { 
    32                 if (lastReleasedEventTime==null) 
    33                         return new DateTime(0); 
    34                 return lastReleasedEventTime; 
    35         } 
     36    /** 
     37     * After a release has been performed, this method is called with the events that 
     38     * were released. The <code>lastReleasedEventTime</code> and <code>latestEqualEntries</code> are then set 
     39     * accordingly. The latest events are selected chronologically by the <code>eventTime</code> field of 
     40     * each <code>releasedEvents</code>. 
     41     * 
     42     * @param latestEvent 
     43     */ 
     44    public void releasePerformed(List<Event> releasedEvents) { 
    3645 
    37         /** 
    38          * @param latestEqualEntries the latestEqualEntries to set 
    39          */ 
    40         public void setLatestEqualEntries(Set<Event> latestEqualEntries) { 
    41                 this.latestEqualEntries = latestEqualEntries; 
    42         } 
     46        for (Event event : releasedEvents){ 
     47                if (lastReleasedEventTime==null) 
     48                    lastReleasedEventTime=event.getEventTime(); 
     49                else{ 
     50                        if (event.getEventTime().isAfter(lastReleasedEventTime)){ 
     51                                lastReleasedEventTime = event.getEventTime(); 
     52                                latestEqualEntries.clear(); 
     53                                latestEqualEntries.add(event); 
     54                        } 
     55                        else if (event.getEventTime().isEqual(lastReleasedEventTime)){ 
     56                            latestEqualEntries.add(event); 
     57                        } 
     58                } 
     59        } 
    4360 
    44         /** 
    45          * @return the latestEqualEntries 
    46          */ 
    47         public Set<Event> getLatestEqualEntries() { 
    48                 return latestEqualEntries; 
    49         } 
     61 
     62    } 
     63 
     64 
     65    /** 
     66     * Returns true if the event is either: 
     67     * 1. Chronologically after the lastReleasedEventTime 
     68     * 2. Is equal to the lastReleasedEventTime but is not in the set <code>latestEqualEntries</code> 
     69     * 
     70     * In effect, the event can be released if it occurred after all other events that have already 
     71     * been released to this endpoint, or occurred at the same time but was not an event that was 
     72     * already sent. 
     73     * 
     74     * @param event the event to check for release 
     75     * @return true if the event has not been released before, false otherwise 
     76     */ 
     77    public boolean hasNotBeenReleased(Event event) { 
     78        if (event.getEventTime().isAfter(getLastReleasedEventTime())) 
     79            return true; 
     80 
     81        else if (event.getEventTime().isEqual(getLastReleasedEventTime())){ 
     82            return !latestEqualEntries.contains(event); 
     83        } 
     84 
     85        return false; 
     86    } 
     87 
     88 
     89    /** 
     90     * @param lastPublishedEntryTime the lastPublishedEntryTime to set 
     91     */ 
     92    public void setLastReleasedEventTime(DateTime lastReleasedEventTime) { 
     93            this.lastReleasedEventTime = lastReleasedEventTime; 
     94    } 
     95 
     96    /** 
     97     * @return the lastPublishedEntryTime if its not null, otherwise a new datetime set 
     98     * to EPOCH is returned (1970-01-01T00:00) 
     99     */ 
     100    public DateTime getLastReleasedEventTime() { 
     101            if (lastReleasedEventTime==null) 
     102                    return new DateTime(0); 
     103            return lastReleasedEventTime; 
     104    } 
     105 
     106    /** 
     107     * @param latestEqualEntries the latestEqualEntries to set 
     108     */ 
     109    public void setLatestEqualEntries(Set<Event> latestEqualEntries) { 
     110            this.latestEqualEntries = latestEqualEntries; 
     111    } 
     112 
     113    /** 
     114     * @return the latestEqualEntries 
     115     */ 
     116    public Set<Event> getLatestEqualEntries() { 
     117            return latestEqualEntries; 
     118    } 
    50119 
    51120} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/impl/EventReleaseClientImpl.java

    r767 r772  
    1818import java.util.List; 
    1919 
     20import org.slf4j.Logger; 
     21import org.slf4j.LoggerFactory; 
     22 
    2023import uk.ac.cardiff.model.ServiceMetadata; 
    2124import uk.ac.cardiff.model.ServiceMetadata; 
     
    3033public class EventReleaseClientImpl implements EventReleaseClient{ 
    3134 
     35        /** Class logger. */ 
     36        private final Logger log = LoggerFactory.getLogger(EventReleaseClientImpl.class); 
     37 
    3238        /** Encapsulation of all endpoints this client can communication with*/ 
    3339        private EndpointRegistry endpointRegistry; 
     
    3642        private EventReleaseEngine eventReleaseEngine; 
    3743 
     44        /** Whether events should be released. Defaults to true. */ 
     45        private boolean enableEventRelease; 
     46 
    3847        public EventReleaseClientImpl(){ 
    3948                eventReleaseEngine = new EventReleaseEngine(); 
     49                enableEventRelease = true; 
    4050        } 
    4151 
     
    4353        @Override 
    4454        public boolean release(List<Event> events, ServiceMetadata serviceMetadata) throws ReleaseFailureException{ 
    45                 boolean success = eventReleaseEngine.release(endpointRegistry, events, serviceMetadata); 
     55                boolean success =false; 
     56                if (enableEventRelease){ 
     57                    log.info("[Event Release Called]"); 
     58                    success = eventReleaseEngine.release(endpointRegistry, events, serviceMetadata); 
     59                    log.info("[--Events released to all listening endpoints {}--]", success); 
     60                } 
     61 
    4662                return success; 
    47  
    4863        } 
    4964 
     
    7489 
    7590 
     91    /** 
     92     * @param enableEventRelease the enableEventRelease to set 
     93     */ 
     94    public void setEnableEventRelease(boolean enableEventRelease) { 
     95        this.enableEventRelease = enableEventRelease; 
     96    } 
     97 
     98 
     99    /** 
     100     * @return the enableEventRelease 
     101     */ 
     102    public boolean isEnableEventRelease() { 
     103        return enableEventRelease; 
     104    } 
     105 
     106 
    76107 
    77108} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r767 r772  
    8787         */ 
    8888        public List query(String query, Object[] parameters); 
    89          
     89 
    9090        /** 
    9191         * 
     
    108108        public Object queryUnique(String query, Object[] parameters); 
    109109 
    110         public void removeEventsBefore(DateTime earliestReleaseTime); 
     110        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries); 
    111111 
    112112 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r736 r772  
    2424import java.util.concurrent.locks.ReentrantLock; 
    2525 
     26import org.joda.time.DateTime; 
    2627import org.slf4j.Logger; 
    2728import org.slf4j.LoggerFactory; 
     
    8283 
    8384    /** 
     85     * @param earliestReleaseTime 
     86     * @return 
     87     */ 
     88    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
     89        List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ?",new Object[]{earliestReleaseTime.toDate()}); 
     90        return query; 
     91    } 
     92 
     93    /** 
    8494     * 
    8595     */ 
     
    125135 
    126136 
    127  
    128  
    129  
    130  
    131137} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/LogFileMemoryEntryHandler.java

    r767 r772  
    7676         * the entries set (which would not allow duplicates) because the set is 
    7777         * cleared when information is sent to the UA. 
    78          *  
     78         * 
    7979         * @return true if this event was added to the entry handler, false otherwise 
    8080         */ 
     
    101101 
    102102        } 
    103          
    104         public void removeEventsBefore(DateTime earliestReleaseTime) { 
     103 
     104        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
     105                        log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)",earliestReleaseTime, 
     106                                latestEqualEntries.size()); 
    105107                        ArrayList<Event> toRemove = new ArrayList<Event>(); 
    106108                        for (Event event : entries){ 
    107109                                if (event.getEventTime().isBefore(earliestReleaseTime)) 
    108110                                                toRemove.add(event); 
     111                                if (event.getEventTime().isEqual(earliestReleaseTime) && latestEqualEntries.contains(event)){ 
     112 
     113                                    toRemove.add(event); 
     114                                } 
    109115                        } 
    110116                        entries.removeAll(toRemove); 
    111                  
     117 
    112118        } 
    113119 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEntryHandler.java

    r767 r772  
    9999                } 
    100100        } 
    101          
    102         public void removeEventsBefore(DateTime earliestReleaseTime) { 
    103                 ArrayList<Event> toRemove = new ArrayList<Event>(); 
    104                 for (Event event : entries){ 
    105                         if (event.getEventTime().isBefore(earliestReleaseTime)) 
    106                                         toRemove.add(event); 
    107                 } 
    108                 entries.removeAll(toRemove); 
    109          
    110 } 
     101 
     102        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
     103            log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)",earliestReleaseTime, 
     104                    latestEqualEntries.size()); 
     105            ArrayList<Event> toRemove = new ArrayList<Event>(); 
     106            for (Event event : entries){ 
     107                    if (event.getEventTime().isBefore(earliestReleaseTime)) 
     108                                    toRemove.add(event); 
     109                    if (event.getEventTime().isEqual(earliestReleaseTime) && latestEqualEntries.contains(event)){ 
     110 
     111                        toRemove.add(event); 
     112                    } 
     113            } 
     114            entries.removeAll(toRemove); 
     115            for (Event left : entries){ 
     116                log.debug("Left {}, earliest {}",left,earliestReleaseTime); 
     117            } 
     118 
     119        } 
     120 
    111121 
    112122        public void setLatestEntryTime(DateTime latestEntryTime) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r767 r772  
    9292                return dataConnection.runQueryUnique(query, null); 
    9393        } 
    94          
     94 
    9595        public List query(String query, Object[] parameters) { 
    9696                log.trace("SQL query to entry handler [{}], with parameters [{}]",query,Arrays.asList(parameters)); 
     
    204204        } 
    205205 
    206         public void removeEventsBefore(DateTime earliestReleaseTime) { 
     206        //TODO Implementation does not work 
     207        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
    207208                dataConnection.runQueryUnique("delete from Event where eventTime <= ?", new Object[]{earliestReleaseTime.toDate()}); 
    208                  
     209 
    209210        } 
    210211 
Note: See TracChangeset for help on using the changeset viewer.