import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
+import com.evernote.edam.error.EDAMErrorCode;
import com.evernote.edam.error.EDAMNotFoundException;
import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
import cx.fbn.nevernote.Global;
import cx.fbn.nevernote.signals.ENRelatedNotesSignal;
+import cx.fbn.nevernote.signals.LimitSignal;
import cx.fbn.nevernote.utilities.ApplicationLogger;
import cx.fbn.nevernote.utilities.Pair;
public class ENRelatedNotesRunner extends QObject implements Runnable{
- private final ApplicationLogger logger;
- private final SyncRunner syncRunner;
- public volatile ENRelatedNotesSignal enRelatedNotesSignal;
- public QMutex mutex;
- private volatile boolean keepRunning;
- private volatile LinkedBlockingQueue<String> workQueue;
+ private final ApplicationLogger logger;
+ private final SyncRunner syncRunner;
+ public volatile ENRelatedNotesSignal enRelatedNotesSignal;
+ public QMutex mutex;
+ private volatile boolean keepRunning;
+ private volatile LinkedBlockingQueue<String> workQueue;
private volatile LinkedBlockingQueue<Pair<String, List<String>>> resultQueue; // ペア<元ノートguid, 関連ノートguidリスト>を溜めておくキュー
+ public volatile LimitSignal limitSignal;
- public ENRelatedNotesRunner(SyncRunner syncRunner, ApplicationLogger logger) {
- this.logger = logger;
+ public ENRelatedNotesRunner(SyncRunner syncRunner, String logname) {
+ this.logger = new ApplicationLogger(logname);
this.syncRunner = syncRunner;
this.enRelatedNotesSignal = new ENRelatedNotesSignal();
this.mutex = new QMutex();
this.keepRunning = true;
this.workQueue = new LinkedBlockingQueue<String>();
this.resultQueue = new LinkedBlockingQueue<Pair<String, List<String>>>();
+ this.limitSignal = new LimitSignal();
}
@Override
} catch (EDAMUserException e) {
logger.log(logger.HIGH, "Evernote関連ノート取得中に例外発生:EDAMUserException");
} catch (EDAMSystemException e) {
+ if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+ limitSignal.rateLimitReached.emit(e.getRateLimitDuration());
+ }
logger.log(logger.HIGH, "Evernote関連ノート取得中に例外発生:EDAMSystemException");
} catch (EDAMNotFoundException e) {
logger.log(logger.HIGH, "Evernote関連ノート取得中に例外発生:EDAMnotFoundException guid = " + guid);
this.keepRunning = keepRunning;
}
- public synchronized boolean addGuid(String guid) {
+ public boolean addGuid(String guid) {
if (workQueue.offer("GET " + guid)) {
return true;
}
return false;
}
- public synchronized boolean addStop() {
+ public boolean addStop() {
if (workQueue.offer("STOP")) {
return true;
}