source: java/main/src/main/java/com/framsticks/hosting/Server.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: 5.7 KB
Line 
1package com.framsticks.hosting;
2
3import org.apache.logging.log4j.Level;
4import org.apache.logging.log4j.Logger;
5import org.apache.logging.log4j.LogManager;
6
7import com.framsticks.core.Tree;
8import com.framsticks.params.annotations.AutoAppendAnnotation;
9import com.framsticks.params.annotations.FramsClassAnnotation;
10import com.framsticks.params.annotations.ParamAnnotation;
11import com.framsticks.util.FramsticksException;
12import com.framsticks.util.dispatching.AbstractJoinable;
13import com.framsticks.util.dispatching.Dispatching;
14import com.framsticks.util.dispatching.Joinable;
15import com.framsticks.util.dispatching.JoinableCollection;
16import com.framsticks.util.dispatching.JoinableParent;
17import com.framsticks.util.dispatching.JoinableState;
18import com.framsticks.util.dispatching.RunAt;
19import com.framsticks.util.dispatching.Task;
20import com.framsticks.util.dispatching.ThrowExceptionHandler;
21
22import java.io.IOException;
23import java.net.InetSocketAddress;
24import java.net.ServerSocket;
25import java.net.Socket;
26import com.framsticks.util.dispatching.Thread;
27
28@FramsClassAnnotation
29public class Server extends AbstractJoinable implements JoinableParent {
30
31        private final static Logger log = LogManager.getLogger(Server.class);
32
33        protected int port;
34
35        protected ServerSocket acceptSocket;
36        protected Tree hosted;
37        protected final JoinableCollection<ClientAtServer> clients = new JoinableCollection<ClientAtServer>();
38
39        public static class Accept {
40        };
41
42        protected Thread<Accept> acceptThread = new Thread<>();
43
44        /**
45         *
46         */
47        public Server() {
48                log.debug("created server");
49                port = 9009;
50        }
51
52        /**
53         * @return the port
54         */
55        @ParamAnnotation
56        public int getPort() {
57                return port;
58        }
59
60        /**
61         * @param port the port to set
62         */
63        @ParamAnnotation
64        public void setPort(int port) {
65                this.port = port;
66        }
67
68        @Override
69        protected void joinableInterrupt() {
70                Dispatching.drop(acceptThread, this);
71                Dispatching.drop(hosted, this);
72                Dispatching.drop(clients, this);
73                try {
74                        acceptSocket.close();
75                } catch (IOException e) {
76                        log.debug("exception caught during socket closing: ", e);
77                }
78                finish();
79        }
80
81        /**
82         * @return the hosted
83         */
84        public Tree getHosted() {
85                return hosted;
86        }
87
88        @AutoAppendAnnotation
89        public void setHosted(Tree hosted) {
90                if (this.hosted != null) {
91                        throw new FramsticksException().msg("hosted tree is already set").arg("current", this.hosted);
92                }
93                this.hosted = hosted;
94                acceptThread.setName(hosted.getName() + " acceptor");
95                clients.setObservableName(hosted.getName() + " clients");
96        }
97
98        @Override
99        public void childChangedState(Joinable joinable, JoinableState state) {
100                proceedToState(state);
101        }
102
103        @Override
104        protected void joinableStart() {
105                Dispatching.use(acceptThread, this);
106                Dispatching.use(hosted, this);
107                Dispatching.use(clients, this);
108                try {
109                        acceptSocket = new ServerSocket();
110                } catch (IOException e) {
111                        throw new FramsticksException().msg("failed to create server socket").cause(e);
112                }
113                tryBind(0);
114        }
115
116        @Override
117        @ParamAnnotation
118        public String getName() {
119                return hosted != null ? hosted.getName() : "server";
120        }
121
122        protected void acceptNext() {
123                if (!isRunning()) {
124                        log.debug("server is not in running state, aborting accepting");
125                        return;
126                }
127                acceptThread.dispatch(new RunAt<Accept>(hosted) {
128                        @Override
129                        protected void runAt() {
130                                try {
131                                        log.debug("accepting");
132                                        final Socket socket = acceptSocket.accept();
133                                        assert socket != null;
134                                        log.debug("accepted socket: {}", socket.getInetAddress().getHostAddress());
135                                        hosted.dispatch(new RunAt<Tree>(this) {
136                                                @Override
137                                                protected void runAt() {
138                                                        ClientAtServer client = new ClientAtServer(Server.this, socket);
139                                                        clients.add(client);
140                                                        log.info("client connected: {}", client);
141                                                }
142                                        });
143                                } catch (IOException e) {
144                                        log.log((isRunning() ? Level.ERROR : Level.DEBUG), "failed to accept socket: {}", e);
145                                }
146                                acceptNext();
147                        }
148                });
149        }
150
151        protected void tryBind(int when) {
152                acceptThread.dispatch(new Task<Accept>(ThrowExceptionHandler.getInstance(), when) {
153                        @Override
154                        protected void runAt() {
155                                try {
156                                        acceptSocket.bind(new InetSocketAddress(port));
157                                        log.debug("started accepting on port {}", port);
158                                        acceptNext();
159                                        return;
160                                } catch (IOException e) {
161                                        log.warn("failed to accept on port {} (repeating): ", port, e);
162                                }
163                                tryBind(1000);
164                        }
165                });
166        }
167
168        @Override
169        protected void joinableFinish() {
170
171        }
172
173        @Override
174        protected void joinableJoin() throws InterruptedException {
175                Dispatching.join(acceptThread);
176                Dispatching.join(hosted);
177                Dispatching.join(clients);
178        }
179
180        // @Override
181        // public FramsClass getInfoFromCache(String id) {
182        //      assert isActive();
183        //      if (id == null) {
184        //              return null;
185        //      }
186        //      FramsClass cached = registry.getFramsClass(id);
187        //      if (cached != null) {
188        //              return cached;
189        //      }
190        //      try {
191        //              Class<?> nativeClass = Class.forName(id);
192        //              FramsClass framsClass = FramsClass.build().forClass(nativeClass);
193
194        //              if (!framsClass.getId().equals(id)) {
195        //                      log.error("no matching id");
196        //                      return null;
197        //              }
198
199        //              registry.registerReflectedClass(null, id, nativeClass);
200        //              registry.putFramsClass(framsClass);
201        //              return framsClass;
202        //      } catch (ClassNotFoundException ignored) {
203        //      } catch (ConstructionException e) {
204        //              log.error("failed to use info from cache: {}", e);
205        //      }
206
207        //      return null;
208        // }
209
210        // @Override
211        // protected void fetchInfo(Path path, Future<FramsClass> future) {
212        //      assert isActive();
213
214        //      FramsClass framsClass = getInfoFromCache(path.getTop().getObject().getClass().getCanonicalName());
215        //      if (framsClass == null) {
216        //              log.error("failed to create frams class for: {}", path.getTop().getObject().getClass());
217        //              future.result(null, new Exception());
218        //              return;
219        //      }
220        //      future.result(framsClass, null);
221        // }
222}
Note: See TracBrowser for help on using the repository browser.