source: java/main/src/main/java/com/framsticks/params/PropertiesAccess.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: 2.7 KB
Line 
1package com.framsticks.params;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import com.framsticks.params.types.ProcedureParam;
7
8
9/**
10 * The Class PropertiesAccess.
11 *
12 * @author Jarek Szymczak <name.surname@gmail.com> (please replace name and
13 *         surname with my personal data)
14 *
15 * @author Piotr Śniegowski
16 */
17public class PropertiesAccess extends SimpleAbstractAccess {
18
19        public Map<String, Object> properties;
20
21        @Override
22        public Map<String, Object> createAccessee() {
23                return PropertiesAccess.createPropertiesMap();
24        }
25
26        public static Map<String, Object> createPropertiesMap() {
27                return new HashMap<String, Object>();
28        }
29
30        public PropertiesAccess(FramsClass framsClass) {
31                super(framsClass);
32        }
33
34        @Override
35        public void clearValues() {
36                assert properties != null;
37                properties.clear();
38        }
39
40        @Override
41        public <T> T get(ValueParam param, Class<T> type) {
42                assert properties != null;
43                assert param != null;
44                Object object = properties.get(param.getId());
45                if (object != null) {
46                        try {
47                                return type.cast(object);
48                        } catch (ClassCastException e) {
49                                throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e);
50                        }
51                }
52                try {
53                        return param.getDef(type);
54                } catch (ClassCastException e) {
55                        throw (ClassCastException) new ClassCastException("default value of property " + param + " is not of type " + type.getName()).initCause(e);
56                }
57
58        }
59
60        @Override
61        protected <T> void internalSet(ValueParam param, T value) {
62                properties.put(param.getId(), value);
63        }
64
65        /**
66         * Sets the new values to operate on. It does not check whether the values
67         * which are set through this method are correct. If set values are not
68         * correct exceptions might occurred while getting / setting the parameters
69         * values
70         *
71         * @param object
72         *            the properties with parameters values
73         */
74        @SuppressWarnings("unchecked")
75        @Override
76        public PropertiesAccess select(Object object) {
77                this.properties = (Map<String, Object>)object;
78                return this;
79        }
80
81        /** covariant */
82        @Override
83        public Map<String, Object> getSelected() {
84                return properties;
85        }
86
87        @Override
88        public PropertiesAccess cloneAccess() {
89                return new PropertiesAccess(framsClass);
90        }
91
92        @Override
93        public void tryAutoAppend(Object object) {
94                throw new InvalidOperationException();
95        }
96
97        @Override
98        public Object call(String id, Object[] arguments) {
99                throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id);
100        }
101
102        @Override
103        public Object call(ProcedureParam param, Object[] arguments) {
104                throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param);
105        }
106
107}
Note: See TracBrowser for help on using the repository browser.