final class SinkSingletonService extends ChannelInitializer<SocketChannel> implements ClusterSingletonService {
private static final Logger LOG = LoggerFactory.getLogger(SinkSingletonService.class);
- private static final ServiceGroupIdentifier SGID =
- ServiceGroupIdentifier.create(SinkSingletonService.class.getName());
+ private static final ServiceGroupIdentifier SGID = new ServiceGroupIdentifier(SinkSingletonService.class.getName());
// TODO: allow different trees?
private static final DOMDataTreeIdentifier TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
YangInstanceIdentifier.of());
@Override
public synchronized void instantiateServiceInstance() {
LOG.info("Replication sink started with source {}", sourceAddress);
- this.bs = bootstrapSupport.newBootstrap();
+ bs = bootstrapSupport.newBootstrap();
doConnect();
}
final class SourceSingletonService extends ChannelInitializer<SocketChannel> implements ClusterSingletonService {
private static final Logger LOG = LoggerFactory.getLogger(SourceSingletonService.class);
private static final ServiceGroupIdentifier SGID =
- ServiceGroupIdentifier.create(SourceSingletonService.class.getName());
+ new ServiceGroupIdentifier(SourceSingletonService.class.getName());
private final BootstrapSupport bootstrapSupport;
private final DOMDataTreeChangeService dtcs;
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>util</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
exports org.opendaylight.mdsal.singleton.common.api;
requires transitive org.opendaylight.yangtools.concepts;
- requires org.opendaylight.yangtools.util;
// Annotations
requires static transitive org.eclipse.jdt.annotation;
*/
package org.opendaylight.mdsal.singleton.common.api;
-import java.io.Serial;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.util.AbstractStringIdentifier;
+import org.opendaylight.yangtools.concepts.Identifier;
/**
- * Identifier represents a service group competence. It's based on String.
+ * An {@link Identifier} of a group of {@link ClusterSingletonService}s.
+ *
+ * @param value String value, must not be {@link String#isBlank()}
*/
-public class ServiceGroupIdentifier extends AbstractStringIdentifier<ServiceGroupIdentifier> {
- @Serial
- private static final long serialVersionUID = 6853612584804702662L;
-
- protected ServiceGroupIdentifier(final @NonNull String string) {
- super(string);
- }
-
- /**
- * Method to create immutable instances of {@link ServiceGroupIdentifier}.
- *
- * @param name the String identifier for the ServiceGroupIdentifier instance
- * @return {@link ServiceGroupIdentifier} new instance
- */
- public static @NonNull ServiceGroupIdentifier create(final String name) {
- return new ServiceGroupIdentifier(name);
- }
+public record ServiceGroupIdentifier(@NonNull String value) implements Identifier {
+ @java.io.Serial
+ private static final long serialVersionUID = 1L;
- public final @NonNull String getName() {
- return getValue();
+ public ServiceGroupIdentifier {
+ if (value.isBlank()) {
+ throw new IllegalArgumentException("Value must not be blank");
+ }
}
}
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.singleton.common.api;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+class ServiceGroupIdentifierTest {
+ @Test
+ void rejectEmptyValue() {
+ final var ex = assertThrows(IllegalArgumentException.class, () -> new ServiceGroupIdentifier(""));
+ assertEquals("Value must not be blank", ex.getMessage());
+ }
+
+ @Test
+ void rejectNullValue() {
+ assertThrows(NullPointerException.class, () -> new ServiceGroupIdentifier(null));
+ }
+}
private ClusterSingletonService verifyRegistration(final ServiceRegistration reg) {
final var service = reg.getInstance();
- verify(identifier.equals(service.getIdentifier().getName()));
+ verify(identifier.equals(service.getIdentifier().value()));
return service;
}
*/
package org.opendaylight.mdsal.singleton.dom.impl;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Strings;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
public synchronized Registration registerClusterSingletonService(final ClusterSingletonService service) {
LOG.debug("Call registrationService {} method for ClusterSingletonService Provider {}", service, this);
- final String serviceIdentifier = service.getIdentifier().getName();
- checkArgument(!Strings.isNullOrEmpty(serviceIdentifier),
- "ClusterSingletonService identifier may not be null nor empty");
-
+ final var serviceIdentifier = service.getIdentifier().value();
final ServiceGroup serviceGroup;
final var existing = serviceGroupMap.get(serviceIdentifier);
if (existing == null) {
LOG.debug("Closing service group {}", serviceIdentifier);
placeHolder = new PlaceholderServiceGroup(lookup, future);
- final var identifier = reg.getInstance().getIdentifier().getName();
+ final var identifier = reg.getInstance().getIdentifier().value();
verify(serviceGroupMap.replace(identifier, lookup, placeHolder));
LOG.debug("Replaced group {} with {}", serviceIdentifier, placeHolder);
}
static class TestClusterSingletonService implements ClusterSingletonService {
- private static final @NonNull ServiceGroupIdentifier SERVICE_ID = ServiceGroupIdentifier.create(SERVICE_NAME);
+ private static final @NonNull ServiceGroupIdentifier SERVICE_ID = new ServiceGroupIdentifier(SERVICE_NAME);
private TestClusterSingletonServiceState serviceState = TestClusterSingletonServiceState.INITIALIZED;
*/
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ActiveServiceGroupTest {
- public static final String SERVICE_IDENTIFIER = "TestServiceIdent";
- public static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = ServiceGroupIdentifier.create(SERVICE_IDENTIFIER);
+ private static final String SERVICE_IDENTIFIER = "TestServiceIdent";
+ private static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = new ServiceGroupIdentifier(SERVICE_IDENTIFIER);
public static final @NonNull DOMEntity MAIN_ENTITY = new DOMEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
public static final @NonNull DOMEntity CLOSE_ENTITY = new DOMEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);