edu.washington.cs.sounddetector.server.api
Interface Method

All Known Implementing Classes:
Classify, GetOldNotifications, GetPendingNotifications, GetSound, GetSounds, RegisterReceiverPhone, RenameDetector, SetSoundClassProperties, Train, UnregisterReceiverPhone, Untrain

public interface Method

Method is an interface that signifies a method that can be requested to be run against the server. Implementations of the Method interface are simple, immutable data objects that hold all the necessary information for a certain method. The actual logic of these methods is put in a separate MethodLogic subclass, and the result of executing a method is put in yet another separate class: a subclass of MethodResult.

The reason for this separation is so that Method objects can easily be shared by the server and its clients without introducing unnecessary dependencies on internal server classes.

Implementing a new Method is unfortunately fairly involved, so the steps are outlined below:

  1. Come up with a name for your method, figure out what it will do, and figure out all the potential error cases that you will be able to detect.
  2. For each error case that you can detect, check if it is in MethodResult.FailureReason, and add it if necessary.
  3. Write the Method data object. This is an implementation of this interface and should be a simple, immutable data object with getters for each of it's fields. Also, try to implement toString, equals, and hashCode.
  4. Write the MethodResult object. This is a subclass of MethodResult, please read the documentation in that class for details on subclassing it.
  5. Write the logic for your method. This should go in either WriteLogic or ReadLogic, depending on if you write or read data in the database.
  6. In MethodLogic, add a constant to MethodLogic.MethodType for your method. Then add this constant and your method to the MethodLogic.methodClassMap. Finally, in MethodLogic.execute, add a case to the switch statement for your method, follow the pattern of all the other cases.
  7. In MethodConverter's constructor, add your Method to the methodMap. Follow the pattern of the other methods.
  8. You're done!

Author:
the.dylan.price@gmail.com



Copyright © 2012. All Rights Reserved.