EventUtilitiesFactory.java
package org.wikimedia.eventutilities.core.event;
import java.io.Serializable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.wikimedia.eventutilities.core.http.BasicHttpClient;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@SuppressFBWarnings("SE_NO_SERIALVERSIONID")
@ThreadSafe
public class EventUtilitiesFactory implements Serializable {
@Nonnull private final EventUtilitiesConfig config;
@Nullable private transient BasicHttpClient httpClient;
@Nullable private transient EventLoggingSchemaLoader eventloggingSchemaLoader;
@Nullable private transient MediawikiEventStreamConfigLoader mediawikiEventStreamConfigLoader;
@Nullable private transient EventStreamConfig eventStreamConfig;
@Nullable private transient EventSchemaLoader eventSchemaLoader;
@Nullable private transient EventStreamFactory eventStreamFactory;
@Nullable private transient EventSchemaValidator eventSchemaValidator;
@Nullable private transient JsonEventGenerator jsonEventGenerator;
public EventUtilitiesFactory(@Nonnull EventUtilitiesConfig config) {
this.config = config;
}
@Nonnull
public synchronized BasicHttpClient getHttpClient() {
if (httpClient == null) httpClient = config.createHttpClient();
return httpClient;
}
@Nonnull
public synchronized EventLoggingSchemaLoader getEventloggingSchemaLoader() {
if (eventloggingSchemaLoader == null)
eventloggingSchemaLoader = config.createEventloggingSchemaLoader(getHttpClient());
return eventloggingSchemaLoader;
}
@Nonnull
public synchronized MediawikiEventStreamConfigLoader getMediawikiEventStreamConfigLoader() {
if (mediawikiEventStreamConfigLoader == null)
mediawikiEventStreamConfigLoader = config.createMediawikiEventStreamConfigLoader(getHttpClient());
return mediawikiEventStreamConfigLoader;
}
@Nonnull
public synchronized EventStreamConfig getEventStreamConfig() {
if (eventStreamConfig == null)
eventStreamConfig = config.createEventStreamConfig(getMediawikiEventStreamConfigLoader());
return eventStreamConfig;
}
@Nonnull
public synchronized EventSchemaLoader getEventSchemaLoader() {
if (eventSchemaLoader == null)
eventSchemaLoader = config.createEventSchemaLoader(getHttpClient());
return eventSchemaLoader;
}
@Nonnull
public synchronized EventStreamFactory getEventStreamFactory() {
if (eventStreamFactory == null)
eventStreamFactory = config.createEventStreamFactory(getEventSchemaLoader(), getEventStreamConfig());
return eventStreamFactory;
}
@Nonnull
public synchronized EventSchemaValidator getEventSchemaValidator() {
if (eventSchemaValidator == null)
eventSchemaValidator = config.createEventSchemaValidator(getEventSchemaLoader());
return eventSchemaValidator;
}
@Nonnull
public synchronized JsonEventGenerator getJsonEventGenerator() {
if (jsonEventGenerator == null)
jsonEventGenerator = config.createJsonEventGenerator(getEventSchemaLoader(), getEventStreamConfig());
return jsonEventGenerator;
}
}