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

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

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