Changeset 1509


Ignore:
Timestamp:
05/02/13 17:39:35 (7 years ago)
Author:
philsmart
Message:
 
Location:
raptor-mua/trunk/src/main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • raptor-mua/trunk/src/main/conf-default/statistical-units-custom.xml

    r1485 r1509  
    266266                        </bean> 
    267267                </property> 
    268                   <property name="attachProcessors"> 
    269             <list> 
    270                 <bean class="uk.ac.cardiff.model.wsmodel.ProcessorInformation"> 
    271                     <property name="processorClass"> 
    272                         <value>uk.ac.cardiff.raptormua.engine.statistics.processor.SamlMetadataNameFormatter</value> 
    273                     </property> 
    274                 </bean> 
    275                 <bean class="uk.ac.cardiff.model.wsmodel.ProcessorInformation"> 
    276                     <property name="processorClass"> 
    277                         <value>uk.ac.cardiff.raptormua.engine.statistics.processor.SortGroupsAlphabeticallyPostProcessor</value> 
    278                     </property> 
    279                     <property name="methodParameters"> 
    280                         <list> 
    281                             <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
    282                                 <property name="parameterType" value="VALUE" /> 
    283                                 <property name="parameterName" value="Ascending"></property>    
    284                                 <property name="value"> 
    285                                     <value type="java.lang.Boolean">true</value> 
    286                                 </property> 
    287                             </bean> 
    288                         </list> 
    289                     </property> 
    290                 </bean>                
    291             </list> 
    292         </property> 
     268                  
    293269        </bean> 
    294270 
  • raptor-mua/trunk/src/main/config/database.xml

    r1505 r1509  
    2828        <property name="mappingResources"> 
    2929            <list> 
    30                 <value>uk/ac/cardiff/model/event/event.hbm.xml</value> 
     30                <value>uk/ac/cardiff/model/event/event-name-limit.hbm.xml</value> 
    3131                <value>uk/ac/cardiff/model/resource/resourcemetadata.hbm.xml</value> 
    3232                <value>uk/ac/cardiff/raptor/registry/releaseInformation.hbm.xml</value> 
  • raptor-mua/trunk/src/main/config/statistical-units-custom.xml

    r1485 r1509  
    267267                        </bean> 
    268268                </property> 
    269                   <property name="attachProcessors"> 
    270             <list> 
    271                 <bean class="uk.ac.cardiff.model.wsmodel.ProcessorInformation"> 
    272                     <property name="processorClass"> 
    273                         <value>uk.ac.cardiff.raptormua.engine.statistics.processor.SamlMetadataNameFormatter</value> 
    274                     </property> 
    275                 </bean> 
    276                 <bean class="uk.ac.cardiff.model.wsmodel.ProcessorInformation"> 
    277                     <property name="processorClass"> 
    278                         <value>uk.ac.cardiff.raptormua.engine.statistics.processor.SortGroupsAlphabeticallyPostProcessor</value> 
    279                     </property> 
    280                     <property name="methodParameters"> 
    281                         <list> 
    282                             <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
    283                                 <property name="parameterType" value="VALUE" /> 
    284                                 <property name="parameterName" value="Ascending"></property>    
    285                                 <property name="value"> 
    286                                     <value type="java.lang.Boolean">true</value> 
    287                                 </property> 
    288                             </bean> 
    289                         </list> 
    290                     </property> 
    291                 </bean>                
    292             </list> 
    293         </property> 
     269                  
    294270        </bean> 
    295271 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/MUAEngine.java

    r1485 r1509  
    312312     */ 
    313313    public void updateStatisticalUnit(final StatisticalUnitInformation statisticalUnitInformation) { 
     314        log.trace("Updating the statistic with start time [{}] and end time [{}]", statisticalUnitInformation 
     315                .getStatisticParameters().getStartTimeAsJavaDate(), statisticalUnitInformation.getStatisticParameters() 
     316                .getEndTimeAsJavaDate()); 
    314317        statisticsHandler.updateStatisticalUnit(statisticalUnitInformation); 
    315318        capabilitiesConstructor.invalidateCache(); 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/service/impl/MUAProcessImpl.java

    r1495 r1509  
    2222import java.util.ArrayList; 
    2323import java.util.List; 
     24import java.util.concurrent.TimeUnit; 
    2425import java.util.concurrent.locks.Lock; 
    2526import java.util.concurrent.locks.ReentrantLock; 
     
    4041import uk.ac.cardiff.model.wsmodel.LogFileUploadResult; 
    4142import uk.ac.cardiff.model.wsmodel.StatisticFunctionType; 
     43import uk.ac.cardiff.model.wsmodel.StatisticParameters.StatisticType; 
    4244import uk.ac.cardiff.model.wsmodel.StatisticalUnitInformation; 
    4345import uk.ac.cardiff.raptor.store.TransactionInProgressException; 
     
    6971 
    7072    /** 
    71      * ReentrantLock to prevent more than one operation at the same time 
     73     * General ReentrantLock to prevent more than one operation at the same time. 
    7274     */ 
    7375    final Lock lockR = new ReentrantLock(); 
    7476 
     77    /** 
     78     * Lock the should be checked by all operations that require write access. 
     79     */ 
     80    final Lock writeLock = new ReentrantLock(); 
     81 
     82    /** 
     83     * A lock that should be checked when a SYSTEM level statistical unit is updated, as these should not happen 
     84     * concurrently. 
     85     */ 
     86    final Lock lockUpdateStatisticalUnitsSystem = new ReentrantLock(); 
     87 
     88    /** 
     89     * A lock that should be checked when a USER level statistical unit is updated, as these should not happen 
     90     * concurrently. 
     91     */ 
     92    final Lock lockUpdateStatisticalUnitsUser = new ReentrantLock(); 
     93 
    7594    @Override 
    7695    public AggregatorGraphModel performStatistic(String statisticName) throws SoapFault { 
    77         if (lockR.tryLock()) { 
    78             try { 
    79                 log.info("WebSservice call for perform statistic [{}] ", statisticName); 
    80                 return engine.performStatistic(statisticName); 
    81             } catch (Exception e) { 
    82                 log.error("{}", e); 
    83             } finally { 
    84                 lockR.unlock(); 
    85             } 
    86         } 
     96        // TODO this could be performing a stat that is being updated. Maybe think about locks here? 
     97        try { 
     98            log.info("WebSservice call for perform statistic [{}] ", statisticName); 
     99            return engine.performStatistic(statisticName); 
     100        } catch (Exception e) { 
     101            log.error("{}", e); 
     102        } 
     103 
    87104        log.warn("Lock was hit for method [performStatistic]"); 
    88105        throw new SoapFault("lock was hit on method performStatistic", new QName("Server")); 
     
    92109    @Override 
    93110    public void release() { 
    94         if (lockR.tryLock()) { 
     111        if (writeLock.tryLock()) { 
    95112            try { 
    96113                engine.release(); 
    97114            } catch (Exception e) { 
    98                 log.error("Error trying to release events, reason = [{}]", e.getMessage()); 
    99             } finally { 
    100                 lockR.unlock(); 
     115                log.error("Error trying to release events, write lock in operation, reason = [{}]", e.getMessage()); 
     116            } finally { 
     117                writeLock.unlock(); 
    101118            } 
    102119        } else { 
     
    114131    public void updateStatisticalUnit(StatisticalUnitInformation statisticalUnitInformation) throws SoapFault { 
    115132        boolean success = false; 
    116         if (lockR.tryLock()) { 
     133        Lock lockToUse = determineCorrectLock(statisticalUnitInformation); 
     134        if (lockToUse.tryLock()) { 
    117135            try { 
    118136                log.info("Updating statistical unit {}", statisticalUnitInformation.getStatisticParameters() 
     
    124142                success = false; 
    125143            } finally { 
    126                 lockR.unlock(); 
     144                lockToUse.unlock(); 
    127145            } 
    128146        } 
     
    194212    public void addAuthentications(EventPushMessage pushed) throws SoapFault { 
    195213        boolean success = false; 
    196         if (lockR.tryLock()) { 
     214        if (writeLock.tryLock()) { 
    197215            try { 
    198216                log.info("MUA has received {} entries from {} [{}]", new Object[] {pushed.getEvents().size(), 
     
    208226                success = false; 
    209227            } finally { 
    210                 lockR.unlock(); 
     228                writeLock.unlock(); 
    211229 
    212230            } 
     
    220238    } 
    221239 
     240    private Lock determineCorrectLock(StatisticalUnitInformation statInformation) { 
     241        StatisticType type = statInformation.getStatisticParameters().getType(); 
     242        if (type == StatisticType.SYSTEM) { 
     243            return lockUpdateStatisticalUnitsSystem; 
     244        } 
     245        if (type == StatisticType.USER) { 
     246            return lockUpdateStatisticalUnitsUser; 
     247        } else { 
     248            // else, return the lock for the system stats as these are more important to protect. 
     249            return lockUpdateStatisticalUnitsSystem; 
     250        } 
     251    } 
     252 
    222253    @Override 
    223254    public AggregatorGraphModel updateAndInvokeStatisticalUnit(StatisticalUnitInformation statisticalUnitInformation) 
    224255            throws SoapFault { 
    225         if (lockR.tryLock()) { 
    226             try { 
    227                 log.info("Webservice call to update and perform statistic [{}]", statisticalUnitInformation 
    228                         .getStatisticParameters().getUnitName()); 
    229                 engine.updateStatisticalUnit(statisticalUnitInformation); 
    230                 return engine.performStatistic(statisticalUnitInformation.getStatisticParameters().getUnitName()); 
    231             } catch (Exception e) { 
    232                 log.error("{}", e); 
    233             } finally { 
    234                 lockR.unlock(); 
    235             } 
    236         } 
    237         log.warn("Lock was hit for method [updateAndInvokeStatisticalUnit]"); 
    238         throw new SoapFault("lock was hit on method updateAndInvokeStatisticalUnit", new QName("Server")); 
     256 
     257        Lock lockToUse = determineCorrectLock(statisticalUnitInformation); 
     258        try { 
     259            if (lockToUse.tryLock(10, TimeUnit.SECONDS)) { 
     260                try { 
     261                    log.info("Webservice call to update and perform statistic [{}]", statisticalUnitInformation 
     262                            .getStatisticParameters().getUnitName()); 
     263                    engine.updateStatisticalUnit(statisticalUnitInformation); 
     264                    return engine.performStatistic(statisticalUnitInformation.getStatisticParameters().getUnitName()); 
     265                } catch (Exception e) { 
     266                    log.error("{}", e); 
     267                } finally { 
     268                    lockToUse.unlock(); 
     269                } 
     270            } else { 
     271 
     272                log.warn("Lock was hit for method [updateAndInvokeStatisticalUnit] - statistics being updated"); 
     273                throw new SoapFault("lock was hit on method updateAndInvokeStatisticalUnit - statistics being updated", 
     274                        new QName("Server")); 
     275            } 
     276        } catch (InterruptedException e) { 
     277            log.error("Error trying to obtain a lock with wait time", e); 
     278        } 
     279 
     280        log.warn("method [updateAndInvokeStatisticalUnit] did not perform any logc!"); 
     281        throw new SoapFault("method [updateAndInvokeStatisticalUnit] did not perform any logc!", new QName("Server")); 
    239282 
    240283    } 
     
    244287        List<LogFileUploadResult> result = new ArrayList<LogFileUploadResult>(); 
    245288        boolean success = false; 
    246         if (lockR.tryLock()) { 
     289        if (writeLock.tryLock()) { 
    247290            try { 
    248291                log.info("Webservice call to parse {} batch log file(s)", uploadFiles.size()); 
     
    259302 
    260303            } finally { 
    261                 lockR.unlock(); 
     304                writeLock.unlock(); 
    262305            } 
    263306        } else { 
     
    276319        List<BatchFile> files = fileUploadEngine.scanDirectories(); 
    277320        if (files != null && files.size() > 0) { 
    278             if (lockR.tryLock()) { 
     321            if (writeLock.tryLock()) { 
    279322                try { 
    280323                    log.info("Uploading {} files from directory", files.size()); 
     
    284327 
    285328                } finally { 
    286                     lockR.unlock(); 
     329                    writeLock.unlock(); 
    287330                } 
    288331            } else { 
Note: See TracChangeset for help on using the changeset viewer.