Class MenuManagerServer

java.lang.Object
com.thecoderscorner.menu.mgr.MenuManagerServer
All Implemented Interfaces:
NewServerConnectionListener

public class MenuManagerServer extends Object implements NewServerConnectionListener
The menu manager server component manages a menu tree locally, handling updates to both state and items, and also dealing with any remote connections. To listen to updates you generally register a MenuManagerListener that will receive updates as items change. These listeners can also register themselves to handle list selection changes and also to provide values for ScrollChoiceMenuItems. In terms of remotes, many types of remote connections can be added, each type of remote is registered as a ServerConnectionManager that handles one or more remote connection. This manager object provides much of the functionality around managing connections, including joining, pairing, bootstrapping, handling the messages and dealing with heartbeats. Any authentication that is required is dealt with by an instance of MenuAuthenticator.
  • Constructor Details

  • Method Details

    • setDialogManager

      public void setDialogManager(DialogManager manager)
      replace the dialog manager with another implementation. By default this class starts with an empty dialog manager that can be replaced with a more suitable implementation
      Parameters:
      manager - the replacement dialog manager
    • getDialogManager

      public DialogManager getDialogManager()
      Returns:
      the dialog manager for this menu
    • addConnectionManager

      public void addConnectionManager(ServerConnectionManager manager)
      Add a connection manager to the list of connection managers. This will be started during start and any connections that are created will be serviced by this manager
      Parameters:
      manager - a new connection manager
    • addMenuManagerListener

      public void addMenuManagerListener(MenuManagerListener listener)
      Add a listener that will receive menu item events, such as when items change, and also when scroll choice values are needed. In addition to the menuHasChanged() method you can register additional methods marking them with the MenuCallback annotation, and for every scroll choice item, you should register a value retrieval method using ScrollChoiceValueRetriever
      Parameters:
      listener - the new listener
      See Also:
    • addTreeStructureChangeListener

      public void addTreeStructureChangeListener(MenuTreeStructureChangeListener structureListener)
      Add a callback that will run when the tree has structurally changed. IE when items are added or removed from sub menus
      Parameters:
      structureListener - the listener
    • start

      public void start()
      Start the manager and all associated server connection managers
    • stop

      public void stop()
      Stop the manager all associated resources
    • isAnyRemoteConnection

      public boolean isAnyRemoteConnection()
      Indicates if there is a remote connection on any of the server connection managers
      Returns:
      true if there is a connection, otherwise false
    • getAllServerConnections

      public List<ServerConnection> getAllServerConnections()
      Returns:
      a list of all connections across all connection managers
    • connectionCreated

      public void connectionCreated(ServerConnection connection)
      Indicates that a connection has been created, implementing the NewServerConnectionListener. For this we register ourselves as the message handler and send initial commands
      Specified by:
      connectionCreated in interface NewServerConnectionListener
      Parameters:
      connection - the new connection
    • getManagedMenu

      public MenuTree getManagedMenu()
      Returns:
      the menu tree belonging to this manager
    • updateMenuItem

      public void updateMenuItem(MenuItem item, Object newValue)
      Update the value for the given menu item. This updates the state in the underlying tree and sends notifications locally and remote
      Parameters:
      item - the item that has changed
      newValue - the new value
    • remoteUpdateHasOccurred

      public void remoteUpdateHasOccurred(MenuItem item, Object value)
      Tell the manager that a remote MenuInMenu style update has occurred, this must not be sent remotely to avoid a loop.
      Parameters:
      item - the item
      value - the value
    • treeStructurallyChanged

      public void treeStructurallyChanged(MenuItem hint)
      Tell the manager that the tree has structurally changed and that any interested parties need notification.
      Parameters:
      hint - either MenuTree.ROOT or another item in the tree
    • getServerName

      public String getServerName()
      Returns:
      the app name
    • getServerUuid

      public UUID getServerUuid()
      Returns:
      UUID of the app, the local UUID
    • sendCommand

      public void sendCommand(MenuCommand command)
      Send a command to all remotes that are connected.
      Parameters:
      command - the command to send
    • getAuthenticator

      public MenuAuthenticator getAuthenticator()
      Returns:
      the authenticator that is being used.