source: java/main/src/main/java/com/framsticks/util/dispatching/AbstractJoinable.java @ 100

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 4.7 KB
Line 
1package com.framsticks.util.dispatching;
2
3import java.util.Collections;
4import java.util.HashSet;
5import java.util.LinkedList;
6import java.util.List;
7import java.util.Set;
8
9import javax.annotation.Nonnull;
10
11import org.apache.commons.collections.CollectionUtils;
12import org.apache.logging.log4j.Logger;
13import org.apache.logging.log4j.LogManager;
14
15import com.framsticks.util.FramsticksException;
16
17public abstract class AbstractJoinable implements Joinable {
18
19        private static final Logger log = LogManager.getLogger(AbstractJoinable.class);
20
21        protected final Set<JoinableParent> owners = new HashSet<JoinableParent>();
22        protected final Set<JoinableParent> joinableListeners = new HashSet<JoinableParent>();
23
24        protected static final Set<AbstractJoinable> joinablesRegistry = Collections.synchronizedSet(new HashSet<AbstractJoinable>());
25
26        protected JoinableState state = JoinableState.INITILIAZED;
27        protected JoinableParent parent;
28        protected Monitor monitor;
29
30        /**
31         *
32         */
33        public AbstractJoinable() {
34                joinablesRegistry.add(this);
35        }
36
37        public static void report() {
38                StringBuilder b = new StringBuilder();
39                synchronized (joinablesRegistry) {
40                        for (AbstractJoinable j : joinablesRegistry) {
41                                b.append("\n").append(j.getState()).append(" : ").append(j);
42                        }
43                }
44                log.debug("state: {}", b);
45        }
46
47        private synchronized boolean changeState(JoinableState state) {
48                if (this.state.ordinal() >= state.ordinal()) {
49                        return false;
50                }
51                if (this.state.ordinal() + 1 != state.ordinal()) {
52                        throw new FramsticksException().msg("failed to change state").arg("from", this.state).arg("to", state).arg("joinable", this);
53                }
54                this.state = state;
55
56                log.debug("{} is notifying {} parents", this, joinableListeners.size());
57
58                List<JoinableParent> parents = new LinkedList<>();
59                CollectionUtils.addAll(parents, joinableListeners.iterator());
60
61                for (JoinableParent p : parents) {
62                        if (p != null) {
63                                Dispatching.childChangedState(p, this, state);
64                        }
65                }
66                this.notifyAll();
67
68                report();
69
70                return true;
71        }
72
73
74
75        public final boolean start() {
76                if (changeState(JoinableState.RUNNING)) {
77                        joinableStart();
78                        return true;
79                }
80                return false;
81        }
82
83        public final boolean interrupt() {
84                if (changeState(JoinableState.FINISHING)) {
85                        joinableInterrupt();
86                        return true;
87                }
88                return false;
89        }
90
91        protected final boolean finish() {
92                if (changeState(JoinableState.JOINABLE)) {
93                        joinableFinish();
94                        return true;
95                }
96                return false;
97        }
98
99
100
101        @Override
102        public final void join() throws InterruptedException {
103                synchronized (this) {
104                        if (this.state.equals(JoinableState.JOINED)) {
105                                return;
106                        }
107                        if (!this.state.equals(JoinableState.JOINABLE)) {
108                                throw new InterruptedException();
109                        }
110                }
111                joinableJoin();
112                synchronized (this) {
113                        this.state = JoinableState.JOINED;
114                }
115        }
116
117        protected final boolean proceedToState(JoinableState state) {
118                switch (state) {
119                        case RUNNING:
120                                return start();
121                        case FINISHING:
122                                return interrupt();
123                        case JOINABLE:
124                                return finish();
125                        default: return false;
126                }
127        }
128
129        protected abstract void joinableStart();
130
131        protected abstract void joinableInterrupt();
132
133        protected abstract void joinableFinish();
134
135        protected abstract void joinableJoin() throws InterruptedException;
136
137        public final boolean use(@Nonnull JoinableParent owner) {
138                boolean start = false;
139                synchronized (this) {
140                        if (owners.contains(owner)) {
141                                throw new FramsticksException().msg("owner is already using that joinable").arg("joinable", this).arg("owner", owner);
142                        }
143                        start = owners.isEmpty();
144                        log.debug("{} is using {}", owner, this);
145                        owners.add(owner);
146                        joinableListeners.add(owner);
147                }
148                if (start) {
149                        assert monitor == null;
150                        monitor = owner.getMonitor();
151                        return this.start();
152                }
153                return false;
154        }
155
156        public final boolean drop(@Nonnull JoinableParent owner) {
157                boolean stop = false;
158                synchronized (this) {
159                        if (!owners.contains(owner)) {
160                                return false;
161                                // throw new FramsticksException().msg("object is not owning that joinable").arg("joinable", this).arg("object", owner);
162                        }
163                        // assert owners.containsKey(owner);
164                        log.debug("{} is droping {}", owner, this);
165                        owners.remove(owner);
166                        stop = owners.isEmpty();
167                }
168                if (stop) {
169                        Dispatching.dispatcherGuardedInvoke(this, new RunAt<Object>(ThrowExceptionHandler.getInstance()) {
170                                @Override
171                                protected void runAt() {
172                                        interrupt();
173                                }
174                        });
175                        return true;
176                }
177                return stop;
178        }
179
180        /**
181         * @return the state
182         */
183        public JoinableState getState() {
184                return state;
185        }
186
187        protected boolean isInState(JoinableState state) {
188                return this.state.equals(state);
189        }
190
191        protected boolean isRunning() {
192                return state.equals(JoinableState.RUNNING);
193        }
194
195        @Override
196        public String toString() {
197                return getName();
198        }
199
200        // @Override
201        public Monitor getMonitor() {
202                return monitor;
203        }
204
205
206}
Note: See TracBrowser for help on using the repository browser.