]> git.basschouten.com Git - openhab-addons.git/blob
790b464168fe35c1f2d9037c36eefb2be8d58636
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.jsscripting.internal;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers;
20
21 /**
22  * Abstraction layer to collect all features injected into the JS runtime during the context creation.
23  *
24  * @author Florian Hotze - Initial contribution
25  */
26 @NonNullByDefault
27 public class JSRuntimeFeatures {
28     /**
29      * All elements of this Map are injected into the JS runtime using their key as the name.
30      */
31     private final Map<String, Object> features = new HashMap<>();
32     public final ThreadsafeTimers threadsafeTimers;
33
34     JSRuntimeFeatures(Object lock) {
35         this.threadsafeTimers = new ThreadsafeTimers(lock);
36
37         features.put("ThreadsafeTimers", threadsafeTimers);
38     }
39
40     /**
41      * Get the features that are to be injected into the JS runtime during context creation.
42      * 
43      * @return the runtime features
44      */
45     public Map<String, Object> getFeatures() {
46         return features;
47     }
48
49     /**
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.
52      */
53     public void close() {
54         threadsafeTimers.clearAll();
55     }
56 }