Remove RegistryHook

Remove RegistryHook which is not longer used. Remove related methods
from ItemRegistry and ItemUiRegistry.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
pull/4568/head
Holger Friedrich 2025-01-19 12:55:15 +01:00
parent 6922d60fd9
commit 3bc927568f
5 changed files with 1 additions and 109 deletions

View File

@ -45,7 +45,6 @@ import org.openhab.core.items.Item;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.items.ItemNotUniqueException;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.RegistryHook;
import org.openhab.core.library.items.CallItem;
import org.openhab.core.library.items.ColorItem;
import org.openhab.core.library.items.ContactItem;
@ -1428,16 +1427,6 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
return itemRegistry.remove(itemName, recursive);
}
@Override
public void addRegistryHook(RegistryHook<Item> hook) {
itemRegistry.addRegistryHook(hook);
}
@Override
public void removeRegistryHook(RegistryHook<Item> hook) {
itemRegistry.removeRegistryHook(hook);
}
@Override
public @Nullable String getUnitForWidget(Widget w) {
String itemName = w.getItem();

View File

@ -15,7 +15,6 @@ package org.openhab.core.internal.items;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -36,7 +35,6 @@ import org.openhab.core.items.ManagedItemProvider;
import org.openhab.core.items.Metadata;
import org.openhab.core.items.MetadataAwareItem;
import org.openhab.core.items.MetadataRegistry;
import org.openhab.core.items.RegistryHook;
import org.openhab.core.items.events.ItemEventFactory;
import org.openhab.core.service.CommandDescriptionService;
import org.openhab.core.service.ReadyService;
@ -68,7 +66,6 @@ public class ItemRegistryImpl extends AbstractRegistry<Item, String, ItemProvide
private final Logger logger = LoggerFactory.getLogger(ItemRegistryImpl.class);
private final List<RegistryHook<Item>> registryHooks = new CopyOnWriteArrayList<>();
private @Nullable StateDescriptionService stateDescriptionService;
private @Nullable CommandDescriptionService commandDescriptionService;
private final MetadataRegistry metadataRegistry;
@ -388,30 +385,9 @@ public class ItemRegistryImpl extends AbstractRegistry<Item, String, ItemProvide
super.notifyListenersAboutUpdatedElement(oldElement, element);
}
@Override
public void added(Provider<Item> provider, Item element) {
for (RegistryHook<Item> registryHook : registryHooks) {
registryHook.beforeAdding(element);
}
super.added(provider, element);
}
@Override
protected void addProvider(Provider<Item> provider) {
for (Item element : provider.getAll()) {
for (RegistryHook<Item> registryHook : registryHooks) {
registryHook.beforeAdding(element);
}
}
super.addProvider(provider);
}
@Override
public void removed(Provider<Item> provider, Item element) {
super.removed(provider, element);
for (RegistryHook<Item> registryHook : registryHooks) {
registryHook.afterRemoving(element);
}
if (provider instanceof ManagedItemProvider) {
// remove our metadata for that item
logger.debug("Item {} was removed, trying to clean up corresponding metadata", element.getUID());
@ -419,26 +395,6 @@ public class ItemRegistryImpl extends AbstractRegistry<Item, String, ItemProvide
}
}
@Override
protected void removeProvider(Provider<Item> provider) {
super.removeProvider(provider);
for (Item element : provider.getAll()) {
for (RegistryHook<Item> registryHook : registryHooks) {
registryHook.afterRemoving(element);
}
}
}
@Override
public void addRegistryHook(RegistryHook<Item> hook) {
registryHooks.add(hook);
}
@Override
public void removeRegistryHook(RegistryHook<Item> hook) {
registryHooks.remove(hook);
}
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
public void setStateDescriptionService(StateDescriptionService stateDescriptionService) {
this.stateDescriptionService = stateDescriptionService;

View File

@ -105,18 +105,4 @@ public interface ItemRegistry extends Registry<Item, String> {
*/
@Nullable
Item remove(String itemName, boolean recursive);
/**
* Add a hook to be informed before adding/after removing items.
*
* @param hook
*/
void addRegistryHook(RegistryHook<Item> hook);
/**
* Remove the hook again.
*
* @param hook
*/
void removeRegistryHook(RegistryHook<Item> hook);
}

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2010-2025 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.items;
import org.openhab.core.common.registry.Identifiable;
/**
* A listener to be informed before entities are added respectively after they are removed.
*
* @author Simon Kaufmann - Initial contribution
*/
public interface RegistryHook<E extends Identifiable<?>> {
/**
* Notifies the listener that an element is going to be added to the registry.
*
* @param element the element to be added
*/
void beforeAdding(E element);
/**
* Notifies the listener that an element was removed from the registry.
*
* @param element the element that was removed
*/
void afterRemoving(E element);
}

View File

@ -96,8 +96,6 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest {
@Test
public void testIntegrationWithGenericItemProvider() throws Exception {
Thread.sleep(2500); // Wait for the ChannelItemProvider to join the game
Collection<Thing> things = thingRegistry.getAll();
assertThat(things.size(), is(0));
@ -133,7 +131,7 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest {
// Now add the model again
modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
assertThat(itemRegistry.getItems().size(), is(2)); // -> ensure ChannelItemProvider cleans up properly
assertThat(itemRegistry.getItems().size(), is(2)); // -> ensure proper clean-up
assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
}