Ignore:
Timestamp:
07/16/13 23:31:35 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

for Joinables running

CHANGELOG:
Add WorkPackageLogic? and classes representing prime experiment state.

Add classes for PrimeExperiment? state.

Extract single netload routine in Simulator.

Working netload with dummy content in PrimeExperiment?.

More development with NetLoadSaveLogic? and PrimeExperiment?.

Improvement around prime.

Improve BufferedDispatcher?.isActive logic.

Add prime-all.xml configuration.

Manual connecting to existing simulators from GUI.

Guard in SimulatorConnector? against expdef mismatch.

Guard against empty target dispatcher in BufferedDispatcher?.

Make BufferedDispatcher? a Dispatcher (and Joinable).

Minor improvements.

Done StackedJoinable?, improve Experiment.

Develop StackedJoinable?.

Add StackedJoinable? utility joinables controller.

Add dependency on apache-commons-lang.

Add ready ListChange? on Simulators.

Improve hints in ListChange?.

Several improvements.

Found bug with dispatching in Experiment.

Minor improvements.

Fix bug with early finishing Server.

Many changes in Dispatching.

Fix bug with connection.

Do not obfuscate log with socket related exceptions.

Add SocketClosedException?.

Add SimulatorConnector?.

Work out conception of experiment composing of logics building blocks.

Rename SinkInterface? to Sink.

Move saving of Accesses into AccessOperations?.

Some improvements to Experiment.

Improve joinables.

Fix issue with joinables closing.

Add direct and managed consoles to popup menu.

File:
1 edited

Legend:

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

    r101 r102  
    22
    33
    4 public class BufferedDispatcher<C> {
     4import org.apache.logging.log4j.Logger;
     5import org.apache.logging.log4j.LogManager;
     6
     7import com.framsticks.util.FramsticksException;
     8import com.framsticks.util.lang.Strings;
     9// import static com.framsticks.util.dispatching.AbstractJoinable.wrap;
     10
     11public class BufferedDispatcher<C> extends AbstractJoinable implements Dispatcher<C>, JoinableParent {
     12        private static final Logger log = LogManager.getLogger(BufferedDispatcher.class);
    513
    614        protected final RunnableQueue<C> queue = new RunnableQueue<>();
     
    816        protected Dispatcher<C> targetDispatcher;
    917
    10         protected boolean buffer = false;
     18        protected boolean buffer = true;
     19        protected Dispatcher<C> parent;
     20
     21        /**
     22         * @param parent
     23         */
     24        public BufferedDispatcher(Dispatcher<C> parent) {
     25                this.parent = parent;
     26        }
    1127
    1228        /**
     
    2137         */
    2238        public synchronized void setTargetDispatcher(Dispatcher<C> targetDispatcher) {
     39                if (this.targetDispatcher != null) {
     40                        throw new FramsticksException().msg("dispatcher is already set").arg("dispatcher", this.targetDispatcher).arg("in", this);
     41                }
     42                if (targetDispatcher == null) {
     43                        throw new FramsticksException().msg("trying to set empty target dispatcher").arg("in", this);
     44                }
     45                log.debug("setting {} to {}", this, targetDispatcher);
    2346                this.targetDispatcher = targetDispatcher;
     47                flushQueue();
    2448        }
    2549
    2650        public synchronized boolean isActive() {
    27                 if (targetDispatcher == null) {
     51                if (targetDispatcher == null || buffer) {
    2852                        return false;
    2953                        // throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this);
     
    4064        }
    4165
     66        protected void flushQueue() {
     67                if (this.buffer || targetDispatcher == null) {
     68                        return;
     69                }
     70                log.debug("flushing {} tasks in {}", queue.size(), this);
     71                while (!queue.isEmpty()) {
     72                        targetDispatcher.dispatch(queue.pollFirst());
     73                }
     74        }
     75
    4276        public synchronized void setBuffer(final boolean buffer) {
    4377                if (this.buffer == buffer) {
     
    4983                }
    5084                this.buffer = false;
    51                 while (!queue.isEmpty()) {
    52                         targetDispatcher.dispatch(queue.pollFirst());
     85                flushQueue();
     86        }
     87
     88        @Override
     89        public String toString() {
     90                return parent + " -> " + Strings.toStringNullProof(targetDispatcher, "<null>");
     91        }
     92
     93        public void createThreadIfNeeded() {
     94                if (targetDispatcher != null) {
     95                        return;
    5396                }
     97                this.setTargetDispatcher(new Thread<C>().setName(parent.getName()));
     98        }
     99
     100        @Override
     101        public String getName() {
     102                return parent + " buffered dispatcher";
     103        }
     104
     105        @Override
     106        protected void joinableStart() {
     107                Dispatching.use(targetDispatcher, this);
     108        }
     109
     110        @Override
     111        protected void joinableInterrupt() {
     112                Dispatching.drop(targetDispatcher, this);
     113
     114                finishJoinable();
     115        }
     116
     117        @Override
     118        protected void joinableFinish() {
    54119
    55120        }
    56121
     122        @Override
     123        protected void joinableJoin() throws InterruptedException {
     124                Dispatching.join(targetDispatcher);
     125        }
    57126
     127        @Override
     128        public void childChangedState(Joinable joinable, JoinableState state) {
     129                proceedToState(state);
     130        }
    58131}
Note: See TracChangeset for help on using the changeset viewer.