Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8131030

Callbacks for hardware state events

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • any

    • generic
    • generic

      In the modern world, it is quite normal that while a JVM is running an application, the executing host machine cycles through several system states. For example, a chat application running on Java SE might be kept open while the laptop hosting the JVM is suspended or sent to hibernation, and after several hours it is resumed.

      Currently the application running inside the JVM (here: the chat app) does not get informed of any state changes of the host. Neither its suspension, nor its wakeup. This is not very smart. Many application might benefit from these events either in a technical or even in a business level sense. For example, the chat app might send a "I'm away now" message to the chat partner so he immediately sees that the friend will be unavailable for longer time, and immediately sees when the friend is back online due to a "I'm back" event transmitted as soon as the laptop is resumed. Another example could be a server application where one node of a cluster kindly informs the other nodes that he will be unavailable due to a power loss detected by the UPS, reported by the OS to the JVM.

      While native applications written e. g. in C will be informed by the OS since decades (e. g. there are Power Status events defined by the Windows API), until now there is no cross-platform API in the JRE. An application that wants to be informed by the OS in case of system status change has to make use of JNI and OS specific APIs. This is neither WORA, nor smart or contemporary.

      Hence I'd like to propose the addition of a very simplistic API. It could look like this for example:

      Runtime.addStateListener(Consumer<StateEvent> event);
      Runtime.removeStateListener(Consumer<StateEvent> event);
      public interface StateEvent {
      }
      public class SuspendStateEvent implements StateEvent {
      }
      public class ResumeStateEvent implements StateEvent {
      }

      While these are the most useful and essential events, certainly it would be beneficial to add more system state events, e. g. IdleStateEvent.

            Unassigned Unassigned
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: