Changeset 672
- Timestamp:
- 04/12/11 18:50:53 (2 years ago)
- Location:
- raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
- Files:
-
- 2 added
- 1 deleted
- 12 edited
- 1 copied
- 2 moved
-
event/expansion/AttributeAssociationEngine.java (modified) (1 diff)
-
exceptions (deleted)
-
remoting/client/EventReleaseClient.java (modified) (1 diff)
-
remoting/client/ReleaseFailureException.java (copied) (copied from raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/exceptions/ReleaseFailureException.java) (1 diff)
-
remoting/client/impl/EventReleaseClientImpl.java (modified) (1 diff)
-
remoting/client/sei/impl/ClientTLSParameters.java (modified) (1 diff)
-
remoting/policy/ElapsedTimePushPolicy.java (modified) (1 diff)
-
remoting/policy/EntryNoElapsedTimePushPolicy.java (modified) (1 diff)
-
remoting/policy/EntryNoPushPolicy.java (modified) (1 diff)
-
store/AsynchronousEntryStorage.java (modified) (2 diffs)
-
store/EntryHandler.java (modified) (7 diffs)
-
store/StorageEngine.java (added)
-
store/StoreEntriesTask.java (modified) (3 diffs)
-
store/StoreEntriesTaskCallbackInterface.java (modified) (1 diff)
-
store/dao/DefaultDataConnection.java (moved) (moved from raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/MUADataConnectionImpl.java) (4 diffs)
-
store/dao/RaptorDataConnection.java (moved) (moved from raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/MUADataConnection.java) (2 diffs)
-
store/dao/StorageException.java (added)
-
store/impl/PersistantEntryHandler.java (modified) (9 diffs)
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 */ 1 16 /** 2 17 * -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java
r627 r672 23 23 import uk.ac.cardiff.model.ClientMetadata; 24 24 import uk.ac.cardiff.model.event.Event; 25 import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException;26 25 27 26 /** -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/ReleaseFailureException.java
r669 r672 14 14 * limitations under the License. 15 15 */ 16 package uk.ac.cardiff.raptor. exceptions;16 package uk.ac.cardiff.raptor.remoting.client; 17 17 18 18 public class ReleaseFailureException extends Exception{ -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/impl/EventReleaseClientImpl.java
r627 r672 20 20 import uk.ac.cardiff.model.ClientMetadata; 21 21 import uk.ac.cardiff.model.event.Event; 22 import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException;23 22 import uk.ac.cardiff.raptor.registry.EndpointRegistry; 24 23 import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 25 24 import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 25 import uk.ac.cardiff.raptor.remoting.client.ReleaseFailureException; 26 26 27 27 -
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 */ 1 16 /** 2 17 * -
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 */ 1 16 package uk.ac.cardiff.raptor.remoting.policy; 2 17 -
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 */ 1 16 package uk.ac.cardiff.raptor.remoting.policy; 2 17 -
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 */ 1 16 package uk.ac.cardiff.raptor.remoting.policy; 2 17 -
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 */ 1 16 package uk.ac.cardiff.raptor.store; 2 17 … … 16 31 /** class logger */ 17 32 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 19 41 public void storageResultCallback(Object result) { 20 log.debug("Storage task completed ");21 42 log.debug("Storage task completed {}, for transaction id [{}]",result, transactionId); 43 22 44 } 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); 27 48 ExecutorService es = Executors.newSingleThreadExecutor(); 28 49 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(); 36 51 } 37 52 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 38 67 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/EntryHandler.java
r669 r672 27 27 28 28 import uk.ac.cardiff.model.event.Event; 29 import uk.ac.cardiff.raptor.store.dao.StorageException; 29 30 30 31 … … 32 33 33 34 /** 34 * 35 * 35 36 * @param entries 36 37 */ 37 public void addEntries(List<Event> entries) ;38 public void addEntries(List<Event> entries) throws StorageException; 38 39 39 40 /** 40 * 41 * 41 42 * @return 42 43 */ … … 44 45 45 46 /** 46 * 47 * 47 48 * @param entries 48 49 */ … … 65 66 66 67 /** 67 * 68 * 68 69 * @param query 69 70 * @return … … 72 73 73 74 /** 74 * 75 * 75 76 * @param query 76 77 * @return … … 79 80 80 81 /** 81 * 82 * 82 83 * @return 83 84 */ … … 91 92 public Object queryUnique(String query, Object[] parameters); 92 93 93 /**94 * @param events95 */96 public void addEntriesAsynchronous(List<Event> events);97 94 98 95 } -
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 */ 1 16 /** 2 17 * … … 4 19 package uk.ac.cardiff.raptor.store; 5 20 21 import java.util.List; 6 22 import java.util.concurrent.Callable; 7 import java.util.concurrent.ExecutorService;8 23 9 24 import org.slf4j.Logger; 10 25 import org.slf4j.LoggerFactory; 11 26 12 import uk.ac.cardiff.raptor.store.dao.MUADataConnection; 13 import uk.ac.cardiff.raptor.store.impl.PersistantEntryHandler; 27 import uk.ac.cardiff.model.event.Event; 28 import uk.ac.cardiff.raptor.store.dao.StorageException; 29 14 30 15 31 … … 19 35 */ 20 36 public class StoreEntriesTask implements Callable<Boolean>{ 21 37 22 38 /** class logger */ 23 39 private final Logger log = LoggerFactory.getLogger(StoreEntriesTask.class); 24 40 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 } 28 55 29 56 public Boolean call() throws Exception { 30 57 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")); 35 67 return true; 36 68 } 37 69 38 /**39 * @param dataConnection the dataConnection to set40 */41 public void setDataConnection(MUADataConnection dataConnection) {42 this.dataConnection = dataConnection;43 }44 45 /**46 * @return the dataConnection47 */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 60 70 } -
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 */ 1 16 package uk.ac.cardiff.raptor.store; 2 17 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java
r669 r672 21 21 import org.apache.log4j.Logger; 22 22 import org.hibernate.SessionFactory; 23 import org.springframework.dao.DataAccessException; 23 24 import org.springframework.dao.support.DataAccessUtils; 24 25 import org.springframework.orm.hibernate3.HibernateTemplate; … … 26 27 /** 27 28 * @author philsmart 28 * 29 * 29 30 */ 30 public class MUADataConnectionImpl implements MUADataConnection {31 public class DefaultDataConnection implements RaptorDataConnection { 31 32 32 33 /* hibernate template to persist classes */ … … 36 37 37 38 /** class logger */ 38 private static Logger log = Logger.getLogger( MUADataConnectionImpl.class);39 private static Logger log = Logger.getLogger(DefaultDataConnection.class); 39 40 40 public void save(Object object) { 41 // log.debug("Saving..."+entry); 41 public void save(Object object) throws DataAccessException{ 42 42 hibernateTemplate.saveOrUpdate(object); 43 // hibernateTemplate.flush();44 45 43 } 46 44 47 public void saveAll(Collection collection) { 48 // log.debug("Saving..."); 45 public void saveAll(Collection collection) throws DataAccessException{ 49 46 hibernateTemplate.saveOrUpdateAll(collection); 50 // hibernateTemplate.flush();51 52 47 } 53 48 … … 78 73 * delete them. Not sure if all these entries are loaded then delete if lazy 79 74 * loading is false.</p> (non-Javadoc) 80 * 75 * 81 76 * @see main.uk.ac.cf.dao.internal.ICADataConnection#deleteAllEntries() 82 77 */ 83 78 @Override 84 public void deleteAllEntries(Collection entries) {79 public void deleteAllEntries(Collection entries) throws DataAccessException{ 85 80 hibernateTemplate.deleteAll(entries); 86 81 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/RaptorDataConnection.java
r669 r672 22 22 import java.util.List; 23 23 24 import org.springframework.dao.DataAccessException; 25 24 26 import uk.ac.cardiff.model.event.Event; 25 27 … … 28 30 * 29 31 */ 30 public interface MUADataConnection {32 public interface RaptorDataConnection { 31 33 32 34 public List runQuery(String query, Object[] parameters); 33 35 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; 37 39 38 40 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java
r669 r672 20 20 21 21 import java.util.ArrayList; 22 import java.util.Arrays; 22 23 import java.util.LinkedHashSet; 23 24 import java.util.List; … … 31 32 import org.slf4j.Logger; 32 33 import org.slf4j.LoggerFactory; 34 import org.springframework.dao.DataAccessException; 33 35 34 36 import uk.ac.cardiff.model.event.Event; … … 38 40 import uk.ac.cardiff.raptor.store.EntryHandler; 39 41 import uk.ac.cardiff.raptor.store.StoreEntriesTask; 40 import uk.ac.cardiff.raptor.store.dao.MUADataConnection; 42 import uk.ac.cardiff.raptor.store.dao.RaptorDataConnection; 43 import uk.ac.cardiff.raptor.store.dao.StorageException; 41 44 42 45 /** 43 46 * @author philsmart 44 * 47 * 45 48 */ 46 49 public class PersistantEntryHandler implements EntryHandler { … … 53 56 54 57 /** data connection used to persist entries */ 55 private MUADataConnection dataConnection;58 private RaptorDataConnection dataConnection; 56 59 57 60 /** … … 60 63 */ 61 64 private Set<Event> entries; 62 65 63 66 /** Used to hold events temporarily before they are persisted, allows 64 67 * resilience if events can not be immediately stored, for example … … 66 69 private Set<Event> storeQueue; 67 70 68 public PersistantEntryHandler( MUADataConnection dataConnection) {71 public PersistantEntryHandler(RaptorDataConnection dataConnection) { 69 72 this.setDataConnection(dataConnection); 70 73 … … 108 111 } 109 112 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{ 111 120 log.info("Persistent Entry Handler has {} entries, with {} new entries inputted", this.getNumberOfEntries(), entries.size()); 112 121 int duplicates = 0; 113 for (Event entry : entries) { 122 List<Event> persist = new ArrayList<Event>(); 123 for (Event event : entries) { 114 124 int hashcode = 0; 115 125 try { 116 hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", e ntry)).intValue();126 hashcode = ((Integer) ReflectionHelper.getValueFromObject("hashCode", event)).intValue(); 117 127 } catch (Exception e) { 128 log.error("Could not get hashcode for event {}, event not stored"); 129 continue; 118 130 } 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); 125 150 } 126 151 … … 149 174 } 150 175 151 public void setDataConnection( MUADataConnection dataConnection) {176 public void setDataConnection(RaptorDataConnection dataConnection) { 152 177 this.dataConnection = dataConnection; 153 178 } 154 179 155 public MUADataConnection getDataConnection() {180 public RaptorDataConnection getDataConnection() { 156 181 return dataConnection; 157 182 } … … 165 190 } 166 191 167 public void addEntriesAsynchronous(List<Event> events) {168 AsynchronousEntryStorage asyncEntryStorage = new AsynchronousEntryStorage();169 asyncEntryStorage.store(events);170 171 }172 192 173 193 }
Note: See TracChangeset
for help on using the changeset viewer.
