private static String namespaceFromId(final WithId withId) { return withId.getId().split(":", 2)[0]; }
private static String namespaceFromId(final WithId withId) { return withId.getId().split(":", 2)[0]; }
private static String namespaceFromId(final WithId withId) { return withId.getId().split(":", 2)[0]; }
private static String namespaceFromId(final WithId withId) { return withId.getId().split(":", 2)[0]; }
static IllegalArgumentException unhandled(final WithId command) { final String msgPattern = "This Thing Actor did not handle the requested Thing with ID <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgPattern, command.getId())); }
static IllegalArgumentException unhandled(final WithId command) { final String msgPattern = "This Thing Actor did not handle the requested Thing with ID <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgPattern, command.getId())); }
@Override public String entityId(final Object message) { if (message instanceof ShardedMessageEnvelope) { return ((ShardedMessageEnvelope) message).getId(); } else if (message instanceof WithId) { return ((WithId) message).getId(); } else if (message instanceof ShardRegion.StartEntity) { return ((ShardRegion.StartEntity) message).entityId(); } return null; }
@Override public String entityId(final Object message) { if (message instanceof ShardedMessageEnvelope) { return ((ShardedMessageEnvelope) message).getId(); } else if (message instanceof WithId) { return ((WithId) message).getId(); } else if (message instanceof ShardRegion.StartEntity) { return ((ShardRegion.StartEntity) message).entityId(); } return null; }
/** * Blocks a {@code signal} if it relates to an entity within a blocked namespace. * * @param signal the signal to block. * @return a completion stage which either completes successfully with the given {@code signal} or exceptionally * with a {@code NamespaceBlockedException}. */ public CompletionStage<WithDittoHeaders> block(final WithDittoHeaders signal) { if (signal instanceof WithId) { final Optional<String> namespaceOptional = NamespaceReader.fromEntityId(((WithId) signal).getId()); if (namespaceOptional.isPresent()) { final String namespace = namespaceOptional.get(); return blockedNamespaces.contains(namespace) .thenApply(containsNamespace -> { if (containsNamespace != null && containsNamespace) { throw NamespaceBlockedException.newBuilder(namespace) .dittoHeaders(signal.getDittoHeaders()) .build(); } else { return signal; } }); } } return CompletableFuture.completedFuture(signal); }