Changeset 699


Ignore:
Timestamp:
04/26/11 18:46:55 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
6 added
4 edited
2 moved

Legend:

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

    r678 r699  
    2525import org.slf4j.LoggerFactory; 
    2626 
     27import uk.ac.cardiff.model.event.Event; 
     28import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 
     29import uk.ac.cardiff.raptor.event.expansion.connector.DataConnector; 
     30import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
     31 
    2732/** 
    2833 * @author philsmart 
     
    3439    private final Logger log = LoggerFactory.getLogger(AttributeAssociationEngine.class); 
    3540 
     41    /** Defines which attributes to add, and what principal to attach to*/ 
     42    private AttributeAssociationDefinition attributeAssociationDefinition; 
     43 
     44    private DataConnector dataConnector; 
     45 
    3646    /** 
    3747     * Default Constructor 
     
    4151    } 
    4252 
    43     public List<String> getAssociatedAttributes(String attributeToAssociate){ 
    44             //AttribtueResolver attributeResolver = new AttributeResolver("mua-attribute-association-resolver"); 
    45         return null; 
    46     } 
    4753 
    4854    /** 
    4955     * Gets associated attributes for the given ... 
    5056     */ 
    51     public void associateAttributesAsynchronous() { 
    52        // AttributeResolver resolver = new AttributeResolver(" foo "); 
     57    public void associateAttributes(List<Event> events) throws AttributeAssociationException{ 
     58        log.info("Has Attribute Definition [{}]",attributeAssociationDefinition!=null); 
     59        if (attributeAssociationDefinition==null){ 
     60            throw new AttributeAssociationException("Attribute association not specified"); 
     61        } 
    5362 
     63        log.info("Attribute Association started for principal field [{}]",attributeAssociationDefinition.getSubjectPrincipalField()); 
     64 
     65        int attached=0; 
     66        int noPrincipal=0; 
     67        for (Event event : events){ 
     68            Object principalObject = ReflectionHelper.getValueFromObject(attributeAssociationDefinition.getSubjectPrincipalField(), event); 
     69            String principal = null; 
     70            if (principalObject instanceof String){ 
     71                principal = (String)principalObject; 
     72            } 
     73            if (principal!=null){ 
     74                try { 
     75                    dataConnector.lookup(principal); 
     76                    attached++; 
     77                } catch (AttributeAssociationException e) { 
     78                    log.error("Association error for principal [{}]",principal,e); 
     79                } 
     80            } 
     81            else{ 
     82                noPrincipal++; 
     83            } 
     84        } 
     85        log.info("Associated information to {} events, where {} events did not have a valid principal",attached,noPrincipal); 
     86    } 
     87 
     88    /** 
     89     * @param attributeAssociationDefinition the attributeAssociationDefinition to set 
     90     */ 
     91    public void setAttributeAssociationDefinition(AttributeAssociationDefinition attributeAssociationDefinition) { 
     92        this.attributeAssociationDefinition = attributeAssociationDefinition; 
     93    } 
     94 
     95    /** 
     96     * @return the attributeAssociationDefinition 
     97     */ 
     98    public AttributeAssociationDefinition getAttributeAssociationDefinition() { 
     99        return attributeAssociationDefinition; 
     100    } 
     101 
     102 
     103    /** 
     104     * @param dataConnector the dataConnector to set 
     105     */ 
     106    public void setDataConnector(DataConnector dataConnector) { 
     107        this.dataConnector = dataConnector; 
     108        dataConnector.initialise(); 
     109    } 
     110 
     111 
     112    /** 
     113     * @return the dataConnector 
     114     */ 
     115    public DataConnector getDataConnector() { 
     116        return dataConnector; 
    54117    } 
    55118 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java

    r694 r699  
    3636/** 
    3737 * @author philsmart 
    38  *  
     38 * 
    3939 */ 
    4040public class ReflectionHelper { 
     
    4242        /** Class logger */ 
    4343        private static final Logger log = LoggerFactory.getLogger(ReflectionHelper.class); 
    44          
     44 
    4545        private static final String EVENT_PACKAGE_NAME ="uk.ac.cardiff.model.event"; 
    46          
     46 
    4747        private static final String JAR_PREFIX = "jar"; 
    4848 
     
    5050         * Checks if an attribute exists on a class by finding if it has a 'get' 
    5151         * method associated on the class 
    52          *  
     52         * 
    5353         * @param entry 
    5454         * @param attributeID 
     
    7373         * setter method, so as the parameter types to the method e.g. using 
    7474         * <code>id.getMethod(..)</code>, do not need to be known. 
    75          *  
     75         * 
    7676         * @param object 
    7777         * @param attributeID 
     
    198198         * This method finds the simple name of the class in the uk.ac.cardiff.model 
    199199         * package that contains the <code>fieldName</code>. 
    200          *  
     200         * 
    201201         * @param fieldName 
    202202         * @return 
     
    246246         * Gets the name, as a string, of the JAR file that contains the package 
    247247         * <code>pckgname</code> 
    248          *  
     248         * 
    249249         * @param pckgname 
    250250         * @return the name, as a <code>String</code>, of the JAR file that contains the package <code>pckgname</code> 
     
    270270         * Gets the names of the classes, as strings, in the jar 
    271271         * <code>jarName</code> and package <code>packageName</code> 
    272          *  
     272         * 
    273273         * @param jarName 
    274274         * @param packageName 
     
    295295                return classes; 
    296296        } 
    297          
     297 
    298298        private static List<String> getClassNamesInJarOrFolder(String jarOrDirectoryName, String packageName){ 
    299299                if (jarOrDirectoryName.endsWith(JAR_PREFIX)){ 
     
    304304                } 
    305305        } 
    306          
     306 
    307307        /** 
    308308         * Gets the names of the classes, as strings, in the directory 
    309309         * <code>directoryName</code> and package <code>packageName</code> 
    310          *  
    311          * @param directoryName the name of the directory to look for classes  
     310         * 
     311         * @param directoryName the name of the directory to look for classes 
    312312         * @param packageName the name of the package the classes belong to 
    313313         * @return a list of class names in the current folder 
     
    336336         * if they exist outside any JAR libraries, use 
    337337         * <code>getClasseNamesInPackageJAR</code> 
    338          *  
     338         * 
    339339         * @param pckgname 
    340340         * @return 
     
    392392         * Checks whether the Object <code>object</code> has the field 
    393393         * <code>fieldName</code> 
    394          *  
     394         * 
    395395         * @param object 
    396396         * @param fieldName 
     
    451451                        String fieldAsMethod = ReflectionHelper.prepareMethodNameGet(fieldname); 
    452452                        Method getter = id.getMethod(fieldAsMethod, new Class[] {}); 
    453                         // log.debug("Trying to Set :"+param) 
    454453                        Object result = getter.invoke(object, new Object[] {}); 
    455454                        return result; 
     
    468467                        String fieldAsMethod = ReflectionHelper.prepareMethodNameSet(fieldname); 
    469468                        Method setter = id.getMethod(fieldAsMethod, new Class[] { param.getClass() }); 
    470                         // log.debug("Trying to Set :"+param) 
    471469                        setter.invoke(object, new Object[] { param }); 
    472470                } catch (Throwable e) { 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/AsynchronousEntryStoragePipeline.java

    r698 r699  
    2525 
    2626import uk.ac.cardiff.model.event.Event; 
     27import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
    2728 
    2829 
    29 public class AsynchronousEntryStorage implements StoreEntriesTaskCallbackInterface{ 
     30public class AsynchronousEntryStoragePipeline implements StoreEntriesTaskCallbackInterface{ 
    3031 
    3132        /** class logger */ 
    32         private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStorage.class); 
     33        private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStoragePipeline.class); 
    3334 
    3435        /** An ID used to track the progress of any transaction */ 
    3536        private int transactionId; 
    3637 
    37         public AsynchronousEntryStorage(int transactionId){ 
    38             this.setTransactionId(transactionId); 
     38        /** entry handler used to store entries (e.g. events)*/ 
     39    private EntryHandler entryHandler; 
     40 
     41    /** Attribute association engine, used to attach additional attributes to events */ 
     42    private AttributeAssociationEngine attributeAssociationEngine; 
     43 
     44        public AsynchronousEntryStoragePipeline(int transactionId, EntryHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine){ 
     45            this.entryHandler = entryHandler; 
     46            this.attributeAssociationEngine = attributeAssociationEngine; 
     47            this.transactionId=transactionId; 
    3948        } 
    4049 
     
    4453        } 
    4554 
    46         public void store(EntryHandler entryHandler, List<Event> events){ 
    47                 StoreEntriesTask storeEntryTask = new StoreEntriesTask(entryHandler, events,this); 
    48                 ExecutorService es = Executors.newSingleThreadExecutor(); 
    49                 es.submit(storeEntryTask); 
    50                 es.shutdown(); 
     55        /** 
     56         * Starts and shuts down the <code>storeEntryTask</code> immediately, so that when it completes 
     57         * it can be re-used. 
     58         * 
     59         * @param events 
     60         */ 
     61        public void execute(List<Event> events){ 
     62            StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(entryHandler, attributeAssociationEngine, events,this); 
     63            ExecutorService es = Executors.newSingleThreadExecutor(); 
     64            es.submit(storeEntryTask); 
     65            es.shutdown(); 
    5166        } 
     67 
    5268 
    5369    /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r672 r699  
    2525 
    2626import uk.ac.cardiff.model.event.Event; 
     27import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
    2728 
    2829/** 
     
    3940 
    4041 
     42    /** Engine used to associate attributes to existing events in the MUA */ 
     43    private AttributeAssociationEngine attributeAssociationEngine; 
     44 
     45 
    4146    /** Default Constructor*/ 
    4247    public StorageEngine(){ 
     
    4752     * @param events 
    4853     */ 
    49     public void addEntriesAsynchronous(int transactionId, List<Event> events){ 
    50         AsynchronousEntryStorage asyncEntryStorage = new AsynchronousEntryStorage(transactionId); 
    51         asyncEntryStorage.store(entryHandler, events); 
     54    public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events){ 
     55        AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, entryHandler,attributeAssociationEngine); 
     56        asyncEntryStorage.execute(events); 
    5257    } 
    5358 
     
    8085    } 
    8186 
     87    /** 
     88     * @param attributeAssociationEngine the attributeAssociationEngine to set 
     89     */ 
     90    public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 
     91        this.attributeAssociationEngine = attributeAssociationEngine; 
     92    } 
     93 
     94    /** 
     95     * @return the attributeAssociationEngine 
     96     */ 
     97    public AttributeAssociationEngine getAttributeAssociationEngine() { 
     98        return attributeAssociationEngine; 
     99    } 
     100 
     101 
    82102 
    83103 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEntriesPipelineTask.java

    r698 r699  
    2626 
    2727import uk.ac.cardiff.model.event.Event; 
     28import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
     29import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 
    2830import uk.ac.cardiff.raptor.store.dao.StorageException; 
    2931 
     
    3436 * 
    3537 */ 
    36 public class StoreEntriesTask implements Callable<Boolean>{ 
     38public class StoreEntriesPipelineTask implements Callable<Boolean>{ 
    3739 
    3840        /** class logger */ 
    39         private final Logger log = LoggerFactory.getLogger(StoreEntriesTask.class); 
     41        private final Logger log = LoggerFactory.getLogger(StoreEntriesPipelineTask.class); 
    4042 
    4143        /** The entry handler used to store entries (e.g. events)*/ 
     
    4547    private StoreEntriesTaskCallbackInterface storeCallback; 
    4648 
     49    /** Attribute association engine, used to attach additional attributes to events */ 
     50    private AttributeAssociationEngine attributeAssociationEngine; 
     51 
    4752    /** The events that need to be stored */ 
    4853    private List<Event> events; 
    4954 
    50     public StoreEntriesTask(EntryHandler entryHandler, List<Event> events, StoreEntriesTaskCallbackInterface storeCallback){ 
     55    public StoreEntriesPipelineTask(EntryHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine,List<Event> events, StoreEntriesTaskCallbackInterface storeCallback){ 
    5156        this.storeCallback = storeCallback; 
     57        this.attributeAssociationEngine = attributeAssociationEngine; 
    5258        this.entryHandler = entryHandler; 
    5359        this.events = events; 
     
    5561 
    5662    public Boolean call() throws Exception { 
    57         log.debug("Storing entries"); 
    5863        try{ 
    59             entryHandler.addEntries(events); 
     64 
     65            associate(); 
     66            store(); 
     67 
    6068        } 
    6169        catch(StorageException e){ 
     
    6876    } 
    6977 
     78    private void store() throws StorageException{ 
     79        entryHandler.addEntries(events); 
     80    } 
     81 
     82    private void associate(){ 
     83        try { 
     84            attributeAssociationEngine.associateAttributes(events); 
     85        } catch (AttributeAssociationException e) { 
     86            log.warn("{}",e.getMessage()); 
     87        } 
     88    } 
     89 
    7090} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r694 r699  
    3838import uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent; 
    3939import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    40 import uk.ac.cardiff.raptor.store.AsynchronousEntryStorage; 
     40import uk.ac.cardiff.raptor.store.AsynchronousEntryStoragePipeline; 
    4141import uk.ac.cardiff.raptor.store.EntryHandler; 
    42 import uk.ac.cardiff.raptor.store.StoreEntriesTask; 
     42import uk.ac.cardiff.raptor.store.StoreEntriesPipelineTask; 
    4343import uk.ac.cardiff.raptor.store.dao.RaptorDataConnection; 
    4444import uk.ac.cardiff.raptor.store.dao.StorageException; 
Note: See TracChangeset for help on using the changeset viewer.