source: java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java @ 98

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

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

File size: 4.9 KB
Line 
1package com.framsticks.hosting;
2
3import static com.framsticks.util.lang.Strings.assureNotEmpty;
4
5import com.framsticks.communication.*;
6import com.framsticks.communication.queries.ApplicationRequest;
7import com.framsticks.communication.queries.CallRequest;
8import com.framsticks.communication.queries.GetRequest;
9import com.framsticks.communication.queries.InfoRequest;
10import com.framsticks.communication.queries.SetRequest;
11import com.framsticks.core.Tree;
12import com.framsticks.core.Path;
13import com.framsticks.params.*;
14import com.framsticks.params.types.ProcedureParam;
15import com.framsticks.parsers.Savers;
16import com.framsticks.util.FramsticksException;
17import com.framsticks.util.dispatching.AbstractJoinable;
18import com.framsticks.util.dispatching.Dispatching;
19import com.framsticks.util.dispatching.ExceptionResultHandler;
20import com.framsticks.util.dispatching.FutureHandler;
21import com.framsticks.util.dispatching.Joinable;
22import com.framsticks.util.dispatching.JoinableParent;
23import com.framsticks.util.dispatching.JoinableState;
24import static com.framsticks.core.TreeOperations.*;
25
26import java.net.Socket;
27import java.util.LinkedList;
28import java.util.List;
29
30/**
31 * @author Piotr Sniegowski
32 */
33public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, ExceptionResultHandler {
34
35        protected final Server server;
36        protected final Tree tree;
37        protected final ServerSideManagedConnection connection;
38
39        public ClientAtServer(Server server, Socket socket) {
40                this.server = server;
41                this.tree = server.hosted;
42                this.connection = new ServerSideManagedConnection(socket, this);
43        }
44
45        @Override
46        public String getName() {
47                return connection + " to " + server;
48        }
49
50        @Override
51        public void handle(final ApplicationRequest request, final ServerSideResponseFuture responseCallback) {
52                assureNotEmpty(request.getPath());
53
54                tryGet(tree, request.getPath(), new FutureHandler<Path>(responseCallback) {
55                        @Override
56                        protected void result(final Path path) {
57
58                                if (!path.getTextual().equals(request.getPath())) {
59                                        throw new FramsticksException().msg("invalid path").arg("path", request.getPath());
60                                }
61
62                                // final AccessInterface access = tree.prepareAccess(path);
63                                final AccessInterface access = bindAccess(path);
64
65                                if (request instanceof SetRequest) {
66                                        SetRequest setRequest = (SetRequest) request;
67                                        //TODO Primitive Param?
68                                        tree.set(path, access.getFramsClass().getParamEntry(setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new FutureHandler<Integer>(responseCallback) {
69                                                @Override
70                                                protected void result(Integer flag) {
71                                                        responseCallback.pass(new Response(true, Flags.write(flag, null), null));
72
73                                                }
74                                        });
75                                        return;
76                                }
77
78                                if (request instanceof GetRequest) {
79                                        Object result = path.getTopObject();
80                                        if (result != access.getSelected()) {
81                                                throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path);
82                                        }
83                                        List<File> files = new LinkedList<File>();
84                                        ListSink sink = new ListSink();
85                                        access.save(sink);
86                                        files.add(new File(path.getTextual(), new ListSource(sink.getOut())));
87                                        responseCallback.pass(new Response(true, "", files));
88
89                                        return;
90                                }
91                                if (request instanceof CallRequest) {
92                                        final CallRequest callRequest = (CallRequest) request;
93                                        tree.call(path, access.getFramsClass().getParamEntry(callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), new FutureHandler<Object>(responseCallback) {
94                                                @Override
95                                                protected void result(Object result) {
96                                                        ListSink sink = new ListSink();
97                                                        sink.print("Result:").breakLine();
98                                                        sink.print("value:").print("[");
99                                                        if (result != null) {
100                                                                sink.print(result);
101                                                        }
102                                                        sink.print("]");
103
104                                                        responseCallback.pass(new Response(true, "", File.single(new File("", new ListSource(sink.getOut())))));
105                                                }
106                                        });
107                                        return;
108                                }
109                                if (request instanceof InfoRequest) {
110                                        FramsClass framsClass = getInfo(path);
111                                        if (framsClass == null) {
112                                                throw new FramsticksException().msg("info should be available");
113                                        }
114                                        responseCallback.pass(new Response(true, null, File.single(new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))));
115                                        return;
116                                }
117
118                                throw new FramsticksException().msg("invalid request type: " + request.getCommand());
119                        }
120                });
121
122        }
123
124        @Override
125        protected void joinableStart() {
126                Dispatching.use(connection, this);
127        }
128
129        @Override
130        protected void joinableInterrupt() {
131                Dispatching.drop(connection, this);
132        }
133
134        @Override
135        protected void joinableFinish() {
136        }
137
138        @Override
139        protected void joinableJoin() throws InterruptedException {
140                Dispatching.join(connection);
141        }
142
143        @Override
144        public void childChangedState(Joinable joinable, JoinableState state) {
145                proceedToState(state);
146        }
147
148        @Override
149        public void handle(FramsticksException exception) {
150                tree.handle(exception);
151        }
152
153}
Note: See TracBrowser for help on using the repository browser.