Changeset 767


Ignore:
Timestamp:
05/08/11 23:19:26 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
2 added
8 edited

Legend:

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

    r656 r767  
    2626 
    2727/** 
     28 *  
     29 * Stores information about an endpoint that a client can send events to. Also includes the Push Policy 
     30 * to determine if events should be sent, an attribute filter policy for determining which attributes 
     31 * of each event should be sent, and information about previous event releases. 
     32 *  
     33 * This class could be subclassed if additional functionality is required. 
     34 *  
    2835 * @author philsmart 
    29  * 
     36 *  
    3037 */ 
    3138public class Endpoint { 
    3239 
    33     private String serviceEndpoint; 
    34     private List<PushPolicy> pushPolicies; 
    35     private AttributeFilterPolicy attributeFilterPolicy; 
     40        /** The URL of the service endpoint */ 
     41        private String serviceEndpoint; 
    3642 
    37     public void setServiceEndpoint(String serviceEndpoint) { 
    38         this.serviceEndpoint = serviceEndpoint; 
    39     } 
     43        /** A List of the PushPolicies defined for this endpoint */ 
     44        private List<PushPolicy> pushPolicies; 
    4045 
    41     public String getServiceEndpoint() { 
    42         return serviceEndpoint; 
    43     } 
     46        /** The filter policy defined for this endpoint **/ 
     47        private AttributeFilterPolicy attributeFilterPolicy; 
    4448 
    45     public void setAttributeFilterPolicy(AttributeFilterPolicy attributeFilterPolicy) { 
    46         this.attributeFilterPolicy = attributeFilterPolicy; 
    47     } 
     49        /** Information about what information has been released to this endpoint */ 
     50        private ReleaseInformation releaseInformation; 
     51         
     52        /** 
     53         * Default constructor. Instantiate <code>releaseInformation</code> 
     54         */ 
     55        public Endpoint(){ 
     56                releaseInformation = new ReleaseInformation(); 
     57        } 
    4858 
    49     public AttributeFilterPolicy getAttributeFilterPolicy() { 
    50         return attributeFilterPolicy; 
    51     } 
     59        public void setServiceEndpoint(String serviceEndpoint) { 
     60                this.serviceEndpoint = serviceEndpoint; 
     61        } 
     62 
     63        public String getServiceEndpoint() { 
     64                return serviceEndpoint; 
     65        } 
     66 
     67        public void setAttributeFilterPolicy(AttributeFilterPolicy attributeFilterPolicy) { 
     68                this.attributeFilterPolicy = attributeFilterPolicy; 
     69        } 
     70 
     71        public AttributeFilterPolicy getAttributeFilterPolicy() { 
     72                return attributeFilterPolicy; 
     73        } 
    5274 
    5375        public void setPushPolicies(List<PushPolicy> pushPolicies) { 
     
    5981        } 
    6082 
     83        /** 
     84         * @return the releaseInformation 
     85         */ 
     86        public ReleaseInformation getReleaseInformation() { 
     87                return releaseInformation; 
     88        } 
     89 
    6190} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EndpointRegistry.java

    r736 r767  
    2828public class EndpointRegistry { 
    2929 
    30     /** Class logger. */ 
    31     private final Logger log = LoggerFactory.getLogger(EndpointRegistry.class); 
     30        /** Class logger. */ 
     31        private final Logger log = LoggerFactory.getLogger(EndpointRegistry.class); 
    3232 
     33        /** List of endpoints for invoking methods on */ 
     34        private List<Endpoint> endpoints; 
    3335 
    34     /** List of endpoints for invoking methods on*/ 
    35     private List<Endpoint> endpoints; 
     36        public EndpointRegistry() { 
     37                setEndpoints(new ArrayList<Endpoint>()); 
     38        } 
    3639 
    37     public EndpointRegistry() { 
    38         setEndpoints(new ArrayList<Endpoint>()); 
    39     } 
     40        public void setEndpoints(List<Endpoint> endpoints) { 
     41                for (Endpoint entry : endpoints) 
     42                        log.info("Registering Service Endpoint: {}", entry.getServiceEndpoint()); 
     43                this.endpoints = endpoints; 
     44        } 
    4045 
    41     public void setEndpoints(List<Endpoint> endpoints) { 
    42         for (Endpoint entry : endpoints) 
    43             log.info("Registering Service Endpoint: {}", entry.getServiceEndpoint()); 
    44         this.endpoints = endpoints; 
    45     } 
    46  
    47     public List<Endpoint> getEndpoints() { 
    48         return endpoints; 
    49     } 
     46        public List<Endpoint> getEndpoints() { 
     47                return endpoints; 
     48        } 
    5049} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EventReleaseEngine.java

    r749 r767  
    1919package uk.ac.cardiff.raptor.registry; 
    2020 
     21import java.util.ArrayList; 
    2122import java.util.Date; 
    2223import java.util.List; 
     
    2627import uk.ac.cardiff.raptor.remoting.policy.PushPolicy; 
    2728 
     29import org.joda.time.DateTime; 
    2830import org.slf4j.Logger; 
    2931import org.slf4j.LoggerFactory; 
     
    6163                int releaseCount = 0; 
    6264                for (Endpoint endpoint : endpointRegistry.getEndpoints()) { 
    63                         boolean shouldRelease = shouldRelease(endpoint,events);//(endpoint.getPushPolicy().getPushOnOrAfterNoEntries() <= events.size()); 
     65                        List<Event> applicableEvents = chronologicalFilter(endpoint, events); 
     66                        boolean shouldRelease = shouldRelease(endpoint,applicableEvents); 
    6467                        log.debug("Endpoint {}, should release {}", endpoint.getServiceEndpoint(), shouldRelease); 
    65                         List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, events); 
     68                        List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
    6669                        EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
    67                         if (shouldRelease) { 
     70                        if (shouldRelease) {                             
    6871                                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
    6972                                boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage,endpoint); 
     
    7174                                if (releaseSuccess == false) 
    7275                                        releasedtoAll = false; 
    73                                 else 
     76                                else if (releaseSuccess ==true){ 
    7477                                        releaseCount++; 
     78                                        endpoint.getReleaseInformation().setLastReleasedEventTime(getLatestEvent(events)); 
     79                                        log.debug("Endpoint [{}] has been sent events up to and including {}",endpoint.getServiceEndpoint(), 
     80                                                        endpoint.getReleaseInformation().getLastReleasedEventTime()); 
     81                                } 
    7582                        } else { 
    7683                                releasedtoAll = false; 
     
    8390                return releasedtoAll; 
    8491 
     92        } 
     93         
     94        /** 
     95         * Filters the input list of events (<code>events</code>) such that only those that are after (chronological) 
     96         * the <code>latestPublishedEventTime</code> of the input <code>Endpoint</code> remain 
     97         *  
     98         * @param endpoint the endpoint that is to be filtered on 
     99         * @param events the list of events that are filtered chronologically 
     100         * @return the list of filtered events 
     101         */ 
     102        private List<Event> chronologicalFilter(Endpoint endpoint, List<Event> events){ 
     103                ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
     104                 
     105                for (Event event : events){ 
     106                        if (event.getEventTime().isAfter(endpoint.getReleaseInformation().getLastReleasedEventTime())){ 
     107                                applicableEvents.add(event); 
     108                        } 
     109                } 
     110                log.info("There are {} events to send to the endpoint [{}] after {}",new Object[]{applicableEvents.size(),endpoint.getServiceEndpoint(),endpoint.getReleaseInformation().getLastReleasedEventTime()}); 
     111                return applicableEvents; 
    85112        } 
    86113 
     
    118145 
    119146        /** 
    120          * Constructs an event push message, which encapsulates the events to send 
     147         * Constructs an event push message, which encapsulates the events to send and some 
     148         * metadata about the list of events. 
    121149         * 
    122150         * @param clientMetadata 
     
    131159                return pushMessage; 
    132160        } 
     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        } 
    133182 
    134183        public void setAttributeFilterEngine(AttrributeFilterEngine attributeFilterEngine) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java

    r749 r767  
    2323import uk.ac.cardiff.model.ServiceMetadata; 
    2424import uk.ac.cardiff.model.event.Event; 
     25import uk.ac.cardiff.raptor.registry.Endpoint; 
     26import uk.ac.cardiff.raptor.registry.EndpointRegistry; 
     27import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 
    2528 
    2629/** 
     
    4043     */ 
    4144        public boolean release(List<Event> events, ServiceMetadata serviceMetadata) throws ReleaseFailureException; 
     45         
     46        /** All concrete implementations of the <code>EventReleaseClient</code> must 
     47         * provide a way of accessing the list of endpoints it is communicating with 
     48         *  
     49         * @return a list of endpoints 
     50         */ 
     51        public List<Endpoint> getEndpoints(); 
     52         
     53 
    4254 
    4355} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/impl/EventReleaseClientImpl.java

    r749 r767  
    2121import uk.ac.cardiff.model.ServiceMetadata; 
    2222import uk.ac.cardiff.model.event.Event; 
     23import uk.ac.cardiff.raptor.registry.Endpoint; 
    2324import uk.ac.cardiff.raptor.registry.EndpointRegistry; 
    2425import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 
     
    4849 
    4950 
     51        public List<Endpoint> getEndpoints() { 
     52                return endpointRegistry.getEndpoints(); 
     53        } 
     54 
     55 
    5056        public void setEndpointRegistry(EndpointRegistry endpointRegistry) { 
    5157                this.endpointRegistry = endpointRegistry; 
     
    6874 
    6975 
     76 
    7077} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r752 r767  
    108108        public Object queryUnique(String query, Object[] parameters); 
    109109 
     110        public void removeEventsBefore(DateTime earliestReleaseTime); 
     111 
    110112 
    111113} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEntryHandler.java

    r752 r767  
    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} 
    101111 
    102112        public void setLatestEntryTime(DateTime latestEntryTime) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r752 r767  
    204204        } 
    205205 
     206        public void removeEventsBefore(DateTime earliestReleaseTime) { 
     207                dataConnection.runQueryUnique("delete from Event where eventTime <= ?", new Object[]{earliestReleaseTime.toDate()}); 
     208                 
     209        } 
     210 
    206211 
    207212 
Note: See TracChangeset for help on using the changeset viewer.