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

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

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File size: 2.2 KB
Line 
1package com.framsticks.hosting;
2
3import com.framsticks.core.*;
4import com.framsticks.params.CompositeParam;
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((CompositeParam)Param.build().name("root").id("root").type("o" + hosted.getClass().getCanonicalName()).finish(), 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 = new FramsClass.Constructor(nativeClass, id).getResult();
60
61                        registry.registerReflectedClass(null, id, nativeClass);
62                        registry.putInfoIntoCache(framsClass);
63                        return framsClass;
64                } catch (ClassNotFoundException ignored) {
65                }
66
67                return null;
68        }
69
70        @Override
71        protected void fetchInfo(Path path, Future<FramsClass> future) {
72                assert isActive();
73
74                FramsClass framsClass = getInfoFromCache(path.getTop().getObject().getClass().getCanonicalName());
75                if (framsClass == null) {
76                        log.error("failed to create frams class for: " + path.getTop().getObject().getClass());
77                        future.result(null, new Exception());
78                        return;
79                }
80                future.result(framsClass, null);
81
82        }
83
84        @Override
85        protected void tryRegisterOnChangeEvents(Path path) {
86        }
87
88}
Note: See TracBrowser for help on using the repository browser.