@@ -52,12 +52,7 @@ public class SocketThread extends Thread {
5252 */
5353 public SocketThread (final BufferedReader reader , final GPSdEndpoint endpoint ,
5454 final AbstractResultParser resultParser , final boolean daemon ) {
55- if (reader == null ) {
56- throw new IllegalArgumentException ("reader can not be null!" );
57- }
58- if (endpoint == null ) {
59- throw new IllegalArgumentException ("endpoint can not be null!" );
60- }
55+
6156 if (resultParser == null ) {
6257 throw new IllegalArgumentException ("resultParser can not be null!" );
6358 }
@@ -81,22 +76,24 @@ public SocketThread(final BufferedReader reader, final GPSdEndpoint endpoint, fi
8176
8277 @ Override
8378 public void run () {
84- while (this .running .get ()) {
85- try {
86- // read line from socket
87- final String s = this .reader .readLine ();
88- if (s == null ) {
89- break ;
90- }
91- if (!s .isEmpty ()) {
92- // parse line and handle it accordingly
93- this .endpoint .handle (this .resultParser .parse (s ));
79+ if (this .reader != null ) {
80+ while (this .running .get ()) {
81+ try {
82+ // read line from socket
83+ final String s = this .reader .readLine ();
84+ if (s == null ) {
85+ break ;
86+ }
87+ if (!s .isEmpty ()) {
88+ // parse line and handle it accordingly
89+ this .endpoint .handle (this .resultParser .parse (s ));
90+ }
91+ } catch (final SocketException e ) {
92+ break ; // stop
93+ } catch (final Exception e ) {
94+ // TODO handle this better
95+ SocketThread .LOG .warn ("Problem encountered while reading/parsing/handling line" , e );
9496 }
95- } catch (final SocketException e ) {
96- break ; // stop
97- } catch (final Exception e ) {
98- // TODO handle this better
99- SocketThread .LOG .warn ("Problem encountered while reading/parsing/handling line" , e );
10097 }
10198 }
10299 if (running .get () && !Thread .interrupted ()) {
@@ -106,13 +103,17 @@ public void run() {
106103 }
107104
108105 protected void retry () {
109- SocketThread .LOG .debug ("Disconnected from GPS socket, retrying connection" );
106+ if (reader != null ) {
107+ SocketThread .LOG .debug ("Disconnected from GPS socket, retrying connection" );
108+ } else {
109+ SocketThread .LOG .debug ("Connecting to GPSD socket" );
110+ }
110111
111112 while (this .running .get ()) {
112113 try {
113114 running .waitFor (this .endpoint .getRetryInterval ());
114115 this .endpoint .handleDisconnected ();
115- SocketThread .LOG .debug ("Reconnected to GPS socket" );
116+ SocketThread .LOG .debug ("Connected to GPS socket" );
116117 running .set (false );
117118 } catch (InterruptedException ix ) {
118119 break ;
0 commit comments