Changeset 1176
- Timestamp:
- 10/26/11 23:07:47 (19 months ago)
- Location:
- raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
- Files:
-
- 32 edited
- 2 moved
-
attribute/AttributeRule.java (modified) (1 diff)
-
attribute/filtering/AttributeFilterException.java (modified) (1 diff)
-
attribute/filtering/AttrributeFilterEngine.java (modified) (3 diffs)
-
attribute/filtering/BaseAttributeRule.java (modified) (2 diffs)
-
attribute/filtering/match/MatchRule.java (modified) (1 diff)
-
event/expansion/AttributeAssociationEngine.java (modified) (5 diffs)
-
event/expansion/AttributeLookup.java (modified) (4 diffs)
-
event/expansion/PrincipalAttributeAssociationDefinition.java (modified) (3 diffs)
-
event/expansion/ResourceCategoryAttributeAssociationDefinition.java (modified) (1 diff)
-
event/expansion/connector/DataConnector.java (modified) (2 diffs)
-
event/expansion/connector/LdapDataConnector.java (modified) (58 diffs)
-
registry/Endpoint.java (modified) (5 diffs)
-
registry/EndpointRegistry.java (modified) (2 diffs)
-
registry/ReleaseInformation.java (modified) (2 diffs)
-
remoting/client/DefaultEventReleaseClient.java (modified) (1 diff)
-
remoting/client/EventReleaseClient.java (modified) (1 diff)
-
remoting/client/EventReleaseEngine.java (modified) (4 diffs)
-
remoting/client/ReleaseFailureException.java (modified) (1 diff)
-
remoting/client/sei/ServiceEndpointClient.java (modified) (2 diffs)
-
remoting/client/sei/impl/ClientTLSParameters.java (modified) (2 diffs)
-
remoting/client/sei/impl/CxfServiceEndpointClient.java (modified) (1 diff)
-
remoting/client/sei/impl/DefaultServiceEndpointClient.java (modified) (2 diffs)
-
remoting/policy/ElapsedTimePushPolicy.java (modified) (2 diffs)
-
remoting/policy/EntryNoElapsedTimePushPolicy.java (modified) (2 diffs)
-
remoting/policy/EntryNoPushPolicy.java (modified) (2 diffs)
-
remoting/policy/PushPolicy.java (moved) (moved from raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/AbstractPushPolicy.java) (2 diffs)
-
runtimeutils/DateUtils.java (modified) (1 diff)
-
runtimeutils/ReflectionHelper.java (modified) (10 diffs)
-
store/AsynchronousEntryStoragePipeline.java (modified) (5 diffs)
-
store/StorageEngine.java (modified) (3 diffs)
-
store/StoreEventsPipelineTask.java (moved) (moved from raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEntriesPipelineTask.java) (2 diffs)
-
store/dao/StorageException.java (modified) (1 diff)
-
store/impl/LogFileMemoryEventHandler.java (modified) (1 diff)
-
store/impl/PersistantEventHandler.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/AttributeRule.java
r1025 r1176 22 22 import uk.ac.cardiff.raptor.attribute.filtering.match.MatchRule; 23 23 24 /* *25 * This is a poor implementation of an attributeRule as taken from the ShibbolethIDP. 24 /* 25 * This is a poor implementation of an attributeRule as taken from the ShibbolethIDP. But as this will be replaced by Shib, leave for now 26 26 */ 27 27 public class AttributeRule { -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeFilterException.java
r1025 r1176 17 17 package uk.ac.cardiff.raptor.attribute.filtering; 18 18 19 /**20 * @author philsmart21 *22 */23 19 public class AttributeFilterException extends Exception { 24 20 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttrributeFilterEngine.java
r1049 r1176 29 29 import uk.ac.cardiff.model.event.Event; 30 30 31 /**32 *33 */34 31 public class AttrributeFilterEngine { 35 32 … … 40 37 * Only runs against the deny rules, and only denies basic:ANY attributes, does not deny individual values. 41 38 * 42 * @param attributeFilterPolicy 43 * @param entries 44 * @return 39 * @param attributeFilterPolicy the policy used to filter attributes from the set <code>events</code> 40 * @param metadata the metadata of the service this attribute filter engine is operating within 41 * @param events the list of events to filter 42 * @return a cloned set of filtered events 45 43 */ 46 44 public List<Event> filter(final AttributeFilterPolicy attributeFilterPolicy, final ServiceMetadata metadata, … … 60 58 * Only process deny rules on the level of basic:ANY attributes. Hence will not deny individual values 61 59 * 62 * @param e ntry63 * @param attributeRule 64 * @param metadata 60 * @param event the events whose attributes need filtering 61 * @param attributeRule the attribute rule used to filter these events 62 * @param metadata the service metadata passed to the attribute rule for use. 65 63 */ 66 64 private void filterAttributes(final Event event, final BaseAttributeRule attributeRule, -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/BaseAttributeRule.java
r1026 r1176 22 22 import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 23 23 24 /* *24 /* 25 25 * A naive implementation of an attributeRule. 26 26 * … … 39 39 40 40 /** 41 * Abstract method that Filters an attribute. This *must* be implemented by all concrete classes. 41 * Abstract method that Filters an attribute based on the concrete implementation of the AttributeRule. This *must* 42 * be implemented by all concrete classes. 42 43 * 43 44 * @param event the event -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/match/MatchRule.java
r1049 r1176 35 35 * @param enabled the new enabled 36 36 */ 37 public void setEnabled(final boolean enabled) {38 this.enabled = enabled;37 public void setEnabled(final boolean isEnabled) { 38 enabled = isEnabled; 39 39 } 40 40 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationEngine.java
r1049 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.event.expansion; 20 21 21 22 import java.util.List; 22 23 23 24 24 import org.slf4j.Logger; … … 30 30 /** 31 31 * @author philsmart 32 * 32 * 33 33 */ 34 public class AttributeAssociationEngine {34 public final class AttributeAssociationEngine { 35 35 36 36 /** Class logger. */ 37 37 private final Logger log = LoggerFactory.getLogger(AttributeAssociationEngine.class); 38 38 39 /** Defines which attributes to add, and what principal to attach to */39 /** Defines which attributes to add, and what principal to attach to */ 40 40 private List<BaseAttributeAssociationDefinition> attributeAssociationDefinitions; 41 41 … … 43 43 * Default Constructor 44 44 */ 45 public AttributeAssociationEngine() {45 public AttributeAssociationEngine() { 46 46 47 47 } … … 50 50 * Gets associated attributes for the given ... 51 51 */ 52 public void associateAttributes(List<Event> events) throws AttributeAssociationException{ 53 for (BaseAttributeAssociationDefinition attributeAssociationDefinition: attributeAssociationDefinitions){ 54 log.info("Attribute Association Definition [{}], is enabled [{}]",attributeAssociationDefinition.getDefiniationName(), attributeAssociationDefinition.isEnabled()); 52 public void associateAttributes(final List<Event> events) throws AttributeAssociationException { 53 for (BaseAttributeAssociationDefinition attributeAssociationDefinition : attributeAssociationDefinitions) { 54 log.info("Attribute Association Definition [{}], is enabled [{}]", 55 attributeAssociationDefinition.getDefiniationName(), attributeAssociationDefinition.isEnabled()); 55 56 56 if (!attributeAssociationDefinition.isEnabled()) {57 if (!attributeAssociationDefinition.isEnabled()) { 57 58 continue; 58 59 } 59 60 60 int attached =0;61 int failedToAssociate =0;62 int current =0;61 int attached = 0; 62 int failedToAssociate = 0; 63 int current = 0; 63 64 final int noOfEvents = events.size(); 64 for (Event event : events) {65 for (Event event : events) { 65 66 printProgressPosition(current, noOfEvents); 66 67 boolean associated = attributeAssociationDefinition.associate(event); 67 if (associated) {68 if (associated) { 68 69 attached++; 69 } 70 else{ 71 failedToAssociate++; 70 } else { 71 failedToAssociate++; 72 72 } 73 73 current++; 74 74 } 75 log.info("Attribute Association Definition {} finished, associated information to {} events, where {} events had no attributes associated", 76 new Object[]{attributeAssociationDefinition.getDefiniationName(),attached,failedToAssociate}); 75 log.info( 76 "Attribute Association Definition {} finished, associated information to {} events, where {} events had no attributes associated", 77 new Object[] {attributeAssociationDefinition.getDefiniationName(), attached, failedToAssociate}); 77 78 } 78 79 79 80 } 80 81 81 82 82 /** 83 83 * Prints, as a percentage of the total, the event currently being processed. 84 * 84 * 85 85 * @param lineCount 86 86 * @param totalNoLines 87 87 */ 88 private void printProgressPosition( int lineCount,int totalNoLines) {89 double linePercentage = (((double) lineCount / (double) totalNoLines) * 100);90 if (linePercentage % 25 >= 0 && linePercentage % 25 <= 0.003)91 log.debug("Attribute Association, Complete {}%", linePercentage);88 private void printProgressPosition(final int lineCount, final int totalNoLines) { 89 double linePercentage = (((double) lineCount / (double) totalNoLines) * 100); 90 if (linePercentage % 25 >= 0 && linePercentage % 25 <= 0.003) 91 log.debug("Attribute Association, Complete {}%", linePercentage); 92 92 } 93 93 94 94 /** 95 95 * Also initialises the definitions 96 * 96 * 97 97 * @param attributeAssociationDefinitions the attributeAssociationDefinitions to set 98 98 */ 99 public void setAttributeAssociationDefinitions(List<BaseAttributeAssociationDefinition> attributeAssociationDefinitions) { 99 public void setAttributeAssociationDefinitions( 100 final List<BaseAttributeAssociationDefinition> attributeAssociationDefinitions) { 100 101 this.attributeAssociationDefinitions = attributeAssociationDefinitions; 101 for (BaseAttributeAssociationDefinition definition : attributeAssociationDefinitions) {102 definition.initialise();102 for (BaseAttributeAssociationDefinition definition : attributeAssociationDefinitions) { 103 definition.initialise(); 103 104 } 104 105 } … … 111 112 } 112 113 113 114 115 116 114 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeLookup.java
r756 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.event.expansion; 20 21 21 22 /** 22 23 * @author philsmart 23 * 24 * 24 25 */ 25 26 public class AttributeLookup { 26 27 27 /** The name of the attribute in the source data store */28 /** The name of the attribute in the source data store. */ 28 29 private String sourceAttributeName; 29 30 30 /** The name of the attribute in the internal model that this attribute maps to */31 /** The name of the attribute in the internal model that this attribute maps to. */ 31 32 private String internalAttributeName; 32 33 … … 34 35 * @param sourceAttributeName the sourceAttributeName to set 35 36 */ 36 public void setSourceAttributeName( String sourceAttributeName) {37 public void setSourceAttributeName(final String sourceAttributeName) { 37 38 this.sourceAttributeName = sourceAttributeName; 38 39 } … … 48 49 * @param internalAttributeName the internalAttributeName to set 49 50 */ 50 public void setInternalAttributeName( String internalAttributeName) {51 public void setInternalAttributeName(final String internalAttributeName) { 51 52 this.internalAttributeName = internalAttributeName; 52 53 } … … 59 60 } 60 61 61 62 62 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/PrincipalAttributeAssociationDefinition.java
r1049 r1176 80 80 * @throws AttributeAssociationException the attribute association exception 81 81 */ 82 public String getInternalAttributeName( String attributeSourceName) throws AttributeAssociationException {82 public String getInternalAttributeName(final String attributeSourceName) throws AttributeAssociationException { 83 83 for (AttributeLookup lookupAttribute : lookupAttributes) { 84 84 if (lookupAttribute.getSourceAttributeName().equals(attributeSourceName)) { … … 98 98 * @throws IllegalAccessException the illegal access exception 99 99 */ 100 private void populate( Map<String, String> attributes,Event event) throws InstantiationException,100 private void populate(final Map<String, String> attributes, final Event event) throws InstantiationException, 101 101 IllegalAccessException { 102 102 … … 121 121 122 122 @Override 123 public boolean associate( Event event) {123 public boolean associate(final Event event) { 124 124 125 125 if (!event.getClass().getCanonicalName().equals(associateWithClass)) { -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/ResourceCategoryAttributeAssociationDefinition.java
r1049 r1176 48 48 49 49 @Override 50 public boolean associate( Event event) {50 public boolean associate(final Event event) { 51 51 52 52 ResourceMetadata resourceMetadata = null; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/DataConnector.java
r756 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.event.expansion.connector; 20 21 … … 23 24 /** 24 25 * @author philsmart 25 * 26 * 26 27 */ 27 28 public interface DataConnector { 28 29 29 public Map<String, String> lookup(String principal) throws AttributeAssociationException; 30 /** 31 * Use this data connector to resolve attributes about the <code>principal</code> 32 * 33 * @param principal the principal name of the subject to resolve attributes about 34 * @return a <code>Map</code> of attribute value pairs resolved about the <code>principal</code> 35 * @throws AttributeAssociationException 36 */ 37 public Map<String, String> lookup(final String principal) throws AttributeAssociationException; 30 38 39 /** 40 * Initiliases the concrete implementation of this data connector 41 */ 31 42 public void initialise(); 32 43 33 public void setReturnAttributes(String[] s); 44 /** 45 * Sets which attributes should be returned by this data connector 46 * 47 * @param attributes the set of attributes which should be returned by this data connector 48 */ 49 public void setReturnAttributes(final String[] attributes); 34 50 35 public void setSearchFilterTemplate(String searchFilterTemplate); 51 /** 52 * Sets the search template specific to the concrete implementation of the data connector used to query this data 53 * connector. 54 * 55 * @param searchFilterTemplate the search template specific to the concrete implementation of the data connector 56 * used to query this data connector. 57 */ 58 public void setSearchFilterTemplate(final String searchFilterTemplate); 36 59 37 60 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/LdapDataConnector.java
r756 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.event.expansion.connector; 17 18 … … 36 37 import javax.net.ssl.TrustManagerFactory; 37 38 38 39 39 import org.opensaml.xml.security.x509.X509Credential; 40 40 import org.opensaml.xml.util.DatatypeHelper; … … 42 42 import org.slf4j.LoggerFactory; 43 43 44 45 44 import edu.vt.middleware.ldap.Ldap; 46 45 import edu.vt.middleware.ldap.LdapConfig; … … 50 49 /** 51 50 * <code>LdapDataConnector</code> provides a plugin to retrieve attributes from an LDAP. 51 */ 52 /* 53 * STOLEN from Shib, needs converting to shib attribute resolution. 52 54 */ 53 55 public class LdapDataConnector implements DataConnector { … … 120 122 private boolean initialized; 121 123 122 /** The ldap search filter template */124 /** The ldap search filter template */ 123 125 private String searchFilterTemplate; 124 126 … … 126 128 private long cacheTimeoutMs; 127 129 128 /** The time at which the cache was last reset */130 /** The time at which the cache was last reset */ 129 131 private long cacheResetTimeMs; 130 132 … … 140 142 */ 141 143 public void initialise() { 142 if (!initialized) {144 if (!initialized) { 143 145 initialized = true; 144 146 initializeLdapPool(); … … 178 180 } 179 181 180 181 182 /** 182 183 * This returns whether this connector will merge multiple search results into one result. The default is false. 183 * 184 * 184 185 * @return <code>boolean</code> 185 186 */ … … 191 192 * This sets whether this connector will merge multiple search results into one result. This method will remove any 192 193 * cached results. 193 * 194 * @see #clearCache() 195 * 194 * 195 * @see #clearCache() 196 * 196 197 * @param b <code>boolean</code> 197 198 */ … … 203 204 /** 204 205 * This returns whether this connector will cache search results. The default is false. 205 * 206 * 206 207 * @return <code>boolean</code> 207 208 */ … … 212 213 /** 213 214 * This sets whether this connector will cache search results. 214 * 215 * 215 216 * @see #initializeCache() 216 * 217 * 217 218 * @param b <code>boolean</code> 218 219 */ … … 228 229 /** 229 230 * This returns whether this connector will throw an exception if no search results are found. The default is false. 230 * 231 * 231 232 * @return <code>boolean</code> 232 233 */ … … 237 238 /** 238 239 * This sets whether this connector will throw an exception if no search results are found. 239 * 240 * 240 241 * @param b <code>boolean</code> 241 242 */ … … 244 245 } 245 246 246 247 247 /** 248 248 * This returns the URL this connector is using. 249 * 249 * 250 250 * @return <code>String</code> 251 251 */ … … 256 256 /** 257 257 * This returns the base DN this connector is using. 258 * 258 * 259 259 * @return <code>String</code> 260 260 */ … … 265 265 /** 266 266 * This returns whether this connector will start TLS for all connections to the ldap. 267 * 267 * 268 268 * @return <code>boolean</code> 269 269 */ … … 274 274 /** 275 275 * This returns the SSL Socket Factory that will be used for all TLS and SSL connections to the ldap. 276 * 276 * 277 277 * @return <code>SSLSocketFactory</code> 278 278 */ … … 284 284 * This sets the SSL Socket Factory that will be used for all TLS and SSL connections to the ldap. This method will 285 285 * remove any cached results and initialize the ldap pool. 286 * 286 * 287 287 * @see #clearCache() 288 288 * @see #initializeLdapPool() 289 * 289 * 290 290 * @param sf <code>SSLSocketFactory</code> 291 291 */ … … 296 296 /** 297 297 * This returns the trust managers that will be used for all TLS and SSL connections to the ldap. 298 * 298 * 299 299 * @return <code>TrustManager[]</code> 300 300 */ … … 306 306 * This sets the trust managers that will be used for all TLS and SSL connections to the ldap. This method will 307 307 * remove any cached results and initialize the ldap pool. 308 * 308 * 309 309 * @see #clearCache() 310 310 * @see #initializeLdapPool() 311 311 * @see #setSslSocketFactory(SSLSocketFactory) 312 * 312 * 313 313 * @param tc <code>X509Credential</code> to create TrustManagers with 314 314 */ … … 339 339 /** 340 340 * This returns the key managers that will be used for all TLS and SSL connections to the ldap. 341 * 341 * 342 342 * @return <code>KeyManager[]</code> 343 343 */ … … 349 349 * This sets the key managers that will be used for all TLS and SSL connections to the ldap. This method will remove 350 350 * any cached results and initialize the ldap pool. 351 * 351 * 352 352 * @see #clearCache() 353 353 * @see #initializeLdapPool() 354 354 * @see #setSslSocketFactory(SSLSocketFactory) 355 * 355 * 356 356 * @param kc <code>X509Credential</code> to create KeyManagers with 357 357 */ … … 381 381 /** 382 382 * This returns the hostname verifier that will be used for all TLS and SSL connections to the ldap. 383 * 383 * 384 384 * @return <code>HostnameVerifier</code> 385 385 */ … … 391 391 * This sets the hostname verifier that will be used for all TLS and SSL connections to the ldap. This method will 392 392 * remove any cached results and initialize the ldap pool. 393 * 393 * 394 394 * @see #clearCache() 395 395 * @see #initializeLdapPool() 396 * 396 * 397 397 * @param hv <code>HostnameVerifier</code> 398 398 */ … … 405 405 /** 406 406 * This returns the authentication type used when binding to the ldap. 407 * 407 * 408 408 * @return <code>AUTHENTICATION_TYPE</code> 409 409 */ … … 431 431 * This sets the authentication type used when binding to the ldap. This method will remove any cached results and 432 432 * initialize the ldap pool. 433 * 433 * 434 434 * @see #clearCache() 435 435 * @see #initializeLdapPool() 436 * 436 * 437 437 * @param type <code>AUTHENTICATION_TYPE</code> 438 438 */ … … 459 459 /** 460 460 * This returns the search scope used when searching the ldap. 461 * 461 * 462 462 * @return <code>int</code> 463 463 */ … … 476 476 /** 477 477 * This sets the search scope used when searching the ldap. This method will remove any cached results. 478 * 479 * @see #clearCache() 480 * 478 * 479 * @see #clearCache() 480 * 481 481 * @param scope directory search scope 482 482 */ … … 494 494 /** 495 495 * This returns the attributes that all searches will request from the ldap. 496 * 496 * 497 497 * @return <code>String[]</code> 498 498 */ … … 504 504 * This sets the attributes that all searches will request from the ldap. This method will remove any cached 505 505 * results. 506 * 507 * @see #clearCache() 508 * 506 * 507 * @see #clearCache() 508 * 509 509 * @param s <code>String[]</code> 510 510 */ 511 511 public void setReturnAttributes(String[] s) { 512 512 returnAttributes = s; 513 // clearCache();513 // clearCache(); 514 514 } 515 515 516 516 /** 517 517 * This sets the attributes that all searches will request from the ldap. s should be a comma delimited string. 518 * 518 * 519 519 * @param s <code>String[]</code> comma delimited returnAttributes 520 520 */ … … 531 531 * This returns the time in milliseconds that the ldap will wait for search results. A value of 0 means to wait 532 532 * indefinitely. 533 * 533 * 534 534 * @return <code>int</code> milliseconds 535 535 */ … … 541 541 * This sets the time in milliseconds that the ldap will wait for search results. A value of 0 means to wait 542 542 * indefinitely. This method will remove any cached results. 543 * 544 * @see #clearCache() 545 * 543 * 544 * @see #clearCache() 545 * 546 546 * @param i <code>int</code> milliseconds 547 547 */ … … 554 554 * This returns the maximum number of search results the ldap will return. A value of 0 all entries will be 555 555 * returned. 556 * 556 * 557 557 * @return <code>long</code> maximum number of search results 558 558 */ … … 564 564 * This sets the maximum number of search results the ldap will return. A value of 0 all entries will be returned. 565 565 * This method will remove any cached results. 566 * 567 * @see #clearCache() 568 * 566 * 567 * @see #clearCache() 568 * 569 569 * @param l <code>long</code> maximum number of search results 570 570 */ … … 576 576 /** 577 577 * This returns whether objects will be returned in the search results. The default is false. 578 * 578 * 579 579 * @return <code>boolean</code> 580 580 */ … … 585 585 /** 586 586 * This sets whether objects will be returned in the search results. This method will remove any cached results. 587 * 588 * @see #clearCache() 589 * 587 * 588 * @see #clearCache() 589 * 590 590 * @param b <code>boolean</code> 591 591 */ … … 597 597 /** 598 598 * This returns whether link dereferencing will be used during the search. The default is false. 599 * 599 * 600 600 * @return <code>boolean</code> 601 601 */ … … 606 606 /** 607 607 * This sets whether link dereferencing will be used during the search. This method will remove any cached results. 608 * 609 * @see #clearCache() 610 * 608 * 609 * @see #clearCache() 610 * 611 611 * @param b <code>boolean</code> 612 612 */ … … 618 618 /** 619 619 * This returns the principal dn used to bind to the ldap for all searches. 620 * 620 * 621 621 * @return <code>String</code> principal dn 622 622 */ … … 628 628 * This sets the principal dn used to bind to the ldap for all searches. This method will remove any cached results 629 629 * and initialize the ldap pool. 630 * 630 * 631 631 * @see #clearCache() 632 632 * @see #initializeLdapPool() 633 * 633 * 634 634 * @param s <code>String</code> principal dn 635 635 */ … … 640 640 /** 641 641 * This returns the principal credential used to bind to the ldap for all searches. 642 * 642 * 643 643 * @return <code>String</code> principal credential 644 644 */ … … 650 650 * This sets the principal credential used to bind to the ldap for all searches. This method will remove any cached 651 651 * results and initialize the ldap pool. 652 * 652 * 653 653 * @see #clearCache() 654 654 * @see #initializeLdapPool() 655 * 655 * 656 656 * @param s <code>String</code> principal credential 657 657 */ … … 663 663 * This sets additional ldap context environment properties. This method will remove any cached results and 664 664 * initialize the ldap pool. 665 * 665 * 666 666 * @see #clearCache() 667 667 * @see #initializeLdapPool() 668 * 668 * 669 669 * @param ldapProperties <code>Map</code> of name/value pairs 670 670 */ … … 677 677 } 678 678 679 private void checkCacheValidity() {680 if (cacheTimeoutMs ==0 || !cacheResults){679 private void checkCacheValidity() { 680 if (cacheTimeoutMs == 0 || !cacheResults) { 681 681 return; 682 682 } 683 683 long currentTimeMillis = System.currentTimeMillis(); 684 boolean shouldReset = (currentTimeMillis - cacheResetTimeMs) > cacheTimeoutMs;685 if (shouldReset) {684 boolean shouldReset = (currentTimeMillis - cacheResetTimeMs) > cacheTimeoutMs; 685 if (shouldReset) { 686 686 log.info("Ldap cache was cleared, timeout reached"); 687 687 clearCache(); … … 689 689 } 690 690 691 692 691 /** {@inheritDoc} */ 693 692 public Map<String, String> lookup(String principal) throws AttributeAssociationException { 694 693 695 String searchFilter = searchFilterTemplate.replace("[principal]", principal);694 String searchFilter = searchFilterTemplate.replace("[principal]", principal); 696 695 searchFilter = searchFilter.trim(); 697 // log.debug("Search: "+searchFilter);698 // check if cache is still valid696 // log.debug("Search: "+searchFilter); 697 // check if cache is still valid 699 698 checkCacheValidity(); 700 699 … … 712 711 // check for empty result set 713 712 if (noResultsIsError && !results.hasNext()) { 714 throw new AttributeAssociationException("No LDAP entry found for " +principal);713 throw new AttributeAssociationException("No LDAP entry found for " + principal); 715 714 } 716 715 // build resolved attributes from LDAP attributes … … 718 717 if (cacheResults && attributes != null) { 719 718 setCachedAttributes(principal, searchFilter, attributes); 720 // log.debug("Stored results in the cache");719 // log.debug("Stored results in the cache"); 721 720 } 722 721 } … … 725 724 } 726 725 727 728 726 /** 729 727 * This searches the LDAP with the supplied filter. 730 * 728 * 731 729 * @param searchFilter <code>String</code> the searchFilter that produced the attributes 732 730 * @return <code>Iterator</code> of search results … … 739 737 return ldap.search(searchFilter, returnAttributes); 740 738 } catch (NamingException e) { 741 //log.error("An error occured when attempting to search the LDAP: {}, {}",ldapConfig.getEnvironment(), e.getMessage()); 742 throw new AttributeAssociationException("An error occurred when attempting to search the LDAP "+e.getMessage()); 739 // log.error("An error occured when attempting to search the LDAP: {}, {}",ldapConfig.getEnvironment(), 740 // e.getMessage()); 741 throw new AttributeAssociationException("An error occurred when attempting to search the LDAP " 742 + e.getMessage()); 743 743 } catch (Exception e) { 744 744 log.error("Could not retrieve Ldap object from pool, {}", e.getMessage()); … … 758 758 /** 759 759 * This returns a map of attribute ids to attributes from the supplied search results. 760 * 760 * 761 761 * @param results <code>Iterator</code> of LDAP search results 762 762 * @return <code>Map</code> of attribute ids to attributes … … 772 772 } 773 773 774 do {774 do { 775 775 SearchResult sr = results.next(); 776 776 Map<String, List<String>> newAttrsMap = null; 777 try {777 try { 778 778 newAttrsMap = LdapUtil.parseAttributes(sr.getAttributes(), true); 779 779 } catch (NamingException e) { … … 781 781 throw new AttributeAssociationException("Error parsing LDAP attributes"); 782 782 } 783 // log.debug("Found {} attributes",newAttrsMap.size());783 // log.debug("Found {} attributes",newAttrsMap.size()); 784 784 for (Map.Entry<String, List<String>> entry : newAttrsMap.entrySet()) { 785 // log.debug("Found the following attribute: {}", entry);785 // log.debug("Found the following attribute: {}", entry); 786 786 String attribute = (String) attributes.get(entry.getKey()); 787 if (attribute == null){787 if (attribute == null) { 788 788 attribute = new String(entry.getKey()); 789 789 … … 792 792 List<String> values = entry.getValue(); 793 793 StringBuilder builder = new StringBuilder(); 794 if (values != null && !values.isEmpty()){795 int count =0;796 for (String value : values){797 if (!DatatypeHelper.isEmpty(value)){794 if (values != null && !values.isEmpty()) { 795 int count = 0; 796 for (String value : values) { 797 if (!DatatypeHelper.isEmpty(value)) { 798 798 builder.append(DatatypeHelper.safeTrimOrNullString(value)); 799 if (count < values.size() -1){799 if (count < values.size() - 1) { 800 800 builder.append(","); 801 801 } … … 806 806 attributes.put(entry.getKey(), builder.toString()); 807 807 } 808 } while (mergeMultipleResults && results.hasNext());808 } while (mergeMultipleResults && results.hasNext()); 809 809 810 810 return attributes; … … 825 825 } 826 826 827 828 827 /** 829 828 * @param startTls the startTls to set … … 875 874 } 876 875 877 878 876 /** 879 877 * This stores the supplied attributes in the cache. 880 * 878 * 881 879 * @param principalName 882 880 * @param searchFiler the searchFilter that produced the attributes … … 896 894 /** 897 895 * This retrieves any cached attributes for the supplied resolution context. Returns null if nothing is cached. 898 * 896 * 899 897 * @param principalName 900 898 * @param searchFilter the search filter the produced the attributes 901 * 899 * 902 900 * @return <code>Map</code> of attributes ids to attributes 903 901 */ 904 protected Map<String, String> getCachedAttributes(String principalName, 905 String searchFilter) { 902 protected Map<String, String> getCachedAttributes(String principalName, String searchFilter) { 906 903 Map<String, String> attributes = null; 907 904 if (cacheResults) { … … 928 925 } 929 926 930 931 932 927 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/Endpoint.java
r1049 r1176 27 27 import uk.ac.cardiff.model.event.Event; 28 28 import uk.ac.cardiff.raptor.attribute.filtering.AttributeFilterPolicy; 29 import uk.ac.cardiff.raptor.remoting.policy. AbstractPushPolicy;29 import uk.ac.cardiff.raptor.remoting.policy.PushPolicy; 30 30 31 31 /** 32 32 * 33 * Stores information about an endpoint that a client can send events to. Also includes the Push Policy to determine if34 * events should be sent, an attribute filter policy for determining which attributes of each event should be sent, and35 * information about previous event releases.33 * Stores information about an endpoint that a client can send events to. Also includes the Push Policy used to 34 * determine if/when events should be sent, an attribute filter policy for determining which attributes of each event 35 * should be sent, and information about previous event releases. 36 36 * 37 37 * This class could be subclassed if additional functionality is required. … … 47 47 48 48 /** A List of the PushPolicies defined for this endpoint. */ 49 private List< AbstractPushPolicy> pushPolicies;49 private List<PushPolicy> pushPolicies; 50 50 51 51 /** The filter policy defined for this endpoint *. */ … … 70 70 * @param filteredEntries the filtered entries 71 71 */ 72 public void releasePerformed( List<Event> filteredEntries) {72 public void releasePerformed(final List<Event> filteredEntries) { 73 73 releaseInformation.releasePerformed(filteredEntries); 74 74 } … … 116 116 * @param pushPolicies the new push policies 117 117 */ 118 public void setPushPolicies(List< AbstractPushPolicy> pushPolicies) {118 public void setPushPolicies(List<PushPolicy> pushPolicies) { 119 119 this.pushPolicies = pushPolicies; 120 120 } … … 125 125 * @return the push policies 126 126 */ 127 public List< AbstractPushPolicy> getPushPolicies() {127 public List<PushPolicy> getPushPolicies() { 128 128 return pushPolicies; 129 129 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EndpointRegistry.java
r1049 r1176 55 55 * @param endpoints the new endpoints 56 56 */ 57 public void setEndpoints( List<Endpoint> endpoints) {57 public void setEndpoints(final List<Endpoint> endpoints) { 58 58 for (Endpoint endpoint : endpoints) { 59 59 log.info("Registering Service Endpoint: {}, persisting event release information {}", … … 102 102 * @return the release information 103 103 */ 104 public ReleaseInformation loadReleaseInformation( Endpoint endpoint) {104 public ReleaseInformation loadReleaseInformation(final Endpoint endpoint) { 105 105 List<?> releaseInfoResults = 106 106 dataConnection.runQuery("from ReleaseInformation where serviceEndpoint=?", -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/ReleaseInformation.java
r1049 r1176 65 65 * @param releasedEvents 66 66 */ 67 public void releasePerformed( List<Event> releasedEvents) {67 public void releasePerformed(final List<Event> releasedEvents) { 68 68 69 69 for (Event event : releasedEvents) { … … 93 93 * @return true if the event has not been released before, false otherwise 94 94 */ 95 public boolean hasNotBeenReleased( Event event) {95 public boolean hasNotBeenReleased(final Event event) { 96 96 if (event.getEventTime().isAfter(getLastReleasedEventTime())) { 97 97 return true; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/DefaultEventReleaseClient.java
r1049 r1176 50 50 * uk.ac.cardiff.model.ServiceMetadata) 51 51 */ 52 public boolean release(List<Event> events, ServiceMetadata serviceMetadata) throws ReleaseFailureException { 52 public boolean release(final List<Event> events, final ServiceMetadata serviceMetadata) 53 throws ReleaseFailureException { 53 54 boolean success = false; 54 55 if (enableEventRelease) { -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java
r1049 r1176 46 46 47 47 /** 48 * A way of accessing the list of endpoints it is communicating with48 * A way of accessing the list of endpoints this client is communicating with 49 49 * 50 50 * @return a list of endpoints -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseEngine.java
r1043 r1176 24 24 import java.util.List; 25 25 26 import org.slf4j.Logger; 27 import org.slf4j.LoggerFactory; 28 29 import uk.ac.cardiff.model.ServiceMetadata; 30 import uk.ac.cardiff.model.event.Event; 31 import uk.ac.cardiff.model.event.auxiliary.EventMetadata; 32 import uk.ac.cardiff.model.wsmodel.EventPushMessage; 26 33 import uk.ac.cardiff.raptor.attribute.filtering.AttrributeFilterEngine; 27 34 import uk.ac.cardiff.raptor.registry.Endpoint; 28 35 import uk.ac.cardiff.raptor.registry.EndpointRegistry; 29 36 import uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient; 30 import uk.ac.cardiff.raptor.remoting.policy.AbstractPushPolicy; 31 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 35 import uk.ac.cardiff.model.ServiceMetadata; 36 import uk.ac.cardiff.model.event.Event; 37 import uk.ac.cardiff.model.event.auxiliary.EventMetadata; 38 import uk.ac.cardiff.model.wsmodel.EventPushMessage; 37 import uk.ac.cardiff.raptor.remoting.policy.PushPolicy; 39 38 40 39 /** … … 151 150 * @return the list of filtered events 152 151 */ 153 private List<Event> chronologicalFilter( Endpoint endpoint,List<Event> events) {152 private List<Event> chronologicalFilter(final Endpoint endpoint, final List<Event> events) { 154 153 ArrayList<Event> applicableEvents = new ArrayList<Event>(); 155 154 … … 172 171 * @return true iff at least one push policy evaluates to true, false otherwise 173 172 */ 174 private boolean shouldRelease( Endpoint endpoint,List<Event> events) {173 private boolean shouldRelease(final Endpoint endpoint, final List<Event> events) { 175 174 boolean shouldRelease = false; 176 for ( AbstractPushPolicy policy : endpoint.getPushPolicies()) {175 for (PushPolicy policy : endpoint.getPushPolicies()) { 177 176 if (policy.evaluatePolicy(events)) 178 177 shouldRelease = true; … … 185 184 * no work is done, and the input allEvents is returned without modification 186 185 * 187 * @param endpoint 188 * @param allEvents 189 * @return 186 * @param endpoint the endpoint that the engine is sending to 187 * @param allEvents the list of <code>Event</code>s to filter 188 * @return a filtered set of events based on any defined attribute filter policies. 190 189 */ 191 190 private List<Event> filterAttributes(ServiceMetadata metadata, Endpoint endpoint, List<Event> allEvents) { -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/ReleaseFailureException.java
r713 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.remoting.client; 17 18 18 public class ReleaseFailureException extends Exception {19 public class ReleaseFailureException extends Exception { 19 20 20 /**21 * Generated serialUID22 */23 private static final long serialVersionUID = -1091443418866759066L;21 /** 22 * Generated serialUID 23 */ 24 private static final long serialVersionUID = -1091443418866759066L; 24 25 25 public ReleaseFailureException (String message, Exception wrappedException){ 26 super (message,wrappedException); 27 } 26 /** Constructor. */ 27 public ReleaseFailureException() { 28 super(); 29 } 30 31 /** 32 * Constructor. 33 * 34 * @param message exception message 35 */ 36 public ReleaseFailureException(final String message) { 37 super(message); 38 } 39 40 /** 41 * Constructor. 42 * 43 * @param wrappedException exception to be wrapped by this one 44 */ 45 public ReleaseFailureException(final Exception wrappedException) { 46 super(wrappedException); 47 } 48 49 /** 50 * Constructor. 51 * 52 * @param message exception message 53 * @param wrappedException exception to be wrapped by this one 54 */ 55 public ReleaseFailureException(final String message, final Exception wrappedException) { 56 super(message, wrappedException); 57 } 28 58 29 59 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/ServiceEndpointClient.java
r639 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.remoting.client.sei; 17 18 … … 21 22 public interface ServiceEndpointClient { 22 23 23 public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint); 24 /** 25 * Sends the <code>EventPushMessage</code> to the endpoint <code>endpoint</code> 26 * 27 * @param pushed the <code>EventPushMessage</code> to send to the <code>endpoint</code> 28 * @param endpoint the endpoint to send the <code>EventPushMessage</code> to 29 * @return true iff event release was successful, false otherwise. Note, this describes success of the transmission 30 * to the client, and not reporting successful processing of that information within the client. 31 */ 32 public boolean sendEvents(final EventPushMessage pushed, final Endpoint endpoint); 24 33 25 34 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/ClientTLSParameters.java
r1025 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.remoting.client.sei.impl; 20 21 … … 36 37 import org.apache.cxf.configuration.jsse.TLSClientParameters; 37 38 38 39 39 /** 40 * Raptor client specific class to hold TLS parameters for easy configuration. Will then 41 * produce an implementationspecific TLS parameter class. Like a factory.42 * 40 * Raptor client specific class to hold TLS parameters for easy configuration. Will then produce an implementation 41 * specific TLS parameter class. Like a factory. 42 * 43 43 * @author philsmart 44 * 44 * 45 45 */ 46 46 public class ClientTLSParameters { 47 47 48 /** The public certificates for trusted servers*/49 private String trustStoreLocation;48 /** The public certificates for trusted servers. */ 49 private String trustStoreLocation; 50 50 51 /** The private certificate for this client*/52 private String keyStoreLocation;51 /** The private certificate for this client. */ 52 private String keyStoreLocation; 53 53 54 /** The password for the trust store*/55 private String trustStorePassword;54 /** The password for the trust store. */ 55 private String trustStorePassword; 56 56 57 /** The password for the key store*/58 private String keyStorePassword;57 /** The password for the key store. */ 58 private String keyStorePassword; 59 59 60 public TLSClientParameters getTlsClientParameters() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException{ 61 final TLSClientParameters tls = new TLSClientParameters(); 60 /** 61 * Gets the tls client parameters. 62 * 63 * @return the tls client parameters 64 * @throws KeyStoreException the key store exception 65 * @throws NoSuchAlgorithmException the no such algorithm exception 66 * @throws CertificateException the certificate exception 67 * @throws FileNotFoundException the file not found exception 68 * @throws IOException Signals that an I/O exception has occurred. 69 * @throws UnrecoverableKeyException the unrecoverable key exception 70 */ 71 public TLSClientParameters getTlsClientParameters() throws KeyStoreException, NoSuchAlgorithmException, 72 CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException { 73 final TLSClientParameters tls = new TLSClientParameters(); 62 74 63 tls.setDisableCNCheck(true);//disable URL and CN on cert match75 tls.setDisableCNCheck(true);// disable URL and CN on cert match 64 76 65 //clients private key / public key66 final KeyStore keyStoreKeyManager = KeyStore.getInstance("JKS");67 final File keyStoreFile = new File(keyStoreLocation);68 keyStoreKeyManager.load(new FileInputStream(keyStoreFile),keyStorePassword.toCharArray());69 final KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());70 keyFactory.init(keyStoreKeyManager, keyStorePassword.toCharArray());77 // clients private key / public key 78 final KeyStore keyStoreKeyManager = KeyStore.getInstance("JKS"); 79 final File keyStoreFile = new File(keyStoreLocation); 80 keyStoreKeyManager.load(new FileInputStream(keyStoreFile), keyStorePassword.toCharArray()); 81 final KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 82 keyFactory.init(keyStoreKeyManager, keyStorePassword.toCharArray()); 71 83 72 final KeyManager[] km = keyFactory.getKeyManagers();73 tls.setKeyManagers(km);84 final KeyManager[] km = keyFactory.getKeyManagers(); 85 tls.setKeyManagers(km); 74 86 75 //servers public key 76 final KeyStore keyStore = KeyStore.getInstance("JKS"); 77 final File truststore = new File(trustStoreLocation); 78 keyStore.load(new FileInputStream(truststore), trustStorePassword.toCharArray()); 79 final TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 80 trustFactory.init(keyStore); 87 // servers public key 88 final KeyStore keyStore = KeyStore.getInstance("JKS"); 89 final File truststore = new File(trustStoreLocation); 90 keyStore.load(new FileInputStream(truststore), trustStorePassword.toCharArray()); 91 final TrustManagerFactory trustFactory = 92 TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 93 trustFactory.init(keyStore); 81 94 82 final TrustManager[] tm = trustFactory.getTrustManagers();83 tls.setTrustManagers(tm);95 final TrustManager[] tm = trustFactory.getTrustManagers(); 96 tls.setTrustManagers(tm); 84 97 85 return tls;98 return tls; 86 99 87 }100 } 88 101 89 public void setTrustStoreLocation(final String trustStoreLocation) { 90 this.trustStoreLocation = trustStoreLocation; 91 } 102 /** 103 * Sets the trust store location. 104 * 105 * @param trustStoreLocation the new trust store location 106 */ 107 public void setTrustStoreLocation(final String trustStoreLocation) { 108 this.trustStoreLocation = trustStoreLocation; 109 } 92 110 93 public String getTrustStoreLocation() { 94 return trustStoreLocation; 95 } 111 /** 112 * Gets the trust store location. 113 * 114 * @return the trust store location 115 */ 116 public String getTrustStoreLocation() { 117 return trustStoreLocation; 118 } 96 119 97 public void setKeyStoreLocation(final String keyStoreLocation) { 98 this.keyStoreLocation = keyStoreLocation; 99 } 120 /** 121 * Sets the key store location. 122 * 123 * @param keyStoreLocation the new key store location 124 */ 125 public void setKeyStoreLocation(final String keyStoreLocation) { 126 this.keyStoreLocation = keyStoreLocation; 127 } 100 128 101 public String getKeyStoreLocation() { 102 return keyStoreLocation; 103 } 129 /** 130 * Gets the key store location. 131 * 132 * @return the key store location 133 */ 134 public String getKeyStoreLocation() { 135 return keyStoreLocation; 136 } 104 137 105 public void setTrustStorePassword(final String trustStorePassword) { 106 this.trustStorePassword = trustStorePassword; 107 } 138 /** 139 * Sets the trust store password. 140 * 141 * @param trustStorePassword the new trust store password 142 */ 143 public void setTrustStorePassword(final String trustStorePassword) { 144 this.trustStorePassword = trustStorePassword; 145 } 108 146 109 public String getTrustStorePassword() { 110 return trustStorePassword; 111 } 147 /** 148 * Gets the trust store password. 149 * 150 * @return the trust store password 151 */ 152 public String getTrustStorePassword() { 153 return trustStorePassword; 154 } 112 155 113 public void setKeyStorePassword(final String keyStorePassword) { 114 this.keyStorePassword = keyStorePassword; 115 } 156 /** 157 * Sets the key store password. 158 * 159 * @param keyStorePassword the new key store password 160 */ 161 public void setKeyStorePassword(final String keyStorePassword) { 162 this.keyStorePassword = keyStorePassword; 163 } 116 164 117 public String getKeyStorePassword() { 118 return keyStorePassword; 119 } 165 /** 166 * Gets the key store password. 167 * 168 * @return the key store password 169 */ 170 public String getKeyStorePassword() { 171 return keyStorePassword; 172 } 120 173 121 174 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/CxfServiceEndpointClient.java
r1025 r1176 46 46 private final Logger log = LoggerFactory.getLogger(CxfServiceEndpointClient.class); 47 47 48 /** Raptor specific TLS parameters class, that can return cxf TLSParameters */48 /** Raptor specific TLS parameters class, that can return cxf specific TLSParameters */ 49 49 private ClientTLSParameters tlsParameters; 50 50 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/DefaultServiceEndpointClient.java
r639 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.remoting.client.sei.impl; 17 18 … … 22 23 public class DefaultServiceEndpointClient implements ServiceEndpointClient { 23 24 24 /* (non-Javadoc) 25 * @see uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient#sendEvents(uk.ac.cardiff.model.wsmodel.EventPushMessage, uk.ac.cardiff.raptor.registry.Endpoint) 26 */ 27 @Override 28 public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint) { 29 // TODO Auto-generated method stub 30 return false; 31 } 25 /* 26 * (non-Javadoc) 27 * 28 * @see uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient#sendEvents(uk.ac.cardiff.model.wsmodel. 29 * EventPushMessage, uk.ac.cardiff.raptor.registry.Endpoint) 30 */ 31 @Override 32 public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint) { 33 // TODO a default? 34 return false; 35 } 32 36 33 37 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/ElapsedTimePushPolicy.java
r1043 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.remoting.policy; 17 18 … … 22 23 23 24 import uk.ac.cardiff.model.event.Event; 24 import uk.ac.cardiff.raptor.remoting.client.EventReleaseEngine;25 25 26 public class ElapsedTimePushPolicy extends AbstractPushPolicy{ 27 28 /** Class logger */ 29 private final Logger log = LoggerFactory.getLogger(ElapsedTimePushPolicy.class); 30 31 /** The time, in milliseconds, that this policy was last evaluated */ 32 private long lastReleasedTime; 33 34 /** How long, in milliseconds, should elapse before release*/ 35 private long pushInterval; 36 37 38 /** 39 * Default constructor, which sets the last evaluated time on initialisation 40 */ 41 public ElapsedTimePushPolicy(){ 42 super(); 43 lastReleasedTime = System.currentTimeMillis(); 44 } 26 /** 27 * The Class ElapsedTimePushPolicy. 28 */ 29 public class ElapsedTimePushPolicy implements PushPolicy { 45 30 46 public boolean evaluatePolicy(List<Event> events) { 47 long currentTime = System.currentTimeMillis(); 48 long difference = currentTime-lastReleasedTime; 49 log.debug("ElapsedTime difference {}, pushInterval {}",difference,pushInterval); 50 if (difference>=getPushInterval()){ 51 lastReleasedTime = currentTime; 52 return true; 53 } 54 return false; 55 } 31 /** Class logger. */ 32 private final Logger log = LoggerFactory.getLogger(ElapsedTimePushPolicy.class); 56 33 57 public void setPushInterval(long pushInterval) { 58 this.pushInterval = pushInterval; 59 } 34 /** The time, in milliseconds, that this policy was last evaluated. */ 35 private long lastReleasedTime; 60 36 61 public long getPushInterval() { 62 return pushInterval; 63 } 37 /** How long, in milliseconds, should elapse before release. */ 38 private long pushInterval; 39 40 /** 41 * Default constructor, which sets the last evaluated time on initialisation. 42 */ 43 public ElapsedTimePushPolicy() { 44 super(); 45 lastReleasedTime = System.currentTimeMillis(); 46 } 47 48 /* 49 * (non-Javadoc) 50 * 51 * @see uk.ac.cardiff.raptor.remoting.policy.AbstractPushPolicy#evaluatePolicy(java.util.List) 52 */ 53 public boolean evaluatePolicy(List<Event> events) { 54 long currentTime = System.currentTimeMillis(); 55 long difference = currentTime - lastReleasedTime; 56 log.debug("ElapsedTime difference {}, pushInterval {}", difference, pushInterval); 57 if (difference >= getPushInterval()) { 58 lastReleasedTime = currentTime; 59 return true; 60 } 61 return false; 62 } 63 64 /** 65 * Sets the push interval. 66 * 67 * @param pushInterval the new push interval 68 */ 69 public void setPushInterval(long pushInterval) { 70 this.pushInterval = pushInterval; 71 } 72 73 /** 74 * Gets the push interval. 75 * 76 * @return the push interval 77 */ 78 public long getPushInterval() { 79 return pushInterval; 80 } 64 81 65 82 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoElapsedTimePushPolicy.java
r1119 r1176 34 34 * 35 35 */ 36 public class EntryNoElapsedTimePushPolicy extends AbstractPushPolicy {36 public class EntryNoElapsedTimePushPolicy implements PushPolicy { 37 37 38 /** Class logger */38 /** Class logger. */ 39 39 private final Logger log = LoggerFactory.getLogger(EntryNoElapsedTimePushPolicy.class); 40 40 41 /** The time, in milliseconds, that this policy was last evaluated */41 /** The time, in milliseconds, that this policy was last evaluated. */ 42 42 private long lastReleasedTime; 43 43 44 /** How long, in milliseconds, should elapse before release */44 /** How long, in milliseconds, should elapse before release. */ 45 45 private long pushInterval; 46 46 47 /** The threshold on the number of events needed before release */47 /** The threshold on the number of events needed before release. */ 48 48 private int pushOnOrAfterNoEntries; 49 49 50 50 /** 51 * Default constructor, which sets the last evaluated time on initialisation 51 * Default constructor, which sets the last evaluated time on initialisation. 52 52 */ 53 53 public EntryNoElapsedTimePushPolicy() { … … 86 86 } 87 87 88 /** 89 * Sets the push interval. 90 * 91 * @param pushInterval the new push interval 92 */ 88 93 public void setPushInterval(long pushInterval) { 89 94 this.pushInterval = pushInterval; 90 95 } 91 96 97 /** 98 * Gets the push interval. 99 * 100 * @return the push interval 101 */ 92 102 public long getPushInterval() { 93 103 return pushInterval; 94 104 } 95 105 106 /** 107 * Sets the push on or after no entries. 108 * 109 * @param pushOnOrAfterNoEntries the new push on or after no entries 110 */ 96 111 public void setPushOnOrAfterNoEntries(int pushOnOrAfterNoEntries) { 97 112 this.pushOnOrAfterNoEntries = pushOnOrAfterNoEntries; 98 113 } 99 114 115 /** 116 * Gets the push on or after no entries. 117 * 118 * @return the push on or after no entries 119 */ 100 120 public int getPushOnOrAfterNoEntries() { 101 121 return pushOnOrAfterNoEntries; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/EntryNoPushPolicy.java
r1043 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.remoting.policy; 17 18 … … 20 21 import uk.ac.cardiff.model.event.Event; 21 22 22 public class EntryNoPushPolicy extends AbstractPushPolicy{ 23 24 /** The threshold on the number of events needed before release*/ 25 private int pushOnOrAfterNoEntries; 26 27 28 public boolean evaluatePolicy(List<Event> events) { 29 if (pushOnOrAfterNoEntries <= events.size()) 30 return true; 31 return false; 32 } 23 public class EntryNoPushPolicy implements PushPolicy { 24 25 /** The threshold on the number of events needed before release */ 26 private int pushOnOrAfterNoEntries; 27 28 public boolean evaluatePolicy(List<Event> events) { 29 if (pushOnOrAfterNoEntries <= events.size()) 30 return true; 31 return false; 32 } 33 33 34 34 public void setPushOnOrAfterNoEntries(int pushOnOrAfterNoEntries) { 35 this.pushOnOrAfterNoEntries = pushOnOrAfterNoEntries;35 this.pushOnOrAfterNoEntries = pushOnOrAfterNoEntries; 36 36 } 37 37 38 38 public int getPushOnOrAfterNoEntries() { 39 return pushOnOrAfterNoEntries;39 return pushOnOrAfterNoEntries; 40 40 } 41 41 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/policy/PushPolicy.java
r1103 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.remoting.policy; 20 21 … … 25 26 /** 26 27 * @author philsmart 27 * 28 * 28 29 */ 29 public abstract class AbstractPushPolicy {30 public interface PushPolicy { 30 31 31 public abstract boolean evaluatePolicy(List<Event> events); 32 32 /** 33 * Determines if the list of <code>events</code> should be sent to an endpoint 34 * 35 * @param events the list of events to evaluate 36 * @return true iff the concrete implementation of this push policy determines the list of events are appropriate to 37 * send to an endpoint, false otherwise 38 */ 39 public boolean evaluatePolicy(final List<Event> events); 33 40 34 41 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/DateUtils.java
r1090 r1176 27 27 * 28 28 */ 29 public class DateUtils {29 public final class DateUtils { 30 30 31 public static String getCurrentTimeFormatted() {31 public final static String getCurrentTimeFormatted() { 32 32 DateTime current = new DateTime(); 33 33 DateTimeFormatter dateFormat = DateTimeFormat.forPattern("HH:mm:ss (dd/MM/yy)"); -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java
r1142 r1176 36 36 import uk.ac.cardiff.model.wsmodel.Suggestion; 37 37 38 /* *39 * @author philsmart38 /* 39 * Complete mess of a class, but with operations fundamental to Raptor, so clean 40 40 * 41 41 */ 42 public class ReflectionHelper {42 public final class ReflectionHelper { 43 43 44 44 /** Class logger */ … … 62 62 return true; 63 63 } catch (Throwable e) { 64 log.error(" {}", e.getMessage());64 log.error("Could not determine if class has attribute", e); 65 65 return false; 66 66 … … 95 95 } 96 96 } catch (Throwable e) { 97 log.error("Field name '" + attributeID + "' does not match internal model attribute"); 98 e.printStackTrace(); 99 System.exit(1); 97 log.error("Field name '{}' does not match internal model attribute", attributeID, e); 98 100 99 } 101 100 … … 199 198 log.error("{}", cnfex); 200 199 } catch (InstantiationException iex) { 201 // We try to instantiate an interface 202 // or an object that does not have a 203 // default constructor 200 // do nothing 204 201 } catch (IllegalAccessException iaex) { 205 // The class is not public202 // do nothing 206 203 } 207 204 } … … 247 244 log.error("{}", cnfex); 248 245 } catch (InstantiationException iex) { 249 // We try to instantiate an interface 250 // or an object that does not have a 251 // default constructor 246 // do nothing 252 247 } catch (IllegalAccessException iaex) { 253 // The class is not public248 // do nothing 254 249 } 255 250 } … … 379 374 File directory = new File(url.getFile()); 380 375 381 // New code382 // ======383 376 if (directory.exists()) { 384 377 // Get the list of the files contained in the package … … 416 409 * Checks whether the Object <code>object</code> has the field <code>fieldName</code> 417 410 * 418 * @param object 419 * @param fieldName 420 * @return 411 * @param object the object to check 412 * @param fieldName the fieldname to check if present on <code>object</code> 413 * @return true iff the object has a field name called <code>fieldName</code>, false otherwise 421 414 */ 422 415 private static Boolean hasField(Object object, String fieldName) { … … 437 430 if (method.length() > 0) { 438 431 String name = "set"; 439 // now capitalise the first letter of the method name440 432 Character firstLetter = method.charAt(0); 441 433 firstLetter = Character.toUpperCase(firstLetter); 442 434 String newMethodName = method.substring(1, method.length()); 443 435 name += firstLetter + newMethodName; 444 // System.out.println("method name: " + name);445 436 return name; 446 437 … … 457 448 if (method.length() > 0) { 458 449 String name = "get"; 459 // now capitalise the first letter of the method name460 450 Character firstLetter = method.charAt(0); 461 451 firstLetter = Character.toUpperCase(firstLetter); 462 452 String newMethodName = method.substring(1, method.length()); 463 453 name += firstLetter + newMethodName; 464 // System.out.println("method name: " + name);465 454 return name; 466 455 … … 478 467 } catch (Throwable e) { 479 468 log.error("Field name '" + fieldname + "' does not match internal model attribute"); 480 e.printStackTrace();481 469 482 470 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/AsynchronousEntryStoragePipeline.java
r1043 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.store; 17 18 … … 28 29 public class AsynchronousEntryStoragePipeline { 29 30 30 /** class logger */31 /** class logger. */ 31 32 private final Logger log = LoggerFactory.getLogger(AsynchronousEntryStoragePipeline.class); 32 33 33 /** An ID used to track the progress of any transaction */34 /** An ID used to track the progress of any transaction. */ 34 35 private int transactionId; 35 36 … … 37 38 private EventHandler eventHandler; 38 39 39 /** Attribute association engine, used to attach additional attributes to events */40 /** Attribute association engine, used to attach additional attributes to events. */ 40 41 private AttributeAssociationEngine attributeAssociationEngine; 41 42 42 public AsynchronousEntryStoragePipeline(int transactionId, EventHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine) { 43 public AsynchronousEntryStoragePipeline(final int transactionId, final EventHandler entryHandler, 44 final AttributeAssociationEngine attributeAssociationEngine) { 43 45 this.eventHandler = entryHandler; 44 46 this.attributeAssociationEngine = attributeAssociationEngine; … … 47 49 48 50 /** 51 * Executes the storage pipeline task to store the list of <code>events</code> into the <code>eventHandler</code> . 49 52 * Starts and shuts down the <code>storeEntryTask</code> immediately, so that when it completes it can be re-used. 50 53 * 51 * @param events 52 * the events to store 54 * @param events the events to store 53 55 */ 54 public void execute(List<Event> events, StoreEntriesTaskCallbackInterface callback) { 55 StoreEntriesPipelineTask storeEntryTask = new StoreEntriesPipelineTask(eventHandler, attributeAssociationEngine, events, callback); 56 public void execute(final List<Event> events, final StoreEntriesTaskCallbackInterface callback) { 57 StoreEventsPipelineTask storeEntryTask = 58 new StoreEventsPipelineTask(eventHandler, attributeAssociationEngine, events, callback); 56 59 ExecutorService es = Executors.newSingleThreadExecutor(); 57 60 es.submit(storeEntryTask); … … 60 63 61 64 /** 62 * @param transactionId 63 * the transactionId to set 65 * @param transactionId the transactionId to set 64 66 */ 65 67 public void setTransactionId(int transactionId) { -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java
r1045 r1176 17 17 * 18 18 */ 19 19 20 package uk.ac.cardiff.raptor.store; 20 21 … … 26 27 import org.slf4j.LoggerFactory; 27 28 28 29 29 import uk.ac.cardiff.model.event.Event; 30 30 import uk.ac.cardiff.model.wsmodel.Suggestion; 31 import uk.ac.cardiff.raptor.store.EventHandler;32 import uk.ac.cardiff.raptor.store.dao.StorageException;33 31 import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 34 32 import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 33 import uk.ac.cardiff.raptor.store.dao.StorageException; 35 34 36 35 /** … … 40 39 public class StorageEngine implements StoreEntriesTaskCallbackInterface { 41 40 42 /** Class logger */ 43 private final Logger log = LoggerFactory.getLogger(StorageEngine.class); 44 45 /** Responsible for storing all entries (e.g. events) */ 46 private EventHandler eventHandler; 47 48 /** Engine used to associate attributes to existing events in the MUA */ 49 private AttributeAssociationEngine attributeAssociationEngine; 50 51 /** The ID of the currently executing transaction */ 52 private int currentTransactionId; 53 54 /** Whether a transaction is currently in progress */ 55 private boolean transactionInProgress; 56 57 /** Default Constructor */ 58 public StorageEngine() { 59 60 } 61 62 public void storageResultCallback(Object result) { 63 log.debug("Storage task completed {}, for transaction id [{}]", result, currentTransactionId); 64 transactionInProgress = false; 65 66 } 67 68 /** 69 * Stores the <code>events</code> asynchronously through the {@link uk.ac.cardiff.raptor.store.EventHandler} 70 * 71 * @param transactionId the numerical Id of this transaction 72 * @param events the events to store 73 */ 74 public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException { 75 if (transactionInProgress) { 76 throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 77 } 78 log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 79 this.currentTransactionId = transactionId; 80 transactionInProgress = true; 81 AsynchronousEntryStoragePipeline asyncEntryStorage = new AsynchronousEntryStoragePipeline(transactionId, eventHandler, attributeAssociationEngine); 82 asyncEntryStorage.execute(events, this); 83 84 } 85 86 public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) throws TransactionInProgressException { 87 if (transactionInProgress) { 88 throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 89 } 90 log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 91 this.currentTransactionId = transactionId; 92 transactionInProgress = true; 93 try { 94 attributeAssociationEngine.associateAttributes(events); 95 eventHandler.addEvents(events); 96 log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 97 } catch (StorageException e) { 98 log.error("Could not store events for transaction id [{}], {}", transactionId); 99 } catch (AttributeAssociationException e) { 100 log.error("Could not store events for transaction id [{}], {}", transactionId); 101 } 102 transactionInProgress = false; 103 } 104 105 /** 106 * Returns events on or after the input time 107 * <code>earliestReleaseTime</code>. 108 * 109 * @param earliestReleaseTime 110 * @return 111 */ 112 public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 113 List<Event> query = (List<Event>) eventHandler.query("from Event where eventTime >= ?", new Object[] { earliestReleaseTime }); 114 return query; 115 } 116 117 /** 118 * Returns events on or after the input time 119 * <code>earliestReleaseTime</code>, but with a maximum of 120 * <code>maxNoResults</code> results (in chronological order). 121 * 122 * @param earliestReleaseTime 123 * @param maxNoResults 124 * @return 125 */ 126 public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 127 List<Event> query = (List<Event>) eventHandler.query("from Event where eventTime >= ? order by eventTime asc", new Object[] { earliestReleaseTime }, 128 maxNoResults); 129 return query; 130 } 131 132 /** 41 /** Class logger */ 42 private final Logger log = LoggerFactory.getLogger(StorageEngine.class); 43 44 /** Responsible for storing all entries (e.g. events) */ 45 private EventHandler eventHandler; 46 47 /** Engine used to associate attributes to existing events in the MUA */ 48 private AttributeAssociationEngine attributeAssociationEngine; 49 50 /** The ID of the currently executing transaction */ 51 private int currentTransactionId; 52 53 /** Whether a transaction is currently in progress */ 54 private boolean transactionInProgress; 55 56 /** Default Constructor */ 57 public StorageEngine() { 58 59 } 60 61 public void storageResultCallback(Object result) { 62 log.debug("Storage task completed {}, for transaction id [{}]", result, currentTransactionId); 63 transactionInProgress = false; 64 65 } 66 67 /** 68 * Stores the <code>events</code> asynchronously through the configured 69 * {@link uk.ac.cardiff.raptor.store.EventHandler} 70 * 71 * @param transactionId the numerical Id of this transaction 72 * @param events the events to store 73 */ 74 public void performAsynchronousEntryStoragePipeline(int transactionId, List<Event> events) 75 throws TransactionInProgressException { 76 if (transactionInProgress) { 77 throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 78 } 79 log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 80 currentTransactionId = transactionId; 81 transactionInProgress = true; 82 AsynchronousEntryStoragePipeline asyncEntryStorage = 83 new AsynchronousEntryStoragePipeline(transactionId, eventHandler, attributeAssociationEngine); 84 asyncEntryStorage.execute(events, this); 85 86 } 87 88 public void performSynchronousEntryStoragePipeline(int transactionId, List<Event> events) 89 throws TransactionInProgressException { 90 if (transactionInProgress) { 91 throw new TransactionInProgressException("Transaction " + currentTransactionId + " currently in processing"); 92 } 93 log.info("Committing {} entries to the storage engine, with transaction id [{}]", events.size(), transactionId); 94 currentTransactionId = transactionId; 95 transactionInProgress = true; 96 try { 97 attributeAssociationEngine.associateAttributes(events); 98 eventHandler.addEvents(events); 99 log.debug("Storage task completed true, for transaction id [{}]", currentTransactionId); 100 } catch (StorageException e) { 101 log.error("Could not store events for transaction id [{}], {}", transactionId); 102 } catch (AttributeAssociationException e) { 103 log.error("Could not store events for transaction id [{}], {}", transactionId); 104 } 105 transactionInProgress = false; 106 } 107 108 /** 109 * Returns events on or after the input time <code>earliestReleaseTime</code>. 110 * 111 * @param earliestReleaseTime 112 * @return 113 */ 114 public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime) { 115 List<Event> query = 116 (List<Event>) eventHandler.query("from Event where eventTime >= ?", new Object[] {earliestReleaseTime}); 117 return query; 118 } 119 120 /** 121 * Returns events on or after the input time <code>earliestReleaseTime</code>, but with a maximum of 122 * <code>maxNoResults</code> results (in chronological order). 123 * 124 * @param earliestReleaseTime 125 * @param maxNoResults 126 * @return 127 */ 128 public List<Event> getEventsOnOrAfter(DateTime earliestReleaseTime, int maxNoResults) { 129 List<Event> query = 130 (List<Event>) eventHandler.query("from Event where eventTime >= ? order by eventTime asc", 131 new Object[] {earliestReleaseTime}, maxNoResults); 132 return query; 133 } 134 135 /** 133 136 * 134 137 */ 135 public void removeAllEntries() { 136 eventHandler.removeAllEvents(); 137 } 138 139 /** 140 * Sets the configured entry handler. Must also then initialise that entry 141 * handler 142 * 143 * @param entryHandler 144 * the entryHandler to set 145 */ 146 public void setEntryHandler(EventHandler entryHandler) { 147 this.eventHandler = entryHandler; 148 entryHandler.initialise(); 149 } 150 151 /** 152 * @return the entryHandler 153 */ 154 public EventHandler getEntryHandler() { 155 return eventHandler; 156 } 157 158 /** 159 * @param attributeAssociationEngine 160 * the attributeAssociationEngine to set 161 */ 162 public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 163 this.attributeAssociationEngine = attributeAssociationEngine; 164 } 165 166 /** 167 * @return the attributeAssociationEngine 168 */ 169 public AttributeAssociationEngine getAttributeAssociationEngine() { 170 return attributeAssociationEngine; 171 } 172 173 /** 174 * Returns the possible values that each of the input field names can take 175 * 176 * @param possibleFieldNameValuesList 177 * @return 178 */ 179 public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 180 ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 181 182 for (String fieldName : possibleFieldNameValuesList) { 183 try { 184 String query = "select " + fieldName + " from Event group by (" + fieldName + ")"; 185 List results = eventHandler.query(query); 186 log.trace("Looking for possible values for field {} using query [{}]",fieldName, query); 187 int noResults=0; 188 for (Object result : results) { 189 if (result instanceof String) { 190 Suggestion suggestion = new Suggestion(); 191 suggestion.setBase(fieldName); 192 suggestion.setValue((String) result); 193 suggestions.add(suggestion); 194 noResults++; 195 } 196 } 197 log.debug("Field {} has {} suggestion values",fieldName,noResults); 198 } catch (RuntimeException e) { 199 log.warn("Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about", fieldName); 200 } 201 202 } 203 204 return suggestions; 205 } 138 public void removeAllEntries() { 139 eventHandler.removeAllEvents(); 140 } 141 142 /** 143 * Sets the configured entry handler. Must also then initialise that entry handler 144 * 145 * @param entryHandler the entryHandler to set 146 */ 147 public void setEntryHandler(EventHandler entryHandler) { 148 this.eventHandler = entryHandler; 149 entryHandler.initialise(); 150 } 151 152 /** 153 * @return the entryHandler 154 */ 155 public EventHandler getEntryHandler() { 156 return eventHandler; 157 } 158 159 /** 160 * @param attributeAssociationEngine the attributeAssociationEngine to set 161 */ 162 public void setAttributeAssociationEngine(AttributeAssociationEngine attributeAssociationEngine) { 163 this.attributeAssociationEngine = attributeAssociationEngine; 164 } 165 166 /** 167 * @return the attributeAssociationEngine 168 */ 169 public AttributeAssociationEngine getAttributeAssociationEngine() { 170 return attributeAssociationEngine; 171 } 172 173 /** 174 * Returns the possible values that each of the input field names can take 175 * 176 * @param possibleFieldNameValuesList 177 * @return 178 */ 179 public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 180 ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 181 182 for (String fieldName : possibleFieldNameValuesList) { 183 try { 184 String query = "select " + fieldName + " from Event group by (" + fieldName + ")"; 185 List results = eventHandler.query(query); 186 log.trace("Looking for possible values for field {} using query [{}]", fieldName, query); 187 int noResults = 0; 188 for (Object result : results) { 189 if (result instanceof String) { 190 Suggestion suggestion = new Suggestion(); 191 suggestion.setBase(fieldName); 192 suggestion.setValue((String) result); 193 suggestions.add(suggestion); 194 noResults++; 195 } 196 } 197 log.debug("Field {} has {} suggestion values", fieldName, noResults); 198 } catch (RuntimeException e) { 199 log.warn( 200 "Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about", 201 fieldName); 202 } 203 204 } 205 206 return suggestions; 207 } 206 208 207 209 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StoreEventsPipelineTask.java
r1103 r1176 35 35 * 36 36 */ 37 public class StoreE ntriesPipelineTask implements Callable<Boolean> {37 public class StoreEventsPipelineTask implements Callable<Boolean> { 38 38 39 39 /** class logger */ 40 private final Logger log = LoggerFactory.getLogger(StoreE ntriesPipelineTask.class);40 private final Logger log = LoggerFactory.getLogger(StoreEventsPipelineTask.class); 41 41 42 42 /** The entry handler used to store entries (e.g. events) */ … … 52 52 private List<Event> events; 53 53 54 public StoreE ntriesPipelineTask(EventHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine,54 public StoreEventsPipelineTask(EventHandler entryHandler, AttributeAssociationEngine attributeAssociationEngine, 55 55 List<Event> events, StoreEntriesTaskCallbackInterface storeCallback) { 56 56 this.storeCallback = storeCallback; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/StorageException.java
r672 r1176 14 14 * limitations under the License. 15 15 */ 16 16 17 package uk.ac.cardiff.raptor.store.dao; 17 18 18 public class StorageException extends Exception {19 public class StorageException extends Exception { 19 20 20 /**21 * 22 */23 private static final long serialVersionUID = -4614661463043866258L;21 /** 22 * Generated serial UID. 23 */ 24 private static final long serialVersionUID = -4614661463043866258L; 24 25 25 public StorageException (String message){ 26 super(message); 27 } 28 29 public StorageException (String message, Exception wrappedException){ 30 super(message,wrappedException); 26 /** Constructor. */ 27 public StorageException() { 28 super(); 31 29 } 32 30 31 /** 32 * Constructor. 33 * 34 * @param message exception message 35 */ 36 public StorageException(final String message) { 37 super(message); 38 } 39 40 /** 41 * Constructor. 42 * 43 * @param wrappedException exception to be wrapped by this one 44 */ 45 public StorageException(final Exception wrappedException) { 46 super(wrappedException); 47 } 48 49 /** 50 * Constructor. 51 * 52 * @param message exception message 53 * @param wrappedException exception to be wrapped by this one 54 */ 55 public StorageException(final String message, final Exception wrappedException) { 56 super(message, wrappedException); 57 } 33 58 34 59 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/LogFileMemoryEventHandler.java
r1046 r1176 29 29 import java.util.Set; 30 30 31 import org.joda.time.DateTime; 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 31 35 import uk.ac.cardiff.model.event.Event; 32 36 import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 33 37 import uk.ac.cardiff.raptor.store.IncrementalEventHandler; 34 38 35 import org.joda.time.DateTime;36 import org.slf4j.Logger;37 import org.slf4j.LoggerFactory;38 39 39 public class LogFileMemoryEventHandler implements IncrementalEventHandler { 40 40 41 /** Class logger */ 42 private final Logger log = LoggerFactory.getLogger(MemoryEventHandler.class); 43 44 /** Pointer to the last recorded entry, for incremental update. */ 45 private DateTime latestEntryTime; 46 47 /** Set of all entries stored by this EntryHandler. */ 48 private Set<Event> entries; 49 50 /** 51 * Stores the set of latest unique entries. That is, those with the latest 52 * and same DateTime, but different state (attribute values). This set is 53 * checked when adding new entries, and is not removed when records are 54 * removed. 55 */ 56 private Set<Event> latestEqualEntries; 57 58 public LogFileMemoryEventHandler() { 59 entries = new LinkedHashSet<Event>(); 60 latestEqualEntries = new LinkedHashSet<Event>(); 61 } 62 63 public void addEntries(List<Event> entries) { 64 log.debug("Current: " + this.entries.size() + " in: " + entries.size()); 65 66 for (Event event : entries) { 67 addEntry(event); 68 69 } 70 log.debug("Total No. of Entries " + this.entries.size() + " Latest Entry at: " + getLatestEntryTime()); 71 } 72 73 /** 74 * First copy the hash of this entry into the <code>eventId</code> column if 75 * its empty. Then, add to the entry set iff its a newer entry. If equal, 76 * first check the <code>latestEqualEntries</code> set, if contained in this 77 * set, then it has already been added, if not add. 78 * 79 * @return true if this event was added to the entry handler, false 80 * otherwise 81 */ 82 public boolean addEntry(Event event) { 83 addEventIdIfNull(event); 84 boolean isAfter = isAfter(event); 85 boolean isEqual = isEqual(event); 86 if (isAfter) { 87 entries.add(event); 88 updateLastEntry(event); 89 return true; 90 } else if (isEqual) { 91 boolean isAlreadyInLatest = latestEqualEntries.contains(event); 92 if (isAlreadyInLatest) { 93 log.trace("Duplicated, probably same event [{}]", event); 94 return false; 95 } 96 if (!isAlreadyInLatest) { 97 entries.add(event); 98 updateLastEntry(event); 99 return true; 100 } 101 } 102 return false; 103 104 } 105 106 public void reset() { 107 entries.clear(); 108 latestEqualEntries.clear(); 109 latestEntryTime = null; 110 } 111 112 /** 113 * Stores the hashcode of the event as the <code>eventId</code> iff there is 114 * no existing eventId (defined as 0), and the event has a valid hashcode. 115 * 116 * @param event 117 */ 118 private void addEventIdIfNull(Event event) { 119 if (event.getEventId() != 0) { 120 return; 121 } 122 int hashCode = ReflectionHelper.getHashCodeFromEventOrNull(event); 123 if (hashCode != 0) { 124 event.setEventId(hashCode); 125 } 126 } 127 128 public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 129 log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)", earliestReleaseTime, latestEqualEntries.size()); 130 ArrayList<Event> toRemove = new ArrayList<Event>(); 131 for (Event event : entries) { 132 if (event.getEventTime().isBefore(earliestReleaseTime)) 133 toRemove.add(event); 134 if (event.getEventTime().isEqual(earliestReleaseTime)) { 135 if (latestEqualEntries.contains(event.getEventId())) { 136 toRemove.add(event); 137 } 138 } 139 } 140 entries.removeAll(toRemove); 141 142 } 143 144 private void updateLastEntry(Event entry) { 145 DateTime entryTime = entry.getEventTime(); 146 if (getLatestEntryTime() == null) 147 setLatestEntryTime(entryTime); 148 if (entryTime.isAfter(getLatestEntryTime())) { 149 setLatestEntryTime(entryTime); 150 latestEqualEntries.clear(); 151 latestEqualEntries.add(entry); 152 } 153 if (entryTime.isEqual(getLatestEntryTime())) { 154 latestEqualEntries.add(entry); 155 } 156 } 157 158 public void setLatestEntryTime(DateTime latestEntryTime) { 159 this.latestEntryTime = latestEntryTime; 160 } 161 162 public DateTime getLatestEntryTime() { 163 return latestEntryTime; 164 } 165 166 /** 167 * @param authE 168 * @return 169 */ 170 public boolean isNewerOrEqual(Event event) { 171 if (latestEntryTime == null) 172 return true; 173 if (!event.getEventTime().isBefore(latestEntryTime)) 174 return true; 175 return false; 176 } 177 178 public boolean isEqual(Event event) { 179 if (latestEntryTime == null) 180 return false; 181 return event.getEventTime().isEqual(latestEntryTime); 182 } 183 184 public boolean isAfter(Event event) { 185 if (latestEntryTime == null) 186 return true; 187 return event.getEventTime().isAfter(latestEntryTime); 188 } 189 190 /** 191 * pushes the latestEntryTime by 1 millisecond (see LogFileParser.java for 192 * explanation) 193 */ 194 public void endTransaction() { 195 latestEntryTime = new DateTime(latestEntryTime.getMillis() + 1); 196 197 } 198 199 /** 200 * @return the list of entries currently stored by the entry handler 201 */ 202 public List<Event> getEntries() { 203 return new ArrayList<Event>(entries); 204 205 } 206 207 /** 208 * Removes all entries, but does not reset last entry, as this is still used 209 * so as not to add previously parsed entries. 210 */ 211 public void removeAllEntries() { 212 entries.clear(); 213 } 214 215 /** 216 * This is a no-op method for the memory entry handler 217 */ 218 public void initialise() { 219 220 } 221 222 public int getNumberOfEntries() { 223 return entries.size(); 224 } 225 226 227 public void setEntries(Set<Event> entries) { 228 this.entries = entries; 229 230 } 231 232 41 /** Class logger */ 42 private final Logger log = LoggerFactory.getLogger(MemoryEventHandler.class); 43 44 /** Pointer to the last recorded entry, for incremental update. */ 45 private DateTime latestEntryTime; 46 47 /** Set of all entries stored by this EntryHandler. */ 48 private Set<Event> entries; 49 50 /** 51 * Stores the set of latest unique entries. That is, those with the latest and same Date and Time, but different 52 * state (attribute values). This set is checked when adding new entries, and is not removed when records are 53 * removed. 54 */ 55 private Set<Event> latestEqualEntries; 56 57 public LogFileMemoryEventHandler() { 58 entries = new LinkedHashSet<Event>(); 59 latestEqualEntries = new LinkedHashSet<Event>(); 60 } 61 62 public void addEntries(List<Event> entries) { 63 log.debug("Current: " + this.entries.size() + " in: " + entries.size()); 64 65 for (Event event : entries) { 66 addEntry(event); 67 68 } 69 log.debug("Total No. of Entries " + this.entries.size() + " Latest Entry at: " + getLatestEntryTime()); 70 } 71 72 /** 73 * First copy the hash of this entry into the <code>eventId</code> column if its empty. Then, add to the entry set 74 * iff its a newer entry. If equal, first check the <code>latestEqualEntries</code> set, if contained in this set, 75 * then it has already been added, if not add. 76 * 77 * @return true if this event was added to the entry handler, false otherwise 78 */ 79 public boolean addEntry(Event event) { 80 addEventIdIfNull(event); 81 boolean isAfter = isAfter(event); 82 boolean isEqual = isEqual(event); 83 if (isAfter) { 84 entries.add(event); 85 updateLastEntry(event); 86 return true; 87 } else if (isEqual) { 88 boolean isAlreadyInLatest = latestEqualEntries.contains(event); 89 if (isAlreadyInLatest) { 90 log.trace("Duplicated, probably same event [{}]", event); 91 return false; 92 } 93 if (!isAlreadyInLatest) { 94 entries.add(event); 95 updateLastEntry(event); 96 return true; 97 } 98 } 99 return false; 100 101 } 102 103 /** 104 * Clears the set of <code>entries</code>, the set of <code>latestEqualEntries</code> and dereferences the 105 * <code>latestEntryTime</code> 106 */ 107 public void reset() { 108 entries.clear(); 109 latestEqualEntries.clear(); 110 latestEntryTime = null; 111 } 112 113 /** 114 * Stores the hashcode of the event as the <code>eventId</code> iff there is no existing eventId (defined as 0), and 115 * the event has a valid hashcode. 116 * 117 * @param event 118 */ 119 private void addEventIdIfNull(Event event) { 120 if (event.getEventId() != 0) { 121 return; 122 } 123 int hashCode = ReflectionHelper.getHashCodeFromEventOrNull(event); 124 if (hashCode != 0) { 125 event.setEventId(hashCode); 126 } 127 } 128 129 public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 130 log.debug("Removing events earlier than {}, or in the set of last equal events sent (from {} events)", 131 earliestReleaseTime, latestEqualEntries.size()); 132 ArrayList<Event> toRemove = new ArrayList<Event>(); 133 for (Event event : entries) { 134 if (event.getEventTime().isBefore(earliestReleaseTime)) 135 toRemove.add(event); 136 if (event.getEventTime().isEqual(earliestReleaseTime)) { 137 if (latestEqualEntries.contains(event.getEventId())) { 138 toRemove.add(event); 139 } 140 } 141 } 142 entries.removeAll(toRemove); 143 144 } 145 146 private void updateLastEntry(Event entry) { 147 DateTime entryTime = entry.getEventTime(); 148 if (getLatestEntryTime() == null) 149 setLatestEntryTime(entryTime); 150 if (entryTime.isAfter(getLatestEntryTime())) { 151 setLatestEntryTime(entryTime); 152 latestEqualEntries.clear(); 153 latestEqualEntries.add(entry); 154 } 155 if (entryTime.isEqual(getLatestEntryTime())) { 156 latestEqualEntries.add(entry); 157 } 158 } 159 160 public void setLatestEntryTime(DateTime latestEntryTime) { 161 this.latestEntryTime = latestEntryTime; 162 } 163 164 public DateTime getLatestEntryTime() { 165 return latestEntryTime; 166 } 167 168 /** 169 * @param authE 170 * @return 171 */ 172 public boolean isNewerOrEqual(Event event) { 173 if (latestEntryTime == null) 174 return true; 175 if (!event.getEventTime().isBefore(latestEntryTime)) 176 return true; 177 return false; 178 } 179 180 public boolean isEqual(Event event) { 181 if (latestEntryTime == null) 182 return false; 183 return event.getEventTime().isEqual(latestEntryTime); 184 } 185 186 public boolean isAfter(Event event) { 187 if (latestEntryTime == null) 188 return true; 189 return event.getEventTime().isAfter(latestEntryTime); 190 } 191 192 /** 193 * pushes the latestEntryTime by 1 millisecond (see LogFileParser.java for explanation) 194 */ 195 public void endTransaction() { 196 latestEntryTime = new DateTime(latestEntryTime.getMillis() + 1); 197 198 } 199 200 /** 201 * @return the list of entries currently stored by the entry handler 202 */ 203 public List<Event> getEntries() { 204 return new ArrayList<Event>(entries); 205 206 } 207 208 /** 209 * Removes all entries, but does not reset last entry, as this is still used so as not to add previously parsed 210 * entries. 211 */ 212 public void removeAllEntries() { 213 entries.clear(); 214 } 215 216 /** 217 * This is a no-op method for the memory entry handler 218 */ 219 public void initialise() { 220 221 } 222 223 public int getNumberOfEntries() { 224 return entries.size(); 225 } 226 227 public void setEntries(Set<Event> entries) { 228 this.entries = entries; 229 230 } 233 231 234 232 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java
r1142 r1176 69 69 70 70 public PersistantEventHandler(RaptorDataConnection dataConnection) { 71 this.setDataConnection(dataConnection);71 setDataConnection(dataConnection); 72 72 persistQueue = new HashSet<Event>(); 73 73 … … 75 75 76 76 /** 77 * Initialises the entry handler. In particular, loads all entries from the main datastore, through the 78 * <code>dataConnection</code> instance. 77 * Initialises the entry handler. 79 78 */ 80 79 public void initialise() { … … 134 133 * The <code>entries</code> are stored in the <code>persistQueue</code> until they are persisted. If an exception is 135 134 * thrown before they are persisted, they remain in the <code>persistQueue</code>. This method then saves this 136 * collection in batch, as opposed to the <code>addE ntry</code> method which stores events one at a time. In order135 * collection in batch, as opposed to the <code>addEvent</code> method which stores events one at a time. In order 137 136 * to detect duplicates, a query is run over the database in order to check duplicates within already stored events, 138 137 * as well as adding new events to a <code>Set</code> <code>persist</code> which prevents duplicates in the … … 182 181 return true; 183 182 } else { 184 log. error("Duplicated event found\n{}", event);183 log.warn("Duplicated event found\n{}", event); 185 184 return false; 186 185 }
Note: See TracChangeset
for help on using the changeset viewer.
