Ignore:
Timestamp:
07/04/13 20:29:50 (11 years ago)
Author:
psniegowski
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/communication/ServerConnection.java

    r90 r96  
    33import com.framsticks.communication.queries.*;
    44import com.framsticks.params.SourceInterface;
     5import com.framsticks.util.FramsticksException;
     6import com.framsticks.util.lang.Holder;
    57import com.framsticks.util.lang.Pair;
    68import com.framsticks.util.lang.Strings;
     9
     10import org.apache.log4j.Level;
    711import org.apache.log4j.Logger;
    812
     
    2024
    2125        public ServerConnection(Socket socket, RequestHandler requestHandler) {
    22                 super("todo");
     26                super(socket.getInetAddress().getHostAddress(), "server connection");
    2327                this.socket = socket;
    2428                this.requestHandler = requestHandler;
    25                 connected = true;
    26 
     29                // socket.setSoTimeout(500);
     30                setupStreams();
    2731        }
    2832
    29         @Override
    30         public String toString() {
    31                 return socket.getInetAddress().getHostAddress();
    32         }
    3333
    3434        @Override
    3535        protected void receiverThreadRoutine() {
    36                 while (connected) {
    37                         processNextRequest();
     36                while (isRunning() && isConnected()) {
     37                        try {
     38                                processNextRequest();
     39                        } catch (Exception e) {
     40                                log.log((isRunning() ? Level.ERROR : Level.DEBUG), "caught exception: ", e);
     41                                break;
     42                        }
    3843                }
     44                interrupt();
     45                finish();
    3946        }
    4047
     
    8592                                output.print(outId);
    8693                                if (Strings.notEmpty(response.getComment())) {
    87                                         output.print(' ');
     94                                        output.print(" \"");
    8895                                        output.print(response.getComment());
     96                                        output.print('"');
    8997                                }
    9098                                output.print('\n');
     
    96104
    97105        protected void processNextRequest() {
    98                 String line = getLine();
    99                 Pair<String, String> command = Strings.splitIntoPair(line, ' ', "\n");
    100                 final Pair<Integer, String> rest = parseRest(command.second);
    101                 if (rest == null) {
    102                         respond(new Response(false, "\"invalid input\"", null), null);
     106                final Holder<Integer> id = new Holder<>();
     107                final String line = getLine();
     108                try {
     109                        Pair<CharSequence, CharSequence> command = Request.takeIdentifier(line);
     110                        final Pair<Integer, CharSequence> rest = takeRequestId(command.second);
     111                        id.set(rest.first);
     112
     113                        final Request request = Request.parse(command.first, rest.second);
     114
     115                        if (log.isTraceEnabled()) {
     116                                log.trace("read request: " + request);
     117                        }
     118
     119                        handleRequest(request, new ResponseCallback<ServerConnection>() {
     120                                @Override
     121                                public void process(Response response) {
     122                                        respond(response, rest.first);
     123                                }
     124                        });
     125                } catch (FramsticksException e) {
     126                        e.arg("id", id.get()).arg("line", line);
     127                        log.error("error: ", e);
     128                        respond(new Response(false, "invalid input: " + e.getMsg(), null), id.get());
    103129                        return;
    104130                }
    105131
    106                 final Request request = Request.createRequestByTypeString(command.first);
    107                 if (request == null) {
    108                         respond(new Response(false, "\"invalid input\"", null), null);
    109                         return;
    110                 }
    111                 request.parseRest(rest.second);
    112                 if (log.isTraceEnabled()) {
    113                         log.trace("read request: " + request);
    114                 }
    115 
    116                 handleRequest(request, new ResponseCallback<ServerConnection>() {
    117                         @Override
    118                         public void process(Response response) {
    119                                 respond(response, rest.first);
    120                         }
    121                 });
    122         }
    123 
    124         @Override
    125         protected void joinableStart() {
    126                 // TODO Auto-generated method stub
    127 
    128132        }
    129133}
Note: See TracChangeset for help on using the changeset viewer.