source: java/main/src/main/java/com/framsticks/communication/StateCallback.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.1 KB
Line 
1package com.framsticks.communication;
2
3import com.framsticks.util.FramsticksException;
4import com.framsticks.util.StateFunctor;
5
6/**
7 * @author Piotr Sniegowski
8 */
9public abstract class StateCallback<C> extends ResponseCallback<C> implements StateFunctor {
10
11
12        protected StateFunctor wrapped;
13
14        public StateCallback(StateFunctor wrapped) {
15                this.wrapped = wrapped;
16        }
17
18        public StateCallback() {
19                this.wrapped = null;
20        }
21
22        protected StateFunctor move() {
23                assert wrapped != null;
24                StateFunctor result = wrapped;
25                wrapped = null;
26                return result;
27        }
28
29        protected abstract void callImpl();
30
31        @Override
32        public final void call() {
33                try {
34                        callImpl();
35                } catch (FramsticksException e) {
36                        handle(e);
37                        return;
38                }
39                if (wrapped != null) {
40                        wrapped.call();
41                }
42        }
43
44        @Override
45        public void handle(FramsticksException exception) {
46                if (wrapped != null) {
47                        wrapped.handle(exception);
48                        return;
49                }
50                throw exception;
51        }
52
53        @Override
54        public void process(Response response) {
55                if (response.getOk()) {
56                        call();
57                } else {
58                        handle(new FramsticksException().msg("non-ok response").arg("comment", response.getComment()));
59                }
60        }
61}
Note: See TracBrowser for help on using the repository browser.