source: java/main/src/main/java/com/framsticks/hosting/Cli.java @ 105

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.5 KB
Line 
1package com.framsticks.hosting;
2
3import java.util.Map;
4import java.util.TreeMap;
5
6import org.apache.logging.log4j.Logger;
7import org.apache.logging.log4j.LogManager;
8
9import com.framsticks.communication.Response;
10import com.framsticks.communication.ServerSideResponseFuture;
11import com.framsticks.params.EventListener;
12import com.framsticks.params.annotations.FramsClassAnnotation;
13import com.framsticks.params.annotations.ParamAnnotation;
14import com.framsticks.params.types.EventParam;
15import com.framsticks.structure.Path;
16import com.framsticks.structure.Tree;
17import com.framsticks.structure.TreeOperations;
18import com.framsticks.util.dispatching.Future;
19import com.framsticks.util.dispatching.ThrowExceptionHandler;
20
21@FramsClassAnnotation
22public class Cli {
23        private static final Logger log =
24                LogManager.getLogger(Cli.class);
25
26
27        protected int eventCounter = 0;
28        protected final Tree tree;
29        protected final ClientAtServer client;
30
31        protected final String address;
32
33        @ParamAnnotation
34        public final Map<String, CliEvent> events = new TreeMap<>();
35
36        /**
37         * @param tree
38         */
39        public Cli(ClientAtServer client) {
40                this.client = client;
41                this.tree = client.getTree();
42                this.address = client.connection.getAddress();
43        }
44
45        public void addListener(Path path, EventParam param, String pathPrefix, ServerSideResponseFuture responseFuture) {
46                log.debug("adding listener for {}: {}", path, param);
47
48                final CliEvent event = new CliEvent();
49                event.cli = this;
50                event.id = "e" + (eventCounter++);
51                event.path = path;
52                event.param = param;
53                event.name = pathPrefix + Path.appendString(path.getTextual(), param.getId());
54                event.pathToEvent = "/cli/events/" + event.id;
55
56                event.listener = new EventListener<Object>() {
57
58                        @Override
59                        public void action(Object argument) {
60                                log.debug("registered event {} happened with {}", event, argument);
61
62                                client.connection.sendFile(
63                                                "event " + event.pathToEvent + " " + event.name,
64                                                ClientAtServer.printToFile("", tree.getRegistry().createAccess(argument.getClass()).select(argument)),
65                                                null,
66                                                client
67                                        );
68                        }
69                };
70
71                // SyncedFuture handler = new SyncedFuture<Void>(ThrowExceptionHandler.getInstance());
72                TreeOperations.addListener(path, param, event.listener, Object.class, Future.doNothing(Void.class, ThrowExceptionHandler.getInstance()));
73
74                events.put(event.id, event);
75                responseFuture.pass(new Response(true, event.pathToEvent));
76                // handler
77        }
78
79        @Override
80        public String toString() {
81                return "CLI for " + tree;
82        }
83
84        /**
85         * @return the address
86         */
87        @ParamAnnotation
88        public String getAddress() {
89                return address;
90        }
91
92}
Note: See TracBrowser for help on using the repository browser.