refactor: Renamed `ShardingStrategy` for HAProxy Runtime API -- MOVE
authorKai Moritz <kai@juplo.de>
Sun, 17 Mar 2024 21:00:08 +0000 (22:00 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 22 Mar 2024 16:39:20 +0000 (17:39 +0100)
src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyRuntimeApiShardingPublisherStrategy.java [new file with mode: 0644]
src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyShardingPublisherStrategy.java [deleted file]

diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyRuntimeApiShardingPublisherStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyRuntimeApiShardingPublisherStrategy.java
new file mode 100644 (file)
index 0000000..ad71d49
--- /dev/null
@@ -0,0 +1,40 @@
+package de.juplo.kafka.chat.backend.implementation.haproxy;
+
+import de.juplo.kafka.chat.backend.domain.ShardingPublisherStrategy;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import reactor.core.publisher.Mono;
+
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+
+@RequiredArgsConstructor
+@Slf4j
+public class HaproxyShardingPublisherStrategy implements ShardingPublisherStrategy
+{
+  private final SocketAddress haproxyAddress;
+  private final String map;
+  private final String instanceId;
+
+
+  @Override
+  public Mono<String> publishOwnership(int shard)
+  {
+    try
+    {
+      SocketChannel socketChannel = SocketChannel.open(haproxyAddress);
+      String command = "set map " + map + " " + Integer.toString(shard) + " " + instanceId + "\n";
+      byte[] commandBytes = command.getBytes();
+      ByteBuffer buffer = ByteBuffer.wrap(commandBytes);
+      socketChannel.write(buffer);
+      socketChannel.close();
+      return Mono.just(instanceId);
+    }
+    catch (Exception e)
+    {
+      return Mono.error(e);
+    }
+  }
+}
diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyShardingPublisherStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyShardingPublisherStrategy.java
deleted file mode 100644 (file)
index ad71d49..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-package de.juplo.kafka.chat.backend.implementation.haproxy;
-
-import de.juplo.kafka.chat.backend.domain.ShardingPublisherStrategy;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import reactor.core.publisher.Mono;
-
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-
-@RequiredArgsConstructor
-@Slf4j
-public class HaproxyShardingPublisherStrategy implements ShardingPublisherStrategy
-{
-  private final SocketAddress haproxyAddress;
-  private final String map;
-  private final String instanceId;
-
-
-  @Override
-  public Mono<String> publishOwnership(int shard)
-  {
-    try
-    {
-      SocketChannel socketChannel = SocketChannel.open(haproxyAddress);
-      String command = "set map " + map + " " + Integer.toString(shard) + " " + instanceId + "\n";
-      byte[] commandBytes = command.getBytes();
-      ByteBuffer buffer = ByteBuffer.wrap(commandBytes);
-      socketChannel.write(buffer);
-      socketChannel.close();
-      return Mono.just(instanceId);
-    }
-    catch (Exception e)
-    {
-      return Mono.error(e);
-    }
-  }
-}