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.

Location:
java/main/src/main/java/com/framsticks/util
Files:
3 added
6 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/util/dispatching/AbstractJoinable.java

    r100 r101  
    3939                synchronized (joinablesRegistry) {
    4040                        for (AbstractJoinable j : joinablesRegistry) {
    41                                 b.append("\n").append(j.getState()).append(" : ").append(j);
     41                                b.append("\n").append(j.getState()).append(" : ").append(j).append(" - ").append(j.getClass());
    4242                        }
    4343                }
     
    7373
    7474
    75         public final boolean start() {
     75        protected final boolean startJoinable() {
    7676                if (changeState(JoinableState.RUNNING)) {
    7777                        joinableStart();
     
    8181        }
    8282
    83         public final boolean interrupt() {
     83        protected final boolean interruptJoinable() {
    8484                if (changeState(JoinableState.FINISHING)) {
    8585                        joinableInterrupt();
     
    8989        }
    9090
    91         protected final boolean finish() {
     91        protected final boolean finishJoinable() {
    9292                if (changeState(JoinableState.JOINABLE)) {
    9393                        joinableFinish();
     
    118118                switch (state) {
    119119                        case RUNNING:
    120                                 return start();
     120                                return startJoinable();
    121121                        case FINISHING:
    122                                 return interrupt();
     122                                return interruptJoinable();
    123123                        case JOINABLE:
    124                                 return finish();
     124                                return finishJoinable();
    125125                        default: return false;
    126126                }
     
    149149                        assert monitor == null;
    150150                        monitor = owner.getMonitor();
    151                         return this.start();
     151                        return this.startJoinable();
    152152                }
    153153                return false;
     
    170170                                @Override
    171171                                protected void runAt() {
    172                                         interrupt();
     172                                        interruptJoinable();
    173173                                }
    174174                        });
  • java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java

    r99 r101  
    55 * @author Piotr Sniegowski
    66 */
    7 public class AtOnceDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> {
     7public class AtOnceDispatcher<C> extends AbstractJoinable implements Dispatcher<C> {
    88
    99        @SuppressWarnings("rawtypes")
     
    3737        @Override
    3838        protected void joinableInterrupt() {
    39                 finish();
     39                finishJoinable();
    4040        }
    4141
  • java/main/src/main/java/com/framsticks/util/dispatching/Dispatcher.java

    r90 r101  
    44 * @author Piotr Sniegowski
    55 */
    6 public interface Dispatcher<C> {
     6public interface Dispatcher<C> extends Joinable {
    77        public boolean isActive();
    88        public void dispatch(RunAt<? extends C> runnable);
  • java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java

    r100 r101  
    11package com.framsticks.util.dispatching;
     2
     3import java.util.Timer;
    24
    35import org.apache.logging.log4j.Logger;
     
    1113public abstract class Dispatching {
    1214        private static final Logger log = LogManager.getLogger(Dispatching.class);
     15
     16        protected static final Timer timer = new Timer();
     17
     18        public static Timer getTimer() {
     19                return timer;
     20        }
    1321
    1422        public static boolean isThreadSafe() {
     
    183191        }
    184192
    185         public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> {
    186                 // protected boolean done = false;
    187                 protected final T dispatcher;
    188                 protected RunAt<? extends C> runnable;
    189 
    190                 /**
    191                  * @param joinable
    192                  */
    193                 public DispatcherWaiter(T dispatcher) {
    194                         this.dispatcher = dispatcher;
    195                 }
    196 
    197                 public synchronized void waitFor() {
    198                         while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) {
    199                                 try {
    200                                         this.wait();
    201                                 } catch (InterruptedException e) {
    202                                 }
    203                         }
    204                         if (runnable != null) {
    205                                 runnable.run();
    206                         }
    207 
    208                 }
    209 
    210                 @Override
    211                 public boolean isActive() {
    212                         return dispatcher.isActive();
    213                 }
    214 
    215                 @Override
    216                 public synchronized void dispatch(RunAt<? extends C> runnable) {
    217                         this.runnable = runnable;
    218                         this.notifyAll();
    219                 }
    220 
    221         }
     193        // public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> {
     194        //      // protected boolean done = false;
     195        //      protected final T dispatcher;
     196        //      protected RunAt<? extends C> runnable;
     197
     198        //      /**
     199        //       * @param joinable
     200        //       */
     201        //      public DispatcherWaiter(T dispatcher) {
     202        //              this.dispatcher = dispatcher;
     203        //      }
     204
     205        //      public synchronized void waitFor() {
     206        //              while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) {
     207        //                      try {
     208        //                              this.wait();
     209        //                      } catch (InterruptedException e) {
     210        //                      }
     211        //              }
     212        //              if (runnable != null) {
     213        //                      runnable.run();
     214        //              }
     215
     216        //      }
     217
     218        //      @Override
     219        //      public boolean isActive() {
     220        //              return dispatcher.isActive();
     221        //      }
     222
     223        //      @Override
     224        //      public synchronized void dispatch(RunAt<? extends C> runnable) {
     225        //              this.runnable = runnable;
     226        //              this.notifyAll();
     227        //      }
     228
     229        // }
    222230
    223231        public static class Waiter {
  • java/main/src/main/java/com/framsticks/util/dispatching/JoinableCollection.java

    r97 r101  
    88import java.util.Set;
    99
     10import com.framsticks.params.ParamFlags;
    1011import com.framsticks.params.annotations.AutoAppendAnnotation;
    1112import com.framsticks.params.annotations.FramsClassAnnotation;
     13import com.framsticks.params.annotations.ParamAnnotation;
    1214import com.framsticks.util.FramsticksException;
    1315import com.framsticks.util.Misc;
     
    7274        protected void joinableInterrupt() {
    7375                if (joinables.isEmpty()) {
    74                         finish();
     76                        finishJoinable();
    7577                        return;
    7678                }
     
    137139        public T get(String name) {
    138140                for (T j : joinables) {
    139                         if (j.getName().equals(name)) {
     141                        if (name.equals(j.getName())) {
    140142                                return j;
    141143                        }
     
    153155
    154156        @Override
     157        @ParamAnnotation
    155158        public String getName() {
    156159                return observableName;
     160        }
     161
     162        @ParamAnnotation(flags = ParamFlags.USERREADONLY)
     163        public final void setName(String name) {
     164                observableName = name;
    157165        }
    158166
     
    185193        }
    186194
     195
     196
    187197}
  • 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
  • java/main/src/main/java/com/framsticks/util/lang/Holder.java

    r96 r101  
    3333        }
    3434
     35        public static <T2> Holder<T2> make(T2 value) {
     36                return new Holder<T2>(value);
     37        }
     38
    3539}
  • java/main/src/main/java/com/framsticks/util/lang/Strings.java

    r99 r101  
    11package com.framsticks.util.lang;
     2
     3import java.util.regex.Matcher;
    24
    35import com.framsticks.util.FramsticksException;
     
    7880        }
    7981
     82        public static CharSequence takeGroup(CharSequence input, Matcher matcher, int group) {
     83                // return (matcher.start(group) == matcher.end(group)) ? null : input.subSequence(matcher.start(group), matcher.end(group));
     84                return input.subSequence(matcher.start(group), matcher.end(group));
     85        }
     86
    8087}
Note: See TracChangeset for help on using the changeset viewer.