Changeset 604
- Timestamp:
- 03/27/11 23:41:52 (2 years ago)
- Location:
- raptor-ica-embedded/trunk/src/main
- Files:
-
- 7 edited
- 2 moved
-
config/dao-beans.xml (modified) (2 diffs)
-
config/data-access.xml (modified) (2 diffs)
-
config/event-release.xml (moved) (moved from raptor-ica-embedded/trunk/src/main/config/ua-registry.xml) (3 diffs)
-
config/ica-core.xml (moved) (moved from raptor-ica-embedded/trunk/src/main/config/beans.xml) (2 diffs)
-
config/raptorica (modified) (1 diff)
-
java/uk/ac/cardiff/raptor/raptorica/engine/ICAEngine.java (modified) (2 diffs)
-
java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java (modified) (1 diff)
-
java/uk/ac/cardiff/raptor/raptorica/server/RunServer.java (modified) (1 diff)
-
java/uk/ac/cardiff/raptor/raptorica/service/impl/ICAProcessImpl.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
raptor-ica-embedded/trunk/src/main/config/dao-beans.xml
r459 r604 20 20 <beans xmlns="http://www.springframework.org/schema/beans" 21 21 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 22 xmlns:jaxws="http://cxf.apache.org/jaxws"23 22 xsi:schemaLocation=" 24 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 25 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 23 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 26 24 27 25 … … 46 44 <property name="mappingResources"> 47 45 <list> 48 <value>uk/ac/cardiff/model/e ntry.hbm.xml</value>46 <value>uk/ac/cardiff/model/event.hbm.xml</value> 49 47 <value>uk/ac/cardiff/raptor/raptorica/model/entrymetadata.hbm.xml</value> 50 48 </list> -
raptor-ica-embedded/trunk/src/main/config/data-access.xml
r528 r604 45 45 --> 46 46 <bean id="shibbolethAuditLFP" class="uk.ac.cardiff.raptor.raptorica.dao.external.file.LogFileParser"> 47 <property name="entryHandler"><ref bean=" persistantEntryHandler"></ref></property>47 <property name="entryHandler"><ref bean="memoryEntryHandler"></ref></property> 48 48 <property name="logfile"> 49 <value>file:/// Users/philsmart/Documents/DataSets/Logs/shib2comb-sorted-to-20110213.log49 <value>file:///home/philsmart/Documents/DataSets/Logs/example.log 50 50 </value> 51 51 </property> … … 60 60 all other fields are ignored, this is run before the exclusion list--> 61 61 <property name="inclusionList"> 62 <bean class="uk.ac.cardiff.raptor.raptorica.model. InclusionList">62 <bean class="uk.ac.cardiff.raptor.raptorica.model.filter.InclusionList"> 63 63 <property name="inclusionEntries"> 64 64 <list> 65 <bean class ="uk.ac.cardiff.raptor.raptorica.model. RegexInclusionEntry">65 <bean class ="uk.ac.cardiff.raptor.raptorica.model.filter.match.RegexInclusionEntry"> 66 66 <property name ="fieldName" value="messageProfileId"/> 67 67 <property name="match" value=":sso"/> -
raptor-ica-embedded/trunk/src/main/config/event-release.xml
r595 r604 26 26 27 27 28 <bean id=" uaRegistry" class="uk.ac.cardiff.raptor.raptorica.engine.UARegistry">29 <property name =" UAEntries">28 <bean id="endpointRegistry" class="uk.ac.cardiff.raptor.registry.EndpointRegistry"> 29 <property name ="endpoints"> 30 30 <list> 31 <bean id="cardiff ShibUA" class="uk.ac.cardiff.raptor.raptorica.model.UAEntry">32 <property name="serviceEndpoint"><value>http://ipower.insrv.cf.ac.uk: 9080/UA/UnitAggregator</value></property>31 <bean id="cardiffRaptorMUA" class="uk.ac.cardiff.raptor.registry.Endpoint"> 32 <property name="serviceEndpoint"><value>http://ipower.insrv.cf.ac.uk:8080/MUA/MultiUnitAggregator</value></property> 33 33 <property name="pushPolicy"><ref bean="genericPushPolicy"></ref></property> 34 34 <!--<property name="attributeFilterPolicy"><ref bean="removePrincipleFilterPolicy"></ref></property>--> … … 40 40 <!-- policy for release of entries to the UA --> 41 41 42 <bean id="genericPushPolicy" class="uk.ac.cardiff.raptor.r aptorica.model.PushPolicy">42 <bean id="genericPushPolicy" class="uk.ac.cardiff.raptor.remoting.policy.PushPolicy"> 43 43 <property name="pushOnOrAfterNoEntries"><value>10</value></property> 44 44 </bean> … … 46 46 <!-- Attribute filter policies --> 47 47 48 <bean id="removePrincipleFilterPolicy" class="uk.ac.cardiff.raptor. raptorica.model.AttributeFilterPolicy">48 <bean id="removePrincipleFilterPolicy" class="uk.ac.cardiff.raptor.attribute.filtering.AttributeFilterPolicy"> 49 49 <property name="policyName"><value>removePrincipleName</value></property> 50 50 <property name="attributeRules"> 51 51 <list> 52 <bean class="uk.ac.cardiff.raptor. raptorica.model.AttributeRule">52 <bean class="uk.ac.cardiff.raptor.attribute.filtering.AttributeRule"> 53 53 <property name="attributeID"><value>requestHost</value></property> 54 54 <property name="denyValueRule"> 55 <bean class="uk.ac.cardiff.raptor. raptorica.model.MatchRule">55 <bean class="uk.ac.cardiff.raptor.attribute.filtering.match.MatchRule"> 56 56 <property name="enabled"><value>true</value></property> 57 57 </bean> -
raptor-ica-embedded/trunk/src/main/config/ica-core.xml
r595 r604 20 20 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 21 21 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 22 23 24 <import resource="classpath:META-INF/cxf/cxf.xml" />25 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />26 <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />27 28 <!-- WEB SERVICE ENDPOINT INTERFACE (SEI) SETUP -->29 <jaxws:endpoint id="collector" implementor="#CollectorEndpoint"30 address="/Collector">31 <jaxws:serviceFactory>32 <ref bean='jaxws-and-aegis-service-factory' />33 </jaxws:serviceFactory>34 </jaxws:endpoint>35 36 <bean id="CollectorEndpoint" class="uk.ac.cardiff.raptor.raptorica.wsinterface.impl.CollectorImpl">37 <property name="processEngine">38 <ref bean="ICAProcess"></ref>39 </property>40 </bean>41 42 <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"43 scope="prototype" />44 <bean id="jaxws-and-aegis-service-factory" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"45 scope="prototype">46 <property name="dataBinding" ref="aegisBean" />47 <property name="properties">48 <map>49 <entry key="writeXsiType">50 <value type="java.lang.Boolean">true</value>51 </entry>52 <entry key="overrideTypesList">53 <list>54 <!-- THIS LIST IS IMPORTANT, it exposes these classes to the aegis XSD creator55 so we can output the generic Entry class in lists in the Collector Service Endpoint Class56 but actually output any of its subclasses. Hence, this is a way of dealing with57 inheritence in CXF and aegis58 -->59 <value>uk.ac.cardiff.model.AuthenticationEntry</value>60 <value>uk.ac.cardiff.model.ShibbolethEntry</value>61 <value>uk.ac.cardiff.model.UsageEntry</value>62 </list>63 </entry>64 </map>65 </property>66 </bean>67 68 <!-- DONE -->69 22 70 23 <!-- Polling trigger setup --> … … 116 69 --> 117 70 <bean id="CaptureEngine" class="uk.ac.cardiff.raptor.raptorica.engine.ICAEngine"> 118 <property name=" authRegister"><ref bean="dataAccessRegister"></ref></property>119 <property name=" uaRegistry"><ref bean="uaRegistry"></ref></property>71 <property name="dataAccessRegister"><ref bean="dataAccessRegister"></ref></property> 72 <property name="eventReleaseClient"><ref bean="eventReleaseClient"></ref></property> 120 73 <property name="icaMetadata"><ref bean="ICAMetadata"></ref></property> 121 122 74 </bean> 123 75 124 76 <!-- ICA Metadata --> 125 <bean id="ICAMetadata" class="uk.ac.cardiff.model. ICAMetadata">126 <property name=" icaName"><value>IdP1 Shibboleth Log File Parser</value></property>77 <bean id="ICAMetadata" class="uk.ac.cardiff.model.ClientMetadata"> 78 <property name="clientName"><value>IdP1 Shibboleth Log File Parser</value></property> 127 79 <property name="organisationName"><value>Cardiff University</value></property> 128 80 <property name="contactEmail"><value>smartp@cf.ac.uk</value></property> 81 <property name="serviceName"><value>Cardiff University Shibboleth Identity Provider</value></property> 129 82 </bean> 130 83 84 <bean id="eventReleaseClient" class="uk.ac.cardiff.raptor.remoting.client.impl.EventReleaseClientImpl"> 85 <property name="endpointRegistry"><ref bean="endpointRegistry"/></property> 86 <property name="eventReleaseEngine"><ref bean="eventReleaseEngine"></ref></property> 87 </bean> 88 89 <bean id="eventReleaseEngine" class="uk.ac.cardiff.raptor.registry.EventReleaseEngine"> 90 <property name="attributeFilterEngine"><ref bean="attributeFilterEngine"/></property> 91 <property name="serviceEndpointInterface"><ref bean="serviceEndpointInterface"/></property> 92 </bean> 131 93 132 133 134 94 <bean id="attributeFilterEngine" class="uk.ac.cardiff.raptor.attribute.filtering.AttrributeFilterEngine"/> 95 96 <bean id="serviceEndpointInterface" class="uk.ac.cardiff.raptor.remoting.client.sei.impl.CxfServiceEndpointInterface"/> 135 97 136 98 <import resource="dao-beans.xml"/> 137 99 <import resource="data-access.xml" /> 138 <import resource=" ua-registry.xml" />100 <import resource="event-release.xml" /> 139 101 140 102 </beans> -
raptor-ica-embedded/trunk/src/main/config/raptorica
r462 r604 45 45 javaExe="/usr/local/java/jre1.6.0_23/bin/$javaCommand" # file name of the Java application launcher executable 46 46 47 javaArgs="-Xmx128M -jar -DconfigurationFiles=/usr/local/raptor/raptor-ica-embedded-0.0.1-SNAPSHOT/conf/ beans.xml raptor-ica-embedded-0.0.1-SNAPSHOT.jar"47 javaArgs="-Xmx128M -jar -DconfigurationFiles=/usr/local/raptor/raptor-ica-embedded-0.0.1-SNAPSHOT/conf/ica-core.xml raptor-ica-embedded-0.0.1-SNAPSHOT.jar" 48 48 # arguments for Java launcher 49 49 javaCommandLine="$javaExe $javaArgs" # command line to start the Java service application -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/engine/ICAEngine.java
r596 r604 35 35 import uk.ac.cardiff.model.Event; 36 36 37 38 37 /** 39 38 * @author philsmart 40 * 41 * Responsible for ALL low level capture operations39 * 40 * Responsible for ALL low level capture operations 42 41 */ 43 42 public class ICAEngine { 44 43 45 /** Class Logger*/46 private final Logger log = LoggerFactory.getLogger(ICAEngine.class);44 /** Class Logger */ 45 private final Logger log = LoggerFactory.getLogger(ICAEngine.class); 47 46 48 private DataAccessRegister authRegister;47 private DataAccessRegister dataAccessRegister; 49 48 private EventReleaseClient eventReleaseClient; 50 49 private ClientMetadata icaMetadata; 51 50 52 public ICAEngine() {53 log.info("ICA Capture Engine is running...");51 public ICAEngine() { 52 log.info("ICA Capture Engine is running..."); 54 53 } 55 54 56 public void capturePerform() throws Exception {57 for (AuthenticationInput authI : authRegister.getAuthenticationModules()){58 log.info("Capturing from {}", authI);55 public void capturePerform() throws Exception { 56 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()) { 57 log.info("Capturing from {}", authI); 59 58 authI.parse(); 60 59 } 61 60 } 62 61 63 public void setAuthRegister(DataAccessRegister authRegister) {64 this.authRegister = authRegister;65 }66 67 public DataAccessRegister getAuthRegister() {68 return authRegister;69 }70 62 71 63 /** 72 * This method removes all stored entries, in this way the ICA must only talk to 73 * one endpoint, otherwise the operation is nonmonotoinc whereas it should be monotonic 74 * remove this method if more sophisticated operation is desired. 64 * This method removes all stored entries, in this way the ICA must only 65 * talk to one endpoint, otherwise the operation is nonmonotoinc whereas it 66 * should be monotonic remove this method if more sophisticated operation is 67 * desired. 75 68 */ 76 69 private void retrieveTransactionFinished() { 77 log.debug("Retrieve Transaction Finished, entries are being removed from the ICA...");78 for (AuthenticationInput authI : authRegister.getAuthenticationModules()){79 authI.removeAllEntries();80 }81 log.debug("Retrieve Transaction Finished, entries are being removed form the ICA...done");70 log.debug("Retrieve Transaction Finished, entries are being removed from the ICA..."); 71 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()) { 72 authI.removeAllEntries(); 73 } 74 log.debug("Retrieve Transaction Finished, entries are being removed form the ICA...done"); 82 75 83 76 } 84 77 85 78 /** 86 * Converts all information from all modules into a single list that is sent to the release engine 79 * Converts all information from all modules into a single list that is sent 80 * to the release engine 81 * 87 82 * @return 88 83 */ 89 84 public boolean release() { 90 List<Event> eventsToSend = new ArrayList<Event>(); 91 boolean success =false; 85 List<Event> eventsToSend = new ArrayList<Event>(); 86 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()){ 87 eventsToSend.addAll(authI.getAuthentications()); 88 } 89 90 boolean success = false; 92 91 try { 93 92 success = eventReleaseClient.release(eventsToSend, getIcaMetadata()); 94 93 } catch (ReleaseFailureException e) { 95 log.error("Release failed ", e);94 log.error("Release failed ", e); 96 95 } 97 if (success) retrieveTransactionFinished(); 98 return success; 96 if (success) 97 retrieveTransactionFinished(); 98 return success; 99 99 } 100 100 101 102 101 public void setIcaMetadata(ClientMetadata icaMetadata) { 103 this.icaMetadata = icaMetadata;102 this.icaMetadata = icaMetadata; 104 103 } 105 104 106 105 public ClientMetadata getIcaMetadata() { 107 return icaMetadata;106 return icaMetadata; 108 107 } 109 108 … … 116 115 } 117 116 117 public void setDataAccessRegister(DataAccessRegister dataAccessRegister) { 118 this.dataAccessRegister = dataAccessRegister; 119 } 120 121 public DataAccessRegister getDataAccessRegister() { 122 return dataAccessRegister; 123 } 118 124 119 125 } -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java
r588 r604 36 36 /** 37 37 * @author philsmart 38 * 38 * 39 39 */ 40 40 public class PersistantEntryHandler implements EntryHandler { 41 41 42 /* class logger */ 43 static Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 44 45 /* information about entries, e.g. last entry */ 46 private EntryMetadata entryInformation; 47 48 private ICADataConnection dataConnection; 49 50 /* set of all entries stored by this EntryHandler */ 51 Set<Event> entries; 52 53 public PersistantEntryHandler(ICADataConnection dataConnection) { 54 // entries = new ArrayList<Entry>(); 55 this.setDataConnection(dataConnection); 56 57 } 58 59 /** 60 * Initialises the entry handler. In particular, loads all entries from the 61 * main datastore, through the <code>dataConnection</code> instance. 62 */ 63 public void initialise() { 64 log.info("Persistant entry handler [{}] initialising", this); 65 Integer rowCount = (Integer) dataConnection.runQueryUnique("select count(*) from Entry", null); 66 log.info("Persistent data store has {} entries", rowCount); 67 entryInformation = (EntryMetadata) dataConnection.runQueryUnique("from EntryMetadata", null); 68 log.debug("Have saved entryInformaiton: " + entryInformation); 69 if (entryInformation == null) 70 entryInformation = new EntryMetadata(); 71 log.debug("Entry Information " + entryInformation.getLatestEqualEntries()); 72 // convert to set from list, maybe expensive 73 List<Event> entriesAsList = dataConnection.runQuery("from Entry", null); 74 entries = new LinkedHashSet<Event>(entriesAsList); 75 log.info("Persistant entry handler [{}] started", this); 76 } 77 78 /* 79 * (non-Javadoc) 80 * 81 * @see main.uk.ac.cf.model.EntryHandler#addEntries(java.util.List) 82 */ 83 @Override 84 public void addEntries(Set<Event> entries) { 85 // Object currentEntries = 86 // dataConnection.runQueryUnique("select count(*) from Entry", null); 87 log.debug("Current: " + entries.size() + " in: " + entries.size()); 88 89 for (Event entry : entries) { 90 if (isNewerOrEqual(entry)) 91 entries.add(entry); 92 93 updateLastEntry(entry); 94 95 } 96 log.debug("Total No. of Entries " + entries.size() + " Latest Entry at: " + entryInformation.getLatestEntryTime()); 97 98 } 99 100 public void addEntry(Event entry) { 101 // log.debug("Trying to add "+entry); 102 boolean isAfter = isAfter(entry); 103 boolean isEqual = isEqual(entry); 104 if (isAfter) { 105 // log.debug("Is After "+entry+" with: "+getLatestEntryTime()); 106 entries.add(entry); 107 updateLastEntry(entry); 108 } else if (isEqual) { 109 Integer hashcode = entry.hashCode(); 110 // log.debug("Equal: Checking hashcode: "+hashcode+" in set of "+entryInformation.getLatestEqualEntries().size()+" found: "+entryInformation.getLatestEqualEntries().contains(hashcode)); 111 boolean isAlreadyInLatest = entryInformation.getLatestEqualEntries().contains(hashcode); 112 if (isAlreadyInLatest) { 113 log.error("Duplicated entries found\n{}", entry); 114 } 115 if (!isAlreadyInLatest) { 116 entries.add(entry); 117 updateLastEntry(entry); 118 } 119 } 120 121 } 122 123 private void updateLastEntry(Event entry) { 124 DateTime entryTime = entry.getEventTime(); 125 if (entryInformation.getLatestEntryTime() == null) 126 entryInformation.setLatestEntryTime(entryTime); 127 if (entryTime.isAfter(getLatestEntryTime())) { 128 setLatestEntryTime(entryTime); 129 entryInformation.getLatestEqualEntries().clear(); 130 entryInformation.getLatestEqualEntries().add(new Integer(entry.hashCode())); 131 } 132 if (entryTime.isEqual(getLatestEntryTime())) { 133 entryInformation.getLatestEqualEntries().add(new Integer(entry.hashCode())); 134 } 135 } 136 137 /* 138 * (non-Javadoc) 139 * 140 * @see main.uk.ac.cf.model.EntryHandler#endTransaction() 141 */ 142 @Override 143 public void endTransaction() { 144 log.debug("Saving entries to persitant storage..."); 145 dataConnection.saveAll(entries); 146 dataConnection.save(entryInformation); 147 log.debug("Saving entries to persitant storage...done"); 148 149 } 150 151 /* 152 * (non-Javadoc) 153 * 154 * @see main.uk.ac.cf.model.EntryHandler#getEntries() 155 */ 156 @Override 157 public Set getEntries() { 158 return entries; 159 } 160 161 /* 162 * (non-Javadoc) 163 * 164 * @see main.uk.ac.cf.model.EntryHandler#isAfter(uk.ac.cardiff.model.Entry) 165 */ 166 @Override 167 public boolean isAfter(Event authE) { 168 if (entryInformation.getLatestEntryTime() == null) 169 return true; 170 return authE.getEventTime().isAfter(entryInformation.getLatestEntryTime()); 171 } 172 173 /* 174 * (non-Javadoc) 175 * 176 * @see 177 * main.uk.ac.cf.model.EntryHandler#isEqualTime(uk.ac.cardiff.model.Entry) 178 */ 179 @Override 180 public boolean isEqual(Event authE) { 181 if (entryInformation.getLatestEntryTime() == null) 182 return false; 183 return authE.getEventTime().isEqual(entryInformation.getLatestEntryTime()); 184 } 185 186 /* 187 * (non-Javadoc) 188 * 189 * @see 190 * main.uk.ac.cf.model.EntryHandler#isNewerOrEqual(uk.ac.cardiff.model.Entry 191 * ) 192 */ 193 @Override 194 public boolean isNewerOrEqual(Event authE) { 195 if (entryInformation.getLatestEntryTime() == null) 196 return true; 197 if (!authE.getEventTime().isBefore(entryInformation.getLatestEntryTime())) 198 return true; 199 return false; 200 } 201 202 /* 203 * (non-Javadoc) 204 * 205 * @see main.uk.ac.cf.model.EntryHandler#removeAllEntries() 206 */ 207 @Override 208 public void removeAllEntries() { 209 210 dataConnection.deleteAllEntries(entries); 211 entries.clear(); 212 // entryInformation.setLatestEntryTime(null); 213 } 214 215 // /** 216 // * <p> Sets the latest time entry on the class, also saves it to the data 217 // store 218 // * to achieve persistence </p> 219 // * 220 // * @param latestEntryTime 221 // */ 222 // public void setLatestEntryTime(DateTime latestEntryTime) { 223 // entryInformation.setLatestEntryTime(latestEntryTime); 224 // //dataConnection.save(entryInformation); 225 // } 226 227 public void setDataConnection(ICADataConnection dataConnection) { 228 this.dataConnection = dataConnection; 229 } 230 231 public ICADataConnection getDataConnection() { 232 return dataConnection; 233 } 234 235 public void setEntryInformation(EntryMetadata entryInformation) { 236 this.entryInformation = entryInformation; 237 } 238 239 public EntryMetadata getEntryInformation() { 240 return entryInformation; 241 } 242 243 /* 244 * (non-Javadoc) 245 * 246 * @see main.uk.ac.cf.model.EntryHandler#getLatestEntryTime() 247 */ 248 @Override 249 public DateTime getLatestEntryTime() { 250 return entryInformation.getLatestEntryTime(); 251 } 252 253 /* 254 * (non-Javadoc) 255 * 256 * @see 257 * main.uk.ac.cf.model.EntryHandler#setLatestEntryTime(org.joda.time.DateTime 258 * ) 259 */ 260 @Override 261 public void setLatestEntryTime(DateTime latestEntryTime) { 262 entryInformation.setLatestEntryTime(latestEntryTime); 263 264 } 42 /* class logger */ 43 static Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 44 45 /* information about entries, e.g. last entry */ 46 private EntryMetadata entryInformation; 47 48 private ICADataConnection dataConnection; 49 50 /* set of all entries stored by this EntryHandler */ 51 Set<Event> entries; 52 53 public PersistantEntryHandler(ICADataConnection dataConnection) { 54 // entries = new ArrayList<Entry>(); 55 this.setDataConnection(dataConnection); 56 57 } 58 59 /** 60 * Initialises the entry handler. In particular, loads all entries from the 61 * main datastore, through the <code>dataConnection</code> instance. 62 */ 63 public void initialise() { 64 log.info("Persistant entry handler [{}] initialising", this); 65 Integer rowCount = (Integer) dataConnection.runQueryUnique("select count(*) from Event", null); 66 log.info("Persistent data store has {} entries", rowCount); 67 entryInformation = (EntryMetadata) dataConnection.runQueryUnique("from EntryMetadata", null); 68 log.debug("Have saved entryInformaiton: " + entryInformation); 69 if (entryInformation == null) 70 entryInformation = new EntryMetadata(); 71 log.debug("Entry Information " + entryInformation.getLatestEqualEntries()); 72 // convert to set from list, maybe expensive 73 List<Event> entriesAsList = dataConnection.runQuery("from Event", null); 74 entries = new LinkedHashSet<Event>(entriesAsList); 75 log.info("Persistant entry handler [{}] started", this); 76 } 77 78 /* 79 * (non-Javadoc) 80 * 81 * @see main.uk.ac.cf.model.EntryHandler#addEntries(java.util.List) 82 */ 83 @Override 84 public void addEntries(Set<Event> entries) { 85 // Object currentEntries = 86 // dataConnection.runQueryUnique("select count(*) from Entry", null); 87 log.debug("Current: " + entries.size() + " in: " + entries.size()); 88 89 for (Event entry : entries) { 90 if (isNewerOrEqual(entry)) 91 entries.add(entry); 92 93 updateLastEntry(entry); 94 95 } 96 log.debug("Total No. of Entries " + entries.size() + " Latest Entry at: " 97 + entryInformation.getLatestEntryTime()); 98 99 } 100 101 public void addEntry(Event entry) { 102 // log.debug("Trying to add "+entry); 103 boolean isAfter = isAfter(entry); 104 boolean isEqual = isEqual(entry); 105 if (isAfter) { 106 // log.debug("Is After "+entry+" with: "+getLatestEntryTime()); 107 entries.add(entry); 108 updateLastEntry(entry); 109 } else if (isEqual) { 110 Integer hashcode = entry.hashCode(); 111 // log.debug("Equal: Checking hashcode: "+hashcode+" in set of "+entryInformation.getLatestEqualEntries().size()+" found: "+entryInformation.getLatestEqualEntries().contains(hashcode)); 112 boolean isAlreadyInLatest = entryInformation.getLatestEqualEntries().contains(hashcode); 113 if (isAlreadyInLatest) { 114 log.error("Duplicated entries found\n{}", entry); 115 } 116 if (!isAlreadyInLatest) { 117 entries.add(entry); 118 updateLastEntry(entry); 119 } 120 } 121 122 } 123 124 private void updateLastEntry(Event entry) { 125 DateTime entryTime = entry.getEventTime(); 126 if (entryInformation.getLatestEntryTime() == null) 127 entryInformation.setLatestEntryTime(entryTime); 128 if (entryTime.isAfter(getLatestEntryTime())) { 129 setLatestEntryTime(entryTime); 130 entryInformation.getLatestEqualEntries().clear(); 131 entryInformation.getLatestEqualEntries().add(new Integer(entry.hashCode())); 132 } 133 if (entryTime.isEqual(getLatestEntryTime())) { 134 entryInformation.getLatestEqualEntries().add(new Integer(entry.hashCode())); 135 } 136 } 137 138 /* 139 * (non-Javadoc) 140 * 141 * @see main.uk.ac.cf.model.EntryHandler#endTransaction() 142 */ 143 @Override 144 public void endTransaction() { 145 log.debug("Saving entries to persitant storage..."); 146 dataConnection.saveAll(entries); 147 dataConnection.save(entryInformation); 148 log.debug("Saving entries to persitant storage...done"); 149 150 } 151 152 /* 153 * (non-Javadoc) 154 * 155 * @see main.uk.ac.cf.model.EntryHandler#getEntries() 156 */ 157 @Override 158 public Set getEntries() { 159 return entries; 160 } 161 162 /* 163 * (non-Javadoc) 164 * 165 * @see main.uk.ac.cf.model.EntryHandler#isAfter(uk.ac.cardiff.model.Entry) 166 */ 167 @Override 168 public boolean isAfter(Event authE) { 169 if (entryInformation.getLatestEntryTime() == null) 170 return true; 171 return authE.getEventTime().isAfter(entryInformation.getLatestEntryTime()); 172 } 173 174 /* 175 * (non-Javadoc) 176 * 177 * @see 178 * main.uk.ac.cf.model.EntryHandler#isEqualTime(uk.ac.cardiff.model.Entry) 179 */ 180 @Override 181 public boolean isEqual(Event authE) { 182 if (entryInformation.getLatestEntryTime() == null) 183 return false; 184 return authE.getEventTime().isEqual(entryInformation.getLatestEntryTime()); 185 } 186 187 /* 188 * (non-Javadoc) 189 * 190 * @see 191 * main.uk.ac.cf.model.EntryHandler#isNewerOrEqual(uk.ac.cardiff.model.Entry 192 * ) 193 */ 194 @Override 195 public boolean isNewerOrEqual(Event authE) { 196 if (entryInformation.getLatestEntryTime() == null) 197 return true; 198 if (!authE.getEventTime().isBefore(entryInformation.getLatestEntryTime())) 199 return true; 200 return false; 201 } 202 203 /* 204 * (non-Javadoc) 205 * 206 * @see main.uk.ac.cf.model.EntryHandler#removeAllEntries() 207 */ 208 @Override 209 public void removeAllEntries() { 210 211 dataConnection.deleteAllEntries(entries); 212 entries.clear(); 213 // entryInformation.setLatestEntryTime(null); 214 } 215 216 217 public void setDataConnection(ICADataConnection dataConnection) { 218 this.dataConnection = dataConnection; 219 } 220 221 public ICADataConnection getDataConnection() { 222 return dataConnection; 223 } 224 225 public void setEntryInformation(EntryMetadata entryInformation) { 226 this.entryInformation = entryInformation; 227 } 228 229 public EntryMetadata getEntryInformation() { 230 return entryInformation; 231 } 232 233 /* 234 * (non-Javadoc) 235 * 236 * @see main.uk.ac.cf.model.EntryHandler#getLatestEntryTime() 237 */ 238 @Override 239 public DateTime getLatestEntryTime() { 240 return entryInformation.getLatestEntryTime(); 241 } 242 243 /* 244 * (non-Javadoc) 245 * 246 * @see 247 * main.uk.ac.cf.model.EntryHandler#setLatestEntryTime(org.joda.time.DateTime 248 * ) 249 */ 250 @Override 251 public void setLatestEntryTime(DateTime latestEntryTime) { 252 entryInformation.setLatestEntryTime(latestEntryTime); 253 254 } 265 255 266 256 } -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/server/RunServer.java
r462 r604 21 21 */ 22 22 23 String configurationFiles = System.getProperty("configurationFiles", System.getProperty("user.dir")+"/target/conf/ beans.xml");23 String configurationFiles = System.getProperty("configurationFiles", System.getProperty("user.dir")+"/target/conf/ica-core.xml"); 24 24 int portNumber = Integer.parseInt(System.getProperty("port", "8089")); 25 25 -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/service/impl/ICAProcessImpl.java
r588 r604 30 30 import uk.ac.cardiff.raptor.raptorica.service.ICAProcess; 31 31 32 33 32 import uk.ac.cardiff.model.Event; 34 33 35 34 /** 36 35 * @author philsmart 37 * 36 * 38 37 * main service suite for the ICA 39 38 */ 40 39 public class ICAProcessImpl implements ICAProcess { 41 static Logger log = LoggerFactory.getLogger(ICAProcess.class);40 static Logger log = LoggerFactory.getLogger(ICAProcess.class); 42 41 43 private ICAEngine engine;42 private ICAEngine engine; 44 43 45 /* how long any retrieve method should wait before it returns an empt set*/46 private final int getTimeout =10000;44 /* how long any retrieve method should wait before it returns an empt set */ 45 private final int getTimeout = 10000; 47 46 48 /*49 * ReentrantLock to prevent both capture and retrieve at the same time50 */51 final Lock lockR = new ReentrantLock();47 /* 48 * ReentrantLock to prevent both capture and retrieve at the same time 49 */ 50 final Lock lockR = new ReentrantLock(); 52 51 53 /* 54 * <p> This class initites the <code>CapturePerform</code> method of the 55 * <code>CaptureEngine</code> once it obtains a lock from the 56 * <code>Lock</code> object. Hence, the processImpl can not both capture and 57 * send entries at the same time. Which prevents concurrency issues. 58 * 59 * (non-Javadoc) 60 * 61 * @see main.uk.ac.cf.service.ICAProcess#capture() 62 */ 63 public void capture() { 64 if (lockR.tryLock()) { 65 try { 66 log.info("Running Capture"); 67 long start = System.currentTimeMillis(); 68 engine.capturePerform(); 69 long end = System.currentTimeMillis(); 70 log.info("Capture Success, taking {} ms",(end - start)); 71 log.info("Running Entry Release"); 72 boolean released = engine.release(); 73 log.info("Entries released to all listening UAs {}",released); 74 } catch (Exception e) { 75 // TODO either throw as service output, or deal with here 76 log.error(e.getMessage()); 77 e.printStackTrace(); 78 } finally { 79 lockR.unlock(); 80 } 52 /* 53 * <p> This class initites the <code>CapturePerform</code> method of the 54 * <code>CaptureEngine</code> once it obtains a lock from the 55 * <code>Lock</code> object. Hence, the processImpl can not both capture and 56 * send entries at the same time. Which prevents concurrency issues. 57 * 58 * (non-Javadoc) 59 * 60 * @see main.uk.ac.cf.service.ICAProcess#capture() 61 */ 62 public void capture() { 63 if (lockR.tryLock()) { 64 try { 65 log.info("Running Capture"); 66 long start = System.currentTimeMillis(); 67 engine.capturePerform(); 68 long end = System.currentTimeMillis(); 69 log.info("Capture Success, taking {} ms", (end - start)); 70 log.info("Running Event Release"); 71 boolean released = engine.release(); 72 log.info("Events released to all listening UAs {}", released); 73 } catch (Exception e) { 74 // TODO either throw as service output, or deal with here 75 log.error(e.getMessage()); 76 e.printStackTrace(); 77 } finally { 78 lockR.unlock(); 79 } 80 } 81 81 82 } 82 83 83 } 84 public void setEngine(ICAEngine engine) { 85 log.debug("Setting ICA CORE Engine"); 86 this.engine = engine; 87 } 84 88 85 public void setEngine(ICAEngine engine) { 86 log.debug("Setting ICA CORE Engine"); 87 this.engine = engine; 88 } 89 90 public ICAEngine getEngine() { 91 return engine; 92 } 93 89 public ICAEngine getEngine() { 90 return engine; 91 } 94 92 95 93 }
Note: See TracChangeset
for help on using the changeset viewer.
