Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.taimos.gpsd4java.types.IGPSObject;
import de.taimos.gpsd4java.types.ParseException;
Expand All @@ -42,7 +42,7 @@
*/
public abstract class AbstractResultParser {

protected static final Logger LOG = Logger.getLogger(ResultParser.class.getName());
protected static final Logger LOG = LoggerFactory.getLogger(ResultParser.class);

protected final DateFormat dateFormat; // Don't make this static!

Expand Down Expand Up @@ -102,18 +102,18 @@ protected <T extends IGPSObject> List<T> parseObjectArray(final JSONArray array,
protected double parseTimestamp(final JSONObject json, final String fieldName) {
try {
final String text = json.optString(fieldName, null);
AbstractResultParser.LOG.log(Level.FINE, fieldName + ": {0}", text);
AbstractResultParser.LOG.debug(fieldName + ": {}", text);

if (text != null) {
final Date date = this.dateFormat.parse(text);
if (AbstractResultParser.LOG.isLoggable(Level.FINE)) {
if (AbstractResultParser.LOG.isDebugEnabled()) {
final String ds = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date);
AbstractResultParser.LOG.log(Level.FINE, "Date: {0}", ds);
AbstractResultParser.LOG.debug("Date: {}", ds);
}
return date.getTime() / 1000.0;
}
} catch (final Exception ex) {
AbstractResultParser.LOG.log(Level.INFO, "Failed to parse time", ex);
AbstractResultParser.LOG.info("Failed to parse time", ex);
}
return Double.NaN;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/de/taimos/gpsd4java/backend/GPSdEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.taimos.gpsd4java.api.IObjectListener;
import de.taimos.gpsd4java.types.ATTObject;
Expand All @@ -54,7 +54,7 @@
*/
public class GPSdEndpoint {

private static final Logger LOG = Logger.getLogger(GPSdEndpoint.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(GPSdEndpoint.class);

private final Socket socket;

Expand Down Expand Up @@ -113,7 +113,7 @@ public void start() {
try {
Thread.sleep(500);
} catch (final InterruptedException e) {
GPSdEndpoint.LOG.log(Level.FINE, null, e);
GPSdEndpoint.LOG.debug("Interrupted while sleeping", e);
}
}

Expand All @@ -124,7 +124,7 @@ public void stop() {
try {
this.listenThread.halt();
} catch (final Exception e) {
GPSdEndpoint.LOG.log(Level.FINE, null, e);
GPSdEndpoint.LOG.debug("Interrupted while waiting for listenThread to stop", e);
}
this.listenThread = null;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ private IGPSObject waitForResult() {
try {
this.asyncWaitMutex.wait(1000);
} catch (final InterruptedException e) {
GPSdEndpoint.LOG.log(Level.INFO, null, e);
GPSdEndpoint.LOG.info("Interrupted while waiting for result", e);
}
if (this.asnycResult != null) {
return this.asnycResult;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/de/taimos/gpsd4java/backend/SocketThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import java.io.IOException;
import java.net.SocketException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* thread reading input from GPSd server
Expand All @@ -34,7 +35,7 @@
*/
public class SocketThread extends Thread {

private static final Logger LOG = Logger.getLogger(SocketThread.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(SocketThread.class);

private final BufferedReader reader;

Expand Down Expand Up @@ -89,7 +90,7 @@ public void run() {
break;
} catch (final Exception e) {
// TODO handle this better
SocketThread.LOG.log(Level.WARNING, null, e);
SocketThread.LOG.warn("Problem encountered while reading/parsing/handling line", e);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/de/taimos/gpsd4java/test/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* #L%
*/

import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.taimos.gpsd4java.api.ObjectListener;
import de.taimos.gpsd4java.backend.GPSdEndpoint;
Expand All @@ -43,7 +43,7 @@
*/
public class Tester {

static final Logger log = Logger.getLogger(Tester.class.getName());
static final Logger log = LoggerFactory.getLogger(Tester.class);


private Tester() {
Expand Down Expand Up @@ -83,51 +83,51 @@ public static void main(final String[] args) {

@Override
public void handleTPV(final TPVObject tpv) {
Tester.log.log(Level.INFO, "TPV: {0}", tpv);
Tester.log.info("TPV: {}", tpv);
}

@Override
public void handleSKY(final SKYObject sky) {
Tester.log.log(Level.INFO, "SKY: {0}", sky);
Tester.log.info("SKY: {}", sky);
for (final SATObject sat : sky.getSatellites()) {
Tester.log.log(Level.INFO, " SAT: {0}", sat);
Tester.log.info(" SAT: {}", sat);
}
}

@Override
public void handleSUBFRAME(final SUBFRAMEObject subframe) {
Tester.log.log(Level.INFO, "SUBFRAME: {0}", subframe);
Tester.log.info("SUBFRAME: {}", subframe);
}

@Override
public void handleATT(final ATTObject att) {
Tester.log.log(Level.INFO, "ATT: {0}", att);
Tester.log.info("ATT: {}", att);
}

@Override
public void handleDevice(final DeviceObject device) {
Tester.log.log(Level.INFO, "Device: {0}", device);
Tester.log.info("Device: {}", device);
}

@Override
public void handleDevices(final DevicesObject devices) {
for (final DeviceObject d : devices.getDevices()) {
Tester.log.log(Level.INFO, "Device: {0}", d);
Tester.log.info("Device: {}", d);
}
}
});

ep.start();

Tester.log.log(Level.INFO, "Version: {0}", ep.version());
Tester.log.info("Version: {}", ep.version());

Tester.log.log(Level.INFO, "Watch: {0}", ep.watch(true, true));
Tester.log.info("Watch: {}", ep.watch(true, true));

Tester.log.log(Level.INFO, "Poll: {0}", ep.poll());
Tester.log.info("Poll: {}", ep.poll());

Thread.sleep(60000);
} catch (final Exception e) {
Tester.log.log(Level.SEVERE, null, e);
Tester.log.error("Problem encountered", e);
}
}
}