Changeset 713


Ignore:
Timestamp:
04/28/11 18:53:39 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationDefinition.java

    r707 r713  
    55 
    66import java.util.List; 
    7  
     7import java.util.Map; 
     8 
     9import org.slf4j.Logger; 
     10import org.slf4j.LoggerFactory; 
     11 
     12import uk.ac.cardiff.model.event.Event; 
    813import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 
     14import uk.ac.cardiff.raptor.event.expansion.connector.DataConnector; 
     15import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    916 
    1017/** 
     
    1421public class AttributeAssociationDefinition { 
    1522 
     23    /** Class logger. */ 
     24    private final Logger log = LoggerFactory.getLogger(AttributeAssociationDefinition.class); 
     25 
     26    /** Human readable name for this definition*/ 
     27    private String definiationName; 
     28 
    1629    /** The name of the field the subject's principal should be extracted from*/ 
    1730    private String subjectPrincipalField; 
     
    1932    private List<AttributeLookup> lookupAttributes; 
    2033 
     34    /** Whether to apply the attribute association*/ 
     35    private boolean enabled; 
     36 
    2137    /** The class type that these attribute definitions are attached to*/ 
    22     private Class internalModelClass; 
    23  
     38    private Class<?> classToAdd; 
     39 
     40    /** The class type that this attribute association is applicable for */ 
     41    private String associateWithClass; 
     42 
     43    /** The data connector used to acquire the attributes*/ 
     44    private DataConnector dataConnector; 
     45 
     46    /** The ldap search filter template*/ 
     47    private String searchFilterTemplate; 
    2448 
    2549    /** 
     
    3559    } 
    3660 
     61    public void initialise(){ 
     62        dataConnector.initialise(); 
     63 
     64    } 
    3765 
    3866 
     
    5078 
    5179 
     80    private void populate(Map<String,String> attributes, Event event) throws InstantiationException, IllegalAccessException{ 
     81 
     82        Object classToPopulate = getClassToAdd().newInstance(); 
     83 
     84        for (Map.Entry<String,String> entry : attributes.entrySet()){ 
     85            String attributeSourceName = entry.getKey(); 
     86            String attributeValue = entry.getValue(); 
     87            log.trace("source [{}], value [{}]",attributeSourceName,attributeValue); 
     88            try{ 
     89                String internalFieldName = getInternalAttributeName(attributeSourceName); 
     90                ReflectionHelper.setValueOnObject(internalFieldName, attributeValue, classToPopulate); 
     91            } 
     92            catch(AttributeAssociationException e){ 
     93                log.warn("Error trying to populate internal model. {}",e.getMessage()); 
     94            } 
     95        } 
     96 
     97        //now attach the object where appropriate on the current <code>Event</code> object 
     98        ReflectionHelper.attachObjectTo(classToPopulate,event); 
     99 
     100       // log.debug("{}",event); 
     101    } 
     102 
     103    /** 
     104     * @param event 
     105     */ 
     106    public boolean associate(Event event) { 
     107       // log.debug("{},v {}",event.getClass().getCanonicalName(),associateWithClass.getClass().getCanonicalName()); 
     108        if (!event.getClass().getCanonicalName().equals(associateWithClass)){ 
     109            return false; 
     110        } 
     111 
     112        Object principalObject = ReflectionHelper.getValueFromObject(getSubjectPrincipalField(), event); 
     113        String principal = null; 
     114        if (principalObject instanceof String){ 
     115            principal = (String)principalObject; 
     116        } 
     117        if (principal!=null){ 
     118            try { 
     119                 dataConnector.setReturnAttributes(getSourceAttributesAsArray()); 
     120                 dataConnector.setSearchFilterTemplate(searchFilterTemplate); 
     121                 Map<String, String> attributes = dataConnector.lookup(principal); 
     122                 populate(attributes,event); 
     123 
     124                 return true; 
     125            } catch (AttributeAssociationException e) { 
     126                log.error("Association error for principal [{}]",principal,e); 
     127            } catch (InstantiationException e) { 
     128                log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
     129            } catch (IllegalAccessException e) { 
     130                log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
     131            } 
     132        } 
     133        return false; 
     134 
     135    } 
     136 
     137 
     138 
    52139    /** 
    53140     * @param subjectPrincipalField the subjectPrincipalField to set 
     
    78165    } 
    79166 
    80  
    81  
    82     /** 
    83      * @param internalModelClass the internalModelClass to set 
    84      */ 
    85     public void setInternalModelClass(Class internalModelClass) { 
    86         this.internalModelClass = internalModelClass; 
    87     } 
    88  
    89  
    90  
    91     /** 
    92      * @return the internalModelClass 
    93      */ 
    94     public Class getInternalModelClass() { 
    95         return internalModelClass; 
    96     } 
    97  
    98  
     167    /** 
     168     * @param enabled the enabled to set 
     169     */ 
     170    public void setEnabled(boolean enabled) { 
     171        this.enabled = enabled; 
     172    } 
     173 
     174 
     175 
     176    /** 
     177     * @return the enabled 
     178     */ 
     179    public boolean isEnabled() { 
     180        return enabled; 
     181    } 
     182 
     183 
     184 
     185    /** 
     186     * @param dataConnector the dataConnector to set 
     187     */ 
     188    public void setDataConnector(DataConnector dataConnector) { 
     189        this.dataConnector = dataConnector; 
     190    } 
     191 
     192 
     193 
     194    /** 
     195     * @return the dataConnector 
     196     */ 
     197    public DataConnector getDataConnector() { 
     198        return dataConnector; 
     199    } 
     200 
     201 
     202 
     203    /** 
     204     * @param searchFilterTemplate the searchFilterTemplate to set 
     205     */ 
     206    public void setSearchFilterTemplate(String searchFilterTemplate) { 
     207        this.searchFilterTemplate = searchFilterTemplate; 
     208    } 
     209 
     210 
     211 
     212    /** 
     213     * @return the searchFilterTemplate 
     214     */ 
     215    public String getSearchFilterTemplate() { 
     216        return searchFilterTemplate; 
     217    } 
     218 
     219 
     220 
     221    /** 
     222     * @param definiationName the definiationName to set 
     223     */ 
     224    public void setDefiniationName(String definiationName) { 
     225        this.definiationName = definiationName; 
     226    } 
     227 
     228 
     229 
     230    /** 
     231     * @return the definiationName 
     232     */ 
     233    public String getDefiniationName() { 
     234        return definiationName; 
     235    } 
     236 
     237    /** 
     238     * @param classToAdd the classToAdd to set 
     239     */ 
     240    public void setClassToAdd(Class<?> classToAdd) { 
     241        this.classToAdd = classToAdd; 
     242    } 
     243 
     244    /** 
     245     * @return the classToAdd 
     246     */ 
     247    public Class<?> getClassToAdd() { 
     248        return classToAdd; 
     249    } 
     250 
     251    /** 
     252     * @param associateWithClass the associateWithClass to set 
     253     */ 
     254    public void setAssociateWithClass(String associateWithClass) { 
     255        this.associateWithClass = associateWithClass; 
     256    } 
     257 
     258    /** 
     259     * @return the associateWithClass 
     260     */ 
     261    public String getAssociateWithClass() { 
     262        return associateWithClass; 
     263    } 
    99264 
    100265 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationEngine.java

    r709 r713  
    4141 
    4242    /** Defines which attributes to add, and what principal to attach to*/ 
    43     private AttributeAssociationDefinition attributeAssociationDefinition; 
    44  
    45     private DataConnector dataConnector; 
     43    private List<AttributeAssociationDefinition> attributeAssociationDefinitions; 
    4644 
    4745    /** 
     
    5250    } 
    5351 
    54  
    5552    /** 
    5653     * Gets associated attributes for the given ... 
    5754     */ 
    5855    public void associateAttributes(List<Event> events) throws AttributeAssociationException{ 
    59         log.info("Has Attribute Definition [{}]",attributeAssociationDefinition!=null); 
    60         if (attributeAssociationDefinition==null){ 
    61             throw new AttributeAssociationException("Attribute association not specified"); 
     56 
     57        for (AttributeAssociationDefinition attributeAssociationDefinition: attributeAssociationDefinitions){ 
     58            log.info("Attribute Association Definition [{}], is enabled [{}]",attributeAssociationDefinition.getDefiniationName(), attributeAssociationDefinition.isEnabled()); 
     59 
     60            if (!attributeAssociationDefinition.isEnabled()){ 
     61                continue; 
     62            } 
     63 
     64            int attached=0; 
     65            int noPrincipal=0; 
     66            int current=0; 
     67            final int noOfEvents = events.size(); 
     68            for (Event event : events){ 
     69                printProgressPosition(current, noOfEvents); 
     70                boolean associated = attributeAssociationDefinition.associate(event); 
     71                if (associated){ 
     72                    attached++; 
     73                } 
     74                else{ 
     75                    noPrincipal++; 
     76                } 
     77                current++; 
     78            } 
     79            log.info("Attribute Association Definition {} finished, associated information to {} events, where {} events where not of a valid class type or did not have the correct principal", 
     80                    new Object[]{attributeAssociationDefinition.getDefiniationName(),attached,noPrincipal}); 
    6281        } 
    63  
    64         log.info("Attribute Association started for principal field [{}]",attributeAssociationDefinition.getSubjectPrincipalField()); 
    65  
    66         int attached=0; 
    67         int noPrincipal=0; 
    68         for (Event event : events){ 
    69             Object principalObject = ReflectionHelper.getValueFromObject(attributeAssociationDefinition.getSubjectPrincipalField(), event); 
    70             String principal = null; 
    71             if (principalObject instanceof String){ 
    72                 principal = (String)principalObject; 
    73             } 
    74             if (principal!=null){ 
    75                 try { 
    76                     dataConnector.setReturnAttributes(attributeAssociationDefinition.getSourceAttributesAsArray()); 
    77                     Map<String, String> attributes = dataConnector.lookup(principal); 
    78                     populate(attributes,event); 
    79                     attached++; 
    80                 } catch (AttributeAssociationException e) { 
    81                     log.error("Association error for principal [{}]",principal,e); 
    82                 } catch (InstantiationException e) { 
    83                     log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
    84                 } catch (IllegalAccessException e) { 
    85                     log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
    86                 } 
    87             } 
    88             else{ 
    89                 noPrincipal++; 
    90             } 
    91         } 
    92         log.info("Associated information to {} events, where {} events did not have a valid principal",attached,noPrincipal); 
    93     } 
    94  
    95     private void populate(Map<String,String> attributes, Event event) throws InstantiationException, IllegalAccessException{ 
    96  
    97         Object classToPopulate = attributeAssociationDefinition.getInternalModelClass().newInstance(); 
    98  
    99         for (Map.Entry<String,String> entry : attributes.entrySet()){ 
    100             String attributeSourceName = entry.getKey(); 
    101             String attributeValue = entry.getValue(); 
    102             log.trace("source [{}], value [{}]",attributeSourceName,attributeValue); 
    103             try{ 
    104                 String internalFieldName = attributeAssociationDefinition.getInternalAttributeName(attributeSourceName); 
    105                 ReflectionHelper.setValueOnObject(internalFieldName, attributeValue, classToPopulate); 
    106             } 
    107             catch(AttributeAssociationException e){ 
    108                 log.warn("Error trying to populate internal model. {}",e.getMessage()); 
    109             } 
    110         } 
    111  
    112         //now attach the object where approppriate on the current <code>Event</code> object 
    113         ReflectionHelper.attachObjectTo(classToPopulate,event); 
    114          
    115         log.debug("{}",event); 
    116     } 
    117  
    118     /** 
    119      * @param attributeAssociationDefinition the attributeAssociationDefinition to set 
    120      */ 
    121     public void setAttributeAssociationDefinition(AttributeAssociationDefinition attributeAssociationDefinition) { 
    122         this.attributeAssociationDefinition = attributeAssociationDefinition; 
    123     } 
    124  
    125     /** 
    126      * @return the attributeAssociationDefinition 
    127      */ 
    128     public AttributeAssociationDefinition getAttributeAssociationDefinition() { 
    129         return attributeAssociationDefinition; 
    13082    } 
    13183 
    13284 
    13385    /** 
    134      * @param dataConnector the dataConnector to set 
     86     * Prints, as a percentage of the total, the event currently being processed. 
     87     * 
     88     * @param lineCount 
     89     * @param totalNoLines 
    13590     */ 
    136     public void setDataConnector(DataConnector dataConnector) { 
    137         this.dataConnector = dataConnector; 
    138         dataConnector.initialise(); 
     91    private void printProgressPosition(int lineCount, int totalNoLines) { 
     92            double linePercentage = (((double) lineCount / (double) totalNoLines) * 100); 
     93            if (linePercentage % 25 >= 0 && linePercentage % 25 <= 0.003) 
     94                    log.debug("Attribute Association, Complete {}%", linePercentage); 
    13995    } 
    14096 
     97    /** 
     98     * Also initialises the definitions 
     99     * 
     100     * @param attributeAssociationDefinitions the attributeAssociationDefinitions to set 
     101     */ 
     102    public void setAttributeAssociationDefinitions(List<AttributeAssociationDefinition> attributeAssociationDefinitions) { 
     103        this.attributeAssociationDefinitions = attributeAssociationDefinitions; 
     104        for (AttributeAssociationDefinition definition : attributeAssociationDefinitions){ 
     105              definition.initialise(); 
     106        } 
     107    } 
    141108 
    142109    /** 
    143      * @return the dataConnector 
     110     * @return the attributeAssociationDefinitions 
    144111     */ 
    145     public DataConnector getDataConnector() { 
    146         return dataConnector; 
     112    public List<AttributeAssociationDefinition> getAttributeAssociationDefinitions() { 
     113        return attributeAssociationDefinitions; 
    147114    } 
    148115 
    149116 
    150117 
     118 
    151119} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/DataConnector.java

    r707 r713  
    1818    public void setReturnAttributes(String[] s); 
    1919 
     20    public void setSearchFilterTemplate(String searchFilterTemplate); 
     21 
    2022} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/LdapDataConnector.java

    r707 r713  
    4242import net.shibboleth.idp.attribute.resolver.BaseDataConnector; 
    4343 
     44import org.joda.time.DateTime; 
    4445import org.opensaml.xml.security.x509.X509Credential; 
    4546import org.opensaml.xml.util.DatatypeHelper; 
     
    4849import org.springframework.context.ApplicationEvent; 
    4950import org.springframework.context.ApplicationListener; 
     51 
     52import uk.ac.cardiff.raptor.event.expansion.AttributeLookup; 
    5053 
    5154import edu.vt.middleware.ldap.Ldap; 
     
    129132    private String searchFilterTemplate; 
    130133 
     134    /** How long the cache remains valid before it is cleared */ 
     135    private long cacheTimeoutMs; 
     136 
     137    /** The time at which the cache was last reset*/ 
     138    private long cacheResetTimeMs; 
    131139 
    132140    /** 
     
    141149     */ 
    142150    public void initialise() { 
    143         initialized = true; 
    144         initializeLdapPool(); 
    145         initializeCache(); 
     151        if (!initialized){ 
     152            initialized = true; 
     153            initializeLdapPool(); 
     154            initializeCache(); 
     155        } 
    146156    } 
    147157 
     
    163173        if (cacheResults && initialized) { 
    164174            cache = new HashMap<String, Map<String, Map<String, String>>>(); 
     175            cacheResetTimeMs = System.currentTimeMillis(); 
    165176        } 
    166177    } 
     
    172183        if (cacheResults && initialized) { 
    173184            cache.clear(); 
     185            cacheResetTimeMs = System.currentTimeMillis(); 
    174186        } 
    175187    } 
     
    289301    public void setSslSocketFactory(SSLSocketFactory sf) { 
    290302        ldapConfig.setSslSocketFactory(sf); 
    291         clearCache(); 
    292         initializeLdapPool(); 
    293303    } 
    294304 
     
    676686    } 
    677687 
     688    private void checkCacheValidity(){ 
     689        if (cacheTimeoutMs==0 || !cacheResults){ 
     690            return; 
     691        } 
     692        long currentTimeMillis = System.currentTimeMillis(); 
     693        boolean shouldReset  = (currentTimeMillis - cacheResetTimeMs) > cacheTimeoutMs; 
     694        if (shouldReset){ 
     695            log.info("Ldap cache was cleared, timeout reached"); 
     696            clearCache(); 
     697        } 
     698    } 
     699 
    678700 
    679701    /** {@inheritDoc} */ 
    680702    public Map<String, String> lookup(String principal) throws AttributeAssociationException { 
     703 
    681704        String searchFilter = searchFilterTemplate.replace("[principal]",principal); 
    682  
    683705        searchFilter = searchFilter.trim(); 
    684         log.debug("Search filter: {}", searchFilter); 
     706        //log.debug("Search: "+searchFilter); 
     707        //check if cache is still valid 
     708        checkCacheValidity(); 
    685709 
    686710        // create Attribute objects to return 
     
    688712 
    689713        // check for cached data 
    690 //        if (cacheResults) { 
    691 //            log.debug("Checking cache for search results"); 
    692 //            attributes = getCachedAttributes(resolutionContext, searchFilter); 
    693 //            if (attributes != null && log.isDebugEnabled()) { 
    694 //                log.debug("Returning attributes from cache"); 
    695 //            } 
    696 //        } 
     714        if (cacheResults) { 
     715            attributes = getCachedAttributes(principal, searchFilter); 
     716        } 
    697717 
    698718        // results not found in the cache 
    699719        if (attributes == null) { 
    700             //log.debug("Retrieving attributes from LDAP"); 
    701720            Iterator<SearchResult> results = searchLdap(searchFilter); 
    702721            // check for empty result set 
    703722            if (noResultsIsError && !results.hasNext()) { 
    704                 throw new AttributeAssociationException("No LDAP entry found for scmps2"); 
     723                throw new AttributeAssociationException("No LDAP entry found for "+principal); 
    705724            } 
    706725            // build resolved attributes from LDAP attributes 
    707726            attributes = buildBaseAttributes(results); 
    708 //            if (cacheResults && attributes != null) { 
    709 //                setCachedAttributes(resolutionContext, searchFilter, attributes); 
    710 //                log.debug("Stored results in the cache"); 
    711 //            } 
     727            if (cacheResults && attributes != null) { 
     728                setCachedAttributes(principal, searchFilter, attributes); 
     729                //log.debug("Stored results in the cache"); 
     730            } 
    712731        } 
    713732 
     
    866885 
    867886 
    868 //    /** 
    869 //     * This stores the supplied attributes in the cache. 
    870 //     * 
    871 //     * @param resolutionContext <code>ResolutionContext</code> 
    872 //     * @param searchFiler the searchFilter that produced the attributes 
    873 //     * @param attributes <code>Map</code> of attribute ids to attributes 
    874 //     */ 
    875 //    protected void setCachedAttributes(AttributeResolutionContext resolutionContext, String searchFiler, 
    876 //            Map<String, Attribute> attributes) { 
    877 //        Map<String, Map<String, Attribute>> results = null; 
    878 //        String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
    879 //        if (cache.containsKey(principal)) { 
    880 //            results = cache.get(principal); 
    881 //        } else { 
    882 //            results = new HashMap<String, Map<String, Attribute>>(); 
    883 //            cache.put(principal, results); 
    884 //        } 
    885 //        results.put(searchFiler, attributes); 
    886 //    } 
    887  
    888 //    /** 
    889 //     * This retrieves any cached attributes for the supplied resolution context. Returns null if nothing is cached. 
    890 //     * 
    891 //     * @param resolutionContext <code>ResolutionContext</code> 
    892 //     * @param searchFilter the search filter the produced the attributes 
    893 //     * 
    894 //     * @return <code>Map</code> of attributes ids to attributes 
    895 //     */ 
    896 //    protected Map<String, Attribute> getCachedAttributes(AttributeResolutionContext resolutionContext, 
    897 //            String searchFilter) { 
    898 //        Map<String, Attribute> attributes = null; 
    899 //        if (cacheResults) { 
    900 //            String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
    901 //            if (cache.containsKey(principal)) { 
    902 //                Map<String, Map<String, Attribute>> results = cache.get(principal); 
    903 //                attributes = results.get(searchFilter); 
    904 //            } 
    905 //        } 
    906 //        return attributes; 
    907 //    } 
     887    /** 
     888     * This stores the supplied attributes in the cache. 
     889     * 
     890     * @param principalName 
     891     * @param searchFiler the searchFilter that produced the attributes 
     892     * @param attributes <code>Map</code> of attribute ids to attributes 
     893     */ 
     894    protected void setCachedAttributes(String principalName, String searchFiler, Map<String, String> attributes) { 
     895        Map<String, Map<String, String>> results = null; 
     896        if (cache.containsKey(principalName)) { 
     897            results = cache.get(principalName); 
     898        } else { 
     899            results = new HashMap<String, Map<String, String>>(); 
     900            cache.put(principalName, results); 
     901        } 
     902        results.put(searchFiler, attributes); 
     903    } 
     904 
     905    /** 
     906     * This retrieves any cached attributes for the supplied resolution context. Returns null if nothing is cached. 
     907     * 
     908     * @param principalName 
     909     * @param searchFilter the search filter the produced the attributes 
     910     * 
     911     * @return <code>Map</code> of attributes ids to attributes 
     912     */ 
     913    protected Map<String, String> getCachedAttributes(String principalName, 
     914            String searchFilter) { 
     915        Map<String, String> attributes = null; 
     916        if (cacheResults) { 
     917            if (cache.containsKey(principalName)) { 
     918                Map<String, Map<String, String>> results = cache.get(principalName); 
     919                attributes = results.get(searchFilter); 
     920            } 
     921        } 
     922        return attributes; 
     923    } 
     924 
     925    /** 
     926     * @param cacheTimeoutMs the cacheTimeoutMs to set 
     927     */ 
     928    public void setCacheTimeoutMs(long cacheTimeoutMs) { 
     929        this.cacheTimeoutMs = cacheTimeoutMs; 
     930    } 
     931 
     932    /** 
     933     * @return the cacheTimeoutMs 
     934     */ 
     935    public long getCacheTimeoutMs() { 
     936        return cacheTimeoutMs; 
     937    } 
    908938 
    909939 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/ReleaseFailureException.java

    r672 r713  
    2222         */ 
    2323        private static final long serialVersionUID = -1091443418866759066L; 
    24          
    25         public ReleaseFailureException (String message, Exception e){ 
    26                 super (message,e); 
     24 
     25        public ReleaseFailureException (String message, Exception wrappedException){ 
     26                super (message,wrappedException); 
    2727        } 
    2828 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/CxfServiceEndpointClient.java

    r656 r713  
    4343 
    4444import uk.ac.cardiff.model.event.AuthenticationEvent; 
     45import uk.ac.cardiff.model.event.EzproxyAuthenticationEvent; 
     46import uk.ac.cardiff.model.event.EzproxyProxyEvent; 
     47import uk.ac.cardiff.model.event.OpenathenslaAuthenticationEvent; 
    4548import uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent; 
    4649import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
     
    7275            overrides.add(ShibbolethIdpAuthenticationEvent.class.getName()); 
    7376            overrides.add(AuthenticationEvent.class.getName()); 
     77            overrides.add(EzproxyAuthenticationEvent.class.getName()); 
     78            overrides.add(OpenathenslaAuthenticationEvent.class.getName()); 
    7479            databinding.setOverrideTypes(overrides); 
    7580 
    7681            for (String typeName : overrides) { 
    77                 Class c = null; 
     82                Class<?> c = null; 
    7883                try { 
    7984                    c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/AsynchronousEntryStoragePipeline.java

    r699 r713  
    2828 
    2929 
    30 public class AsynchronousEntryStoragePipeline implements StoreEntriesTaskCallbackInterface{ 
     30public class AsynchronousEntryStoragePipeline { 
    3131 
    3232        /** class logger */ 
     
    4848        } 
    4949 
    50         public void storageResultCallback(Object result) { 
    51                 log.debug("Storage task completed {}, for transaction id [{}]",result, transactionId); 
    52  
    53         } 
    54  
    5550        /** 
    5651         * Starts and shuts down the <code>storeEntryTask</code> immediately, so that when it completes 
     
    5954         * @param events 
    6055         */ 
    61         public void execute(List<Event> events){ 
    62             StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(entryHandler, attributeAssociationEngine, events,this); 
     56        public void execute(List<Event> events, StoreEntriesTaskCallbackInterface callback){ 
     57            StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(entryHandler, attributeAssociationEngine, events,callback); 
    6358            ExecutorService es = Executors.newSingleThreadExecutor(); 
    6459            es.submit(storeEntryTask); 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r699 r713  
    3131 * 
    3232 */ 
    33 public class StorageEngine { 
     33public class StorageEngine  implements StoreEntriesTaskCallbackInterface{ 
    3434 
    3535    /** Class logger*/ 
     
    4343    private AttributeAssociationEngine attributeAssociationEngine; 
    4444 
     45    /** The ID of the currently executing transaction */ 
     46    private int currentTransactionId; 
     47 
     48    /** Whether a transaction is currently in progress*/ 
     49    private boolean transactionInProgress; 
    4550 
    4651    /** Default Constructor*/ 
    4752    public StorageEngine(){ 
     53        transactionInProgress=false; 
     54    } 
    4855 
     56    public void storageResultCallback(Object result) { 
     57        log.debug("Storage task completed {}, for transaction id [{}]",result, currentTransactionId); 
     58        transactionInProgress=false; 
    4959    } 
    5060 
     
    5262     * @param events 
    5363     */ 
    54     public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events){ 
     64    public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException{ 
     65        if (transactionInProgress){ 
     66            throw new TransactionInProgressException("Transaction "+currentTransactionId+" currently in processing"); 
     67        } 
     68        log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(),transactionId); 
     69        transactionInProgress=true; 
     70        this.currentTransactionId = transactionId; 
    5571        AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, entryHandler,attributeAssociationEngine); 
    56         asyncEntryStorage.execute(events); 
     72        asyncEntryStorage.execute(events,this); 
    5773    } 
    5874 
     
    103119 
    104120 
     121 
     122 
    105123} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r707 r713  
    121121                                hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
    122122                        } catch (Exception e) { 
    123                             log.error("Could not get hashcode for event {}, event not stored"); 
     123                            log.error("Could not get hashcode for event {}, event not stored", event); 
    124124                            continue; 
    125125                        } 
Note: See TracChangeset for help on using the changeset viewer.