Changeset 790


Ignore:
Timestamp:
05/12/11 19:06:57 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeFilterException.java

    r783 r790  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeRule.java

    r785 r790  
    3535    private MatchRule denyValueRule; 
    3636 
     37    /** The class type that this attribute rule is defined for*/ 
     38    private Class<?> eventType; 
     39 
    3740    public abstract void filterAttribute(Event event, ServiceMetadata metadata) throws AttributeFilterException; 
     41 
     42 
     43    /** 
     44     * @return true if this attribute rule is enabled, and should be applied to the input class type. 
     45     */ 
     46    public boolean shouldApply(Class<?> eventType) { 
     47        boolean enabled = getDenyValueRule().isEnabled(); 
     48        boolean classEquivelent = (this.eventType==eventType); 
     49        if (enabled && classEquivelent){ 
     50            return true; 
     51        } 
     52        return false; 
     53 
     54    } 
    3855 
    3956    protected void nullAttribute(Event event, String attributeID) { 
     
    6784    } 
    6885 
     86    /** 
     87     * @param eventType the eventType to set 
     88     */ 
     89    public void setEventType(Class<?> eventType) { 
     90        this.eventType = eventType; 
     91    } 
     92 
     93    /** 
     94     * @return the eventType 
     95     */ 
     96    public Class<?> getEventType() { 
     97        return eventType; 
     98    } 
     99 
     100 
    69101 
    70102} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttrributeFilterEngine.java

    r785 r790  
    7070        private void filterAttributes(Event event, AttributeRule attributeRule, ServiceMetadata metadata) { 
    7171            try{ 
    72                 if (attributeRule.getDenyValueRule().isEnabled()) { 
    73                         attributeRule.filterAttribute(event, metadata); 
     72                if (attributeRule.shouldApply(event.getClass())){ 
     73                    attributeRule.filterAttribute(event, metadata); 
    7474                } 
    7575            } 
     
    8181 
    8282        private  List<Event> clone(List<Event> events) { 
    83  
    8483                List<Event> clonedSet = new ArrayList<Event>(); 
    85                  
    86                 log.debug("Events cloned"); 
    87                 for (Event event : events) {                     
    88                         clonedSet.add(event.newInstance()); 
     84                for (Event event : events) { 
     85                        clonedSet.add(event.copy()); 
    8986                } 
     87                log.trace("The event set of {} events has been cloned into the event set of {} events",events.size(),clonedSet.size()); 
    9088                return clonedSet; 
    9189        } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/HashAttributeRule.java

    r785 r790  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
     
    4863                    String hashedValue = number.toString(16); 
    4964                    this.setValueForObject(event, hashedValue, getAttributeId()); 
    50                     log.debug("hash: "+number.toString(16)); 
    5165                } 
    5266                else{ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/NullAttributeRule.java

    r783 r790  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EndpointRegistry.java

    r775 r790  
    9393                                new Object[]{releaseInformaiton.getServiceEndpoint(),releaseInformaiton.getLastReleasedEventTime(), 
    9494                                releaseInformaiton.getLatestEqualEntries().size()}); 
     95                        if (releaseInformaiton.getLatestEqualEntries().size()>0){ 
     96                            log.debug("Latest Equal Entry Is {}",releaseInformaiton.getLatestEqualEntries().iterator().next()); 
     97                        } 
    9598                        return releaseInformaiton; 
    9699                } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EventReleaseEngine.java

    r774 r790  
    7676                                else if (releaseSuccess ==true){ 
    7777                                        releaseCount++; 
    78                                         endpoint.releasePerformed(filteredEntries); 
     78                                        /* Saves the state of the event before modification e.g. <code>applicableEvents</code> 
     79                                         * not <code>applicableEvents</code> */ 
     80                                        endpoint.releasePerformed(applicableEvents); 
    7981                                        log.debug("Endpoint [{}] has been sent events up to and including {}",endpoint.getServiceEndpoint(), 
    8082                                                        endpoint.getReleaseInformation().getLastReleasedEventTime()); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/ReleaseInformation.java

    r775 r790  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.registry; 
    217 
     
    1025 
    1126import uk.ac.cardiff.model.event.Event; 
     27import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    1228 
    1329public class ReleaseInformation { 
     
    2339 
    2440        /** 
    25          * Stores the set of latest unique entries. That is, those with the latest 
     41         * Stores a set of the latest equal entries hashcodes. That is, those with the latest 
    2642         * and same DateTime, but different state (attribute values). 
    2743         */ 
    28         private Set<Event> latestEqualEntries; 
     44        private Set<Integer> latestEqualEntries; 
    2945 
    3046        /** 
     
    4056         */ 
    4157        public ReleaseInformation(){ 
    42             latestEqualEntries = new HashSet<Event>(); 
     58            latestEqualEntries = new HashSet<Integer>(); 
    4359 
    4460        } 
     
    6177                                lastReleasedEventTime = event.getEventTime(); 
    6278                                latestEqualEntries.clear(); 
    63                                 latestEqualEntries.add(event); 
     79                                int hashcode = 0; 
     80                                try { 
     81                                        hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     82                                } catch (Exception e) { 
     83                                    log.error("Could not get hashcode for event {}", event); 
     84                                } 
     85                                latestEqualEntries.add(hashcode); 
    6486                        } 
    6587                        else if (event.getEventTime().isEqual(lastReleasedEventTime)){ 
    66                             latestEqualEntries.add(event); 
     88                            int hashcode = 0; 
     89                            try { 
     90                                    hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     91                            } catch (Exception e) { 
     92                                log.error("Could not get hashcode for event {}", event); 
     93                            } 
     94                            latestEqualEntries.add(hashcode); 
    6795                        } 
    6896                } 
     
    90118 
    91119        else if (event.getEventTime().isEqual(getLastReleasedEventTime())){ 
    92             return !latestEqualEntries.contains(event); 
     120            int hashcode = 0; 
     121            try { 
     122                    hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     123            } catch (Exception e) { 
     124                log.error("Could not get hashcode for event {}, event not stored", event); 
     125            } 
     126            return !latestEqualEntries.contains(hashcode); 
    93127        } 
    94128 
     
    117151     * @param latestEqualEntries the latestEqualEntries to set 
    118152     */ 
    119     public void setLatestEqualEntries(Set<Event> latestEqualEntries) { 
     153    public void setLatestEqualEntries(Set<Integer> latestEqualEntries) { 
    120154            this.latestEqualEntries = latestEqualEntries; 
    121155    } 
     
    124158     * @return the latestEqualEntries 
    125159     */ 
    126     public Set<Event> getLatestEqualEntries() { 
     160    public Set<Integer> getLatestEqualEntries() { 
    127161            return latestEqualEntries; 
    128162    } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/releaseInformation.hbm.xml

    r775 r790  
    11<?xml version="1.0"?> 
     2<!-- 
     3 
     4    Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     5 
     6    Licensed under the Apache License, Version 2.0 (the "License"); 
     7    you may not use this file except in compliance with the License. 
     8    You may obtain a copy of the License at 
     9 
     10            http://www.apache.org/licenses/LICENSE-2.0 
     11 
     12    Unless required by applicable law or agreed to in writing, software 
     13    distributed under the License is distributed on an "AS IS" BASIS, 
     14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     15    See the License for the specific language governing permissions and 
     16    limitations under the License. 
     17 
     18--> 
    219<!DOCTYPE hibernate-mapping PUBLIC 
    320         "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
     
    2643 
    2744    <!--  Set is mapped through a collections table --> 
    28         <set name="latestEqualEntries" lazy="false"> 
     45        <set name="latestEqualEntries" lazy="false" > 
    2946            <key column="latestEqualEntries_id" /> 
    30               <many-to-many  class="uk.ac.cardiff.model.event.Event"/> 
     47              <element column="hashcode" type="integer"/> 
    3148        </set> 
    3249 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java

    r767 r790  
    4343     */ 
    4444        public boolean release(List<Event> events, ServiceMetadata serviceMetadata) throws ReleaseFailureException; 
    45          
     45 
    4646        /** All concrete implementations of the <code>EventReleaseClient</code> must 
    4747         * provide a way of accessing the list of endpoints it is communicating with 
    48          *  
     48         * 
    4949         * @return a list of endpoints 
    5050         */ 
    5151        public List<Endpoint> getEndpoints(); 
    52          
     52 
     53        /** Used to determine if the event release client has been enabled*/ 
     54        public boolean isEnabled(); 
     55 
    5356 
    5457 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/impl/EventReleaseClientImpl.java

    r774 r790  
    9696        } 
    9797 
     98        public boolean isEnabled(){ 
     99            return isEnableEventRelease(); 
     100        } 
     101 
    98102} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java

    r783 r790  
    532532    } 
    533533 
     534    /** 
     535     * @param event 
     536     */ 
     537    public static Integer getHashCodeFromEventOrNull(Event event) { 
     538        try { 
     539                int hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     540                return hashcode; 
     541        } catch (Exception e) { 
     542            return null; 
     543        } 
     544 
     545    } 
     546 
    534547 
    535548} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r775 r790  
    116116        public Object queryUnique(String query, Object[] parameters); 
    117117 
    118         public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries); 
     118        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries); 
    119119 
    120120 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/LogFileMemoryEntryHandler.java

    r775 r790  
    2525 
    2626import java.util.ArrayList; 
     27import java.util.Iterator; 
    2728import java.util.LinkedHashSet; 
    2829import java.util.List; 
     
    3031 
    3132import uk.ac.cardiff.model.event.Event; 
     33import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    3234import uk.ac.cardiff.raptor.store.EntryHandler; 
    3335 
     
    102104        } 
    103105 
    104         public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
     106        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 
    105107                        log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)",earliestReleaseTime, 
    106108                                latestEqualEntries.size()); 
     
    109111                                if (event.getEventTime().isBefore(earliestReleaseTime)) 
    110112                                                toRemove.add(event); 
    111                                 if (event.getEventTime().isEqual(earliestReleaseTime) && latestEqualEntries.contains(event)){ 
    112  
    113                                     toRemove.add(event); 
     113                                if (event.getEventTime().isEqual(earliestReleaseTime)){ 
     114                                    int hashcode = 0; 
     115                                    try { 
     116                                            hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     117                                    } catch (Exception e) { 
     118                                        log.error("Could not get hashcode for event {}", event); 
     119                                    } 
     120                                    if (latestEqualEntries.contains(hashcode)){ 
     121                                        toRemove.add(event); 
     122                                    } 
    114123                                } 
    115124                        } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEntryHandler.java

    r775 r790  
    100100        } 
    101101 
    102         public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
     102        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 
    103103            log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)",earliestReleaseTime, 
    104104                    latestEqualEntries.size()); 
     
    107107                    if (event.getEventTime().isBefore(earliestReleaseTime)) 
    108108                                    toRemove.add(event); 
    109                     if (event.getEventTime().isEqual(earliestReleaseTime) && latestEqualEntries.contains(event)){ 
    110  
    111                         toRemove.add(event); 
     109                    if (event.getEventTime().isEqual(earliestReleaseTime)){ 
     110                        int hashcode = 0; 
     111                        try { 
     112                                hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
     113                        } catch (Exception e) { 
     114                            log.error("Could not get hashcode for event {}, event not stored", event); 
     115                        } 
     116                        if (latestEqualEntries.contains(hashcode)){ 
     117                            toRemove.add(event); 
     118                        } 
    112119                    } 
    113120            } 
    114121            entries.removeAll(toRemove); 
    115             for (Event left : entries){ 
    116                 log.debug("Left {}, earliest {}",left,earliestReleaseTime); 
    117             } 
    118  
    119         } 
     122 
     123} 
    120124 
    121125 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r783 r790  
    2323import java.util.Date; 
    2424import java.util.HashSet; 
     25import java.util.Iterator; 
    2526import java.util.LinkedHashSet; 
    2627import java.util.List; 
     
    3132import java.util.concurrent.FutureTask; 
    3233 
     34import org.jaxen.function.LastFunction; 
    3335import org.joda.time.DateTime; 
    3436import org.joda.time.LocalDateTime; 
     
    129131 
    130132                for (Event event : persistQueue) { 
    131                         int hashcode = 0; 
    132                         try { 
    133                                 hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
    134                         } catch (Exception e) { 
     133                        Integer hashcodeInteger =  ReflectionHelper.getHashCodeFromEventOrNull(event); 
     134                        if (hashcodeInteger==null){ 
    135135                            log.error("Could not get hashcode for event {}, event not stored", event); 
    136136                            continue; 
    137137                        } 
    138                         String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = '"+event.getEventTime()+"' and hashCode =?"; 
    139                         Object[] parameters= new Object[]{hashcode}; 
    140                         //int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
    141                         int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
    142                                      + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
     138                        int hashcode = hashcodeInteger.intValue(); 
     139                        String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and hashCode =?"; 
     140                        Object[] parameters= new Object[]{event.getEventTime().toDate(),hashcode}; 
     141                        int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
     142//                      int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
     143//                                     + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
    143144 
    144145                        if (numberOfDuplicates == 0){ 
    145                             log.debug("dups [{}], params {} ",numberOfDuplicates, "select count(*) from " + event.getClass().getSimpleName() 
    146                                     + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'"); 
    147                             Date local = new Date(event.getEventTime().getMillis()); 
    148                             DateTime newTime = new DateTime(local); 
    149                             log.debug("Before: {} [{}] Local:{} [{}], back {} [{}]",new Object[] 
    150                                     {event.getEventTime(),event.getEventTime().getMillis(), local, local.getTime(), newTime, newTime.getMillis()}); 
     146                            //log.debug("dups [{}], params {} ",numberOfDuplicates, "select count(*) from " + event.getClass().getSimpleName() 
     147                            //        + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'"); 
     148                            //Date local = new Date(event.getEventTime().getMillis()); 
     149                           // DateTime newTime = new DateTime(local); 
     150                           // log.debug("Before: {} [{}] Local:{} [{}], back {} [{}]",new Object[] 
     151                            //        {event.getEventTime(),event.getEventTime().getMillis(), local, local.getTime(), newTime, newTime.getMillis()}); 
    151152                            persist.add(event); 
    152153                        } 
     
    155156                        } 
    156157                } 
    157  
     158                log.debug("After both internal (from the list of events send) and external (from the store) duplicate checking" + 
     159                                "there are {} events left to persit",persist.size()); 
    158160                try{ 
    159161                    dataConnection.saveAll(persist); 
     
    218220        } 
    219221 
    220         //TODO Implementation does not work 
    221         public void removeEventsBefore(DateTime earliestReleaseTime, Set<Event> latestEqualEntries) { 
    222                 dataConnection.runQueryUnique("delete from Event where eventTime <= ?", new Object[]{earliestReleaseTime.toDate()}); 
     222        //TODO Implementation may not work - PLEASE DO USE 
     223        public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 
     224                dataConnection.runQueryUnique("delete from Event where eventTime < ?", new Object[]{earliestReleaseTime.toDate()}); 
     225                for (Iterator<Integer> entries = latestEqualEntries.iterator();entries.hasNext();){ 
     226                    Integer hash = entries.next(); 
     227                    dataConnection.runQueryUnique("delete from Event where hashCode = ?", new Object[]{hash}); 
     228                } 
     229 
    223230 
    224231        } 
  • raptor-client/trunk/src/test/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelperTest.java

    r707 r790  
    3232                        equals(classForField.equals("ShibbolethIdpAuthenticationEvent")); 
    3333 
    34                         classForField = ReflectionHelper.findEntrySubclassForMethod("serviceHost"); 
     34                        classForField = ReflectionHelper.findEntrySubclassForMethod("serviceId"); 
    3535                        System.out.println("Event = "+classForField); 
    3636                        equals(classForField.equals("Event")); 
Note: See TracChangeset for help on using the changeset viewer.