Package jmri

Interface MemoryManager

  • All Superinterfaces:
    Manager<Memory>, PropertyChangeProvider, ProvidingManager<Memory>, SilenceablePropertyChangeProvider, VetoableChangeProvider
    All Known Implementing Classes:
    AbstractMemoryManager, DefaultMemoryManager

    public interface MemoryManager
    extends ProvidingManager<Memory>
    Locate a Memory object representing some specific information.

    Memory objects are obtained from a MemoryManager, which in turn is generally located from the InstanceManager. A typical call sequence might be:

     Memory memory = InstanceManager.memoryManagerInstance().provideMemory("status");
     

    Each Memory has two names. The "user" name is entirely free form, and can be used for any purpose. The "system" name is provided by the system-specific implementations, if any, and provides a unique mapping to the layout control system (for example LocoNet or NCE) and address within that system. Note that most (all?) layout systems don't have anything corresponding to this, in which case the "Internal" Memory objects are still available with names like IM23.

    Much of the bookkeeping is implemented in the AbstractMemoryManager class, which can form the basis for a system-specific implementation.

    See Also:
    Memory, AbstractMemoryManager, InstanceManager
    • Method Detail

      • provideMemory

        @Nonnull
        Memory provideMemory​(@Nonnull
                             java.lang.String name)
                      throws java.lang.IllegalArgumentException
        Get the Memory with the user name, then system name if needed; if that fails, create a new Memory. If the name is a valid system name, it will be used for the new Memory. Otherwise, the makeSystemName method will attempt to turn it into a valid system name.
        Parameters:
        name - User name, system name, or address which can be promoted to system name
        Returns:
        Never null
        Throws:
        java.lang.IllegalArgumentException - if Memory doesn't already exist and the manager cannot create the Memory due to an illegal name or name that can't be parsed.
      • getMemory

        @CheckForNull
        Memory getMemory​(@Nonnull
                         java.lang.String name)
        Get an existing Turnout or return null if it doesn't exist. Locates via user name, then system name if needed.
        Parameters:
        name - User name or system name to match
        Returns:
        null if no match found
      • getByUserName

        @CheckForNull
        Memory getByUserName​(@Nonnull
                             java.lang.String userName)
        Locate an existing Memory based on a user name. Returns null if no instance already exists.
        Specified by:
        getByUserName in interface Manager<Memory>
        Parameters:
        userName - the user name
        Returns:
        requested Memory object or null if none exists
      • newMemory

        @Nonnull
        Memory newMemory​(@Nonnull
                         java.lang.String systemName,
                         @CheckForNull
                         java.lang.String userName)
                  throws java.lang.IllegalArgumentException
        Return a Memory with the specified system and user names. Note that two calls with the same arguments will get the same instance; there is only one Memory object representing a given physical Memory and therefore only one with a specific system or user name.

        This will always return a valid object reference; a new object will be created if necessary. In that case:

        • If a null reference is given for user name, no user name will be associated with the Memory object created; a valid system name must be provided
        • If both names are provided, the system name defines the hardware access of the desired Memory, and the user address is associated with it. The system name must be valid.
        Note that it is possible to make an inconsistent request if both addresses are provided, but the given values are associated with different objects. This is a problem, and we don't have a good solution except to issue warnings. This will mostly happen if you're creating Memory objects when you should be looking them up.
        Parameters:
        systemName - the system name
        userName - the user name
        Returns:
        requested Memory object (never null)
        Throws:
        java.lang.IllegalArgumentException - if cannot create the Memory due to e.g. an illegal name or name that can't be parsed.
      • newMemory

        @Nonnull
        Memory newMemory​(@CheckForNull
                         java.lang.String userName)
                  throws java.lang.IllegalArgumentException
        For use with User GUI, to allow the auto generation of systemNames, where the user can optionally supply a username.

        This will always return a valid object reference; a new object will be created if necessary.

        Parameters:
        userName - the user name, can be null
        Returns:
        requested Memory object (never null)
        Throws:
        java.lang.IllegalArgumentException - if cannot create the Memory due to e.g. an illegal name or name that can't be parsed.