|
JavaTM 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 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。