Changeset 775


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

Legend:

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

    r774 r775  
    3131 
    3232/** 
    33  *  
     33 * 
    3434 * Stores information about an endpoint that a client can send events to. Also includes the Push Policy 
    3535 * to determine if events should be sent, an attribute filter policy for determining which attributes 
    3636 * of each event should be sent, and information about previous event releases. 
    37  *  
     37 * 
    3838 * This class could be subclassed if additional functionality is required. 
    39  *  
     39 * 
    4040 * @author philsmart 
    41  *  
     41 * 
    4242 */ 
    4343public class Endpoint { 
    44          
     44 
    4545        /** class logger */ 
    4646        private final Logger log = LoggerFactory.getLogger(Endpoint.class); 
     
    5959        private ReleaseInformation releaseInformation; 
    6060 
    61          
     61 
    6262        /** 
    6363         * Default constructor. Instantiate <code>releaseInformation</code> 
    6464         */ 
    6565        public Endpoint(){ 
    66                 releaseInformation = new ReleaseInformation(serviceEndpoint); 
     66                releaseInformation = new ReleaseInformation(); 
    6767        } 
    68          
    6968 
    70         /**  
     69 
     70        /** 
    7171         * Actions the <code>releasedPerformed</code> on the <code>releaseInformation</code> object. 
    72          *  
     72         * 
    7373         * @param filteredEntries 
    7474         */ 
     
    7676                releaseInformation.releasePerformed(filteredEntries); 
    7777        } 
    78          
     78 
    7979        public void setServiceEndpoint(String serviceEndpoint) { 
    8080                this.serviceEndpoint = serviceEndpoint; 
     81                releaseInformation.setServiceEndpoint(serviceEndpoint); 
    8182        } 
    8283 
     
    107108                return releaseInformation; 
    108109        } 
    109          
     110 
    110111 
    111112        /** 
    112113         * Sets the releaseInformation 
    113          *  
     114         * 
    114115         * @param releaseInformation 
    115116         */ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EndpointRegistry.java

    r774 r775  
    3535        /** List of endpoints for invoking methods on */ 
    3636        private List<Endpoint> endpoints; 
    37          
     37 
    3838        /** Whether release information should be persisted. */ 
    3939        private boolean persistReleaseInformation; 
    40          
     40 
    4141        /** The data connection class to use for persisting 
    4242         * release information 
     
    5757                                } 
    5858                        } 
    59                          
     59 
    6060                } 
    6161                this.endpoints = endpoints; 
     
    6565                return endpoints; 
    6666        } 
    67          
     67 
    6868 
    6969        public void storeReleaseInformationIfEnabled() { 
    7070                if (!isPersistReleaseInformation()) 
    7171                        return; 
    72                          
     72 
    7373                for (Endpoint entry : endpoints){ 
     74                    log.debug("Saving release information for the endpoint [{}], has persistentId {} and {} latestEqualEntrie(s)", 
     75                            new Object[]{entry.getServiceEndpoint(),entry.getReleaseInformation().getPersistantId(), entry.getReleaseInformation().getLatestEqualEntries().size()}); 
    7476                        dataConnection.save(entry.getReleaseInformation()); 
    7577                } 
    76                  
     78 
    7779        } 
    78          
    79          
     80 
     81 
    8082        public ReleaseInformation loadReleaseInformation(Endpoint endpoint){ 
    8183                List releaseInfoResults = dataConnection.runQuery("from ReleaseInformation where serviceEndpoint=?",new Object[]{endpoint.getServiceEndpoint()}); 
    8284                if (releaseInfoResults==null){ 
    83                         log.error("Loading error...no release information found, blank release information used"); 
     85                        log.warn("Loading error...no release information found, blank release information used"); 
    8486                } 
    8587                if (releaseInfoResults.size()>1){ 
     
    8789                } 
    8890                if (releaseInfoResults.size()==1){ 
    89                         return (ReleaseInformation) releaseInfoResults.get(0); 
     91                        ReleaseInformation releaseInformaiton = (ReleaseInformation) releaseInfoResults.get(0); 
     92                        log.info("Loaded ReleaseInformation for {}, with latest event released time of {}, and {} latest equal entrie(s)", 
     93                                new Object[]{releaseInformaiton.getServiceEndpoint(),releaseInformaiton.getLastReleasedEventTime(), 
     94                                releaseInformaiton.getLatestEqualEntries().size()}); 
     95                        return releaseInformaiton; 
    9096                } 
    9197                return null; 
    92                  
     98 
    9399        } 
    94          
     100 
    95101 
    96102        /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/ReleaseInformation.java

    r774 r775  
    1515    /** Class logger */ 
    1616    private final Logger log = LoggerFactory.getLogger(ReleaseInformation.class); 
    17      
     17 
    1818    /** Unique identifier for the persistance layer*/ 
    1919    private long persistantId; 
     
    2727         */ 
    2828        private Set<Event> latestEqualEntries; 
    29          
     29 
    3030        /** 
    3131         * This field is the primary key of this releaseInformation instance 
     
    3939         * Default constructor. Instantiate <code>latestEqualEntries</code> 
    4040         */ 
    41         public ReleaseInformation(String forServiceEndpoint){ 
     41        public ReleaseInformation(){ 
    4242            latestEqualEntries = new HashSet<Event>(); 
    43             this.setServiceEndpoint(forServiceEndpoint); 
     43 
    4444        } 
    4545 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/releaseInformation.hbm.xml

    r774 r775  
    88    <class name="uk.ac.cardiff.raptor.registry.ReleaseInformation" table="release_information" dynamic-update="true" 
    99        dynamic-insert="false"> 
    10          
    11          
     10 
     11 
    1212        <id name="persistantId" column="persistantId" type="long" 
    13             unsaved-value="null"> 
     13            unsaved-value="0"> 
    1414            <generator class="native"> 
    15                 <param name="sequence">hib_entity_seq</param> 
     15                <param name="sequence">hib_release_information_seq</param> 
    1616            </generator> 
    1717        </id> 
    1818 
    1919 
    20         <property name="serviceEndpoint" column="serviceEndpoint" type="string"/> 
     20        <property name="serviceEndpoint" column="serviceEndpoint" type="string" not-null="true"/> 
    2121 
    2222 
    2323        <property name="lastReleasedEventTime" type="org.joda.time.contrib.hibernate.PersistentDateTime" 
    24             update="true" insert="true" column="lastReleasedEventTime" not-null="false" /> 
     24            update="true" insert="true" column="lastReleasedEventTime" /> 
    2525 
    2626 
    27         <set name="latestEqualEntries" inverse="true"> 
     27    <!--  Set is mapped through a collections table --> 
     28        <set name="latestEqualEntries" lazy="false"> 
    2829            <key column="latestEqualEntries_id" /> 
    29             <one-to-many class="uk.ac.cardiff.model.event.Event" /> 
     30              <many-to-many  class="uk.ac.cardiff.model.event.Event"/> 
    3031        </set> 
    3132 
    32     </class> 
     33       </class> 
    3334 
    3435</hibernate-mapping> 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoElapsedTimePushPolicy.java

    r672 r775  
    3131 * <code>pushInterval</code> is only effective if the number of entries does not 
    3232 * suppress the threshold in the given time interval. 
    33  *  
     33 * 
    3434 * @author philsmart 
    35  *  
     35 * 
    3636 */ 
    3737public class EntryNoElapsedTimePushPolicy extends PushPolicy { 
     
    5959        public boolean evaluatePolicy(List<Event> events) { 
    6060                long currentTime = System.currentTimeMillis(); 
    61                 if (pushOnOrAfterNoEntries < events.size()) { 
     61                if (pushOnOrAfterNoEntries <= events.size()) { 
    6262                        lastReleasedTime = currentTime; 
    6363                        return true; 
    64                 } else {                         
     64                } else { 
    6565                        long difference = currentTime - lastReleasedTime; 
    6666                        //log.debug("ElapsedTime difference {}, pushInterval {}", difference, pushInterval); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r772 r775  
    9191         * 
    9292         * @param query 
     93         * @param parameters 
     94         * @return 
     95         */ 
     96        public List query(String query, Object[] parameters, int maxNoResults); 
     97 
     98        /** 
     99         * 
     100         * @param query 
    93101         * @return 
    94102         */ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r772 r775  
    8383 
    8484    /** 
     85     * Returns events on or after the input time <code>earliestReleaseTime</code>. 
     86     * 
    8587     * @param earliestReleaseTime 
    8688     * @return 
     
    8890    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
    8991        List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ?",new Object[]{earliestReleaseTime.toDate()}); 
     92        return query; 
     93    } 
     94 
     95    /** 
     96     * Returns events on or after the input time <code>earliestReleaseTime</code>, but with a maximum of 
     97     * <code>maxNoResults</code> results (in chronological order). 
     98     * 
     99     * @param earliestReleaseTime 
     100     * @param maxNoResults 
     101     * @return 
     102     */ 
     103    public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 
     104        List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ? order by eventTime asc",new Object[]{earliestReleaseTime.toDate()},maxNoResults); 
    90105        return query; 
    91106    } 
     
    135150 
    136151 
     152 
     153 
    137154} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java

    r752 r775  
    5454        } 
    5555 
     56        public List runQuery(String query, Object[] parameters, int maxResultSize) throws DataAccessException { 
     57            hibernateTemplate.setMaxResults(maxResultSize); 
     58            List result =  hibernateTemplate.find(query, parameters); 
     59            hibernateTemplate.setMaxResults(0); 
     60            return result; 
     61        } 
     62 
    5663        public Object runQueryUnique(String query, Object[] parameters) { 
    5764                if (parameters!=null) 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/RaptorDataConnection.java

    r672 r775  
    3737        public void deleteAllEntries(Collection entries) throws DataAccessException; 
    3838        public void saveAll(Collection collection) throws DataAccessException; 
     39        public List runQuery(String query, Object[] parameters, int maxResultSize)throws DataAccessException; 
    3940 
    4041 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/LogFileMemoryEntryHandler.java

    r772 r775  
    201201 
    202202        /** 
    203          * This is a no-op method for the memory entry handler 
     203         * This is a no-op method for all in-memory entry handlers 
    204204         */ 
    205205        public List query(String query) { 
     
    208208 
    209209        /** 
    210          * This is a no-op method for the memory entry handler 
     210         * This is a no-op method for all in-memory entry handlers 
    211211         */ 
    212212        public Object queryUnique(String query) { 
     
    215215 
    216216        /** 
    217          * This is a no-op method for the memory entry handler 
     217         * This is a no-op method for all in-memory entry handlers 
    218218         */ 
    219219        public Object queryUnique(String query, Object[] parameters) { 
     
    227227 
    228228        /** 
    229          * This is a no-op method for the memory entry handler 
     229         * This is a no-op method for all in-memory entry handlers 
    230230         */ 
    231231        public List query(String query, Object[] parameters) { 
     
    233233        } 
    234234 
     235   /** 
     236    * This is a no-op method for all in-memory entry handlers 
     237    */ 
     238    public List query(String query, Object[] parameters, int maxNoResults) { 
     239        return null; 
     240    } 
     241 
    235242 
    236243 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEntryHandler.java

    r772 r775  
    163163 
    164164        /** 
    165          * This is a no-op method for the memory entry handler 
     165         *  This is a no-op method for all in-memory entry handlers 
    166166         */ 
    167167        public void initialise() { 
     
    175175 
    176176    /** 
    177      * This is a no-op method for the memory entry handler 
     177     *  This is a no-op method for all in-memory entry handlers 
    178178     */ 
    179179    public List query(String query) { 
     
    182182 
    183183    /** 
    184      * This is a no-op method for the memory entry handler 
     184     * T This is a no-op method for all in-memory entry handlers 
    185185     */ 
    186186    public Object queryUnique(String query) { 
     
    189189 
    190190    /** 
    191      * This is a no-op method for the memory entry handler 
     191     *  This is a no-op method for all in-memory entry handlers 
    192192     */ 
    193193    public Object queryUnique(String query, Object[] parameters) { 
     
    201201 
    202202    /** 
    203      * This is a no-op method for the memory entry handler 
     203     *  This is a no-op method for all in-memory entry handlers 
    204204     */ 
    205205        public List query(String query, Object[] parameters) { 
     
    207207        } 
    208208 
     209        /** 
     210         *  This is a no-op method for all in-memory entry handlers 
     211         */ 
     212    public List query(String query, Object[] parameters, int maxNoResults) { 
     213        return null; 
     214    } 
     215 
    209216 
    210217 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r774 r775  
    100100        public Object queryUnique(String query, Object[] parameters) { 
    101101                return dataConnection.runQueryUnique(query, parameters); 
     102        } 
     103 
     104 
     105        public List query(String query, Object[] parameters, int maxNoResults) { 
     106              return dataConnection.runQuery(query, parameters, maxNoResults); 
    102107        } 
    103108 
     
    129134                            continue; 
    130135                        } 
    131                         String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and hashCode =?"; 
    132                         Object[] parameters= new Object[]{event.getEventTime().toDate(),hashcode}; 
    133                         int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
     136                        String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = '"+event.getEventTime()+"' and hashCode =?"; 
     137                        Object[] parameters= new Object[]{hashcode}; 
     138                        //int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
     139                        int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
     140                                     + " where eventTime = '" + event.getEventTime() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
    134141 
    135142                        if (numberOfDuplicates == 0){ 
     143                            log.debug("dups [{}], params {} ",numberOfDuplicates, "select count(*) from " + event.getClass().getSimpleName() 
     144                                    + " where eventTime = '" + event.getEventTime() + "' and hashCode ='" + hashcode + "'"); 
    136145                            persist.add(event); 
    137146                        } 
     
    212221 
    213222 
     223 
     224 
    214225} 
Note: See TracChangeset for help on using the changeset viewer.