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.

  • Field Details

    • MSGTYPES_CANNOT_OVERRIDE

      public static final Set<MessageField> MSGTYPES_CANNOT_OVERRIDE
  • Constructor Details

  • Method Details

    • setBoardSerialProvider

      public void setBoardSerialProvider(Supplier<Integer> provider)
      Allows for customization of the board serial number as a Supplier of Long. This will be called whenever the serial number is needed, and should return the value promptly to avoid connectivity issues.
      Parameters:
      provider - the function that returns the serial number when requested.
    • addCustomMessageProcessor

      public void addCustomMessageProcessor(MessageField msgType, BiConsumer<MenuManagerServer,MenuCommand> processor)
      Allows user level additional message processors for custom messages. Using this you can provide your own message type at the API protocol level, and then use this to apply the additional functionality to the manager. The provided consumer will be called each time this custom message is applied. Note that you cannot override the core security based message types, any attempt to do so results in an exception.
      Parameters:
      msgType - the message type for your custom message
      processor - the processor to handle the message.
    • 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(Object sender, 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
    • 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.