source: java/main/src/main/java/com/framsticks/communication/Request.java @ 101

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

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 3.8 KB
Line 
1package com.framsticks.communication;
2
3import java.util.regex.Matcher;
4import java.util.regex.Pattern;
5
6import com.framsticks.communication.queries.*;
7import com.framsticks.util.FramsticksException;
8import com.framsticks.util.lang.Pair;
9import com.framsticks.util.lang.Strings;
10
11/**
12 * Class stores information about query sent to manager.
13 */
14public abstract class Request {
15
16        public abstract String getCommand();
17
18        protected abstract StringBuilder construct(StringBuilder buffer);
19
20
21
22
23        public static void quoteValue(StringBuilder builder, String value) {
24                String quote = ((value.indexOf(' ') > 0) || (value.length() == 0) ? "\"" : "");
25                builder.append(quote).append(value).append(quote);
26        }
27
28        public static Request parse(CharSequence type, CharSequence rest) {
29                final Request request = Request.createRequestByTypeString(type.toString());
30                request.parseRest(rest);
31                return request;
32        }
33
34        public static Request createRequestByTypeString(String type) {
35                switch (type) {
36                        case "get": return new GetRequest();
37                        case "set": return new SetRequest();
38                        case "info": return new InfoRequest();
39                        case "call": return new CallRequest();
40                        case "reg": return new RegisterRequest();
41                        case "use": return new UseRequest();
42                        case "version": return new VersionRequest();
43                }
44                throw new FramsticksException().msg("unknown request type").arg("type", type);
45        }
46
47        public abstract CharSequence parseRest(CharSequence rest);
48
49        @Override
50        public String toString() {
51                // return getCommand();
52                return "request " + stringRepresentation();
53        }
54
55        public String stringRepresentation() {
56                return construct(new StringBuilder().append(getCommand()).append(" ")).toString();
57        }
58
59        public static final Pattern EVENT_PATTERN = Pattern.compile("^\\s*(\\S+)\\s*(\\S+)");
60
61        public static final Pattern STRING_BREAKER_PATTERN = Pattern.compile("^\\s*(?:(?:\\\"([^\"]*)\\\")|([^ ]+))\\s*(.*)$");
62        public static final Pattern IDENTIFIER_BREAKER_PATTERN = Pattern.compile("^\\s*([^ ]+)\\s*(.*)$");
63
64        // public static Matcher match(Pattern pattern, CharSequence line) {
65        //      Matcher matcher = pattern.matcher(line);
66        //      if (!matcher.matches()) {
67        //              return null;
68        //              // throw new FramsticksException().msg("failed to take").arg("pattern", pattern).arg("line", line);
69        //      }
70        //      return matcher;
71        // }
72
73        public static Pair<CharSequence, CharSequence> takeIdentifier(CharSequence line) {
74                Matcher matcher = IDENTIFIER_BREAKER_PATTERN.matcher(line);
75                if (!matcher.matches()) {
76                        return null;
77                }
78                return new Pair<CharSequence, CharSequence>(line.subSequence(matcher.start(1), matcher.end(1)), line.subSequence(matcher.start(2), matcher.end(2)));
79        }
80
81
82        public static Pair<CharSequence, CharSequence> takeString(CharSequence line) {
83                Matcher matcher = STRING_BREAKER_PATTERN.matcher(line);
84                if (!matcher.matches()) {
85                        return null;
86                }
87                assert ((matcher.start(1) == -1) != (matcher.start(2) == -1));
88                return new Pair<CharSequence, CharSequence>(Strings.takeGroup(line, matcher, (matcher.start(1) != -1 ? 1 : 2)), Strings.takeGroup(line, matcher, 3));
89        }
90
91        protected static final Pattern REQUEST_ID_BREAKER_PATTERN = Pattern.compile("^\\s*(-?[0-9]+)\\s*(.*)$");
92
93        protected final static Pair<Integer, CharSequence> takeRequestId(boolean withId, CharSequence line) {
94                if (withId) {
95                        Matcher matcher = REQUEST_ID_BREAKER_PATTERN.matcher(line);
96                        if (!matcher.matches()) {
97                                return null;
98                        }
99                        return new Pair<Integer, CharSequence>(Integer.valueOf(Strings.takeGroup(line, matcher, 1).toString()), Strings.takeGroup(line, matcher, 2));
100                }
101                return new Pair<Integer, CharSequence>(null, line);
102        }
103
104        public static StringBuilder quoteArgumentIfNeeded(StringBuilder builder, Object argument) {
105                String r = argument.toString();
106                if (r.indexOf(' ') != -1) {
107                        builder.append('"').append(r).append('"');
108                } else {
109                        builder.append(r);
110                }
111                return builder;
112        }
113
114}
Note: See TracBrowser for help on using the repository browser.