source: java/main/src/main/java/com/framsticks/hosting/InstanceClient.java @ 90

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 3.6 KB
Line 
1package com.framsticks.hosting;
2
3import com.framsticks.communication.*;
4import com.framsticks.communication.queries.ApplicationRequest;
5import com.framsticks.communication.queries.GetRequest;
6import com.framsticks.communication.queries.InfoRequest;
7import com.framsticks.core.Instance;
8import com.framsticks.core.Path;
9import com.framsticks.params.*;
10import com.framsticks.parsers.Savers;
11import com.framsticks.core.LocalInstance;
12import com.framsticks.util.dispatching.AbstractJoinable;
13import com.framsticks.util.dispatching.Dispatching;
14import com.framsticks.util.dispatching.Future;
15import com.framsticks.util.dispatching.Joinable;
16import com.framsticks.util.dispatching.JoinableParent;
17import com.framsticks.util.dispatching.JoinableState;
18
19import java.net.Socket;
20import java.util.ArrayList;
21import java.util.LinkedList;
22import java.util.List;
23import com.framsticks.util.dispatching.RunAt;
24
25/**
26 * @author Piotr Sniegowski
27 */
28public class InstanceClient extends AbstractJoinable implements RequestHandler, JoinableParent {
29
30        protected final LocalInstance instance;
31        protected final ServerConnection connection;
32
33        public InstanceClient(LocalInstance instance, Socket socket) {
34                this.instance = instance;
35                connection = new ServerConnection(socket, this);
36        }
37
38        @Override
39        public String toString() {
40                return instance + "|" + connection.toString();
41        }
42
43        @Override
44        public void handle(final ApplicationRequest request, final ResponseCallback<?> responseCallback) {
45                instance.dispatch(new RunAt<Instance>() {
46                        @Override
47                        public void run() {
48                                final Path path = instance.getPath(request.getPath());
49                                if (!path.isResolved(request.getPath())) {
50                                        responseCallback.process(new Response(false, "\"invalid path\"", null));
51                                        return;
52                                }
53                                if (request instanceof GetRequest) {
54                                        instance.findInfo(path, new Future<FramsClass>() {
55                                                @Override
56                                                public void result(FramsClass result, Exception e) {
57                                                        if (result == null) {
58                                                                responseCallback.process(new Response(false, "\"failed to find info for access bind\"", null));
59                                                                return;
60                                                        }
61                                                        List<File> files = new LinkedList<File>();
62                                                        AccessInterface access = instance.bindAccess(path);
63
64                                                        if (access == null) {
65
66                                                                responseCallback.process(new Response(false, "\"failed to bind access\"", null));
67                                                                return;
68                                                        }
69                                                        ListSink sink = new ListSink();
70                                                        access.save(sink);
71                                                        files.add(new File(path.getTextual(), new ListSource(sink.getOut())));
72                                                        responseCallback.process(new Response(true, "", files));
73                                                }
74                                        });
75                                        return;
76                                }
77                                if (request instanceof InfoRequest) {
78                                        instance.findInfo(path, new Future<FramsClass>() {
79                                                @Override
80                                                public void result(FramsClass result, Exception e) {
81                                                        if (result == null) {
82                                                                responseCallback.process(new Response(false, "\"info not found\"", null));
83                                                                return;
84                                                        }
85                                                        ListSink sink = new ListSink();
86                                                        Savers.saveFramsClass(sink, result);
87                                                        List<File> files = new ArrayList<File>();
88                                                        files.add(new File(path.getTextual(), new ListSource(sink.getOut())));
89                                                        responseCallback.process(new Response(true, null, files));
90                                                }
91                                        });
92                                        return;
93                                }
94                                responseCallback.process(new Response(false, "invalid", null));
95                        }
96                });
97
98        }
99
100        @Override
101        protected void joinableStart() {
102                Dispatching.use(connection, this);
103        }
104
105        @Override
106        protected void joinableInterrupt() {
107                Dispatching.drop(connection, this);
108        }
109
110        @Override
111        protected void joinableFinish() {
112        }
113
114        @Override
115        protected void joinableJoin() throws InterruptedException {
116                Dispatching.join(connection);
117        }
118
119        @Override
120        public void childChangedState(Joinable joinable, JoinableState state) {
121                proceedToState(state);
122        }
123
124}
Note: See TracBrowser for help on using the repository browser.