📄 uithreadpoolmonitor.java
字号:
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
package com.funambol.mailclient.ui.controller;
import com.funambol.mailclient.sm.SyncClient;
import com.funambol.mailclient.ui.view.ContactList;
import com.funambol.mailclient.loc.Localization;
import com.funambol.syncml.spds.SyncException;
import com.funambol.util.CodedException;
import com.funambol.util.Log;
import com.funambol.util.ThreadPoolMonitor;
import com.funambol.mailclient.config.ConfigException;
import com.funambol.mailclient.config.MailClientConfig;
import com.funambol.push.OTAService;
import com.funambol.util.ChunkedString;
import java.util.Date;
import javax.microedition.lcdui.DateField;
/**
* ThreadPoolMonitor to handle exceptions in threads.
* i.e. exceptions occurring in sync threads
*/
public class UIThreadPoolMonitor extends ThreadPoolMonitor {
private boolean syncTimerAlarmActivated = false;
/**
* Handles any throwable event occurring in Thread Pool when running a task
* This implementation shows a specific alert for specific exception occuring
* i.e. SecurityException causes an alert for offline mode
*/
public void handleThrowable(Class clazz, Runnable runnable, Throwable throwable) {
Log.error("Error running thread. Error: " + throwable + ". Class: " +
clazz.getName() + ". Runnable: " + runnable + ".");
if (throwable instanceof OutOfMemoryError) {
Log.error("OutOfMemoryError occurred... recovering client");
UIController.freeMemory();
//UIController.showErrorAlert(Localization.getMessages().OUTOFMEMORY_ERROR);
// If error occurs in separate thread the Inbox List
// (affected by network operations) need to be reset
Log.info("[UIThreadPoolMonitor] Resetting inbox message list...");
UIController.resetInboxMessageList();
//ENABLE GetMail command if there is an Exception during any operation
UIController.enableSyncCommands(true);
return;
}
if ((runnable instanceof SyncClient) && !(throwable instanceof SecurityException)) {
//UIController.updateInboxMessageList(null);
} else if (runnable instanceof ContactList) {
UIController.getContactList().setTitle(
Localization.getMessages().SELECT_RECIPIENTS);
}
if (throwable instanceof SecurityException) {
Log.debug(throwable.getMessage());
if (OTAService.syncViaSMS) {
OTAService.syncViaSMS = false;
if (OTAService.firstSMS) {
UIController.showInfoAlert(Localization.getMessages().APPLICATION_SYNC_VIA_SMS_OFFLINE_MODE);
OTAService.firstSMS = false;
}
} else {
// wait that inbox finishes before showing the alert to make it modal
while (UIController.getInboxMessageList().isLoadingMessages()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
UIController.showInfoAlert(
Localization.getMessages().APPLICATION_IS_IN_OFFLINE_MODE);
Log.error("User didn't allow Funambol to connect to the network");
//#ifndef RepeatQuestion
UIController.enableSyncCommands(false);
UIController.setOfflineMode(true);
//#endif
}
} else if (throwable instanceof ConfigException) {
Log.error("Configuration Exception occurred");
UIController.showErrorAlert(
Localization.getMessages().CONFIGURATION_ERROR,
UIController.getAccountSettingsForm(
UIController.getInboxMessageList()));
} else if (throwable instanceof CodedException) {
CodedException ce = (CodedException) throwable;
String msg, longMsg = null;
switch (ce.getCode()) {
case CodedException.CONCURRENCE_ERROR:
Log.info("[CodedException] Concurrence error: " + ce.toString());
return;
case CodedException.STORAGE_ERROR:
// Hiding the error to the users, just logging. It is the case of an attempt of deleting
// a missing item in the client because of a delete coming from the server
// check: is it the only case? is it always true we don't want to show alert?
Log.error("[CodedException] Storage error" + ce.toString());
return;
case CodedException.LIMIT_ERROR:
msg = Localization.getMessages().AB_LIMIT_ERROR_MSG;
UIController.enableContactSync(false);
break;
// Sync codes
case SyncException.AUTH_ERROR: //401
msg = Localization.getMessages().AUTHENTICATION_ERROR_MSG;
break;
case SyncException.ACCESS_ERROR: //404
msg = Localization.getMessages().ACCESS_ERROR_MSG;
longMsg = Localization.getMessages().ACCESS_ERROR_LONG_MSG;
break;
case SyncException.READ_SERVER_RESPONSE_ERROR: //406
case SyncException.WRITE_SERVER_REQUEST_ERROR: //406
case SyncException.CONN_NOT_FOUND: //406
msg = Localization.getMessages().ACCESS_ERROR_MSG;
longMsg = Localization.getMessages().ACCESS_ERROR_LONG_MSG;
//set the sync timer task to display the message just after
//the 2nd timer attempt
if (UIController.getSyncCaller()!=UIController.USER) {
refreshSyncTimerAlarm();
} else {
syncTimerAlarmActivated = false;
}
break;
case SyncException.DATA_NULL: //407
msg = Localization.getMessages().SERVER_ERROR_MSG;
break;
case SyncException.ILLEGAL_ARGUMENT: //409
msg = Localization.getMessages().ILLEGAL_ARGUMENT_MSG;
break;
case SyncException.CLIENT_ERROR: //400
Log.error("[CodedException] Client error" + ce.toString());
return;
case SyncException.SERVER_ERROR: //500
msg = Localization.getMessages().SERVER_ERROR_MSG;
break;
case SyncException.SERVER_BUSY: //503
msg = Localization.getMessages().BUSY_ERROR_MSG;
break;
case SyncException.CONNECTION_BLOCKED_BY_USER:
// Hiding the error to the users, just logging.
UIController.enableSyncCommands(true);
UIController.resetTitles();
Log.error("[Syncexception] connection denied by user" + ce.toString());
return;
case SyncException.BACKEND_ERROR: //506
msg = Localization.getMessages().EMAIL_ERROR_MSG;
longMsg = Localization.getMessages().EMAIL_LONG_ERROR_MSG;
String exMessage = ce.getMessage();
ChunkedString cs = new ChunkedString(exMessage);
if (cs.indexOf("ALERT")>0) {
longMsg = Localization.getMessages().EMAIL_LONG_AUTH_ERROR_MSG;
}
if (cs.indexOf("Account information not found")>0) {
longMsg = Localization.getMessages().EMAIL_LONG_ACCOUNT_INFORMATION_NOT_FOUND_ERROR_MSG;
}
break;
case SyncException.BACKEND_AUTH_ERROR: //511
msg = Localization.getMessages().EMAIL_ERROR_MSG;
longMsg = Localization.getMessages().EMAIL_LONG_ERROR_MSG;
longMsg = Localization.getMessages().EMAIL_LONG_AUTH_ERROR_MSG;
break;
case SyncException.FORBIDDEN_ERROR: //403
msg = Localization.getMessages().FORBIDDEN_ERROR_MSG;
break;
case SyncException.NOT_FOUND_URI_ERROR: //405
Log.error("[CodedException] URI not found error" + ce.toString());
return;
default:
msg = Localization.getMessages().GENERIC_ERROR_MESSAGE;
Log.error("Error: " + ce.toString());
UIController.enableSyncCommands(true);
UIController.resetTitles();
return;
}
Log.error("[CodedException] code: " + ce.getCode() +
" Error during send/receive: " + ce.toString());
//in case of broken connection or network problems:
//display the message just after the 2nd timer attempt
if (!syncTimerAlarmActivated) {
if (longMsg != null) {
UIController.showErrorDetailedAlert(msg, longMsg);
} else {
UIController.showErrorAlert(msg);
}
}
UIController.enableSyncCommands(true);
UIController.resetTitles();
} else {
Log.error("GENERIC ERROR: " + throwable.toString());
UIController.enableSyncCommands(true);
}
UIController.resetInboxTitle();
// we seems to be robust here, so we're commenting this out.
// this may be needed if an error occurs in separate thread
// and we need to reset the inbox
/*
if (!UIController.getInboxMessageList().isLoadingMessages()) {
Log.info("[UIThreadPoolMonitor] Resetting inbox message list...");
UIController.resetInboxMessageList();
}*/
// if we have an exception while the splash screen is displayed but we
// are not loading the inbox, we need to go to the inbox to avoid
// locking the user in the splash screen forever
if (UIController.display.getCurrent() ==
UIController.midlet.getSplashScreen() &&
(!UIController.getInboxMessageList().isLoadingMessages())) {
UIController.display.setCurrent(UIController.getInboxMessageList());
}
//ENABLE GetMail command if there is an Exception during any operation
//UIController.enableSyncCommands(true);
}
private void refreshSyncTimerAlarm() {
AlarmManager am = AlarmManager.getInstance();
UIController.alarmCounter++;
if (UIController.alarmCounter < 3) {
Log.info("timer alarm started after sync request");
am.startOneShotSyncTimerTask(UIController.CONNECTION_RETRY_TIME);
Log.info("Total timer alarm starts: " + UIController.alarmCounter + " time");
syncTimerAlarmActivated = true;
} else {
Log.info("Network error after timer expired for " + (UIController.alarmCounter) + " times");
Log.info("No more sync timer task to load");
syncTimerAlarmActivated = false;
UIController.alarmCounter=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -