Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CloudEventValidatorProvider thread safe #650

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.cloudevents.CloudEvent;
import io.cloudevents.core.validator.CloudEventValidator;

import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ServiceLoader;

/**
Expand All @@ -30,10 +30,14 @@ public class CloudEventValidatorProvider {

private static final CloudEventValidatorProvider cloudEventValidatorProvider = new CloudEventValidatorProvider();

private final ServiceLoader<CloudEventValidator> loader;
private final Collection<CloudEventValidator> validators;

private CloudEventValidatorProvider(){
loader = ServiceLoader.load(CloudEventValidator.class);
private CloudEventValidatorProvider() {
final ServiceLoader<CloudEventValidator> loader = ServiceLoader.load(CloudEventValidator.class);
this.validators = new ArrayList<>(2);
for (CloudEventValidator cloudEventValidator : loader) {
validators.add(cloudEventValidator);
}
}

public static CloudEventValidatorProvider getInstance() {
Expand All @@ -42,10 +46,11 @@ public static CloudEventValidatorProvider getInstance() {

/**
* iterates through available Cloudevent validators.
* @param cloudEvent
*
* @param cloudEvent event to validate.
*/
public void validate(CloudEvent cloudEvent){
for (final CloudEventValidator validator : loader) {
public void validate(CloudEvent cloudEvent) {
for (final CloudEventValidator validator : validators) {
validator.validate(cloudEvent);
}
}
Expand Down
Loading