Changeset 878


Ignore:
Timestamp:
02/11/14 22:16:48 (10 years ago)
Author:
jts21
Message:

Make FrameShare attempt to continue after (previously) uncaught exceptions (just means that if it can't find a file or gets a null pointer exception but is still in a working state then it'll keep going rather than having to be restarted)

Location:
trunk/src/org/expeditee/network
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/network/DefaultServer.java

    r838 r878  
    5858                //MessageBay.displayMessage(this.getName() + " started on port "
    5959                //              + socket.getLocalPort());
     60                int fail = 0;
    6061
    6162                while (!_stop) {
    6263                        try {
    6364                                listenForMessages();
    64        
     65                                fail = 0;
    6566                        } catch (IOException e) {
    6667                                e.printStackTrace();
     68                        } catch (Exception e) {
     69                                /**
     70                                 * If we hit an Exception we don't want to crash,
     71                                 * but we also don't want to get into an infinite loop of ignoring fatal exceptions.
     72                                 * so try again but count the failures to make sure we don't get into an infinite loop.
     73                                 * (don't just use a boolean because the next message we parse could also cause another
     74                                 *  non-fatal exception, and we don't want to exit unless absolutely necessary)
     75                                 */
     76                                e.printStackTrace();
     77                                if(fail > 10) {
     78                                        System.out.println("*****\nIt appears that we've failed to continue from an uncaught exception\n*****");
     79                                        // close all the servers
     80                                        FrameShare.getInstance().finalise();
     81                                        // attempt to restart
     82                                        // (don't do this yet since there's currently no way to know if the restart fails,
     83                                        //  so we could get stuck in a loop)
     84                                        // FrameShare.restart();
     85                                       
     86                                        // if we're only running the frameshare server, exit
     87                                        if(FrameShare.isHeadless()) {
     88                                                System.exit(1);
     89                                        }
     90                                } else {
     91                                        fail++;
     92                                        System.out.println("*****\nEncountered an uncaught exception, attempting to continue\n*****");
     93                                }
    6794                        }
    6895                }
     96               
     97                closeSocket();
     98        }
     99       
     100        protected void closeSocket() {
    69101                socket.close();
    70102        }
  • trunk/src/org/expeditee/network/FrameShare.java

    r856 r878  
    4343
    4444        private static FrameShare _theSession;
     45       
     46        private static boolean headless = false;
    4547
    4648        private Map<String, Peer> _peers;
     
    511513                }
    512514        }
     515       
     516        public static void restart() {
     517                if(_theSession != null) {
     518                        _theSession.finalise();
     519                        _theSession = new FrameShare(_theSession._port);
     520                }
     521        }
     522       
     523        public static boolean isHeadless() {
     524                return headless;
     525        }
    513526
    514527
     
    535548           
    536549            String port_str = args[0];
     550           
     551            FrameShare.headless = true;
    537552
    538553            try {
  • trunk/src/org/expeditee/network/ImageSaver.java

    r856 r878  
    113113       
    114114        @Override
    115         public void run() {
    116                 //MessageBay.displayMessage(this.getName() + " started on port "
    117                 //              + socket.getLocalPort());
    118 
    119                 while (!_stop) {
    120                         try {
    121                                 listenForMessages();
    122        
    123                         } catch (IOException e) {
    124                                 e.printStackTrace();
    125                         }
     115        protected void closeSocket() {
     116                try {
     117                        socket.close();
     118                } catch (IOException e) {
     119                        e.printStackTrace();
    126120                }
    127                 try {
    128                 socket.close();
    129         } catch (IOException e) {
    130                 e.printStackTrace();
    131         }
    132121        }
    133 
    134122}
  • trunk/src/org/expeditee/network/ImageServer.java

    r856 r878  
    9191       
    9292        @Override
    93         public void run() {
    94                 //MessageBay.displayMessage(this.getName() + " started on port "
    95                 //              + socket.getLocalPort());
    96 
    97                 while (!_stop) {
    98                         try {
    99                                 listenForMessages();
    100        
    101                         } catch (IOException e) {
    102                                 e.printStackTrace();
    103                         }
     93        protected void closeSocket() {
     94                try {
     95                        socket.close();
     96                } catch (IOException e) {
     97                        e.printStackTrace();
    10498                }
    105                 try {
    106                 socket.close();
    107         } catch (IOException e) {
    108                 e.printStackTrace();
    109         }
    11099        }
    111100
Note: See TracChangeset for help on using the changeset viewer.