source: java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.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: 3.6 KB
Line 
1package com.framsticks.communication;
2
3import com.framsticks.communication.queries.*;
4import com.framsticks.params.SourceInterface;
5import com.framsticks.util.FramsticksException;
6import com.framsticks.util.lang.Holder;
7import com.framsticks.util.lang.Pair;
8import com.framsticks.util.lang.Strings;
9
10import org.apache.log4j.Logger;
11
12import java.net.Socket;
13import com.framsticks.util.dispatching.RunAt;
14
15/**
16 * @author Piotr Sniegowski
17 */
18public class ServerSideManagedConnection extends ManagedConnection {
19
20        private final static Logger log = Logger.getLogger(ServerSideManagedConnection.class);
21
22        protected final RequestHandler requestHandler;
23
24        public ServerSideManagedConnection(Socket socket, RequestHandler requestHandler) {
25                setAddress(new Address(socket.getInetAddress().getHostAddress(), socket.getPort()));
26                setDescription("server connection");
27                this.socket = socket;
28                this.requestHandler = requestHandler;
29                // socket.setSoTimeout(500);
30                setupStreams();
31        }
32
33
34        protected void processNextInputBatch() {
35                processNextRequest();
36        }
37
38        @Override
39        protected void receiverThreadRoutine() {
40
41                processInputBatchesUntilClosed();
42        }
43
44        protected void handleRequest(Request request, ServerSideResponseFuture responseCallback) {
45                if (request instanceof ApplicationRequest) {
46                        requestHandler.handle((ApplicationRequest) request, responseCallback);
47                        return;
48                }
49                if (request instanceof ProtocolRequest) {
50                        if (request instanceof VersionRequest) {
51                                responseCallback.pass(new Response(true, null, null));
52                                return;
53                        }
54                        if (request instanceof UseRequest) {
55                                String feature = ((UseRequest)request).getFeature();
56                                if (feature.equals("request_id")) {
57                                        requestIdEnabled = true;
58                                        responseCallback.pass(new Response(true, null, null));
59                                        return;
60                                }
61                                responseCallback.pass(new Response(false, "unknown feature: " + feature, null));
62                                return;
63                        }
64
65                }
66                log.error("unhandled request: " + request);
67                responseCallback.pass(new Response(false, "unhandled", null));
68        }
69
70        protected final void respond(final Response response, final Integer id) {
71                senderThread.dispatch(new RunAt<Connection>(requestHandler) {
72                        @Override
73                        protected void runAt() {
74                                String outId = id != null ? " " + id : "";
75                                if (response.getFiles() != null) {
76                                        for (File f : response.getFiles()) {
77                                                putLine("file" + outId/* + " " + f.getPath()*/);
78                                                SourceInterface content = f.getContent();
79                                                String line;
80                                                while ((line = content.readLine()) != null) {
81                                                        putLine(line);
82                                                }
83                                                putLine("eof");
84                                        }
85                                }
86                                StringBuilder statusLine = new StringBuilder();
87                                statusLine.append(response.getOk() ? "ok" : "error").append(outId);
88                                if (Strings.notEmpty(response.getComment())) {
89                                        statusLine.append(" \"").append(response.getComment()).append('"');
90                                }
91                                putLine(statusLine.toString());
92                                flushOut();
93                        }
94                });
95
96        }
97
98
99        protected void processNextRequest() {
100                final Holder<Integer> id = new Holder<>();
101                final String line = getLine();
102                try {
103                        Pair<CharSequence, CharSequence> command = Request.takeIdentifier(line);
104                        final Pair<Integer, CharSequence> rest = takeRequestId(command.second);
105                        id.set(rest.first);
106
107                        final Request request = Request.parse(command.first, rest.second);
108
109                        if (log.isTraceEnabled()) {
110                                log.trace("read request: " + request);
111                        }
112
113                        //TODO what to do here?
114                        handleRequest(request, new ServerSideResponseFuture() {
115                                @Override
116                                protected void result(Response response) {
117                                        respond(response, rest.first);
118                                }
119                        });
120                } catch (FramsticksException e) {
121                        e.arg("id", id.get()).arg("line", line);
122                        log.error("error: ", e);
123                        respond(new Response(false, "invalid input: " + e.getMsg(), null), id.get());
124                        return;
125                }
126
127        }
128}
Note: See TracBrowser for help on using the repository browser.