Process operations asynchronously (#15801)
Resolves #14927 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
b503382e93
commit
2df66bfee2
|
@ -21,10 +21,13 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import org.openhab.core.common.NamedThreadFactory;
|
||||||
import org.openhab.core.config.core.ConfigurableService;
|
import org.openhab.core.config.core.ConfigurableService;
|
||||||
import org.openhab.core.i18n.TimeZoneProvider;
|
import org.openhab.core.i18n.TimeZoneProvider;
|
||||||
import org.openhab.core.items.GroupItem;
|
import org.openhab.core.items.GroupItem;
|
||||||
|
@ -71,6 +74,9 @@ public class JdbcPersistenceService extends JdbcMapper implements ModifiablePers
|
||||||
|
|
||||||
private final ItemRegistry itemRegistry;
|
private final ItemRegistry itemRegistry;
|
||||||
|
|
||||||
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1,
|
||||||
|
new NamedThreadFactory(JdbcPersistenceServiceConstants.SERVICE_ID));
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public JdbcPersistenceService(final @Reference ItemRegistry itemRegistry,
|
public JdbcPersistenceService(final @Reference ItemRegistry itemRegistry,
|
||||||
final @Reference TimeZoneProvider timeZoneProvider) {
|
final @Reference TimeZoneProvider timeZoneProvider) {
|
||||||
|
@ -131,21 +137,21 @@ public class JdbcPersistenceService extends JdbcMapper implements ModifiablePers
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void store(Item item) {
|
public void store(Item item) {
|
||||||
internalStore(item, null, item.getState());
|
scheduler.execute(() -> internalStore(item, null, item.getState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void store(Item item, @Nullable String alias) {
|
public void store(Item item, @Nullable String alias) {
|
||||||
// alias is not supported
|
// alias is not supported
|
||||||
internalStore(item, null, item.getState());
|
scheduler.execute(() -> internalStore(item, null, item.getState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void store(Item item, ZonedDateTime date, State state) {
|
public void store(Item item, ZonedDateTime date, State state) {
|
||||||
internalStore(item, date, state);
|
scheduler.execute(() -> internalStore(item, date, state));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void internalStore(Item item, @Nullable ZonedDateTime date, State state) {
|
private synchronized void internalStore(Item item, @Nullable ZonedDateTime date, State state) {
|
||||||
// Do not store undefined/uninitialized data
|
// Do not store undefined/uninitialized data
|
||||||
if (state instanceof UnDefType) {
|
if (state instanceof UnDefType) {
|
||||||
logger.debug("JDBC::store: ignore Item '{}' because it is UnDefType", item.getName());
|
logger.debug("JDBC::store: ignore Item '{}' because it is UnDefType", item.getName());
|
||||||
|
|
Loading…
Reference in New Issue