forked from openhab/openhab-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rest] Add caching for TagResource & De-duplicate code for caching (o…
…penhab#3729) * [rest] Add caching for TagResource * [core] Add & use RegistryChangedRunnableListener class Signed-off-by: Florian Hotze <[email protected]>
- Loading branch information
1 parent
79fd459
commit e1741cf
Showing
5 changed files
with
121 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
....core/src/main/java/org/openhab/core/common/registry/RegistryChangedRunnableListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) 2010-2023 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.common.registry; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* {@link RegistryChangedRunnableListener} can be added to {@link Registry} services, to execute a given | ||
* {@link Runnable} on all types of changes. | ||
* | ||
* @author Florian Hotze - Initial contribution | ||
* | ||
* @param <E> type of the element in the registry | ||
*/ | ||
@NonNullByDefault | ||
public class RegistryChangedRunnableListener<E> implements RegistryChangeListener<E> { | ||
final Runnable runnable; | ||
|
||
public RegistryChangedRunnableListener(Runnable runnable) { | ||
this.runnable = runnable; | ||
} | ||
|
||
@Override | ||
public void added(E element) { | ||
runnable.run(); | ||
} | ||
|
||
@Override | ||
public void removed(E element) { | ||
runnable.run(); | ||
} | ||
|
||
@Override | ||
public void updated(E oldElement, E newElement) { | ||
runnable.run(); | ||
} | ||
} |