|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjavax.management.NotificationBroadcasterSupport
javax.management.timer.Timer
public class Timer
提供對計時器 MBean 的實作。計時器 MBean 將在指定的時間發出警告,以喚醒所有註冊的偵聽器來接收計時器通知。
此類別管理一個過期的計時器通知列表。這是一種允許使用者根據需要任意添加/移除通知的方法。當計時器發出計時器通知並過時後,會將該通知自動從計時器通知列表中移除。
可以將其他計時器通知添加到常規重複發送的通知中。
註:
Timer 類別的主機的系統日期。如果偵聽器主機具有不同的系統日期,則偵聽器可能會不合時宜地接收到通知。為了避免此類別問題,要同步所有需要計時的主機的系統日期。
Timer 中指定。為了使用固定速率執行,要使用重載的 addNotification(String, String, Object, Date, long, long, boolean) 方法。
NotificationBroadcasterSupport。
| 欄位摘要 | |
|---|---|
static long |
ONE_DAY
一天內的毫秒數。 |
static long |
ONE_HOUR
一小時內的毫秒數。 |
static long |
ONE_MINUTE
一分鐘內的毫秒數。 |
static long |
ONE_SECOND
一秒鐘內的毫秒數。 |
static long |
ONE_WEEK
一周內的毫秒數。 |
| 建構子摘要 | |
|---|---|
Timer()
預設的建構子。 |
|
| 方法摘要 | |
|---|---|
Integer |
addNotification(String type,
String message,
Object userData,
Date date)
創建具有指定 type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期以及 null 時段和出現數量的通知列表中。 |
Integer |
addNotification(String type,
String message,
Object userData,
Date date,
long period)
創建具有指定 type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期和時段,以及 null 出現數量的通知列表中。 |
Integer |
addNotification(String type,
String message,
Object userData,
Date date,
long period,
long nbOccurences)
創建具有指定 type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期、時段和出現數量的通知列表中。 |
Integer |
addNotification(String type,
String message,
Object userData,
Date date,
long period,
long nbOccurences,
boolean fixedRate)
創建具有指定 type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期、時段和出現數量的通知列表中。 |
Vector<Integer> |
getAllNotificationIDs()
獲得所有在通知列表中註冊的計時器通知標識符。 |
Date |
getDate(Integer id)
獲得與計時器通知關聯的日期的一個副本。 |
Boolean |
getFixedRate(Integer id)
獲得此種標誌的一個副本:該標誌指示是以固定延遲 方式執行定期通知,還是以固定速率 方式執行。 |
int |
getNbNotifications()
獲得在通知列表中註冊的計時器通知數。 |
Long |
getNbOccurences(Integer id)
獲得與計時器通知關聯的剩餘出現數量的一個副本。 |
Vector<Integer> |
getNotificationIDs(String type)
獲得所有與指定型別對應的計時器通知的標識符。 |
MBeanNotificationInfo[] |
getNotificationInfo()
返回一個陣列,指示此 MBean 可能發送的每個通知的 Java 類別名和通知型別。 |
String |
getNotificationMessage(Integer id)
獲得與指定標識符對應的計時器通知的詳細訊息。 |
String |
getNotificationType(Integer id)
獲得與指定標識符對應的計時器通知型別。 |
Object |
getNotificationUserData(Integer id)
獲得與指定標識符對應的計時器通知使用者資料物件。 |
Long |
getPeriod(Integer id)
獲得與計時器通知關聯的時段(以毫秒為單位)的一個副本。 |
boolean |
getSendPastNotifications()
獲得一個指示計時器是否發送過期通知的標誌。 |
boolean |
isActive()
測試計時器 MBean 是否處於啟動狀態。 |
boolean |
isEmpty()
測試計時器通知列表是否為空。 |
void |
postDeregister()
允許計時器 MBean 在 MBean 伺服器註銷它之後執行任何所需的操作。 |
void |
postRegister(Boolean registrationDone)
允許計時器 MBean 在 MBean 伺服器中註冊後或註冊失敗後執行任何所需的操作。 |
void |
preDeregister()
允許計時器 MBean 在 MBean 伺服器註銷它之前執行任何所需的操作。 |
ObjectName |
preRegister(MBeanServer server,
ObjectName name)
允許計時器 MBean 在 MBean 伺服器中註冊之前執行任何所需的操作。 |
void |
removeAllNotifications()
從通知列表中刪除所有計時器通知並重置用來更新計時器通知標識符的計數器。 |
void |
removeNotification(Integer id)
從通知列表中移除與指定標識符對應的計時器通知。 |
void |
removeNotifications(String type)
從通知列表中移除與指定型別對應的所有計時器通知。 |
void |
setSendPastNotifications(boolean value)
設置指示計時器是否發送過期通知的標誌。 |
void |
start()
啟動計時器。 |
void |
stop()
停止計時器。 |
| 從類別 javax.management.NotificationBroadcasterSupport 繼承的方法 |
|---|
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 欄位詳細資訊 |
|---|
public static final long ONE_SECOND
addNotification 方法的有用常數。
public static final long ONE_MINUTE
addNotification 方法的有用常數。
public static final long ONE_HOUR
addNotification 方法的有用常數。
public static final long ONE_DAY
addNotification 方法的有用常數。
public static final long ONE_WEEK
addNotification 方法的有用常數。
| 建構子詳細資訊 |
|---|
public Timer()
| 方法詳細資訊 |
|---|
public ObjectName preRegister(MBeanServer server,
ObjectName name)
throws Exception
未在此上下文中使用。
MBeanRegistration 中的 preRegisterserver - 將在其中註冊計時器 MBean 的 MBean 伺服器。name - 計時器 MBean 的物件名。
Exceptionpublic void postRegister(Boolean registrationDone)
未在此上下文中使用。
MBeanRegistration 中的 postRegisterregistrationDone - 指示該 MBean 是否已在 MBean 伺服器中成功註冊。false 值意味著註冊階段已失敗。
public void preDeregister()
throws Exception
停止計時器。
MBeanRegistration 中的 preDeregisterExceptionpublic void postDeregister()
未在此上下文中使用。
MBeanRegistration 中的 postDeregisterpublic MBeanNotificationInfo[] getNotificationInfo()
NotificationBroadcaster 複製的描述返回一個陣列,指示此 MBean 可能發送的每個通知的 Java 類別名和通知型別。
MBean 發送此陣列中未描述的通知是合法的。但是,某些 MBean 伺服器的客戶端要想正常運行,可能要依賴完整的陣列。
NotificationBroadcaster 中的 getNotificationInfoNotificationBroadcasterSupport 中的 getNotificationInfopublic void start()
如果有一個或多個計時器通知早於通知列表中的時間,則將根據 sendPastNotifications 標誌發送通知,然後根據其週期和剩餘出現數量更新通知。如果計時器通知日期早於當前日期,則僅從通知列表中移除此通知。
TimerMBean 中的 startpublic void stop()
TimerMBean 中的 stop
public Integer addNotification(String type,
String message,
Object userData,
Date date,
long period,
long nbOccurences,
boolean fixedRate)
throws IllegalArgumentException
type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期、時段和出現數量的通知列表中。
如果要插入的計時器通知其日期早於當前的日期,則該方法具有把指定的日期當做當前日期的行為。
對於“一次性”通知,將立即發出該通知。
對於定期通知,將立即發出第一個通知,而後續通知將根據 period 參數指定的間隔提供。
注意,一旦將計時器通知添加到通知列表中,將不能更新其相關的日期、時段和出現數量。
如果是定期通知,則參數 fixedRate 的值將用來指定執行方案,如在 Timer 中指定的那樣。
TimerMBean 中的 addNotificationtype - 計時器通知型別。message - 計時器通知詳細訊息。userData - 計時器通知使用者資料物件。date - 發出通知時的日期。period - 計時器通知的時段(以毫秒為單位)。nbOccurences - 將發出的計時器通知的總數。fixedRate - 如果為 true 並且通知是定期的,則使用固定速率 執行方案安排該通知。如果為 false 並且通知是定期的,則使用固定延遲 執行方案安排通知。如果通知不是定期的,則將被忽略。
IllegalArgumentException - 如果 date 為 null 或者 period 或出現的數量為負數。addNotification(String, String, Object, Date, long, long)
public Integer addNotification(String type,
String message,
Object userData,
Date date,
long period,
long nbOccurences)
throws IllegalArgumentException
type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期、時段和出現數量的通知列表中。
如果要插入的計時器通知其日期早於當前的日期,則該方法具有把指定的日期當做當前日期的行為。
對於“一次性”通知,將立即發出該通知。
對於定期通知,將立即發出第一個通知,而後續通知將根據 period 參數指定的間隔提供。
注意,一旦將計時器通知添加到通知列表中,將不能更新其相關的日期、時段和出現數量。
如果是定期通知,則使用固定延遲 執行方案,如在 Timer 中指定的那樣。為了使用固定速率 執行方案,要使用 addNotification(String, String, Object, Date, long, long, boolean)。
TimerMBean 中的 addNotificationtype - 計時器通知型別。message - 計時器通知詳細訊息。userData - 計時器通知使用者資料物件。date - 發出通知時的日期。period - 計時器通知的時段(以毫秒為單位)。nbOccurences - 將發出的計時器通知的總數。
IllegalArgumentException - 如果 date 為 null 或者 period 或出現的數量為負數。addNotification(String, String, Object, Date, long, long, boolean)
public Integer addNotification(String type,
String message,
Object userData,
Date date,
long period)
throws IllegalArgumentException
type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期和時段,以及 null 出現數量的通知列表中。
通過使用固定延遲 執行方案,計時器通知將持續重複使用計時器時段,如在 Timer 中指定的那樣。為了使用固定速率 執行方案,要使用 addNotification(String, String, Object, Date, long, long, boolean)。
如果要插入的計時器通知其日期早於當前的日期,則該方法具有把指定的日期當做當前日期的行為。將立即發出第一個通知,而後續通知將根據 period 參數指定的間隔提供。
TimerMBean 中的 addNotificationtype - 計時器通知型別。message - 計時器通知詳細訊息。userData - 計時器通知使用者資料物件。date - 發出通知時的日期。period - 計時器通知的時段(以毫秒為單位)。
IllegalArgumentException - 如果 date 為 null 或者 period 或出現的數量為負數。
public Integer addNotification(String type,
String message,
Object userData,
Date date)
throws IllegalArgumentException
type、message 和 userData 的新計時器通知,並將其插入到帶有給定日期以及 null 時段和出現數量的通知列表中。
計時器通知將在指定的日期一次性處理。
如果要插入的計時器通知其日期早於當前的日期,則該方法具有把指定的日期當做當前日期的行為,並且將立即發出通知。
TimerMBean 中的 addNotificationtype - 計時器通知型別。message - 計時器通知詳細訊息。userData - 計時器通知使用者資料物件。date - 發出通知時的日期。
IllegalArgumentException - 如果 date 為 null。
public void removeNotification(Integer id)
throws InstanceNotFoundException
TimerMBean 中的 removeNotificationid - 計時器通知標識符。
InstanceNotFoundException - 如果指定的標識符不能與此計時器 MBean 通知列表中的任何計時器通知對應。
public void removeNotifications(String type)
throws InstanceNotFoundException
TimerMBean 中的 removeNotificationstype - 計時器通知型別。
InstanceNotFoundException - 如果指定型別不能與此計時器 MBean 通知列表中的任何計時器通知對應。public void removeAllNotifications()
TimerMBean 中的 removeAllNotificationspublic int getNbNotifications()
TimerMBean 中的 getNbNotificationspublic Vector<Integer> getAllNotificationIDs()
TimerMBean 中的 getAllNotificationIDsInteger 物件的向量。public Vector<Integer> getNotificationIDs(String type)
TimerMBean 中的 getNotificationIDstype - 計時器通知型別。
Integer 物件的向量,該物件包含所有帶指定 type 的計時器通知的標識符。type 的計時器 MBean 註冊的計時器通知,則該向量為空。public String getNotificationType(Integer id)
TimerMBean 中的 getNotificationTypeid - 計時器通知標識符。
public String getNotificationMessage(Integer id)
TimerMBean 中的 getNotificationMessageid - 計時器通知標識符。
public Object getNotificationUserData(Integer id)
TimerMBean 中的 getNotificationUserDataid - 計時器通知標識符。
public Date getDate(Integer id)
TimerMBean 中的 getDateid - 計時器通知標識符。
public Long getPeriod(Integer id)
TimerMBean 中的 getPeriodid - 計時器通知標識符。
public Long getNbOccurences(Integer id)
TimerMBean 中的 getNbOccurencesid - 計時器通知標識符。
public Boolean getFixedRate(Integer id)
TimerMBean 中的 getFixedRateid - 計時器通知標識符。
public boolean getSendPastNotifications()
false。
TimerMBean 中的 getSendPastNotificationssetSendPastNotifications(boolean)public void setSendPastNotifications(boolean value)
false。
TimerMBean 中的 setSendPastNotificationsvalue - 過期通知發送開/關標誌值。getSendPastNotifications()public boolean isActive()
start 方法時,計時器 MBean 被標記為啟動。當調用 stop 方法時,該標記變為非啟動。false。
TimerMBean 中的 isActivetrue;否則返回 false。public boolean isEmpty()
TimerMBean 中的 isEmptytrue,否則返回 false。
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。