Changeset 1024 for raptor-client


Ignore:
Timestamp:
06/22/11 22:33:04 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
1 deleted
5 edited
1 copied

Legend:

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

    r595 r1024  
    2121/** 
    2222 * @author philsmart 
    23  * 
     23 *  
    2424 */ 
    2525public class AttributeFilterPolicy { 
     
    3030 
    3131    public void setAttributeRules(List<AttributeRule> attributeRules) { 
    32         this.attributeRules = attributeRules; 
     32        this.attributeRules = attributeRules; 
    3333    } 
    3434 
    3535    public List<AttributeRule> getAttributeRules() { 
    36         return attributeRules; 
     36        return attributeRules; 
    3737    } 
    3838 
    3939    public void setPolicyName(String policyName) { 
    40         this.policyName = policyName; 
     40        this.policyName = policyName; 
    4141    } 
    4242 
    4343    public String getPolicyName() { 
    44         return policyName; 
     44        return policyName; 
    4545    } 
    4646 
    47  
    48  
    4947} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeRule.java

    r790 r1024  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptor.attribute.filtering; 
    2021 
     
    2627/** 
    2728 * This is a poor implementation of an attributeRule. 
    28  * 
     29 *  
    2930 * @author philsmart 
    30  * 
     31 *  
    3132 */ 
    3233public abstract class AttributeRule { 
    3334 
    3435    private MatchRule permitValueRule; 
     36 
    3537    private MatchRule denyValueRule; 
    3638 
    37     /** The class type that this attribute rule is defined for*/ 
     39    /** The class type that this attribute rule is defined for */ 
    3840    private Class<?> eventType; 
    3941 
    4042    public abstract void filterAttribute(Event event, ServiceMetadata metadata) throws AttributeFilterException; 
    41  
    4243 
    4344    /** 
     
    4647    public boolean shouldApply(Class<?> eventType) { 
    4748        boolean enabled = getDenyValueRule().isEnabled(); 
    48         boolean classEquivelent = (this.eventType==eventType); 
    49         if (enabled && classEquivelent){ 
     49        boolean classEquivelent = (this.eventType == eventType); 
     50        if (enabled && classEquivelent) { 
    5051            return true; 
    5152        } 
     
    6869 
    6970    protected void setValueForObject(Event event, String value, String attributeID) { 
    70          ReflectionHelper.setValueOnObject(attributeID, value, event); 
     71        ReflectionHelper.setValueOnObject(attributeID, value, event); 
    7172    } 
    7273 
     
    7475        this.permitValueRule = permitValueRule; 
    7576    } 
     77 
    7678    public MatchRule getPermitValueRule() { 
    7779        return permitValueRule; 
    7880    } 
     81 
    7982    public void setDenyValueRule(MatchRule denyValueRule) { 
    8083        this.denyValueRule = denyValueRule; 
    8184    } 
     85 
    8286    public MatchRule getDenyValueRule() { 
    8387        return denyValueRule; 
     
    98102    } 
    99103 
    100  
    101  
    102104} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/DefaultEventReleaseClient.java

    r1014 r1024  
    1414 * limitations under the License. 
    1515 */ 
    16 package uk.ac.cardiff.raptor.remoting.client.impl; 
     16package uk.ac.cardiff.raptor.remoting.client; 
    1717 
    1818import java.util.List; 
     
    2525import uk.ac.cardiff.raptor.registry.Endpoint; 
    2626import uk.ac.cardiff.raptor.registry.EndpointRegistry; 
    27 import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 
    28 import uk.ac.cardiff.raptor.remoting.client.EventReleaseEngine; 
    29 import uk.ac.cardiff.raptor.remoting.client.ReleaseFailureException; 
    3027 
    31 public class EventReleaseClientImpl implements EventReleaseClient { 
     28public class DefaultEventReleaseClient implements EventReleaseClient { 
    3229 
    3330        /** Class logger. */ 
    34         private final Logger log = LoggerFactory.getLogger(EventReleaseClientImpl.class); 
     31        private final Logger log = LoggerFactory.getLogger(DefaultEventReleaseClient.class); 
    3532 
    36         /** Encapsulation of all endpoints this client can communication with */ 
     33        /** Encapsulation of all endpoints this client can communication with. */ 
    3734        private EndpointRegistry endpointRegistry; 
    3835 
    39         /** The engine that performs event release to a client endpoint */ 
     36        /** The engine that performs event release to a client endpoint. */ 
    4037        private EventReleaseEngine eventReleaseEngine; 
    4138 
     
    4340        private boolean enableEventRelease; 
    4441 
    45         public EventReleaseClientImpl() { 
     42        public DefaultEventReleaseClient() { 
    4643                eventReleaseEngine = new EventReleaseEngine(); 
    4744                enableEventRelease = true; 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r1014 r1024  
    3939/** 
    4040 * @author philsmart 
    41  * 
     41 *  
    4242 */ 
    43 public class StorageEngine  implements StoreEntriesTaskCallbackInterface{ 
    44  
    45     /** Class logger*/ 
    46     private final Logger log = LoggerFactory.getLogger(StorageEngine.class); 
    47  
    48     /** Responsible for storing all entries (e.g. events) */ 
    49     private EntryHandler entryHandler; 
    50  
    51  
    52     /** Engine used to associate attributes to existing events in the MUA */ 
    53     private AttributeAssociationEngine attributeAssociationEngine; 
    54  
    55     /** The ID of the currently executing transaction */ 
    56     private int currentTransactionId; 
    57  
    58  
    59     /** Whether a transaction is currently in progress*/ 
    60     private boolean transactionInProgress; 
    61  
    62  
    63     /** Default Constructor*/ 
    64     public StorageEngine(){ 
    65  
    66     } 
    67  
    68     public void storageResultCallback(Object result) { 
    69         log.debug("Storage task completed {}, for transaction id [{}]",result, currentTransactionId); 
    70         transactionInProgress=false; 
    71  
    72     } 
    73  
    74     /** 
    75      * @param events 
    76      */ 
    77     public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException{ 
    78         if (transactionInProgress){ 
    79             throw new TransactionInProgressException("Transaction "+currentTransactionId+" currently in processing"); 
    80         } 
    81         log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(),transactionId); 
    82         this.currentTransactionId = transactionId; 
    83         transactionInProgress=true; 
    84         AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, entryHandler,attributeAssociationEngine); 
    85         asyncEntryStorage.execute(events,this); 
    86  
    87  
    88     } 
    89      
    90     public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException{ 
    91         if (transactionInProgress){ 
    92             throw new TransactionInProgressException("Transaction "+currentTransactionId+" currently in processing"); 
    93         } 
    94         log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(),transactionId); 
    95         this.currentTransactionId = transactionId; 
    96         transactionInProgress=true; 
    97         try { 
    98                 attributeAssociationEngine.associateAttributes(events); 
    99             entryHandler.addEntries(events); 
    100             log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 
    101         } catch (StorageException e) { 
    102            log.error("Could not store events for transaction id [{}], {}",transactionId); 
    103         } catch (AttributeAssociationException e) { 
    104                  log.error("Could not store events for transaction id [{}], {}",transactionId); 
    105                 } 
    106         transactionInProgress=false; 
    107     } 
    108  
    109     /** 
    110      * Returns events on or after the input time <code>earliestReleaseTime</code>. 
    111      * 
    112      * @param earliestReleaseTime 
    113      * @return 
    114      */ 
    115     public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
    116         List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ?",new Object[]{earliestReleaseTime}); 
    117         return query; 
    118     } 
    119  
    120     /** 
    121      * Returns events on or after the input time <code>earliestReleaseTime</code>, but with a maximum of 
    122      * <code>maxNoResults</code> results (in chronological order). 
    123      * 
    124      * @param earliestReleaseTime 
    125      * @param maxNoResults 
    126      * @return 
    127      */ 
    128     public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 
    129         List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ? order by eventTime asc",new Object[]{earliestReleaseTime},maxNoResults); 
    130         return query; 
    131     } 
    132  
    133  
    134     /** 
     43public class StorageEngine implements StoreEntriesTaskCallbackInterface { 
     44 
     45        /** Class logger */ 
     46        private final Logger log = LoggerFactory.getLogger(StorageEngine.class); 
     47 
     48        /** Responsible for storing all entries (e.g. events) */ 
     49        private EntryHandler entryHandler; 
     50 
     51        /** Engine used to associate attributes to existing events in the MUA */ 
     52        private AttributeAssociationEngine attributeAssociationEngine; 
     53 
     54        /** The ID of the currently executing transaction */ 
     55        private int currentTransactionId; 
     56 
     57        /** Whether a transaction is currently in progress */ 
     58        private boolean transactionInProgress; 
     59 
     60        /** Default Constructor */ 
     61        public StorageEngine() { 
     62 
     63        } 
     64 
     65        public void storageResultCallback(Object result) { 
     66                log.debug("Storage task completed {}, for transaction id [{}]", result, currentTransactionId); 
     67                transactionInProgress = false; 
     68 
     69        } 
     70 
     71        /** 
     72         * @param events 
     73         */ 
     74        public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException { 
     75                if (transactionInProgress) { 
     76                        throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 
     77                } 
     78                log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 
     79                this.currentTransactionId = transactionId; 
     80                transactionInProgress = true; 
     81                AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, entryHandler, attributeAssociationEngine); 
     82                asyncEntryStorage.execute(events, this); 
     83 
     84        } 
     85 
     86        public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException { 
     87                if (transactionInProgress) { 
     88                        throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 
     89                } 
     90                log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 
     91                this.currentTransactionId = transactionId; 
     92                transactionInProgress = true; 
     93                try { 
     94                        attributeAssociationEngine.associateAttributes(events); 
     95                        entryHandler.addEntries(events); 
     96                        log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 
     97                } catch (StorageException e) { 
     98                        log.error("Could not store events for transaction id [{}], {}", transactionId); 
     99                } catch (AttributeAssociationException e) { 
     100                        log.error("Could not store events for transaction id [{}], {}", transactionId); 
     101                } 
     102                transactionInProgress = false; 
     103        } 
     104 
     105        /** 
     106         * Returns events on or after the input time 
     107         * <code>earliestReleaseTime</code>. 
     108         *  
     109         * @param earliestReleaseTime 
     110         * @return 
     111         */ 
     112        public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 
     113                List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ?", new Object[] { earliestReleaseTime }); 
     114                return query; 
     115        } 
     116 
     117        /** 
     118         * Returns events on or after the input time 
     119         * <code>earliestReleaseTime</code>, but with a maximum of 
     120         * <code>maxNoResults</code> results (in chronological order). 
     121         *  
     122         * @param earliestReleaseTime 
     123         * @param maxNoResults 
     124         * @return 
     125         */ 
     126        public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 
     127                List<Event> query = (List<Event>) entryHandler.query("from Event where eventTime >= ? order by eventTime asc", new Object[] { earliestReleaseTime }, 
     128                                maxNoResults); 
     129                return query; 
     130        } 
     131 
     132        /** 
    135133     * 
    136134     */ 
    137     public void removeAllEntries() { 
    138         entryHandler.removeAllEntries(); 
    139     } 
    140  
    141  
    142  
    143     /** 
    144      * Sets the configured entry handler. Must also then initialise that entry 
    145      * handler 
    146      * 
    147      * @param entryHandler the entryHandler to set 
    148      */ 
    149     public void setEntryHandler(EntryHandler entryHandler) { 
    150         this.entryHandler = entryHandler; 
    151         entryHandler.initialise(); 
    152     } 
    153  
    154  
    155     /** 
    156      * @return the entryHandler 
    157      */ 
    158     public EntryHandler getEntryHandler() { 
    159         return entryHandler; 
    160     } 
    161  
    162     /** 
    163      * @param attributeAssociationEngine the attributeAssociationEngine to set 
    164      */ 
    165     public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 
    166         this.attributeAssociationEngine = attributeAssociationEngine; 
    167     } 
    168  
    169     /** 
    170      * @return the attributeAssociationEngine 
    171      */ 
    172     public AttributeAssociationEngine getAttributeAssociationEngine() { 
    173         return attributeAssociationEngine; 
    174     } 
    175          
    176     /** 
    177      * Returns the possible values that each of the input field names can take 
    178      *  
    179      * @param possibleFieldNameValuesList 
    180      * @return 
    181      */ 
    182     public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 
    183         ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 
    184          
    185         for (String fieldName : possibleFieldNameValuesList){ 
    186             try{ 
    187             List results = entryHandler.query("select "+fieldName+" from Event group by ("+fieldName+")"); 
    188             for (Object result : results){ 
    189                 if (result instanceof String){ 
    190                         Suggestion suggestion = new Suggestion(); 
    191                         suggestion.setBase(fieldName); 
    192                         suggestion.setValue((String)result); 
    193                         suggestions.add(suggestion); 
    194                 } 
    195             } 
    196             } 
    197             catch(RuntimeException e){ 
    198                 log.warn("Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about",fieldName); 
    199             } 
    200  
    201         } 
    202          
    203          
    204         return suggestions; 
    205     } 
    206  
    207  
    208  
    209  
    210  
    211  
    212  
    213  
     135        public void removeAllEntries() { 
     136                entryHandler.removeAllEntries(); 
     137        } 
     138 
     139        /** 
     140         * Sets the configured entry handler. Must also then initialise that entry 
     141         * handler 
     142         *  
     143         * @param entryHandler 
     144         *            the entryHandler to set 
     145         */ 
     146        public void setEntryHandler(EntryHandler entryHandler) { 
     147                this.entryHandler = entryHandler; 
     148                entryHandler.initialise(); 
     149        } 
     150 
     151        /** 
     152         * @return the entryHandler 
     153         */ 
     154        public EntryHandler getEntryHandler() { 
     155                return entryHandler; 
     156        } 
     157 
     158        /** 
     159         * @param attributeAssociationEngine 
     160         *            the attributeAssociationEngine to set 
     161         */ 
     162        public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 
     163                this.attributeAssociationEngine = attributeAssociationEngine; 
     164        } 
     165 
     166        /** 
     167         * @return the attributeAssociationEngine 
     168         */ 
     169        public AttributeAssociationEngine getAttributeAssociationEngine() { 
     170                return attributeAssociationEngine; 
     171        } 
     172 
     173        /** 
     174         * Returns the possible values that each of the input field names can take 
     175         *  
     176         * @param possibleFieldNameValuesList 
     177         * @return 
     178         */ 
     179        public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 
     180                ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 
     181 
     182                for (String fieldName : possibleFieldNameValuesList) { 
     183                        try { 
     184                                String query = "select " + fieldName + " from Event group by (" + fieldName + ")"; 
     185                                List results = entryHandler.query(query); 
     186                                log.trace("Looking for possible values for field {} using query [{}]",fieldName, query); 
     187                                int noResults=0; 
     188                                for (Object result : results) { 
     189                                        if (result instanceof String) { 
     190                                                Suggestion suggestion = new Suggestion(); 
     191                                                suggestion.setBase(fieldName); 
     192                                                suggestion.setValue((String) result); 
     193                                                suggestions.add(suggestion); 
     194                                                noResults++; 
     195                                        } 
     196                                } 
     197                                log.debug("Field {} has {} suggestion values",fieldName,noResults); 
     198                        } catch (RuntimeException e) { 
     199                                log.warn("Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about", fieldName); 
     200                        } 
     201 
     202                } 
     203 
     204                return suggestions; 
     205        } 
    214206 
    215207} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java

    r808 r1024  
    1616package uk.ac.cardiff.raptor.store.dao; 
    1717 
     18import java.sql.SQLException; 
    1819import java.util.Arrays; 
    1920import java.util.Collection; 
    2021import java.util.List; 
    2122 
    22  
     23import org.hibernate.HibernateException; 
     24import org.hibernate.Query; 
     25import org.hibernate.Session; 
    2326import org.hibernate.SessionFactory; 
    2427import org.slf4j.Logger; 
     
    2629import org.springframework.dao.DataAccessException; 
    2730import org.springframework.dao.support.DataAccessUtils; 
     31import org.springframework.orm.hibernate3.HibernateCallback; 
    2832import org.springframework.orm.hibernate3.HibernateTemplate; 
    2933 
    3034/** 
    3135 * @author philsmart 
    32  * 
     36 *  
    3337 */ 
    3438public class DefaultDataConnection implements RaptorDataConnection { 
    3539 
    36         /* hibernate template to persist classes */ 
     40        /** hibernate template to persist classes */ 
    3741        private HibernateTemplate hibernateTemplate; 
    3842 
     
    4246        private static Logger log = LoggerFactory.getLogger(DefaultDataConnection.class); 
    4347 
    44         public void save(Object object) throws DataAccessException{ 
     48        public void save(Object object) throws DataAccessException { 
    4549                hibernateTemplate.saveOrUpdate(object); 
    4650        } 
    4751 
    48         public void saveAll(Collection collection) throws DataAccessException{ 
     52        public void saveAll(Collection collection) throws DataAccessException { 
    4953                hibernateTemplate.saveOrUpdateAll(collection); 
    5054        } 
    5155 
    52         public List runQuery(String query, Object[] parameters)  throws DataAccessException{ 
     56        public List runQuery(String query, Object[] parameters) throws DataAccessException { 
    5357                return hibernateTemplate.find(query, parameters); 
    5458        } 
    55          
    56         public void runUpdate(String query, Object[] parameters) throws DataAccessException{ 
    57                 hibernateTemplate.bulkUpdate(query,parameters); 
     59 
     60        public void runUpdate(String query, Object[] parameters) throws DataAccessException { 
     61                hibernateTemplate.bulkUpdate(query, parameters); 
    5862        } 
    5963 
    6064        public List runQuery(String query, Object[] parameters, int maxResultSize) throws DataAccessException { 
    61             hibernateTemplate.setMaxResults(maxResultSize); 
    62             List result =  hibernateTemplate.find(query, parameters); 
    63             hibernateTemplate.setMaxResults(0); 
    64             return result; 
    65         } 
     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(); 
     82        return template.executeFind(new HibernateCallback() { 
     83            public Object doInHibernate(Session session) throws HibernateException, SQLException { 
     84                Query queryToRun = session.createQuery(query); 
     85                queryToRun.setMaxResults(pageSize); 
     86                queryToRun.setFirstResult(pageSize * pageNumber); 
     87                return queryToRun.list(); 
     88            } 
     89        }); 
     90        } 
    6691 
    67         public Object runQueryUnique(String query, Object[] parameters)  throws DataAccessException{ 
    68                 if (parameters!=null) 
    69                         log.trace("Query to db, {}, with params [{}]",query,Arrays.asList(parameters)); 
     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)); 
    7095                Object object = DataAccessUtils.uniqueResult(getHibernateTemplate().find(query, parameters)); 
    7196                return object; 
     
    86111 
    87112        /** 
    88          * <p> import, here we load all entries to bind them in hibernate then we 
    89          * delete them. Not sure if all these entries are loaded then delete if lazy 
    90          * loading is false.</p> (non-Javadoc) 
    91          * 
     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         *  
    92120         * @see main.uk.ac.cf.dao.internal.ICADataConnection#deleteAllEntries() 
    93121         */ 
    94122        @Override 
    95         public void deleteAllEntries(Collection entries) throws DataAccessException{ 
     123        public void deleteAllEntries(Collection entries) throws DataAccessException { 
    96124                hibernateTemplate.deleteAll(entries); 
    97125 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r841 r1024  
    4545        // method of the engine class 
    4646 
    47         /** class logger */ 
     47        /** class logger. */ 
    4848        private final Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 
    4949 
    50         /** data connection used to persist entries */ 
     50        /** data connection used to persist entries. */ 
    5151        private RaptorDataConnection dataConnection; 
    5252 
     
    217217                    Integer hash = entries.next(); 
    218218                    dataConnection.runQueryUnique("delete from Event where hashCode = ?", new Object[]{hash}); 
    219                 } 
    220  
    221  
    222         } 
     219        } 
     220 
     221    } 
    223222 
    224223} 
Note: See TracChangeset for help on using the changeset viewer.