Class BlockManager
- All Implemented Interfaces:
PropertyChangeListener
,VetoableChangeListener
,EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,InstanceManagerAutoDefault
,Manager<Block>
,ProvidingManager<Block>
public class BlockManager extends AbstractManager<Block> implements ProvidingManager<Block>, InstanceManagerAutoDefault
Note that this does not enforce any particular system naming convention.
Note this is a concrete class, unlike the interface/implementation pairs of most Managers, because there are currently only one implementation for Blocks.
This file is part of JMRI.
JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
Nested Class Summary
Nested classes/interfaces inherited from interface jmri.Manager
Manager.ManagerDataEvent<E extends NamedBean>, Manager.ManagerDataListener<E extends NamedBean>, Manager.NameValidity
-
Field Summary
Fields Modifier and Type Field Description ShutDownTask
shutDownTask
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedProperties
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, deprecatedManagerLogger, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, LOGIXNG_STRING_ACTIONS, LOGIXNG_STRING_EXPRESSIONS, LOGIXNG_TABLES, LOGIXNGS, LOGIXS, MEMORIES, METERFRAMES, METERS, OBLOCKS, PANELFILES, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
-
Constructor Summary
Constructors Constructor Description BlockManager()
-
Method Summary
Modifier and Type Method Description Block
createNewBlock(String userName)
Create a new Block using an automatically incrementing system name.Block
createNewBlock(String systemName, String userName)
Create a new Block, only if it does not exist.void
dispose()
Free resources when no longer used.String
getBeanTypeHandled(boolean plural)
Get the user-readable name of the type of NamedBean handled by this manager.Block
getBlock(String name)
Get an existing Block.List<Block>
getBlocksOccupiedByRosterEntry(BasicRosterEntry re)
Get a list of blocks which the supplied roster entry appears to be occupying.Block
getByDisplayName(String key)
String
getDefaultSpeed()
Class<Block>
getNamedBeanClass()
Get the class of NamedBean supported by this Manager.int
getXMLOrder()
Determine the order that types should be written when storing panel files.boolean
isSavedPathInfo()
void
propertyChange(PropertyChangeEvent e)
Listen for changes to the power state from any power managers in use in order to track how long it's been since power was applied to the layout.Block
provide(String name)
Get an existing instance via user name, then system name; if no matching instance is found, create a new NameBean from the system name.Block
provideBlock(String name)
If the Block exists, return it, otherwise create a new one and return it.void
setDefaultSpeed(String speed)
void
setSavedPathInfo(boolean save)
long
timeSinceLastLayoutPowerOn()
Get the amount of time since the layout was last powered up, in milliseconds.char
typeLetter()
Methods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, createSystemName, deleteBean, deregister, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getBySystemName, getByUserName, getIncrement, getIncrementFromExistingNumber, getInstanceBySystemName, getInstanceByUserName, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanList, getNamedBeanSet, getNextValidAddress, getNextValidAddress, getObjectCount, getSystemNameList, getSystemPrefix, handleUserNameUniqueness, makeSystemName, register, registerSelf, registerUserName, removeDataListener, setDataListenerMute, setPropertyChangesSilenced, updateAutoNumber, validSystemNameFormat, vetoableChange
Methods inherited from class jmri.beans.VetoableChangeSupport
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jmri.Manager
addDataListener, deleteBean, deregister, getBeanBySystemName, getBeanByUserName, getBeanTypeHandled, getBySystemName, getByUserName, getEntryToolTip, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanList, getNamedBeanSet, getObjectCount, getSubSystemNamePrefix, getSystemNameList, getSystemNamePrefix, getSystemPrefix, isValidSystemNameFormat, makeSystemName, makeSystemName, makeSystemName, register, removeDataListener, setDataListenerMute, setPropertyChangesMuted, validateBadCharsInSystemNameFormat, validateIntegerSystemNameFormat, validateNmraAccessorySystemNameFormat, validateSystemNameFormat, validateSystemNameFormat, validateSystemNameFormatOnlyNumeric, validateSystemNamePrefix, validateTrimmedMin1NumberSystemNameFormat, validateTrimmedSystemNameFormat, validateUppercaseTrimmedSystemNameFormat, validSystemNameFormat
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface jmri.beans.SilenceablePropertyChangeProvider
setPropertyChangesSilenced
Methods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
Constructor Details
-
BlockManager
public BlockManager()
-
-
Method Details
-
dispose
Description copied from class:AbstractManager
Free resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected. -
getXMLOrder
Description copied from interface:Manager
Determine the order that types should be written when storing panel files. Uses one of the constants defined in this class.Yes, that's an overly-centralized methodology, but it works for now.
- Specified by:
getXMLOrder
in interfaceManager<Block>
- Returns:
- write order for this Manager; larger is later.
-
typeLetter
- Specified by:
typeLetter
in interfaceManager<Block>
- Returns:
- The type letter for a specific implementation
-
getNamedBeanClass
Description copied from interface:Manager
Get the class of NamedBean supported by this Manager. This should be the generic class used in the Manager's class declaration.- Specified by:
getNamedBeanClass
in interfaceManager<Block>
- Returns:
- the class supported by this Manager.
-
isSavedPathInfo
-
setSavedPathInfo
-
createNewBlock
@CheckForNull public Block createNewBlock(@Nonnull String systemName, @CheckForNull String userName)Create a new Block, only if it does not exist.- Parameters:
systemName
- the system nameuserName
- the user name- Returns:
- null if a Block with the same systemName or userName already exists, or if there is trouble creating a new Block
-
createNewBlock
Create a new Block using an automatically incrementing system name.- Parameters:
userName
- the user name for the new Block- Returns:
- null if a Block with the same systemName or userName already exists, or if there is trouble creating a new Block.
-
provideBlock
If the Block exists, return it, otherwise create a new one and return it. If the argument starts with the system prefix and type letter, usually "IB", then the argument is considered a system name, otherwise it's considered a user name and a system name is automatically created.- Parameters:
name
- the system name or the user name for the block- Returns:
- a new or existing Block
- Throws:
IllegalArgumentException
- if cannot create block or no name supplied; never returns null
-
getBlock
Get an existing Block. First looks up assuming that name is a User Name. If this fails looks up assuming that name is a System Name. If both fail, returns null.- Parameters:
name
- the name of an existing block- Returns:
- a Block or null if none found
-
getByDisplayName
-
setDefaultSpeed
- Parameters:
speed
- the speed- Throws:
IllegalArgumentException
- if provided speed is invalid
-
getDefaultSpeed
-
getBeanTypeHandled
Description copied from interface:Manager
Get the user-readable name of the type of NamedBean handled by this manager.For instance, in the code where we are dealing with just a bean and a message that needs to be passed to the user or in a log.
- Specified by:
getBeanTypeHandled
in interfaceManager<Block>
- Parameters:
plural
- true to return plural form of the type; false to return singular form- Returns:
- a string of the bean type that the manager handles, eg Turnout, Sensor etc
-
getBlocksOccupiedByRosterEntry
@CheckReturnValue @Nonnull public List<Block> getBlocksOccupiedByRosterEntry(@Nonnull BasicRosterEntry re)Get a list of blocks which the supplied roster entry appears to be occupying. A block is assumed to contain this roster entry if its value is the RosterEntry itself, or a string with the entry's id or dcc address.- Parameters:
re
- the roster entry- Returns:
- list of block system names
-
propertyChange
Listen for changes to the power state from any power managers in use in order to track how long it's been since power was applied to the layout. This information is used inBlock.goingActive()
when deciding whether to restore a block's last value. Also listen for additions/removals or PowerManagers- Specified by:
propertyChange
in interfacePropertyChangeListener
- Overrides:
propertyChange
in classAbstractManager<Block>
- Parameters:
e
- the change event
-
timeSinceLastLayoutPowerOn
Get the amount of time since the layout was last powered up, in milliseconds. If the layout has not been powered up as far as JMRI knows it returns a very long time indeed.- Returns:
- long int
-
provide
Description copied from interface:ProvidingManager
Get an existing instance via user name, then system name; if no matching instance is found, create a new NameBean from the system name.If the name is a valid system name, it will be used for the new NamedBean. Otherwise, the
Manager.makeSystemName(java.lang.String)
method will attempt to turn it into a valid system name which the manager will attempt to use. If that fails, an exception is thrown.This is similar to the specific methods found in certain type-specific managers:
TurnoutManager.provideTurnout(java.lang.String)
,SensorManager.provideSensor(java.lang.String)
, et al. Those might be more mnemonic; this one is more generic. Neither is preferred nor deprecated; use your choice.- Specified by:
provide
in interfaceProvidingManager<Block>
- Parameters:
name
- User name, system name, or address which can be promoted to system name- Returns:
- Never null
-