Changeset 672 for raptor-client


Ignore:
Timestamp:
04/12/11 18:50:53 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
2 added
1 deleted
12 edited
1 copied
2 moved

Legend:

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

    r663 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java

    r627 r672  
    2323import uk.ac.cardiff.model.ClientMetadata; 
    2424import uk.ac.cardiff.model.event.Event; 
    25 import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException; 
    2625 
    2726/** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/ReleaseFailureException.java

    r669 r672  
    1414 * limitations under the License. 
    1515 */ 
    16 package uk.ac.cardiff.raptor.exceptions; 
     16package uk.ac.cardiff.raptor.remoting.client; 
    1717 
    1818public class ReleaseFailureException extends Exception{ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/impl/EventReleaseClientImpl.java

    r627 r672  
    2020import uk.ac.cardiff.model.ClientMetadata; 
    2121import uk.ac.cardiff.model.event.Event; 
    22 import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException; 
    2322import uk.ac.cardiff.raptor.registry.EndpointRegistry; 
    2423import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 
    2524import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 
     25import uk.ac.cardiff.raptor.remoting.client.ReleaseFailureException; 
    2626 
    2727 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/ClientTLSParameters.java

    r654 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/ElapsedTimePushPolicy.java

    r656 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.remoting.policy; 
    217 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoElapsedTimePushPolicy.java

    r656 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.remoting.policy; 
    217 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoPushPolicy.java

    r656 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.remoting.policy; 
    217 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/AsynchronousEntryStorage.java

    r669 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.store; 
    217 
     
    1631        /** class logger */ 
    1732        private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStorage.class); 
    18                  
     33 
     34        /** An ID used to track the progress of any transaction */ 
     35        private int transactionId; 
     36 
     37        public AsynchronousEntryStorage(int transactionId){ 
     38            this.setTransactionId(transactionId); 
     39        } 
     40 
    1941        public void storageResultCallback(Object result) { 
    20                 log.debug("Storage task completed"); 
    21                  
     42                log.debug("Storage task completed {}, for transaction id [{}]",result, transactionId); 
     43 
    2244        } 
    23          
    24         public void store(List<Event> events){ 
    25                 StoreEntriesTask storeEntryTask = new StoreEntriesTask(); 
    26                 storeEntryTask.setAsynchronousEntryStorage(this); 
     45 
     46        public void store(EntryHandler entryHandler, List<Event> events){ 
     47                StoreEntriesTask storeEntryTask = new StoreEntriesTask(entryHandler, events,this); 
    2748                ExecutorService es = Executors.newSingleThreadExecutor(); 
    2849                es.submit(storeEntryTask); 
    29 //              try { 
    30 //                      task.get(); 
    31 //                      log.debug("Result from task.get () = "); 
    32 //              } catch (Exception e) { 
    33 //                      log.error("Error adding events to the database...events stored for future storage...",e); 
    34 //              } 
    35 //              es.shutdown(); 
     50                es.shutdown(); 
    3651        } 
    3752 
     53    /** 
     54     * @param transactionId the transactionId to set 
     55     */ 
     56    public void setTransactionId(int transactionId) { 
     57        this.transactionId = transactionId; 
     58    } 
     59 
     60    /** 
     61     * @return the transactionId 
     62     */ 
     63    public int getTransactionId() { 
     64        return transactionId; 
     65    } 
     66 
    3867} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java

    r669 r672  
    2727 
    2828import uk.ac.cardiff.model.event.Event; 
     29import uk.ac.cardiff.raptor.store.dao.StorageException; 
    2930 
    3031 
     
    3233 
    3334        /** 
    34          *  
     35         * 
    3536         * @param entries 
    3637         */ 
    37         public void addEntries(List<Event> entries); 
     38        public void addEntries(List<Event> entries) throws StorageException; 
    3839 
    3940        /** 
    40          *  
     41         * 
    4142         * @return 
    4243         */ 
     
    4445 
    4546        /** 
    46          *  
     47         * 
    4748         * @param entries 
    4849         */ 
     
    6566 
    6667        /** 
    67          *  
     68         * 
    6869         * @param query 
    6970         * @return 
     
    7273 
    7374        /** 
    74          *  
     75         * 
    7576         * @param query 
    7677         * @return 
     
    7980 
    8081        /** 
    81          *  
     82         * 
    8283         * @return 
    8384         */ 
     
    9192        public Object queryUnique(String query, Object[] parameters); 
    9293 
    93         /** 
    94          * @param events 
    95          */ 
    96         public void addEntriesAsynchronous(List<Event> events); 
    9794 
    9895} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEntriesTask.java

    r669 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116/** 
    217 * 
     
    419package uk.ac.cardiff.raptor.store; 
    520 
     21import java.util.List; 
    622import java.util.concurrent.Callable; 
    7 import java.util.concurrent.ExecutorService; 
    823 
    924import org.slf4j.Logger; 
    1025import org.slf4j.LoggerFactory; 
    1126 
    12 import uk.ac.cardiff.raptor.store.dao.MUADataConnection; 
    13 import uk.ac.cardiff.raptor.store.impl.PersistantEntryHandler; 
     27import uk.ac.cardiff.model.event.Event; 
     28import uk.ac.cardiff.raptor.store.dao.StorageException; 
     29 
    1430 
    1531 
     
    1935 */ 
    2036public class StoreEntriesTask implements Callable<Boolean>{ 
    21          
     37 
    2238        /** class logger */ 
    2339        private final Logger log = LoggerFactory.getLogger(StoreEntriesTask.class); 
    2440 
    25     private MUADataConnection dataConnection; 
    26      
    27     private AsynchronousEntryStorage asynchronousEntryStorage; 
     41        /** The entry handler used to store entries (e.g. events)*/ 
     42    private EntryHandler entryHandler; 
     43 
     44    /** The callback interface that is called once the <code>call</code> method has completed*/ 
     45    private StoreEntriesTaskCallbackInterface storeCallback; 
     46 
     47    /** The events that need to be stored */ 
     48    private List<Event> events; 
     49 
     50    public StoreEntriesTask(EntryHandler entryHandler, List<Event> events, StoreEntriesTaskCallbackInterface storeCallback){ 
     51        this.storeCallback = storeCallback; 
     52        this.entryHandler = entryHandler; 
     53        this.events = events; 
     54    } 
    2855 
    2956    public Boolean call() throws Exception { 
    3057        log.debug("Storing entries"); 
    31         for (int i=0; i < 10000000; i++){ 
    32                 //System.out.println("1"); 
    33                  
    34         } 
     58        try{ 
     59            entryHandler.addEntries(events); 
     60        } 
     61        catch(StorageException e){ 
     62            log.error("Failed to store events asynchronously"); 
     63            storeCallback.storageResultCallback(new Boolean("false")); 
     64            return false; 
     65        } 
     66        storeCallback.storageResultCallback(new Boolean("true")); 
    3567        return true; 
    3668    } 
    3769 
    38     /** 
    39      * @param dataConnection the dataConnection to set 
    40      */ 
    41     public void setDataConnection(MUADataConnection dataConnection) { 
    42         this.dataConnection = dataConnection; 
    43     } 
    44  
    45     /** 
    46      * @return the dataConnection 
    47      */ 
    48     public MUADataConnection getDataConnection() { 
    49         return dataConnection; 
    50     } 
    51  
    52         public void setAsynchronousEntryStorage(AsynchronousEntryStorage asynchronousEntryStorage) { 
    53                 this.asynchronousEntryStorage = asynchronousEntryStorage; 
    54         } 
    55  
    56         public AsynchronousEntryStorage getAsynchronousEntryStorage() { 
    57                 return asynchronousEntryStorage; 
    58         } 
    59  
    6070} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEntriesTaskCallbackInterface.java

    r669 r672  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.store; 
    217 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java

    r669 r672  
    2121import org.apache.log4j.Logger; 
    2222import org.hibernate.SessionFactory; 
     23import org.springframework.dao.DataAccessException; 
    2324import org.springframework.dao.support.DataAccessUtils; 
    2425import org.springframework.orm.hibernate3.HibernateTemplate; 
     
    2627/** 
    2728 * @author philsmart 
    28  *  
     29 * 
    2930 */ 
    30 public class MUADataConnectionImpl implements MUADataConnection { 
     31public class DefaultDataConnection implements RaptorDataConnection { 
    3132 
    3233        /* hibernate template to persist classes */ 
     
    3637 
    3738        /** class logger */ 
    38         private static Logger log = Logger.getLogger(MUADataConnectionImpl.class); 
     39        private static Logger log = Logger.getLogger(DefaultDataConnection.class); 
    3940 
    40         public void save(Object object) { 
    41                 // log.debug("Saving..."+entry); 
     41        public void save(Object object) throws DataAccessException{ 
    4242                hibernateTemplate.saveOrUpdate(object); 
    43                 // hibernateTemplate.flush(); 
    44  
    4543        } 
    4644 
    47         public void saveAll(Collection collection) { 
    48                 // log.debug("Saving..."); 
     45        public void saveAll(Collection collection) throws DataAccessException{ 
    4946                hibernateTemplate.saveOrUpdateAll(collection); 
    50                 // hibernateTemplate.flush(); 
    51  
    5247        } 
    5348 
     
    7873         * delete them. Not sure if all these entries are loaded then delete if lazy 
    7974         * loading is false.</p> (non-Javadoc) 
    80          *  
     75         * 
    8176         * @see main.uk.ac.cf.dao.internal.ICADataConnection#deleteAllEntries() 
    8277         */ 
    8378        @Override 
    84         public void deleteAllEntries(Collection entries) { 
     79        public void deleteAllEntries(Collection entries) throws DataAccessException{ 
    8580                hibernateTemplate.deleteAll(entries); 
    8681 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/RaptorDataConnection.java

    r669 r672  
    2222import java.util.List; 
    2323 
     24import org.springframework.dao.DataAccessException; 
     25 
    2426import uk.ac.cardiff.model.event.Event; 
    2527 
     
    2830 * 
    2931 */ 
    30 public interface MUADataConnection { 
     32public interface RaptorDataConnection { 
    3133 
    3234        public List runQuery(String query, Object[] parameters); 
    3335        public Object runQueryUnique(String query, Object[] parameters); 
    34         public void save(Object object); 
    35         public void deleteAllEntries(Collection entries); 
    36         public void saveAll(Collection collection); 
     36        public void save(Object object) throws DataAccessException; 
     37        public void deleteAllEntries(Collection entries) throws DataAccessException; 
     38        public void saveAll(Collection collection) throws DataAccessException; 
    3739 
    3840 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r669 r672  
    2020 
    2121import java.util.ArrayList; 
     22import java.util.Arrays; 
    2223import java.util.LinkedHashSet; 
    2324import java.util.List; 
     
    3132import org.slf4j.Logger; 
    3233import org.slf4j.LoggerFactory; 
     34import org.springframework.dao.DataAccessException; 
    3335 
    3436import uk.ac.cardiff.model.event.Event; 
     
    3840import uk.ac.cardiff.raptor.store.EntryHandler; 
    3941import uk.ac.cardiff.raptor.store.StoreEntriesTask; 
    40 import uk.ac.cardiff.raptor.store.dao.MUADataConnection; 
     42import uk.ac.cardiff.raptor.store.dao.RaptorDataConnection; 
     43import uk.ac.cardiff.raptor.store.dao.StorageException; 
    4144 
    4245/** 
    4346 * @author philsmart 
    44  *  
     47 * 
    4548 */ 
    4649public class PersistantEntryHandler implements EntryHandler { 
     
    5356 
    5457        /** data connection used to persist entries */ 
    55         private MUADataConnection dataConnection; 
     58        private RaptorDataConnection dataConnection; 
    5659 
    5760        /** 
     
    6063         */ 
    6164        private Set<Event> entries; 
    62          
     65 
    6366        /** Used to hold events temporarily before they are persisted, allows 
    6467         * resilience if events can not be immediately stored, for example 
     
    6669        private Set<Event> storeQueue; 
    6770 
    68         public PersistantEntryHandler(MUADataConnection dataConnection) { 
     71        public PersistantEntryHandler(RaptorDataConnection dataConnection) { 
    6972                this.setDataConnection(dataConnection); 
    7073 
     
    108111        } 
    109112 
    110         public void addEntries(List<Event> entries) { 
     113        /** 
     114         * 
     115         * 
     116         * @param entries the list of events that are to be stored 
     117         * @throws 
     118         */ 
     119        public void addEntries(List<Event> entries) throws StorageException{ 
    111120                log.info("Persistent Entry Handler has {} entries, with {} new entries inputted", this.getNumberOfEntries(), entries.size()); 
    112121                int duplicates = 0; 
    113                 for (Event entry : entries) { 
     122                List<Event> persist = new ArrayList<Event>(); 
     123                for (Event event : entries) { 
    114124                        int hashcode = 0; 
    115125                        try { 
    116                                 hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", entry)).intValue(); 
     126                                hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 
    117127                        } catch (Exception e) { 
     128                            log.error("Could not get hashcode for event {}, event not stored"); 
     129                            continue; 
    118130                        } 
    119                         int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + entry.getClass().getSimpleName() 
    120                                         + " where eventTime = '" + entry.getEventTime() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
    121                         if (numberOfDuplicates == 0) 
    122                                 dataConnection.save(entry); 
    123                         else 
    124                                 duplicates++; 
     131                        //int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
     132                        //              + " where eventTime = '" + event.getEventTime() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
     133                        Object[] parameters= new Object[]{event.getEventTime(),hashcode}; 
     134                        log.debug("Values: "+Arrays.toString(parameters)); 
     135                        int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName()+" where eventTime = ? " + 
     136                                        "and hashCode =?", parameters)).intValue(); 
     137 
     138                        if (numberOfDuplicates == 0){ 
     139                            persist.add(event); 
     140                        } 
     141                        else{ 
     142                            duplicates++; 
     143                        } 
     144                } 
     145                try{ 
     146                    dataConnection.saveAll(persist); 
     147                } 
     148                catch(DataAccessException e){ 
     149                    throw new StorageException("Could not persist events",e); 
    125150                } 
    126151 
     
    149174        } 
    150175 
    151         public void setDataConnection(MUADataConnection dataConnection) { 
     176        public void setDataConnection(RaptorDataConnection dataConnection) { 
    152177                this.dataConnection = dataConnection; 
    153178        } 
    154179 
    155         public MUADataConnection getDataConnection() { 
     180        public RaptorDataConnection getDataConnection() { 
    156181                return dataConnection; 
    157182        } 
     
    165190        } 
    166191 
    167         public void addEntriesAsynchronous(List<Event> events) { 
    168                 AsynchronousEntryStorage asyncEntryStorage = new AsynchronousEntryStorage(); 
    169                 asyncEntryStorage.store(events); 
    170  
    171         } 
    172192 
    173193} 
Note: See TracChangeset for help on using the changeset viewer.