Ignore:
Timestamp:
07/14/13 23:20:04 (11 years ago)
Author:
psniegowski
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java

    r100 r101  
    33import com.framsticks.communication.queries.ApplicationRequest;
    44import com.framsticks.communication.queries.CallRequest;
     5import com.framsticks.communication.queries.NeedFile;
     6import com.framsticks.communication.queries.NeedFileAcceptor;
    57import com.framsticks.communication.queries.ProtocolRequest;
    68import com.framsticks.communication.queries.RegisterRequest;
     
    4345        private boolean isHandshakeDone = false;
    4446
     47        protected NeedFileAcceptor needFileAcceptor;
     48
     49        /**
     50         * @return the needFileAcceptor
     51         */
     52        public NeedFileAcceptor getNeedFileAcceptor() {
     53                return needFileAcceptor;
     54        }
     55
     56        /**
     57         * @param needFileAcceptor the needFileAcceptor to set
     58         */
     59        public void setNeedFileAcceptor(NeedFileAcceptor needFileAcceptor) {
     60                this.needFileAcceptor = needFileAcceptor;
     61        }
    4562
    4663        /**
     
    6481                protocolVersion = -1;
    6582        }
    66 
    67 
    6883
    6984        protected List<String> readFileContent() {
     
    116131        }
    117132
    118         private Map<Integer, SentQuery<?>> queryMap = new HashMap<>();
    119 
    120         private SentQuery<?> currentlySentQuery;
    121 
    122133        public void send(ProtocolRequest request, ClientSideResponseFuture callback) {
    123134                //TODO RunAt
     
    154165                sentQuery.dispatcher = dispatcher;
    155166
     167
    156168                senderThread.dispatch(new RunAt<Connection>(callback) {
    157169                        @Override
    158170                        protected void runAt() {
    159                                 Integer id;
    160                                 synchronized (ClientSideManagedConnection.this) {
    161 
    162                                         while (!(requestIdEnabled || currentlySentQuery == null)) {
    163                                                 try {
    164                                                         ClientSideManagedConnection.this.wait();
    165                                                 } catch (InterruptedException ignored) {
    166                                                         break;
    167                                                 }
    168                                         }
    169                                         if (requestIdEnabled) {
    170                                                 queryMap.put(nextQueryId, sentQuery);
    171                                                 id = nextQueryId++;
    172                                         } else {
    173                                                 currentlySentQuery = sentQuery;
    174                                                 id = null;
    175                                         }
    176                                 }
     171                                Integer id = sentQueries.put(null, sentQuery);
     172
    177173                                String command = sentQuery.request.getCommand();
    178174                                StringBuilder message = new StringBuilder();
     
    188184                                flushOut();
    189185                                log.debug("sending query: {}", out);
    190 
    191186                        }
    192187                });
    193                 /*
    194                 synchronized (this) {
    195                         log.debug("queueing query: {}", query);
    196                         queryQueue.offer(sentQuery);
    197                         notifyAll();
    198                 }
    199                  */
    200188        }
    201189
     
    204192                return "client connection " + address;
    205193        }
    206 
    207194
    208195        private void sendQueryVersion(final int version, final Future<Void> future) {
     
    229216        }
    230217
    231         private synchronized @Nonnull SentQuery<?> fetchQuery(@Nullable Integer id, boolean remove) {
    232                 try {
    233                         if (id == null) {
    234                                 if (requestIdEnabled) {
    235                                         throw new FramsticksException().msg("request_id is enabled and id is missing");
    236                                 }
    237                                 SentQuery<?> result = currentlySentQuery;
    238                                 if (remove) {
    239                                         currentlySentQuery = null;
    240                                         notifyAll();
    241                                 }
    242                                 return result;
    243                         }
    244 
    245                         if (!queryMap.containsKey(id)) {
    246                                 throw new FramsticksException().msg("id is unknown").arg("id", id);
    247                         }
    248 
    249                         SentQuery<?> result = queryMap.get(id);
    250                         if (remove) {
    251                                 queryMap.remove(id);
    252                         }
    253                         return result;
    254 
    255                 } catch (FramsticksException e) {
    256                         throw new FramsticksException().msg("failed to match response to sent query").cause(e);
    257                 }
    258         }
     218        protected class IdCollection<T> {
     219
     220
     221                protected final Map<Integer, T> map = new HashMap<>();
     222                protected T current;
     223
     224                public Integer put(Integer idProposition, T value) {
     225                        synchronized (ClientSideManagedConnection.this) {
     226                                while (!(requestIdEnabled || current == null)) {
     227                                        try {
     228                                                ClientSideManagedConnection.this.wait();
     229                                        } catch (InterruptedException ignored) {
     230                                                break;
     231                                        }
     232                                }
     233                                if (!requestIdEnabled) {
     234                                        current = value;
     235                                        return null;
     236                                }
     237                                if (idProposition == null) {
     238                                        idProposition = nextQueryId++;
     239                                }
     240                                map.put(idProposition, value);
     241                                return idProposition;
     242                        }
     243                }
     244
     245                public void clear(Integer id) {
     246                        if (requestIdEnabled) {
     247                                current = null;
     248                        } else {
     249                                map.remove(id);
     250                        }
     251                }
     252
     253                public @Nonnull T fetch(@Nullable Integer id, boolean remove) {
     254                        synchronized (ClientSideManagedConnection.this) {
     255                                try {
     256                                        if (id == null) {
     257                                                if (requestIdEnabled) {
     258                                                        throw new FramsticksException().msg("request_id is enabled and id is missing");
     259                                                }
     260                                                T result = current;
     261                                                current = null;
     262                                                ClientSideManagedConnection.this.notifyAll();
     263                                                return result;
     264                                        }
     265                                        if (!map.containsKey(id)) {
     266                                                throw new FramsticksException().msg("id is unknown").arg("id", id);
     267                                        }
     268
     269                                        T result = map.get(id);
     270                                        if (remove) {
     271                                                map.remove(id);
     272                                        }
     273                                        return result;
     274
     275                                } catch (FramsticksException e) {
     276                                        throw new FramsticksException().msg("failed to match response to sent query").cause(e);
     277                                }
     278                        }
     279                }
     280        }
     281
     282        protected IdCollection<SentQuery<?>> sentQueries = new IdCollection<>();
     283        protected IdCollection<NeedFile> needFiles = new IdCollection<>();
    259284
    260285        private int nextQueryId = 0;
     
    269294                        throw new FramsticksException().msg("expected file line").arg("got", fileLine);
    270295                }
    271                 String eventObjectPath = Request.takeGroup(rest, matcher, 1).toString();
    272                 String eventCalleePath = Request.takeGroup(rest, matcher, 2).toString();
     296                String eventObjectPath = Strings.takeGroup(rest, matcher, 1).toString();
     297                String eventCalleePath = Strings.takeGroup(rest, matcher, 2).toString();
    273298                final File file = new File("", new ListSource(readFileContent()));
    274299                log.debug("firing event {}", eventObjectPath);
     
    277302                        listener = registeredListeners.get(eventObjectPath);
    278303                }
    279                 if (listener  == null) {
     304                if (listener == null) {
    280305                        throw new FramsticksException().msg("failed to find registered event").arg("event path", eventObjectPath).arg("object", eventCalleePath);
    281306                }
     
    283308        }
    284309
     310        protected void processNeedFile(Pair<Integer, CharSequence> rest) {
     311                final Integer id = rest.first;
     312                String suggestedName = null;
     313                String description = null;
     314                Pair<CharSequence, CharSequence> s = Request.takeString(rest.second);
     315                if (s != null) {
     316                        suggestedName = s.first.toString();
     317                        Pair<CharSequence, CharSequence> d = Request.takeString(s.second);
     318                        if (d != null) {
     319                                description = d.first.toString();
     320                        }
     321                }
     322
     323                final Future<File> future = new Future<File>() {
     324
     325                        protected void send(final File result) {
     326                                log.info("sending file: " + result);
     327                                needFiles.clear(id);
     328                                sendFile(null, result, id, ClientSideManagedConnection.this);
     329
     330                        }
     331
     332                        @Override
     333                        protected void result(File result) {
     334                                send(result);
     335                        }
     336
     337                        @Override
     338                        public void handle(FramsticksException exception) {
     339                                send(new File("", ListSource.createFrom("# invalid", "# " + exception.getMessage())));
     340                        }
     341                };
     342
     343                NeedFile needFile = new NeedFile(suggestedName, description, future);
     344
     345                if (needFileAcceptor.acceptNeed(needFile)) {
     346                        return;
     347                }
     348
     349                future.handle(new FramsticksException().msg("acceptor did not accepted need"));
     350        }
     351
    285352        protected void processFile(Pair<Integer, CharSequence> rest) {
    286                 final SentQuery<?> sentQuery = fetchQuery(rest.first, false);
     353                final SentQuery<?> sentQuery = sentQueries.fetch(rest.first, false);
    287354
    288355                String currentFilePath = rest.second.toString();
     
    292359
    293360                sentQuery.files.add(new File(currentFilePath, new ListSource(readFileContent())));
    294 
    295361        }
    296362
     
    318384                        if (keyword.equals("ok") || keyword.equals("error")) {
    319385
    320                                 final SentQuery<?> sentQuery = fetchQuery(rest.first, true);
     386                                final SentQuery<?> sentQuery = sentQueries.fetch(rest.first, true);
    321387
    322388                                log.debug("parsing response for request {}", sentQuery);
    323389
    324390                                sentQuery.dispatchResponseProcess(new Response(command.first.equals("ok"), rest.second.toString(), sentQuery.getFiles()));
     391                                return;
     392                        }
     393                        if (keyword.equals("needfile")) {
     394                                processNeedFile(rest);
    325395                                return;
    326396                        }
     
    336406                @Override
    337407                public void handle(FramsticksException exception) {
    338                         interrupt();
     408                        interruptJoinable();
    339409                        // finish();
    340410                }
Note: See TracChangeset for help on using the changeset viewer.