📄 uithreadpoolmonitor.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.mailclient.ui.controller;
import com.funambol.mailclient.mm.SyncTaskManager;
import com.funambol.mailclient.ui.view.FunCanvasContactList;
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 java.util.Date;
/**
* ThreadPoolMonitor to handle exceptions in threads.
* i.e. exceptions occurring in sync threads
*/
public class UIThreadPoolMonitor extends ThreadPoolMonitor {
/**
* 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;
// TO BE ENABLED
//Set new alarm to restart the app after 30 seconds
/*
AlarmManager alarmManager = AlarmManager.getInstance();
Date now = new Date();
alarmManager.setAlarm(now.getTime() + 30000);
try {
Thread.sleep(3000);
alarmManager.scheduleMIDletAlarm();
} catch (Exception e) {
Log.error("Error scheduling alarm: " + e);
e.printStackTrace();
}
//Close the application...
UIController.getThreadPool().startThread(LifeCycleController.getInstance());
return;
**/
}
if ((runnable instanceof SyncTaskManager)
&& !(throwable instanceof SecurityException )) {
//UIController.updateInboxMessageList(null);
} else if (runnable instanceof FunCanvasContactList) {
UIController.getContactList().setTitle(
Localization.getMessages().SELECT_RECIPIENTS);
}
if (throwable instanceof SecurityException ) {
if(OTAMessagesListener.syncViaSMS){
OTAMessagesListener.syncViaSMS = false;
if(OTAMessagesListener.firstSMS){
UIController.showErrorAlert(Localization.getMessages().APPLICATION_SYNC_VIA_SMS_OFFLINE_MODE);
OTAMessagesListener.firstSMS = false;
}
}else{
UIController.showErrorAlert(Localization.getMessages().APPLICATION_IS_IN_OFFLINE_MODE);
}
} 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;
Log.error("[CodedException] code: " + ce.getCode() +
" Error during send/receive: " + ce.toString());
String msg = null;
switch(ce.getCode()) {
case CodedException.CONCURRENCE_ERROR :
// TODO: Hide the alert for sync in progress...
//msg=Localization.getMessages().SYNC_IN_PROGRESS_MSG;
Log.error("[CodedException] Concurrence error");
return;
//break;
case CodedException.STORAGE_ERROR :
msg=Localization.getMessages().STORAGE_ERROR_MSG;
break;
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().NETWORK_ERROR_MSG;
break;
case SyncException.CLIENT_ERROR : //400
case SyncException.SERVER_ERROR : //500
msg=Localization.getMessages().SYNC_ERROR_MSG;
break;
case SyncException.SERVER_BUSY: //503
msg=Localization.getMessages().BUSY_ERROR_MSG;
break;
case SyncException.BACKEND_ERROR: //506
msg=Localization.getMessages().EMAIL_ERROR_MSG;
break;
default:
msg=Localization.getMessages().GENERIC_ERROR_MESSAGE;
Log.error("Error: "+ ce.toString());
}
UIController.showErrorAlert(msg);
} else {
Log.info("GENERIC ERROR");
throwable.printStackTrace();
UIController.showErrorAlert(
Localization.getMessages().GENERIC_ERROR_MESSAGE);
}
// 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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -