source: java/main/src/main/java/com/framsticks/util/dispatching/StackedJoinable.java @ 102

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

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 size: 2.9 KB
Line 
1package com.framsticks.util.dispatching;
2
3import java.util.LinkedList;
4import java.util.ListIterator;
5import java.util.TimerTask;
6
7import org.apache.logging.log4j.Logger;
8import org.apache.logging.log4j.LogManager;
9
10import com.framsticks.params.annotations.AutoAppendAnnotation;
11import com.framsticks.params.annotations.FramsClassAnnotation;
12import com.framsticks.params.annotations.ParamAnnotation;
13
14@FramsClassAnnotation
15public class StackedJoinable extends AbstractJoinable implements JoinableParent {
16        private static final Logger log = LogManager.getLogger(StackedJoinable.class);
17
18
19        protected final LinkedList<Joinable> joinables = new LinkedList<Joinable>();
20        protected ListIterator<Joinable> iterator;
21        protected Joinable currentJoinable;
22
23        protected double interval = 1;
24
25        /**
26         *
27         */
28        public StackedJoinable() {
29                super();
30        }
31
32        @AutoAppendAnnotation
33        public void addJoinable(Joinable joinable) {
34                joinables.add(joinable);
35        }
36
37        @Override
38        public String getName() {
39                return "stacked";
40        }
41
42        @Override
43        public void childChangedState(Joinable joinable, JoinableState state) {
44                // log.error("{} notified {} about changing state to {}", joinable, this, state);
45                if (state.equals(JoinableState.RUNNING)) {
46                        if (joinable == currentJoinable) {
47                                Dispatching.getTimer().schedule(new TimerTask() {
48                                        @Override
49                                        public void run() {
50                                                startNext();
51                                        }
52                                }, (int)(interval * 1000));
53                        }
54                        return;
55                }
56                if (state.equals(JoinableState.FINISHING)) {
57                        if (joinable == currentJoinable) {
58                                Dispatching.getTimer().schedule(new TimerTask() {
59                                        @Override
60                                        public void run() {
61                                                stopNext();
62                                        }
63                                }, (int)(interval * 1000));
64                        }
65                        return;
66                }
67
68        }
69
70        protected void startNext() {
71                if (!iterator.hasNext()) {
72                        currentJoinable = null;
73                        log.debug("started all");
74                        return;
75                }
76                currentJoinable = iterator.next();
77                log.debug("starting {}", currentJoinable);
78                Dispatching.use(currentJoinable, this);
79        }
80
81        protected void stopNext() {
82                if (!iterator.hasPrevious()) {
83                        finishJoinable();
84                        return;
85                }
86                currentJoinable = iterator.previous();
87                log.debug("stoping {}", currentJoinable);
88                Dispatching.drop(currentJoinable, this);
89        }
90
91        @Override
92        protected void joinableStart() {
93                iterator = joinables.listIterator();
94                startNext();
95        }
96
97        @Override
98        protected void joinableInterrupt() {
99                log.debug("interupting");
100                stopNext();
101        }
102
103        @Override
104        protected void joinableFinish() {
105                // here process ends and StackedJoinable transists to the joinable state
106
107        }
108
109        @Override
110        protected void joinableJoin() throws InterruptedException {
111
112        }
113
114        /**
115         * @return the interval
116         */
117        @ParamAnnotation
118        public double getInterval() {
119                return interval;
120        }
121
122        /**
123         * @param interval the interval to set
124         */
125        @ParamAnnotation
126        public void setInterval(double interval) {
127                this.interval = interval;
128        }
129
130        public Joinable get(int number) {
131                return joinables.get(number);
132        }
133
134        public int size() {
135                return joinables.size();
136        }
137}
Note: See TracBrowser for help on using the repository browser.