Skip to content
Open
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
38 changes: 32 additions & 6 deletions src/com/woopra/tracking/android/WoopraTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

Expand All @@ -34,7 +36,7 @@ public class WoopraTracker {

private static final String TAG = WoopraTracker.class.getName();
private static final String W_EVENT_ENDPOINT = "http://www.woopra.com/track/ce/";

private ScheduledExecutorService pingScheduler;
private final ExecutorService executor;
private final String domain;
Expand All @@ -47,7 +49,7 @@ public class WoopraTracker {
//
private String referer = null, deviceType=null;
private WoopraVisitor visitor = null;


WoopraTracker(ExecutorService executor, String domain, WoopraVisitor vistor, WoopraClientInfo clientInfo) {
this.executor = executor;
Expand All @@ -56,16 +58,40 @@ public class WoopraTracker {
this.domain = domain;
}

/**
* Tracks given event. This is asynchronous method.
*
* This method is deprecated, use {@link #trackEventWithFuture(WoopraEvent)}
* @param event event to track
* @return false, if failed to add event to queue
*/
@Deprecated
public boolean trackEvent(WoopraEvent event) {
EventRunner runner = new EventRunner(event);
try {
executor.execute(runner);
executor.submit(runner);
} catch (Exception e) {
return false;
}
return true;
}

/**
* Tracks given event. This is asynchronous method.
* @param event event to track
* @return future object, allows to track progress of execution or null, if failed to add event to queue
*/
public Future<Boolean> trackEventWithFuture(WoopraEvent event) {
EventRunner runner = new EventRunner(event);
try {
return executor.submit(runner);
} catch (Exception e) {
return null;
}
}



private boolean trackEventImpl(WoopraEvent event) {
// generate request url
StringBuilder urlBuilder = new StringBuilder();
Expand Down Expand Up @@ -208,17 +234,17 @@ public synchronized void setVisitorProperties(Map<String,String> newProperties)
getVisitor().setProperties(newProperties);
}

class EventRunner implements Runnable {
class EventRunner implements Callable<Boolean> {
WoopraEvent event = null;

public EventRunner(WoopraEvent event) {
this.event = event;
}

@Override
public void run() {
public Boolean call() {
// send track event
trackEventImpl(event);
return trackEventImpl(event);
}
}
}