@@ -65,6 +65,8 @@ public class GPSdEndpoint {
6565
6666 private SocketThread listenThread ;
6767
68+ private final boolean daemon ;
69+
6870 private final List <IObjectListener > listeners = new ArrayList <IObjectListener >(1 );
6971
7072 private IGPSObject asyncResult = null ;
@@ -88,11 +90,13 @@ public class GPSdEndpoint {
8890 *
8991 * @param server the server name or IP
9092 * @param port the server port
91- * @param resultParser
93+ * @param resultParser the result parser
94+ * @param daemon whether to start the underlying socket thread as a daemon, as defined in {@link Thread#setDaemon}
9295 * @throws UnknownHostException
9396 * @throws IOException
9497 */
95- public GPSdEndpoint (final String server , final int port , final AbstractResultParser resultParser ) throws UnknownHostException , IOException {
98+ public GPSdEndpoint (final String server , final int port , final AbstractResultParser resultParser , final boolean daemon )
99+ throws UnknownHostException , IOException {
96100 this .server = server ;
97101 this .port = port ;
98102 if (server == null ) {
@@ -109,13 +113,28 @@ public GPSdEndpoint(final String server, final int port, final AbstractResultPar
109113 this .in = new BufferedReader (new InputStreamReader (this .socket .getInputStream ()));
110114 this .out = new BufferedWriter (new OutputStreamWriter (this .socket .getOutputStream ()));
111115 this .resultParser = resultParser ;
116+
117+ this .daemon = daemon ;
118+ }
119+
120+ /**
121+ * Instantiate this class to connect to a GPSd server
122+ *
123+ * @param server the server name or IP
124+ * @param port the server port
125+ * @param resultParser the result parser
126+ * @throws UnknownHostException
127+ * @throws IOException
128+ */
129+ public GPSdEndpoint (final String server , final int port , final AbstractResultParser resultParser ) throws UnknownHostException , IOException {
130+ this (server , port , resultParser , true );
112131 }
113132
114133 /**
115134 * start the endpoint
116135 */
117136 public void start () {
118- this .listenThread = new SocketThread (this .in , this , this .resultParser );
137+ this .listenThread = new SocketThread (this .in , this , this .resultParser , this . daemon );
119138 this .listenThread .start ();
120139 }
121140
@@ -324,7 +343,7 @@ void handleDisconnected() throws IOException {
324343 this .in = new BufferedReader (new InputStreamReader (this .socket .getInputStream ()));
325344 this .out = new BufferedWriter (new OutputStreamWriter (this .socket .getOutputStream ()));
326345
327- this .listenThread = new SocketThread (this .in , this , this .resultParser );
346+ this .listenThread = new SocketThread (this .in , this , this .resultParser , this . daemon );
328347 this .listenThread .start ();
329348 if (lastWatch != null ) { // restore watch if we had one.
330349 this .syncCommand (lastWatch , WatchObject .class );
0 commit comments