source: java/main/src/main/java/com/framsticks/portals/Portal.java @ 96

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

HIGHLIGHTS:

  • cleanup Instance management
    • extract Instance interface
    • extract Instance common algorithms to InstanceUtils?
  • fix closing issues: Ctrl+C or window close button

properly shutdown whole program

by Java Framsticks framework

  • fix parsing and printing of all request types
  • hide exception passing in special handle method of closures
    • substantially improve readability of closures
    • basically enable use of exception in asynchronous closures

(thrown exception is transported back to the caller)

  • implement call request on both sides

CHANGELOG:
Further improve calling.

Improve instance calling.

Calling is working on both sides.

Improve exception handling in testing.

Waiters do not supercede other apllication exception being thrown.

Finished parsing and printing of all request types (with tests).

Move implementation and tests of request parsing to Request.

Add tests for Requests.

Improve waits in asynchronours tests.

Extract more algorithms to InstanceUtils?.

Extract Instance.resolve to InstanceUtils?.

Improve naming.

Improve passing exception in InstanceClient?.

Hide calling of passed functor in StateCallback?.

Hide Exception passing in asynchronous closures.

Hide exception passing in Future.

Make ResponseCallback? an abstract class.

Make Future an abstract class.

Minor change.

Move getPath to Path.to()

Move bindAccess to InstanceUtils?.

Extract common things to InstanceUtils?.

Fix synchronization bug in Connection.

Move resolve to InstanceUtils?.

Allow names of Joinable to be dynamic.

Add support for set request server side.

More fixes in communication.

Fix issues with parsing in connection.

Cut new line characters when reading.

More improvements.

Migrate closures to FramsticksException?.

Several changes.

Extract resolveAndFetch to InstanceUtils? algorithms.

Test resolving and fetching.

More fixes with function signature deduction.

Do not print default values in SimpleAbstractAccess?.

Add test of FramsClass? printing.

Improve FramsticksException? messages.

Add explicit dispatcher synchronization feature.

Rework assertions in tests.

Previous solution was not generic enough.

Allow addition of joinables to collection after start.

Extract SimulatorInstance? from RemoteInstance?.

Remove PrivateJoinableCollection?.

Improve connections.

Move shutdown hook to inside the Monitor.

It should work in TestNG tests, but it seems that
hooks are not called.

In ServerTest? client connects to testing server.

Move socket initialization to receiver thread.

Add proper closing on Ctrl+C (don't use signals).

Fix bugs with server accepting connections.

Merge Entity into Joinable.

Reworking ServerInstance?.

Extract more algorithm to InstanceUtils?.

Extract some common functionality from AbstractInstance?.

Functions were placed in InstanceUtils?.

Hide registry of Instance.

Use ValueParam? in Instance interface.

Minor change.

Extract Instance interface.

Old Instance is now AbstractInstance?.

File size: 1.9 KB
Line 
1package com.framsticks.portals;
2
3
4import com.framsticks.core.AbstractInstanceListener;
5import com.framsticks.core.Instance;
6import com.framsticks.core.InstanceUtils;
7import com.framsticks.core.Path;
8import com.framsticks.params.annotations.FramsClassAnnotation;
9import com.framsticks.params.annotations.ParamAnnotation;
10import com.framsticks.util.Logging;
11import com.framsticks.util.dispatching.Dispatching;
12import com.framsticks.util.dispatching.Future;
13import com.framsticks.util.dispatching.JoinableCollection;
14import com.framsticks.util.dispatching.RunAt;
15
16import org.apache.log4j.Logger;
17
18
19/**
20 * @author Piotr Sniegowski
21 */
22@FramsClassAnnotation
23public class Portal extends JoinableCollection<Instance> {
24
25        private final static Logger log = Logger.getLogger(Portal.class.getName());
26
27        @ParamAnnotation
28        public Integer counter = 0;
29
30        public Portal() {
31        }
32
33        // @Override
34        // public void run() {
35        //      super.run();
36        //      new PeriodicTask<Portal>(this, 1000) {
37
38        //              @Override
39        //              public void run() {
40        //                      ++counter;
41        //                      log.debug("counter is now: " + counter);
42        //                      again();
43        //              }
44        //      };
45        // }
46
47        @Override
48        public void add(final Instance instance) {
49                super.add(instance);
50                instance.addListener(new AbstractInstanceListener() {
51                        @Override
52                        public void onRun(Exception e) {
53                                assert Dispatching.isThreadSafe();
54
55                                super.onRun(e);
56
57                                if (e != null) {
58                                        return;
59                                }
60                                final String path = "/simulator/genepools/groups/0/genotypes";
61                                instance.dispatch(new RunAt<Instance>() {
62                                        @Override
63                                        public void run() {
64                                                InstanceUtils.resolve(instance, path, new Future<Path>(Logging.logger(log, "resolve", path)) {
65                                                        @Override
66                                                        public void result(Path result) {
67                                                                Logging.log(log, "resolve", path, null);
68                                                        }
69                                                });
70                                        }
71                                });
72                        }
73                });
74        }
75
76        @ParamAnnotation(id = "counter_squared", name = "Counter Squared")
77        public Double getCounterSquared() {
78                return (double)(counter * counter);
79        }
80
81}
Note: See TracBrowser for help on using the repository browser.