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

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

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

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