Ignore:
Timestamp:
07/16/13 23:31:35 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

for Joinables running

CHANGELOG:
Add WorkPackageLogic? and classes representing prime experiment state.

Add classes for PrimeExperiment? state.

Extract single netload routine in Simulator.

Working netload with dummy content in PrimeExperiment?.

More development with NetLoadSaveLogic? and PrimeExperiment?.

Improvement around prime.

Improve BufferedDispatcher?.isActive logic.

Add prime-all.xml configuration.

Manual connecting to existing simulators from GUI.

Guard in SimulatorConnector? against expdef mismatch.

Guard against empty target dispatcher in BufferedDispatcher?.

Make BufferedDispatcher? a Dispatcher (and Joinable).

Minor improvements.

Done StackedJoinable?, improve Experiment.

Develop StackedJoinable?.

Add StackedJoinable? utility joinables controller.

Add dependency on apache-commons-lang.

Add ready ListChange? on Simulators.

Improve hints in ListChange?.

Several improvements.

Found bug with dispatching in Experiment.

Minor improvements.

Fix bug with early finishing Server.

Many changes in Dispatching.

Fix bug with connection.

Do not obfuscate log with socket related exceptions.

Add SocketClosedException?.

Add SimulatorConnector?.

Work out conception of experiment composing of logics building blocks.

Rename SinkInterface? to Sink.

Move saving of Accesses into AccessOperations?.

Some improvements to Experiment.

Improve joinables.

Fix issue with joinables closing.

Add direct and managed consoles to popup menu.

File:
1 edited

Legend:

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

    r101 r102  
    1818import java.io.PrintWriter;
    1919import java.net.Socket;
    20 import java.net.SocketTimeoutException;
    2120import java.util.Collection;
    2221import java.util.HashSet;
     
    8786        public Connection setAddress(String address) {
    8887                return setAddress(new Address(address));
    89         }
    90 
    91         public synchronized boolean isConnected() {
    92                 return socket != null && socket.isConnected();
    9388        }
    9489
     
    131126
    132127                                readChars = 0;
    133                                 while (readChars == 0) {
    134                                         try {
    135                                                 readChars = input.read(readBuffer);
    136                                         } catch (SocketTimeoutException ignored) {
    137                                                 //timeout - continue
    138                                         }
     128                                readChars = input.read(readBuffer);
     129                                if (readChars < 0) {
     130                                        throw new SocketClosedException().msg("socket is closed");
    139131                                }
    140132                                iterator = 0;
     
    143135                        throw new InterruptedException();
    144136                } catch (Exception e) {
    145                         throw new FramsticksException().msg("failed to read line").cause(e);
     137                        log.debug("failed to read line (closing): {}", e.getMessage());
     138                        throw new SocketClosedException().msg("failed to read line").cause(e);
    146139                }
    147140        }
     
    162155        protected abstract void processNextInputBatch();
    163156
     157
    164158        protected final void processInputBatchesUntilClosed() {
    165                 while (isRunning() && isConnected()) {
     159                while (isRunning() && !socket.isClosed()) {
    166160                        try {
    167161                                processNextInputBatch();
     162                        } catch (SocketClosedException e) {
     163                                log.log(isRunning() ? Level.ERROR : Level.DEBUG, "socket is closing: {}", e.getShortMessage(new StringBuilder()));
     164                                // log.log(isRunning() ? Level.ERROR : Level.DEBUG, "caught exception: ", e);
     165                                break;
    168166                        } catch (FramsticksException e) {
     167                                log.debug("{} caught exception in receiver thread {}", this, e.getMessage());
    169168                                handle(e);
    170169                        } catch (Exception e) {
     
    173172                        }
    174173                }
     174                log.debug("{} finished processing input", this);
    175175        }
    176176
     
    227227                Dispatching.use(threads, this);
    228228
    229                 senderThread.dispatch(new RunAt<Connection>(ThrowExceptionHandler.getInstance()) {
     229                senderThread.dispatch(new RunAt<Connection>(this) {
    230230                        @Override
    231231                        protected void runAt() {
     
    238238                });
    239239
    240                 receiverThread.dispatch(new RunAt<Connection>(ThrowExceptionHandler.getInstance()) {
     240                receiverThread.dispatch(new RunAt<Connection>(this) {
    241241                        @Override
    242242                        protected void runAt() {
    243243                                receiverThreadRoutine();
    244244                                interruptJoinable();
    245                                 finishJoinable();
     245                                // finishJoinable();
    246246                        }
    247247                });
     
    260260
    261261        protected static void startClientConnection(Connection connection) {
    262                 while (connection.isRunning() && !connection.isConnected()) {
     262                while (connection.isRunning() && connection.socket == null) {
    263263                        log.debug("connecting to {}", connection.address);
    264264                        try {
    265265                                connection.socket = new Socket(connection.getAddressObject().getHostName(), connection.getAddressObject().getPort());
    266266                        } catch (IOException e) {
    267                                 log.info("{} failed to connect (retrying): ", connection, e);
     267                                log.warn("{} failed to connect (retrying): {}", connection, e.getMessage());
    268268                                Dispatching.sleep(0.5);
    269269                        }
     
    272272                log.debug("{} connected", connection);
    273273                try {
    274                         connection.socket.setSoTimeout(500);
     274                        // connection.socket.setSoTimeout(500);
    275275                        connection.setupStreams();
    276276                } catch (Exception e) {
     
    319319        @Override
    320320        public void handle(FramsticksException exception) {
     321                log.debug("{} handling {}", this, exception.getMessage());
    321322                exceptionHandler.handle(exception);
    322323        }
     
    358359        }
    359360
     361        public synchronized boolean isConnected() {
     362                return socket != null && socket.isConnected();
     363        }
     364
    360365}
Note: See TracChangeset for help on using the changeset viewer.