source: java/main/src/main/java/com/framsticks/hosting/ServerInstance.java @ 78

Last change on this file since 78 was 78, checked in by psniegowski, 11 years ago

Add f0 parsing and f0->Model transformation.

File size: 2.4 KB
Line 
1package com.framsticks.hosting;
2
3import com.framsticks.core.*;
4import com.framsticks.params.FramsClass;
5import com.framsticks.params.ParamBuilder;
6import com.framsticks.params.types.CompositeParam;
7import com.framsticks.core.LocalInstance;
8import com.framsticks.util.Future;
9import org.apache.log4j.Logger;
10
11/**
12 * @author Piotr Sniegowski
13 */
14public class ServerInstance extends LocalInstance {
15
16    private final static Logger LOGGER = Logger.getLogger(ServerInstance.class.getName());
17
18    Entity hosted;
19
20    public ServerInstance(Parameters parameters) {
21        super(parameters);
22    }
23
24    @Override
25    protected void run() {
26        super.run();
27        assert hosted != null;
28        hosted.start();
29    }
30
31    @Override
32    protected void configure() throws Exception {
33        super.configure();
34
35        Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this, null);
36        hosted = Program.configureEntity(p);
37        if (hosted == null) {
38            LOGGER.fatal("failed to create hosted entity");
39            return;
40        }
41        hosted.configurePublic();
42        root = new Node((CompositeParam)new ParamBuilder().setName("root").setId("root").setType("o" + hosted.getClass().getCanonicalName()).build(), hosted);
43    }
44
45    @Override
46    public FramsClass getInfoFromCache(String id) {
47        assert isActive();
48        if (id == null) {
49            return null;
50        }
51                FramsClass cached = registry.getInfoFromCache(id);
52        if (cached != null) {
53                        return cached;
54        }
55        try {
56            Class nativeClass = Class.forName(id);
57            FramsClass framsClass = new FramsClass.Constructor(nativeClass, id).getResult();
58
59            registry.registerReflectedClass(null, id, nativeClass);
60            registry.putInfoIntoCache(framsClass);
61            return framsClass;
62        } catch (ClassNotFoundException ignored) {
63        }
64
65        return null;
66    }
67
68    @Override
69    protected void fetchInfo(Path path, Future<FramsClass> future) {
70        assert isActive();
71
72        FramsClass framsClass = getInfoFromCache(path.getTop().getObject().getClass().getCanonicalName());
73        if (framsClass == null) {
74            LOGGER.error("failed to create frams class for: " + path.getTop().getObject().getClass());
75            future.result(null, new Exception());
76            return;
77        }
78        future.result(framsClass, null);
79
80    }
81
82    @Override
83    protected void tryRegisterOnChangeEvents(Path path) {
84    }
85
86}
Note: See TracBrowser for help on using the repository browser.