Changeset 604


Ignore:
Timestamp:
03/27/11 23:41:52 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-ica-embedded/trunk/src/main
Files:
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • raptor-ica-embedded/trunk/src/main/config/dao-beans.xml

    r459 r604  
    2020<beans xmlns="http://www.springframework.org/schema/beans" 
    2121        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    22         xmlns:jaxws="http://cxf.apache.org/jaxws" 
    2322        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"> 
    2624 
    2725 
     
    4644                <property name="mappingResources"> 
    4745                        <list> 
    48                                 <value>uk/ac/cardiff/model/entry.hbm.xml</value> 
     46                                <value>uk/ac/cardiff/model/event.hbm.xml</value> 
    4947                                <value>uk/ac/cardiff/raptor/raptorica/model/entrymetadata.hbm.xml</value> 
    5048                        </list> 
  • raptor-ica-embedded/trunk/src/main/config/data-access.xml

    r528 r604  
    4545                                --> 
    4646                                <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> 
    4848                                        <property name="logfile"> 
    49                                                 <value>file:///Users/philsmart/Documents/DataSets/Logs/shib2comb-sorted-to-20110213.log 
     49                                                <value>file:///home/philsmart/Documents/DataSets/Logs/example.log 
    5050                                                </value> 
    5151                                        </property> 
     
    6060                                         all other fields are ignored, this is run before the exclusion list--> 
    6161                                        <property name="inclusionList"> 
    62                                                         <bean class="uk.ac.cardiff.raptor.raptorica.model.InclusionList"> 
     62                                                        <bean class="uk.ac.cardiff.raptor.raptorica.model.filter.InclusionList"> 
    6363                                                                <property name="inclusionEntries"> 
    6464                                                                        <list> 
    65                                                                                 <bean class ="uk.ac.cardiff.raptor.raptorica.model.RegexInclusionEntry"> 
     65                                                                                <bean class ="uk.ac.cardiff.raptor.raptorica.model.filter.match.RegexInclusionEntry"> 
    6666                                                                                        <property name ="fieldName" value="messageProfileId"/> 
    6767                                                                                        <property name="match" value=":sso"/> 
  • raptor-ica-embedded/trunk/src/main/config/event-release.xml

    r595 r604  
    2626 
    2727 
    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"> 
    3030                        <list> 
    31                                 <bean id="cardiffShibUA" 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> 
    3333                                        <property name="pushPolicy"><ref bean="genericPushPolicy"></ref></property> 
    3434                                        <!--<property name="attributeFilterPolicy"><ref bean="removePrincipleFilterPolicy"></ref></property>--> 
     
    4040        <!--  policy for release of entries to the UA --> 
    4141 
    42         <bean id="genericPushPolicy" class="uk.ac.cardiff.raptor.raptorica.model.PushPolicy"> 
     42        <bean id="genericPushPolicy" class="uk.ac.cardiff.raptor.remoting.policy.PushPolicy"> 
    4343                <property name="pushOnOrAfterNoEntries"><value>10</value></property> 
    4444        </bean> 
     
    4646        <!-- Attribute filter policies --> 
    4747 
    48         <bean id="removePrincipleFilterPolicy" class="uk.ac.cardiff.raptor.raptorica.model.AttributeFilterPolicy"> 
     48        <bean id="removePrincipleFilterPolicy" class="uk.ac.cardiff.raptor.attribute.filtering.AttributeFilterPolicy"> 
    4949                <property name="policyName"><value>removePrincipleName</value></property> 
    5050                <property name="attributeRules"> 
    5151                <list> 
    52                         <bean class="uk.ac.cardiff.raptor.raptorica.model.AttributeRule"> 
     52                        <bean class="uk.ac.cardiff.raptor.attribute.filtering.AttributeRule"> 
    5353                                <property name="attributeID"><value>requestHost</value></property> 
    5454                                <property name="denyValueRule"> 
    55                                         <bean class="uk.ac.cardiff.raptor.raptorica.model.MatchRule"> 
     55                                        <bean class="uk.ac.cardiff.raptor.attribute.filtering.match.MatchRule"> 
    5656                                                <property name="enabled"><value>true</value></property> 
    5757                                        </bean> 
  • raptor-ica-embedded/trunk/src/main/config/ica-core.xml

    r595 r604  
    2020        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    2121        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 creator 
    55                                         so we can output the generic Entry class in lists in the Collector Service Endpoint Class 
    56                                         but actually output any of its subclasses. Hence, this is a way of dealing with 
    57                                         inheritence in CXF and aegis 
    58 --> 
    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 --> 
    6922 
    7023        <!-- Polling trigger setup --> 
     
    11669        --> 
    11770        <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> 
    12073                <property name="icaMetadata"><ref bean="ICAMetadata"></ref></property> 
    121  
    12274        </bean> 
    12375 
    12476        <!-- 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> 
    12779                <property name="organisationName"><value>Cardiff University</value></property> 
    12880                <property name="contactEmail"><value>smartp@cf.ac.uk</value></property> 
     81                <property name="serviceName"><value>Cardiff University Shibboleth Identity Provider</value></property> 
    12982        </bean> 
    13083 
     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> 
    13193 
    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"/> 
    13597 
    13698        <import resource="dao-beans.xml"/> 
    13799        <import resource="data-access.xml" /> 
    138         <import resource="ua-registry.xml" /> 
     100        <import resource="event-release.xml" /> 
    139101 
    140102</beans> 
  • raptor-ica-embedded/trunk/src/main/config/raptorica

    r462 r604  
    4545javaExe="/usr/local/java/jre1.6.0_23/bin/$javaCommand"                      # file name of the Java application launcher executable 
    4646 
    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" 
     47javaArgs="-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" 
    4848      # arguments for Java launcher 
    4949javaCommandLine="$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  
    3535import uk.ac.cardiff.model.Event; 
    3636 
    37  
    3837/** 
    3938 * @author philsmart 
    40  * 
    41  * Responsible for ALL low level capture operations 
     39 *  
     40 *         Responsible for ALL low level capture operations 
    4241 */ 
    4342public class ICAEngine { 
    4443 
    45         /** Class Logger*/ 
    46         private final Logger log = LoggerFactory.getLogger(ICAEngine.class); 
     44        /** Class Logger */ 
     45        private final Logger log = LoggerFactory.getLogger(ICAEngine.class); 
    4746 
    48         private DataAccessRegister authRegister; 
     47        private DataAccessRegister dataAccessRegister; 
    4948        private EventReleaseClient eventReleaseClient; 
    5049        private ClientMetadata icaMetadata; 
    5150 
    52         public ICAEngine(){ 
    53                 log.info("ICA Capture Engine is running..."); 
     51        public ICAEngine() { 
     52                log.info("ICA Capture Engine is running..."); 
    5453        } 
    5554 
    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); 
    5958                        authI.parse(); 
    6059                } 
    6160        } 
    6261 
    63         public void setAuthRegister(DataAccessRegister authRegister) { 
    64                 this.authRegister = authRegister; 
    65         } 
    66  
    67         public DataAccessRegister getAuthRegister() { 
    68                 return authRegister; 
    69         } 
    7062 
    7163        /** 
    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. 
    7568         */ 
    7669        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"); 
    8275 
    8376        } 
    8477 
    8578        /** 
    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         *  
    8782         * @return 
    8883         */ 
    8984        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; 
    9291                try { 
    9392                        success = eventReleaseClient.release(eventsToSend, getIcaMetadata()); 
    9493                } catch (ReleaseFailureException e) { 
    95                         log.error("Release failed ",e); 
     94                        log.error("Release failed ", e); 
    9695                } 
    97             if (success) retrieveTransactionFinished(); 
    98             return success; 
     96                if (success) 
     97                        retrieveTransactionFinished(); 
     98                return success; 
    9999        } 
    100100 
    101  
    102101        public void setIcaMetadata(ClientMetadata icaMetadata) { 
    103             this.icaMetadata = icaMetadata; 
     102                this.icaMetadata = icaMetadata; 
    104103        } 
    105104 
    106105        public ClientMetadata getIcaMetadata() { 
    107             return icaMetadata; 
     106                return icaMetadata; 
    108107        } 
    109108 
     
    116115        } 
    117116 
     117        public void setDataAccessRegister(DataAccessRegister dataAccessRegister) { 
     118                this.dataAccessRegister = dataAccessRegister; 
     119        } 
     120 
     121        public DataAccessRegister getDataAccessRegister() { 
     122                return dataAccessRegister; 
     123        } 
    118124 
    119125} 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java

    r588 r604  
    3636/** 
    3737 * @author philsmart 
    38  * 
     38 *  
    3939 */ 
    4040public class PersistantEntryHandler implements EntryHandler { 
    4141 
    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        } 
    265255 
    266256} 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/server/RunServer.java

    r462 r604  
    2121         */ 
    2222 
    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"); 
    2424        int portNumber = Integer.parseInt(System.getProperty("port", "8089")); 
    2525 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/service/impl/ICAProcessImpl.java

    r588 r604  
    3030import uk.ac.cardiff.raptor.raptorica.service.ICAProcess; 
    3131 
    32  
    3332import uk.ac.cardiff.model.Event; 
    3433 
    3534/** 
    3635 * @author philsmart 
    37  * 
     36 *  
    3837 *         main service suite for the ICA 
    3938 */ 
    4039public class ICAProcessImpl implements ICAProcess { 
    41     static Logger log = LoggerFactory.getLogger(ICAProcess.class); 
     40        static Logger log = LoggerFactory.getLogger(ICAProcess.class); 
    4241 
    43     private ICAEngine engine; 
     42        private ICAEngine engine; 
    4443 
    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; 
    4746 
    48     /* 
    49     * ReentrantLock to prevent both capture and retrieve at the same time 
    50     */ 
    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(); 
    5251 
    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 
    8182        } 
    8283 
    83     } 
     84        public void setEngine(ICAEngine engine) { 
     85                log.debug("Setting ICA CORE Engine"); 
     86                this.engine = engine; 
     87        } 
    8488 
    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        } 
    9492 
    9593} 
Note: See TracChangeset for help on using the changeset viewer.