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) {
35 this.threadsafeTimers = new ThreadsafeTimers(lock);
37 features.put("ThreadsafeTimers", threadsafeTimers);
41 * Get the features that are to be injected into the JS runtime during context creation.
43 * @return the runtime features
45 public Map<String, Object> getFeatures() {
50 * Un-initialization hook, called when the engine is closed.
51 * Use this method to clean up resources or cancel operations that were created by the JS runtime.
54 threadsafeTimers.clearAll();