2 * Copyright (c) 2010-2022 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;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers;
22 * Abstraction layer to collect all features injected into the JS runtime during the context creation.
24 * @author Florian Hotze - Initial contribution
27 public class JSRuntimeFeatures {
29 * All elements of this Map are injected into the JS runtime using their key as the name.
31 private final Map<String, Object> features = new HashMap<>();
32 public final ThreadsafeTimers threadsafeTimers;
34 JSRuntimeFeatures(Object lock, JSScriptServiceUtil jsScriptServiceUtil) {
35 this.threadsafeTimers = new ThreadsafeTimers(lock, jsScriptServiceUtil.getScriptExecution(),
36 jsScriptServiceUtil.getScheduler());
38 features.put("ThreadsafeTimers", threadsafeTimers);
42 * Get the features that are to be injected into the JS runtime during context creation.
44 * @return the runtime features
46 public Map<String, Object> getFeatures() {
51 * Un-initialization hook, called when the engine is closed.
52 * Use this method to clean up resources or cancel operations that were created by the JS runtime.
55 threadsafeTimers.clearAll();