Changeset 736


Ignore:
Timestamp:
05/03/11 18:59:20 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
6 edited

Legend:

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

    r650 r736  
    3030    /** Class logger. */ 
    3131    private final Logger log = LoggerFactory.getLogger(EndpointRegistry.class); 
    32     
     32 
    3333 
    3434    /** List of endpoints for invoking methods on*/ 
     
    4040 
    4141    public void setEndpoints(List<Endpoint> endpoints) { 
    42         log.info("Setting Service Endpoints"); 
    4342        for (Endpoint entry : endpoints) 
    44             log.info("Registering: {}", entry.getClass()); 
     43            log.info("Registering Service Endpoint: {}", entry.getServiceEndpoint()); 
    4544        this.endpoints = endpoints; 
    4645    } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/server/sei/MultiUnitAggregator.java

    r730 r736  
    3131import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
    3232import uk.ac.cardiff.model.wsmodel.LogFileUpload; 
     33import uk.ac.cardiff.model.wsmodel.LogFileUploadResult; 
    3334import uk.ac.cardiff.model.wsmodel.StatisticalUnitInformation; 
    3435 
     
    6667 
    6768        /** Send a batch of log files to the MUA to store */ 
    68         public boolean batchUpload(List<LogFileUpload> uploadFiles); 
     69        public List<LogFileUploadResult> batchUpload(List<LogFileUpload> uploadFiles); 
    6970 
    7071} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r707 r736  
    4444         * @param event 
    4545         */ 
    46         public void addEntry(Event event); 
     46        public boolean addEntry(Event event); 
    4747 
    4848        /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r713 r736  
    2020 
    2121import java.util.List; 
     22import java.util.concurrent.TimeUnit; 
     23import java.util.concurrent.locks.Lock; 
     24import java.util.concurrent.locks.ReentrantLock; 
    2225 
    2326import org.slf4j.Logger; 
     
    4649    private int currentTransactionId; 
    4750 
     51 
    4852    /** Whether a transaction is currently in progress*/ 
    4953    private boolean transactionInProgress; 
    5054 
     55 
    5156    /** Default Constructor*/ 
    5257    public StorageEngine(){ 
    53         transactionInProgress=false; 
     58 
    5459    } 
    5560 
     
    5762        log.debug("Storage task completed {}, for transaction id [{}]",result, currentTransactionId); 
    5863        transactionInProgress=false; 
     64 
    5965    } 
    6066 
     
    6773        } 
    6874        log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(),transactionId); 
     75        this.currentTransactionId = transactionId; 
    6976        transactionInProgress=true; 
    70         this.currentTransactionId = transactionId; 
    7177        AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, entryHandler,attributeAssociationEngine); 
    7278        asyncEntryStorage.execute(events,this); 
     79 
     80 
    7381    } 
    7482 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/MemoryEntryHandler.java

    r707 r736  
    2525 
    2626import java.util.ArrayList; 
     27import java.util.HashMap; 
    2728import java.util.LinkedHashSet; 
    2829import java.util.List; 
     30import java.util.Map; 
    2931import java.util.Set; 
    3032 
    3133import uk.ac.cardiff.model.event.Event; 
     34import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    3235import uk.ac.cardiff.raptor.store.EntryHandler; 
    3336 
     
    5154        private Set<Event> entries; 
    5255 
    53         /** stores the set of latest unique entries. That is, those with the latest and same 
    54          *  DateTime, but different state (attribute values). This set is check when adding new 
    55          *  entries, and is not removed when records are removed. 
    56          */ 
    57         private Set<Event> latestEqualEntries; 
    5856 
    5957        public MemoryEntryHandler(){ 
    6058                entries = new LinkedHashSet<Event>(); 
    61                 latestEqualEntries = new LinkedHashSet<Event>(); 
    6259        } 
    6360 
    6461        public void addEntries(List<Event> entries){ 
    6562                log.debug("Current: "+this.entries.size()+" in: "+entries.size()); 
    66  
     63                int notAdded = 0; 
    6764                for (Event event: entries){ 
    68                     addEntry(event); 
     65                    boolean didAdd = addEntry(event); 
     66                    if (didAdd==false) 
     67                        notAdded++; 
    6968 
    7069                } 
    71                 log.debug("Total No. of Entries "+this.entries.size()+" Latest Entry at: "+getLatestEntryTime()); 
     70                log.debug("Total No. of Entries {}, Lastest Entry at: {}, with {} duplicates",new Object[]{this.entries.size(),getLatestEntryTime(),notAdded}); 
    7271        } 
    7372 
    7473 
     74 
    7575        /** 
    76          * If newer entry, just add to the set. 
    77          * If equal, first check the <code>latestEqualEntries</code> set, 
    78          * if contained in this set, then it has already been added. If not 
    79          * add. Importantly, we do not just add to the entries set (which would 
    80          * not allow duplicates) because the set is cleared when information is sent 
    81          * to the UA. 
     76         * Checks whether this event is already stored, if not, then it 
     77         * adds the <code>event</code> to the <code>entries<code> set. 
     78         * 
     79         * @param event the event to store 
    8280         */ 
    83         public void addEntry(Event entry){ 
    84             boolean isAfter = isAfter(entry); 
    85             boolean isEqual = isEqual(entry); 
    86             if (isAfter){ 
    87                 entries.add(entry); 
    88                 updateLastEntry(entry); 
     81        public boolean addEntry(Event event){ 
     82            if (!entries.contains(event)){ 
     83                entries.add(event); 
     84                updateLastEntry(event); 
     85                return true; 
    8986            } 
    90             else if (isEqual){ 
    91                 boolean isAlreadyInLatest = latestEqualEntries.contains(entry); 
    92                 if (isAlreadyInLatest){ 
    93                     log.error("Duplicated entries found\n{}",entry); 
    94                 } 
    95                 if (!isAlreadyInLatest){ 
    96                     entries.add(entry); 
    97                     updateLastEntry(entry); 
    98                 } 
     87            else{ 
     88                return false; 
    9989            } 
    10090 
    10191        } 
    10292 
    103         private void updateLastEntry(Event entry){ 
    104                 DateTime entryTime = entry.getEventTime(); 
     93        private void updateLastEntry(Event event){ 
     94                DateTime entryTime = event.getEventTime(); 
    10595                if (getLatestEntryTime()==null)setLatestEntryTime(entryTime); 
    10696                if (entryTime.isAfter(getLatestEntryTime())){ 
    10797                    setLatestEntryTime(entryTime); 
    108                     latestEqualEntries.clear(); 
    109                     latestEqualEntries.add(entry); 
    110                 } 
    111                 if (entryTime.isEqual(getLatestEntryTime())){ 
    112                     latestEqualEntries.add(entry); 
     98 
    11399                } 
    114100        } 
     
    122108        } 
    123109 
    124         /** 
    125          * @param authE 
    126          * @return 
    127          */ 
    128         public boolean isNewerOrEqual(Event event) { 
    129                 if (latestEntryTime==null) return true; 
    130                 if (!event.getEventTime().isBefore(latestEntryTime)) return true; 
    131                 return false; 
    132         } 
    133110 
    134  
    135         public boolean isEqual(Event event) { 
    136             if (latestEntryTime==null) return false; 
    137             return event.getEventTime().isEqual(latestEntryTime); 
    138         } 
    139  
    140         public boolean isAfter(Event event) { 
    141             if (latestEntryTime==null) return true; 
    142             return event.getEventTime().isAfter(latestEntryTime); 
    143         } 
    144111 
    145112        /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r713 r736  
    6767        /** Used to hold events temporarily before they are persisted, allows 
    6868         * resilience if events can not be immediately stored, for example 
    69          * failure of the underlying persistent store */ 
     69         * failure of the underlying persistent store. Also, as its a set, it 
     70         * prevents the addition of duplicate values */ 
    7071        private Set<Event> persistQueue; 
    7172 
     
    103104        /** 
    104105         * The <code>entries</code> are stored in the <code>persistQueue</code> until they are persisted. If an exception is thrown before 
    105          * they are persisted, they remain in the <code>persistQueue</code>. 
     106         * they are persisted, they remain in the <code>persistQueue</code>. This method then saves this collection in batch, as opposed to the 
     107         * <code>addEntry</code> method which stores events one at a time. In order to detect duplicates, a query is run over the database in order 
     108         * to check duplicates within already stored events, as well as adding new events to a <code>Set</code> <code>persist</code> which 
     109         * prevents duplicates in the incomming <code>List</code> of entries 
    106110         * 
    107111         * @param entries the list of events that are to be stored 
     
    114118                int duplicates = 0; 
    115119                persistQueue.addAll(entries); 
    116                 List<Event> persist = new ArrayList<Event>(); 
     120 
     121                Set<Event> persist = new HashSet<Event>(); 
    117122 
    118123                for (Event event : persistQueue) { 
     
    146151        } 
    147152 
    148         public void addEntry(Event event) { 
     153        public boolean addEntry(Event event) { 
    149154                int hashcode = 0; 
    150155                try { 
     
    152157                } catch (Exception e) { 
    153158                    log.error("Could not get hashcode for event {}, event not stored"); 
    154                     return; 
     159                    return false; 
    155160                } 
    156161                String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and hashCode =?"; 
     
    160165                if (numberOfDuplicates == 0){ 
    161166                   dataConnection.save(event); 
     167                   return true; 
    162168                } 
    163169                else{ 
    164170                        log.error("Duplicated event found\n{}", event); 
    165                 } 
    166  
     171                        return false; 
     172                } 
    167173 
    168174        } 
Note: See TracChangeset for help on using the changeset viewer.