Device I/O API
Proposal for Java ME 8

Package jdk.dio.power

Interfaces and classes for power management of devices.

See: Description

Package jdk.dio.power Description

Interfaces and classes for power management of devices.

A Device implementing class may implement the PowerManaged interface if the underlying device supports some form of power management and saving states that can be mapped to the states defined by this API.

The following sample code gives an examples of using the power saving/management API:

 class SignalLevelMonitor implements MonitoringListener, PowerSavingHandler {

     private ADCChannel channel = null;
     private boolean inRange = false;

     public void start(int channelID, int low, int high) throws IOException, UnavailableDeviceException,
             DeviceNotFoundException {
         channel = (ADCChannel) DeviceManager.open(channelID);
         channel.setSamplingInterval(1000); // every 1 seconds
         channel.startMonitoring(low, high, this);
         if (channel instanceof PowerManaged) {
             ((PowerManaged) channel).enablePowerSaving(PowerManaged.LOW_POWER, this); // Only enable LOW_POWER saving mode (POWER_ON is implicit)
         }
     }

     @Override
     public void thresholdReached(MonitoringEvent event) {
         inRange = (event.getType() == MonitoringEvent.BACK_TO_RANGE);
     }

     @Override
     public <P extends Device<? super P>> long handlePowerStateChangeRequest(P device,
             PowerManaged.Group group, int currentState, int requestedState, long duration) {
         if (requestedState == PowerManaged.LOW_POWER) {
             return inRange ? duration : 0; // Only accept to change to LOW_POWER if signal is back in range
         }
         return duration; // Accept returning to POWER_ON
     }

     @Override
     public <P extends Device<? super P>> void handlePowerStateChange(P device,
             PowerManaged.Group group, int currentState, int requestedState, long duration) {
         // Do nothing
     }

     public void stop() throws IOException {
         if (channel != null) {
             channel.stopMonitoring();
             if (channel instanceof PowerManaged) {
                 ((PowerManaged) channel).disablePowerSaving();
             }
             channel.close();
         }
     }
 }
 

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Device I/O API
Proposal for Java ME 8