From: yuki Date: Tue, 22 Oct 2013 09:11:06 +0000 (+0900) Subject: Evernote APIの帯域制限超過時にエラーメッセージを表示するようにした X-Git-Tag: version0.4~1^2~11 X-Git-Url: http://git.osdn.net/view?p=neighbornote%2FNeighborNote.git;a=commitdiff_plain;h=7b79a07951a083236298195d0214c9748ce38569 Evernote APIの帯域制限超過時にエラーメッセージを表示するようにした --- diff --git a/src/cx/fbn/nevernote/NeverNote.java b/src/cx/fbn/nevernote/NeverNote.java index fe7cdaf..90adc7b 100644 --- a/src/cx/fbn/nevernote/NeverNote.java +++ b/src/cx/fbn/nevernote/NeverNote.java @@ -49,6 +49,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.h2.tools.ChangeFileEncryption; +import com.evernote.edam.error.EDAMErrorCode; import com.evernote.edam.error.EDAMNotFoundException; import com.evernote.edam.error.EDAMSystemException; import com.evernote.edam.error.EDAMUserException; @@ -484,6 +485,7 @@ public class NeverNote extends QMainWindow{ syncRunner.status.message.connect(this, "setMessage(String)"); syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)"); syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()"); + syncRunner.limitSignal.rateLimitReached.connect(this, "informRateLimit(Integer)"); syncRunning = false; if (syncTime > 0) { automaticSync = true; @@ -6223,6 +6225,9 @@ public class NeverNote extends QMainWindow{ setMessage("EDAMUserException: " +e.getMessage()); return; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds.")); + } setMessage("EDAMSystemException: " +e.getMessage()); return; } catch (EDAMNotFoundException e) { @@ -6283,6 +6288,9 @@ public class NeverNote extends QMainWindow{ waitCursor(false); return null; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds.")); + } setMessage("EDAMSystemException: " +e.getMessage()); waitCursor(false); return null; @@ -6347,6 +6355,9 @@ public class NeverNote extends QMainWindow{ setMessage("EDAMUserException: " +e.getMessage()); return; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds.")); + } setMessage("EDAMSystemException: " +e.getMessage()); return; } catch (TException e) { @@ -7790,4 +7801,10 @@ public class NeverNote extends QMainWindow{ public RensoNoteList getRensoNoteList() { return rensoNoteListDock.getRensoNoteList(); } + + // 帯域制限の超過をユーザに通知 + @SuppressWarnings("unused") + private void informRateLimit(Integer rateLimitDuration) { + QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + rateLimitDuration + " seconds.")); + } } diff --git a/src/cx/fbn/nevernote/dialog/ShareNotebook.java b/src/cx/fbn/nevernote/dialog/ShareNotebook.java index 560c23e..bc14d4b 100644 --- a/src/cx/fbn/nevernote/dialog/ShareNotebook.java +++ b/src/cx/fbn/nevernote/dialog/ShareNotebook.java @@ -28,6 +28,7 @@ package cx.fbn.nevernote.dialog; import java.util.ArrayList; import java.util.List; +import com.evernote.edam.error.EDAMErrorCode; import com.evernote.edam.error.EDAMNotFoundException; import com.evernote.edam.error.EDAMSystemException; import com.evernote.edam.error.EDAMUserException; @@ -45,6 +46,7 @@ import com.trolltech.qt.gui.QFontMetrics; import com.trolltech.qt.gui.QHBoxLayout; import com.trolltech.qt.gui.QIcon; import com.trolltech.qt.gui.QLabel; +import com.trolltech.qt.gui.QMessageBox; import com.trolltech.qt.gui.QPushButton; import com.trolltech.qt.gui.QTableWidget; import com.trolltech.qt.gui.QTableWidgetItem; @@ -231,6 +233,9 @@ public class ShareNotebook extends QDialog { } catch (EDAMNotFoundException e) { e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds.")); + } e.printStackTrace(); } catch (TException e) { e.printStackTrace(); diff --git a/src/cx/fbn/nevernote/gui/RensoNoteList.java b/src/cx/fbn/nevernote/gui/RensoNoteList.java index ba8ed62..5c23860 100644 --- a/src/cx/fbn/nevernote/gui/RensoNoteList.java +++ b/src/cx/fbn/nevernote/gui/RensoNoteList.java @@ -79,6 +79,7 @@ public class RensoNoteList extends QListWidget { enRelatedNotesCache = new HashMap>(); this.enRelatedNotesRunner = new ENRelatedNotesRunner(this.syncRunner, this.logger); this.enRelatedNotesRunner.enRelatedNotesSignal.getENRelatedNotesFinished.connect(this, "enRelatedNotesComplete()"); + this.enRelatedNotesRunner.limitSignal.rateLimitReached.connect(parent, "informRateLimit(Integer)"); this.enRelatedNotesThread = new QThread(enRelatedNotesRunner, "ENRelatedNotes Thread"); this.getEnRelatedNotesThread().start(); diff --git a/src/cx/fbn/nevernote/signals/LimitSignal.java b/src/cx/fbn/nevernote/signals/LimitSignal.java new file mode 100644 index 0000000..565d60f --- /dev/null +++ b/src/cx/fbn/nevernote/signals/LimitSignal.java @@ -0,0 +1,26 @@ +/* + * This file is part of NeighborNote + * Copyright 2013 Yuki Takahashi + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * +*/ + +package cx.fbn.nevernote.signals; + +import com.trolltech.qt.QSignalEmitter; + +public class LimitSignal extends QSignalEmitter { + public Signal1 rateLimitReached = new Signal1(); +} diff --git a/src/cx/fbn/nevernote/threads/ENRelatedNotesRunner.java b/src/cx/fbn/nevernote/threads/ENRelatedNotesRunner.java index 296faea..abc6c6d 100644 --- a/src/cx/fbn/nevernote/threads/ENRelatedNotesRunner.java +++ b/src/cx/fbn/nevernote/threads/ENRelatedNotesRunner.java @@ -23,6 +23,7 @@ import java.util.ArrayList; 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; @@ -37,18 +38,20 @@ import com.trolltech.qt.core.QObject; 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 workQueue; + private final ApplicationLogger logger; + private final SyncRunner syncRunner; + public volatile ENRelatedNotesSignal enRelatedNotesSignal; + public QMutex mutex; + private volatile boolean keepRunning; + private volatile LinkedBlockingQueue workQueue; private volatile LinkedBlockingQueue>> resultQueue; // ペア<元ノートguid, 関連ノートguidリスト>を溜めておくキュー + public volatile LimitSignal limitSignal; public ENRelatedNotesRunner(SyncRunner syncRunner, ApplicationLogger logger) { this.logger = logger; @@ -58,6 +61,7 @@ public class ENRelatedNotesRunner extends QObject implements Runnable{ this.keepRunning = true; this.workQueue = new LinkedBlockingQueue(); this.resultQueue = new LinkedBlockingQueue>>(); + this.limitSignal = new LimitSignal(); } @Override @@ -134,6 +138,9 @@ public class ENRelatedNotesRunner extends QObject implements Runnable{ } 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); diff --git a/src/cx/fbn/nevernote/threads/SyncRunner.java b/src/cx/fbn/nevernote/threads/SyncRunner.java index 4ecda4c..ecd18c4 100644 --- a/src/cx/fbn/nevernote/threads/SyncRunner.java +++ b/src/cx/fbn/nevernote/threads/SyncRunner.java @@ -46,6 +46,7 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; +import com.evernote.edam.error.EDAMErrorCode; import com.evernote.edam.error.EDAMNotFoundException; import com.evernote.edam.error.EDAMSystemException; import com.evernote.edam.error.EDAMUserException; @@ -75,6 +76,7 @@ import com.trolltech.qt.core.QObject; import com.trolltech.qt.core.QTextCodec; import com.trolltech.qt.gui.QMessageBox; +import cx.fbn.nevernote.signals.LimitSignal; import cx.fbn.nevernote.signals.NoteIndexSignal; import cx.fbn.nevernote.signals.NoteResourceSignal; import cx.fbn.nevernote.signals.NoteSignal; @@ -118,6 +120,7 @@ public class SyncRunner extends QObject implements Runnable { public volatile SavedSearchSignal searchSignal; public volatile NoteResourceSignal resourceSignal; public volatile SyncSignal syncSignal; + public volatile LimitSignal limitSignal; public volatile boolean authRefreshNeeded; public volatile boolean syncNeeded; public volatile boolean disableUploads; @@ -172,6 +175,7 @@ public class SyncRunner extends QObject implements Runnable { searchSignal = new SavedSearchSignal(); syncSignal = new SyncSignal(); resourceSignal = new NoteResourceSignal(); + limitSignal = new LimitSignal(); resourceUrl = r; indexUrl = i; // ICHANGED @@ -324,6 +328,10 @@ public class SyncRunner extends QObject implements Runnable { enDisconnect(); return; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } + e1.printStackTrace(); status.message.emit(tr("System error user account information. Aborting sync and disconnecting!")); syncSignal.errorDisconnect.emit(); @@ -354,6 +362,9 @@ public class SyncRunner extends QObject implements Runnable { enDisconnect(); return; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } e.printStackTrace(); status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!")); syncSignal.errorDisconnect.emit(); @@ -522,6 +533,9 @@ public class SyncRunner extends QObject implements Runnable { } catch (EDAMUserException e) { logger.log(logger.LOW, "EDAM User Excepton in syncExpunged: " +expunged.get(i).guid); // This can happen if we try to delete a deleted note } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "EDAM System Excepton in syncExpunged: "+expunged.get(i).guid); logger.log(logger.LOW, e.getStackTrace()); error=true; @@ -586,6 +600,9 @@ public class SyncRunner extends QObject implements Runnable { //logger.log(logger.LOW, e.toString()); //error = true; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotes "+e); status.message.emit(tr("Error: ") +e); logger.log(logger.LOW, e.toString()); @@ -670,6 +687,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e.toString()); error = true; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotes "+e); status.message.emit(tr("Error: ") +e); logger.log(logger.LOW, e.toString()); @@ -705,6 +725,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.toString()); error = true; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotebooks getting remote Notebook List"); status.message.emit(tr("Error: ") +e1); logger.log(logger.LOW, e1.toString()); @@ -764,6 +787,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e.toString() + ": Stack : " +enNotebook.getStack()); error = true; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotebooks"); logger.log(logger.LOW, e.toString()); error = true; @@ -795,6 +821,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.toString()); error = true; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalTags getting remote Tag List"); status.message.emit(tr("Error: ") +e1); logger.log(logger.LOW, e1.toString()); @@ -869,6 +898,9 @@ public class SyncRunner extends QObject implements Runnable { badTagSync.put(enTag.getGuid(),null); error = true; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "** EDAM System Excepton syncLocalTags: " +enTag.getName()); logger.log(logger.LOW, e.toString()); badTagSync.put(enTag.getGuid(),null); @@ -912,6 +944,9 @@ public class SyncRunner extends QObject implements Runnable { error = true; e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalLinkedNotebooks"); status.message.emit(tr("Error: ") +e); logger.log(logger.LOW, e.toString()); @@ -942,6 +977,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.toString()); error = true; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton syncLocalTags getting remote saved search List"); status.message.emit(tr("Error: ") +e1); logger.log(logger.LOW, e1.toString()); @@ -1001,6 +1039,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e.toString()); error = true; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "** EDAM System Excepton syncLocalTags"); logger.log(logger.LOW, e.toString()); error = true; @@ -1055,6 +1096,9 @@ public class SyncRunner extends QObject implements Runnable { e.printStackTrace(); status.message.emit(e.getMessage()); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } error = true; e.printStackTrace(); status.message.emit(e.getMessage()); @@ -1357,6 +1401,9 @@ public class SyncRunner extends QObject implements Runnable { error = true; e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton getEvernoteNote"); logger.log(logger.LOW, e.toString()); error = true; @@ -1386,6 +1433,9 @@ public class SyncRunner extends QObject implements Runnable { error = true; e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } logger.log(logger.LOW, "*** EDAM System Excepton getEvernoteNote"); logger.log(logger.LOW, e.toString()); error = true; @@ -1567,6 +1617,9 @@ public class SyncRunner extends QObject implements Runnable { isConnected = false; return false; } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } QMessageBox mb = new QMessageBox(QMessageBox.Icon.Critical, "EDAM System Excepton", e.getLocalizedMessage()); mb.exec(); e.printStackTrace(); @@ -1632,6 +1685,9 @@ public class SyncRunner extends QObject implements Runnable { } catch (EDAMUserException e1) { e1.printStackTrace(); } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } e1.printStackTrace(); } catch (TException e1) { e1.printStackTrace(); @@ -1759,6 +1815,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.getMessage()); return; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } e1.printStackTrace(); status.message.emit(tr("System exception Listing shared notebooks.")); logger.log(logger.LOW, e1.getMessage()); @@ -1788,6 +1847,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.getMessage()); return; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } e1.printStackTrace(); status.message.emit(tr("System exception Listing notebooks.")); logger.log(logger.LOW, e1.getMessage()); @@ -1813,6 +1875,9 @@ public class SyncRunner extends QObject implements Runnable { logger.log(logger.LOW, e1.getMessage()); return; } catch (EDAMSystemException e1) { + if (e1.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e1.getRateLimitDuration()); + } e1.printStackTrace(); status.message.emit(tr("System exception Listing linked notebooks.")); logger.log(logger.LOW, e1.getMessage()); @@ -1960,6 +2025,9 @@ public class SyncRunner extends QObject implements Runnable { error = true; e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } error = true; logger.log(logger.LOW, "System error authenticating against shared notebook. "+ "Key: "+books.get(i).getShareKey() +" Error:" +e.getMessage()); @@ -2036,6 +2104,9 @@ public class SyncRunner extends QObject implements Runnable { e.printStackTrace(); logger.log(logger.LOW, tr("EDAM UserException synchronizing linked notbook ")+ e.getMessage()); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } syncError = true; status.message.emit(tr("EDAM SystemException synchronizing linked notbook. See the log for datails.")); e.printStackTrace(); @@ -2091,6 +2162,9 @@ public class SyncRunner extends QObject implements Runnable { readOnly = true; e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } readOnly = true; e.printStackTrace(); } catch (TException e) { @@ -2118,6 +2192,9 @@ public class SyncRunner extends QObject implements Runnable { } catch (EDAMUserException e) { e.printStackTrace(); } catch (EDAMSystemException e) { + if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) { + limitSignal.rateLimitReached.emit(e.getRateLimitDuration()); + } e.printStackTrace(); } catch (EDAMNotFoundException e) { e.printStackTrace();