Remove RegistryHook (#4568)
Remove RegistryHook which is not longer used. Remove related methods from ItemRegistry and ItemUiRegistry. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>pull/4577/head
parent
ce374252fa
commit
7548f26db6
|
@ -45,7 +45,6 @@ import org.openhab.core.items.Item;
|
||||||
import org.openhab.core.items.ItemNotFoundException;
|
import org.openhab.core.items.ItemNotFoundException;
|
||||||
import org.openhab.core.items.ItemNotUniqueException;
|
import org.openhab.core.items.ItemNotUniqueException;
|
||||||
import org.openhab.core.items.ItemRegistry;
|
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.CallItem;
|
||||||
import org.openhab.core.library.items.ColorItem;
|
import org.openhab.core.library.items.ColorItem;
|
||||||
import org.openhab.core.library.items.ContactItem;
|
import org.openhab.core.library.items.ContactItem;
|
||||||
|
@ -1428,16 +1427,6 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
||||||
return itemRegistry.remove(itemName, recursive);
|
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
|
@Override
|
||||||
public @Nullable String getUnitForWidget(Widget w) {
|
public @Nullable String getUnitForWidget(Widget w) {
|
||||||
String itemName = w.getItem();
|
String itemName = w.getItem();
|
||||||
|
|
|
@ -15,7 +15,6 @@ package org.openhab.core.internal.items;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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.Metadata;
|
||||||
import org.openhab.core.items.MetadataAwareItem;
|
import org.openhab.core.items.MetadataAwareItem;
|
||||||
import org.openhab.core.items.MetadataRegistry;
|
import org.openhab.core.items.MetadataRegistry;
|
||||||
import org.openhab.core.items.RegistryHook;
|
|
||||||
import org.openhab.core.items.events.ItemEventFactory;
|
import org.openhab.core.items.events.ItemEventFactory;
|
||||||
import org.openhab.core.service.CommandDescriptionService;
|
import org.openhab.core.service.CommandDescriptionService;
|
||||||
import org.openhab.core.service.ReadyService;
|
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 Logger logger = LoggerFactory.getLogger(ItemRegistryImpl.class);
|
||||||
|
|
||||||
private final List<RegistryHook<Item>> registryHooks = new CopyOnWriteArrayList<>();
|
|
||||||
private @Nullable StateDescriptionService stateDescriptionService;
|
private @Nullable StateDescriptionService stateDescriptionService;
|
||||||
private @Nullable CommandDescriptionService commandDescriptionService;
|
private @Nullable CommandDescriptionService commandDescriptionService;
|
||||||
private final MetadataRegistry metadataRegistry;
|
private final MetadataRegistry metadataRegistry;
|
||||||
|
@ -388,30 +385,9 @@ public class ItemRegistryImpl extends AbstractRegistry<Item, String, ItemProvide
|
||||||
super.notifyListenersAboutUpdatedElement(oldElement, element);
|
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
|
@Override
|
||||||
public void removed(Provider<Item> provider, Item element) {
|
public void removed(Provider<Item> provider, Item element) {
|
||||||
super.removed(provider, element);
|
super.removed(provider, element);
|
||||||
for (RegistryHook<Item> registryHook : registryHooks) {
|
|
||||||
registryHook.afterRemoving(element);
|
|
||||||
}
|
|
||||||
if (provider instanceof ManagedItemProvider) {
|
if (provider instanceof ManagedItemProvider) {
|
||||||
// remove our metadata for that item
|
// remove our metadata for that item
|
||||||
logger.debug("Item {} was removed, trying to clean up corresponding metadata", element.getUID());
|
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)
|
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
|
||||||
public void setStateDescriptionService(StateDescriptionService stateDescriptionService) {
|
public void setStateDescriptionService(StateDescriptionService stateDescriptionService) {
|
||||||
this.stateDescriptionService = stateDescriptionService;
|
this.stateDescriptionService = stateDescriptionService;
|
||||||
|
|
|
@ -105,18 +105,4 @@ public interface ItemRegistry extends Registry<Item, String> {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Item remove(String itemName, boolean recursive);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -96,8 +96,6 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntegrationWithGenericItemProvider() throws Exception {
|
public void testIntegrationWithGenericItemProvider() throws Exception {
|
||||||
Thread.sleep(2500); // Wait for the ChannelItemProvider to join the game
|
|
||||||
|
|
||||||
Collection<Thing> things = thingRegistry.getAll();
|
Collection<Thing> things = thingRegistry.getAll();
|
||||||
assertThat(things.size(), is(0));
|
assertThat(things.size(), is(0));
|
||||||
|
|
||||||
|
@ -133,7 +131,7 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest {
|
||||||
|
|
||||||
// Now add the model again
|
// Now add the model again
|
||||||
modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
|
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));
|
assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue