2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.jsscripting.internal;
15 import java.util.HashMap;
17 import java.util.concurrent.locks.Lock;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers;
23 * Abstraction layer to collect all features injected into the JS runtime during the context creation.
25 * @author Florian Hotze - Initial contribution
28 public class JSRuntimeFeatures {
30 * All elements of this Map are injected into the JS runtime using their key as the name.
32 private final Map<String, Object> features = new HashMap<>();
33 public final ThreadsafeTimers threadsafeTimers;
35 JSRuntimeFeatures(Lock lock, JSScriptServiceUtil jsScriptServiceUtil) {
36 this.threadsafeTimers = new ThreadsafeTimers(lock, jsScriptServiceUtil.getScriptExecution(),
37 jsScriptServiceUtil.getScheduler());
39 features.put("ThreadsafeTimers", threadsafeTimers);
43 * Get the features that are to be injected into the JS runtime during context creation.
45 * @return the runtime features
47 public Map<String, Object> getFeatures() {
52 * Un-initialization hook, called when the engine is closed.
53 * Use this method to clean up resources or cancel operations that were created by the JS runtime.
56 threadsafeTimers.clearAll();