/server-kernel/src/main/java/be/abollaert/domotics/light/server/kernel/persistence/Storage.java

https://github.com/abollaert/smartlights · Java · 167 lines · 24 code · 20 blank · 123 comment · 0 complexity · 5c91794f1a18c91f821a5820e3a4b69e MD5 · raw file

  1. package be.abollaert.domotics.light.server.kernel.persistence;
  2. import java.util.Date;
  3. import java.util.List;
  4. import be.abollaert.domotics.light.api.ChannelState;
  5. import be.abollaert.domotics.light.api.SwitchEvent;
  6. /**
  7. * The storage takes care of the persistence.
  8. *
  9. * @author alex
  10. */
  11. public interface Storage {
  12. /**
  13. * Load the configuration for a particular channel.
  14. *
  15. * @param moduleId The ID of the module.
  16. * @param channelNumber The channel number.
  17. *
  18. * @return The stored configuration, <code>null</code> if there is no stored configuration.
  19. *
  20. * @throws StorageException If a storage error occurs.
  21. */
  22. StoredChannelConfiguration loadChannelConfiguration(final int moduleId, final int channelNumber) throws StorageException;
  23. /**
  24. * Starts the storage engine.
  25. *
  26. * @throws StorageException If a storage error occurs.
  27. */
  28. void start() throws StorageException;
  29. /**
  30. * Stops the storage engine.
  31. *
  32. * @throws StorageException If a storage error occurs.
  33. */
  34. void stop() throws StorageException;
  35. /**
  36. * Save the configuration for a particular channel.
  37. *
  38. * @param moduleId The ID of the module.
  39. * @param channelNumber The channel number.
  40. * @param configuration The new configuration.
  41. */
  42. void saveChannelConfiguration(int moduleId, int channelNumber, StoredChannelConfiguration configuration);
  43. /**
  44. * Logs an on/off event.
  45. *
  46. * @param moduleId The module ID.
  47. * @param channelNumber The channel number.
  48. * @param on <code>true</code> if on, <code>false</code> if not.
  49. */
  50. void logOnOffEvent(final int moduleId, final int channelNumber, final boolean on);
  51. /**
  52. * Log a dim event.
  53. *
  54. * @param moduleId The module ID.
  55. * @param channelNumber The channel number.
  56. * @param percentage The percentage.
  57. */
  58. void logDimEvent(final int moduleId, final int channelNumber, final int percentage);
  59. /**
  60. * Get the switch events for the given period.
  61. *
  62. * @param moduleId The ID of the module.
  63. * @param channelNumber The channel number.
  64. * @param startDate The start date. When null, epoch is assumed.
  65. * @param endDate The end date. When null, now is assumed.
  66. *
  67. * @return The {@link List} of switch events which occurred for the given channel during the given period. Ordered ascendingly.
  68. */
  69. List<SwitchEvent> getSwitchEventsForPeriod(final int moduleId, final int channelNumber, final Date startDate, final Date endDate);
  70. /**
  71. * Add the given mood to storage.
  72. *
  73. * @param moodId The ID of the mood.
  74. * @param moodName The name of the mood.
  75. */
  76. StoredMoodInfo saveMoodInformation(final int moodId, final String moodName);
  77. /**
  78. * Loads the stored mood info for the given ID.
  79. *
  80. * @param moodId The mood ID.
  81. *
  82. * @return The Mood information, null if none.
  83. */
  84. StoredMoodInfo loadMoodInformationFor(final int moodId);
  85. /**
  86. * Add a switch element to the given mood.
  87. *
  88. * @param moodId The ID of the mood.
  89. * @param moduleId The module ID.
  90. * @param channelNumber The channel number.
  91. * @param state The requested state.
  92. */
  93. void saveMoodSwitchElement(final int moodId, final int moduleId, final int channelNumber, final ChannelState state);
  94. /**
  95. * Add a dim element to the given mood.
  96. *
  97. * @param moodId The ID of the mood.
  98. * @param moduleId The module ID.
  99. * @param channelNumber The channel number.
  100. * @param percentage The percentage.
  101. */
  102. void saveMoodDimElement(final int moodId, final int moduleId, final int channelNumber, final int percentage);
  103. /**
  104. * Remove the given switch element from the given mood.
  105. *
  106. * @param moodId The ID of the mood.
  107. * @param moduleId The module ID.
  108. * @param channelNumber The channel number.
  109. */
  110. void removeMoodSwitchElement(final int moodId, final int moduleId, final int channelNumber);
  111. /**
  112. * Removes the given dim element from the given mood.
  113. *
  114. * @param moodId The ID of the mood.
  115. * @param moduleId The module ID.
  116. * @param channelNumber The channel number.
  117. */
  118. void removeMoodDimElement(final int moodId, final int moduleId, final int channelNumber);
  119. /**
  120. * Removes the given mood.
  121. *
  122. * @param moodId The ID of the mood to remove.
  123. */
  124. void removeMood(final int moodId);
  125. /**
  126. * Returns basic information about the stored moods.
  127. *
  128. * @return Basic information about the stored moods.
  129. */
  130. List<StoredMoodInfo> getStoredMoods();
  131. /**
  132. * Returns the switch elements that are attached to the given mood.
  133. *
  134. * @param moodId The ID of the mood.
  135. *
  136. * @return The switch elements attached to it.
  137. */
  138. List<StoredSwitchMoodElement> getSwitchElementsForMood(final int moodId);
  139. /**
  140. * Returns the dim elements that are attached to the given mood.
  141. *
  142. * @param moodId The ID of the mood.
  143. *
  144. * @return The dim elements attached to it.
  145. */
  146. List<StoredDimMoodElement> getDimElementsForMood(final int moodId);
  147. }