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/util/dispatching/Thread.java

    r100 r101  
    33import org.apache.logging.log4j.Logger;
    44import org.apache.logging.log4j.LogManager;
    5 
    6 import java.util.LinkedList;
    7 import java.util.ListIterator;
    85
    96
     
    1411 * @author Piotr Sniegowski
    1512 */
    16 public class Thread<C> extends AbstractJoinable implements JoinableDispatcher<C> {
     13public class Thread<C> extends AbstractJoinable implements Dispatcher<C> {
    1714
    1815        private static final Logger log = LogManager.getLogger(Thread.class);
     
    2017        protected final java.lang.Thread thread;
    2118
    22         private final LinkedList<Task<? extends C>> queue = new LinkedList<>();
     19        protected final Object condition = new Object();
     20        private RunnableQueue<C> queue = new RunnableQueue<>();
    2321
    2422        public Thread() {
    25                 thread = new java.lang.Thread(new java.lang.Runnable() {
     23                thread = new java.lang.Thread(new Runnable() {
    2624                        @Override
    2725                        public void run() {
     
    3028                });
    3129        }
    32 
    3330
    3431        public Thread(java.lang.Thread thread) {
     
    5148                ExceptionHandler exceptionHandler = getMonitor().getTaskExceptionHandler();
    5249                while (!java.lang.Thread.interrupted()) {
    53                         Task<? extends C> task;
    54                         synchronized (queue) {
     50                        RunAt<? extends C> runnable;
     51                        synchronized (condition) {
    5552                                if (queue.isEmpty()) {
    5653                                        try {
    57                                                 queue.wait();
     54                                                condition.wait();
    5855                                        } catch (InterruptedException ignored) {
    5956                                                break;
     
    6158                                        continue;
    6259                                }
    63                                 task = queue.peekFirst();
    64                                 assert task != null;
    65                                 if (task.moment > System.currentTimeMillis()) {
    66                                         try {
    67                                                 queue.wait(task.moment - System.currentTimeMillis());
    68                                         } catch (InterruptedException ignored) {
    69                                                 continue;
     60                                runnable = queue.pollFirst();
     61                        }
     62                        if (runnable != null) {
     63                                try {
     64                                        runnable.run();
     65                                } catch (Exception e) {
     66                                        if (exceptionHandler != null) {
     67                                                if (exceptionHandler.handle(this, e)) {
     68                                                        continue;
     69                                                }
    7070                                        }
    71                                         continue;
     71                                        log.error("error in thread: ", e);
    7272                                }
    73                                 queue.pollFirst();
    74                         }
    75                         try {
    76                                 task.run();
    77                         } catch (Exception e) {
    78                                 if (exceptionHandler != null) {
    79                                         if (exceptionHandler.handle(this, e)) {
    80                                                 continue;
    81                                         }
    82                                 }
    83                                 log.error("error in thread: ", e);
    8473                        }
    8574                }
    8675                log.debug("finishing thread {}", this);
    87                 finish();
     76                finishJoinable();
    8877        }
    8978
    90         protected void enqueueTask(Task<? extends C> task) {
    91                 synchronized (queue) {
    92                         ListIterator<Task<? extends C>> i = queue.listIterator();
    93                         while (i.hasNext()) {
    94                                 Task<? extends C> t = i.next();
    95                                 if (t.getMoment() > task.getMoment()) {
    96                                         i.previous();
    97                                         i.add(task);
    98                                         task = null;
    99                                         break;
    100                                 }
    101                         }
    102                         if (task != null) {
    103                                 queue.add(task);
    104                         }
    10579
    106                         /*
    107                         Iterator<Task> j = queue.iterator();
    108                         Task prev = null;
    109                         while (j.hasNext()) {
    110                                 Task next = j.next();
    111                                 assert (prev == null) || prev.getMoment() <= next.getMoment();
    112                                 prev = next;
    113                         }
    114                         */
    115                         queue.notify();
     80        @Override
     81        public void dispatch(RunAt<? extends C> runnable) {
     82                synchronized (condition) {
     83                        queue.push(runnable);
     84                        condition.notifyAll();
    11685                }
    11786        }
    11887
    119         @Override
    120         public void dispatch(final RunAt<? extends C> runnable) {
    121                 if (!(runnable instanceof Task)) {
    122                         enqueueTask(new Task<C>(runnable) {
    123                                 @Override
    124                                 protected void runAt() {
    125                                         runnable.run();
    126                                 }
    127                         });
    128                         return;
     88        public RunnableQueue<C> switchQueue(RunnableQueue<C> queue) {
     89                synchronized (condition) {
     90                        RunnableQueue<C> result = this.queue;
     91                        this.queue = queue;
     92                        return result;
    12993                }
    130                 enqueueTask((Task<? extends C>) runnable);
    13194        }
    13295
Note: See TracChangeset for help on using the changeset viewer.