Stick Squad 3 v1.2.5.9版本的 MD5 值为:375cf7f77a7075270cd68d1397368279
以下内容为反编译后的 ScribeEventRecorder.java 源代码,内容仅作参考
package com.fusepowered.m2.common.event;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import com.fusepowered.m2.common.VisibleForTesting;
import com.fusepowered.m2.common.logging.MoPubLog;
import com.fusepowered.m2.network.ScribeBackoffPolicy;
import com.fusepowered.m2.network.ScribeRequest;
import com.fusepowered.m2.network.ScribeRequestManager;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class ScribeEventRecorder implements EventRecorder {
private static final int EVENT_COUNT_SEND_THRESHHOLD = 100;
private static final int POLLING_PERIOD_MS = 120000;
private static final int QUEUE_MAX_SIZE = 500;
private static final String SCRIBE_URL = "https://analytics.mopub.com/i/jot/exchange_client_event";
@NonNull
private final Queue<BaseEvent> mEventQueue;
@NonNull
private final EventSampler mEventSampler;
@NonNull
private final EventSerializer mEventSerializer;
@NonNull
private final Handler mPollHandler;
@NonNull
private final PollingRunnable mPollingRunnable;
@NonNull
private final ScribeRequestManager mScribeRequestManager;
public ScribeEventRecorder(@NonNull Looper looper) {
this(new EventSampler(), new LinkedList(), new EventSerializer(), new ScribeRequestManager(looper), new Handler(looper));
}
@VisibleForTesting
ScribeEventRecorder(@NonNull EventSampler eventSampler, @NonNull Queue<BaseEvent> eventQueue, @NonNull EventSerializer eventSerializer, @NonNull ScribeRequestManager scribeRequestManager, @NonNull Handler handler) {
this.mEventSampler = eventSampler;
this.mEventQueue = eventQueue;
this.mEventSerializer = eventSerializer;
this.mScribeRequestManager = scribeRequestManager;
this.mPollHandler = handler;
this.mPollingRunnable = new PollingRunnable();
}
@Override
public void record(@NonNull BaseEvent baseEvent) {
if (this.mEventSampler.sample(baseEvent)) {
if (this.mEventQueue.size() >= 500) {
MoPubLog.d("EventQueue is at max capacity. Event \"" + baseEvent.getName() + "\" is being dropped.");
return;
}
this.mEventQueue.add(baseEvent);
if (this.mEventQueue.size() >= 100) {
sendEvents();
}
scheduleNextPoll();
}
}
@VisibleForTesting
void sendEvents() {
if (!this.mScribeRequestManager.isAtCapacity()) {
final List<BaseEvent> events = dequeueEvents();
if (!events.isEmpty()) {
this.mScribeRequestManager.makeRequest(new ScribeRequest.ScribeRequestFactory() {
@Override
public ScribeRequest createRequest(ScribeRequest.Listener listener) {
return new ScribeRequest(ScribeEventRecorder.SCRIBE_URL, events, ScribeEventRecorder.this.mEventSerializer, listener);
}
}, new ScribeBackoffPolicy());
}
}
}
@VisibleForTesting
@NonNull
List<BaseEvent> dequeueEvents() {
ArrayList<BaseEvent> baseEvents = new ArrayList<>();
while (this.mEventQueue.peek() != null && baseEvents.size() < 100) {
baseEvents.add(this.mEventQueue.poll());
}
return baseEvents;
}
@VisibleForTesting
void scheduleNextPoll() {
if (!this.mPollHandler.hasMessages(0) && !this.mEventQueue.isEmpty()) {
this.mPollHandler.postDelayed(this.mPollingRunnable, 120000L);
}
}
public class PollingRunnable implements Runnable {
PollingRunnable() {
}
@Override
public void run() {
ScribeEventRecorder.this.sendEvents();
ScribeEventRecorder.this.scheduleNextPoll();
}
}
}