ServerActivityMonitor.java

net.minecraft.server.notifications.ServerActivityMonitor

信息

  • 全限定名:net.minecraft.server.notifications.ServerActivityMonitor
  • 类型:public class
  • 包:net.minecraft.server.notifications
  • 源码路径:src/main/java/net/minecraft/server/notifications/ServerActivityMonitor.java
  • 起始行号:L8
  • 职责:

    TODO

字段/常量

  • minimumMillisBetweenNotifications

    • 类型: long
    • 修饰符: private final
    • 源码定位: L9
    • 说明:

      TODO

  • lastNotificationTime

    • 类型: AtomicLong
    • 修饰符: private final
    • 源码定位: L10
    • 说明:

      TODO

  • serverActivity

    • 类型: AtomicBoolean
    • 修饰符: private final
    • 源码定位: L11
    • 说明:

      TODO

  • notificationManager

    • 类型: NotificationManager
    • 修饰符: private final
    • 源码定位: L12
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ServerActivityMonitor(NotificationManager notificationManager, int secondsBetweenNotifications) @ L14

  • 构造器名:ServerActivityMonitor
  • 源码定位:L14
  • 修饰符:public

参数:

  • notificationManager: NotificationManager
  • secondsBetweenNotifications: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void tick() @ L19

  • 方法名:tick
  • 源码定位:L19
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void reportLoginActivity() @ L23

  • 方法名:reportLoginActivity
  • 源码定位:L23
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private void processWithRateLimit() @ L28

  • 方法名:processWithRateLimit
  • 源码定位:L28
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

代码

public class ServerActivityMonitor {
    private final long minimumMillisBetweenNotifications;
    private final AtomicLong lastNotificationTime = new AtomicLong();
    private final AtomicBoolean serverActivity = new AtomicBoolean(false);
    private final NotificationManager notificationManager;
 
    public ServerActivityMonitor(NotificationManager notificationManager, int secondsBetweenNotifications) {
        this.notificationManager = notificationManager;
        this.minimumMillisBetweenNotifications = TimeUnit.SECONDS.toMillis(secondsBetweenNotifications);
    }
 
    public void tick() {
        this.processWithRateLimit();
    }
 
    public void reportLoginActivity() {
        this.serverActivity.set(true);
        this.processWithRateLimit();
    }
 
    private void processWithRateLimit() {
        long now = Util.getMillis();
        if (this.serverActivity.get() && now - this.lastNotificationTime.get() >= this.minimumMillisBetweenNotifications) {
            this.notificationManager.serverActivityOccured();
            this.lastNotificationTime.set(Util.getMillis());
        }
 
        this.serverActivity.set(false);
    }
}

引用的其他类