1 package de.juplo.kafka.chat.backend.domain;
5 import java.util.Arrays;
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.util.stream.Collectors;
11 public class ShardNotOwnedException extends IllegalStateException
14 private final ChatHomeService chatHomeService;
16 private final ChatRoomInfo chatRoomInfo;
18 private final int shard;
20 private final int[] ownedShards;
23 public ShardNotOwnedException(
24 ChatHomeService chatHomeService,
25 ChatRoomInfo chatRoomInfo,
27 Collection<Integer> ownedShards)
33 ShardNotOwnedException.toArray(ownedShards));
36 public ShardNotOwnedException(
37 ChatHomeService chatHomeService,
38 ChatRoomInfo chatRoomInfo,
44 " does not own the shard " +
51 .mapToObj(ownedShard -> Integer.toString(ownedShard))
52 .collect(Collectors.joining(", ")));
53 this.chatHomeService = chatHomeService;
54 this.chatRoomInfo = chatRoomInfo;
56 this.ownedShards = ownedShards;
60 private static int[] toArray(Collection<Integer> collection)
62 int[] array = new int[collection.size()];
63 Iterator<Integer> iterator = collection.iterator();
64 for (int i = 0; iterator.hasNext(); i++)
65 array[i] = iterator.next();