From 46bef2322f46c0f3834e7f5390977f64239d38b3 Mon Sep 17 00:00:00 2001 From: Ivan Bodrov Date: Thu, 9 Nov 2023 12:33:55 -0500 Subject: [PATCH] kafka-event-sink: bind resources in a module --- .../eventsink/kafka/KafkaConnector.java | 4 -- .../eventsink/kafka/KafkaEventSink.java | 2 - .../kafka/KafkaEventSinkConfiguration.java | 2 - .../plugins/eventsink/kafka/KafkaModule.java | 50 +++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaModule.java diff --git a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaConnector.java b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaConnector.java index 5155b392a3..8f95271106 100644 --- a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaConnector.java +++ b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaConnector.java @@ -28,14 +28,10 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Properties; -@Named -@Singleton public class KafkaConnector implements BackgroundTask { private static final Logger log = LoggerFactory.getLogger(KafkaConnector.class); diff --git a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSink.java b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSink.java index 301d7c521a..5dfd8af0a9 100644 --- a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSink.java +++ b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSink.java @@ -31,11 +31,9 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; -import javax.inject.Named; import java.util.Collections; import java.util.List; -@Named public class KafkaEventSink implements ProcessEventListener, ProcessLogListener, AuditLogListener { private static final Logger log = LoggerFactory.getLogger(KafkaEventSink.class); diff --git a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSinkConfiguration.java b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSinkConfiguration.java index b47f6cfaa8..45795101de 100644 --- a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSinkConfiguration.java +++ b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaEventSinkConfiguration.java @@ -24,10 +24,8 @@ import javax.annotation.Nullable; import javax.inject.Inject; -import javax.inject.Named; import java.io.Serializable; -@Named public class KafkaEventSinkConfiguration implements Serializable { private static final long serialVersionUID = 1L; diff --git a/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaModule.java b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaModule.java new file mode 100644 index 0000000000..29d25563d8 --- /dev/null +++ b/server/plugins/kafka-event-sink/src/main/java/com/walmartlabs/concord/server/plugins/eventsink/kafka/KafkaModule.java @@ -0,0 +1,50 @@ +package com.walmartlabs.concord.server.plugins.eventsink.kafka; + +/*- + * ***** + * Concord + * ----- + * Copyright (C) 2017 - 2023 Walmart Inc. + * ----- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ===== + */ + +import com.google.inject.Binder; +import com.google.inject.Module; +import com.walmartlabs.concord.server.sdk.BackgroundTask; +import com.walmartlabs.concord.server.sdk.audit.AuditLogListener; +import com.walmartlabs.concord.server.sdk.events.ProcessEventListener; +import com.walmartlabs.concord.server.sdk.log.ProcessLogListener; + +import javax.inject.Named; + +import static com.google.inject.Scopes.SINGLETON; +import static com.google.inject.multibindings.Multibinder.newSetBinder; + +@Named +public class KafkaModule implements Module { + + @Override + public void configure(Binder binder) { + binder.bind(KafkaEventSinkConfiguration.class).in(SINGLETON); + + binder.bind(KafkaEventSink.class).in(SINGLETON); + newSetBinder(binder, ProcessEventListener.class).addBinding().to(KafkaEventSink.class); + newSetBinder(binder, ProcessLogListener.class).addBinding().to(KafkaEventSink.class); + newSetBinder(binder, AuditLogListener.class).addBinding().to(KafkaEventSink.class); + + binder.bind(KafkaConnector.class).in(SINGLETON); + newSetBinder(binder, BackgroundTask.class).addBinding().to(KafkaConnector.class); + } +}