Class BlockManager
- java.lang.Object
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.beans.VetoableChangeListener,java.util.EventListener,PropertyChangeFirer,PropertyChangeProvider,SilenceablePropertyChangeProvider,VetoableChangeFirer,VetoableChangeProvider,InstanceManagerAutoDefault,Manager<Block>,ProvidingManager<Block>
public class BlockManager extends AbstractManager<Block> implements ProvidingManager<Block>, InstanceManagerAutoDefault
Basic implementation of a BlockManager.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 static java.lang.StringPROPERTY_DEFAULT_BLOCK_SPEED_CHANGEString constant for property Default Block Speed ChangeShutDownTaskshutDownTask-
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedProperties
-
Fields inherited from class jmri.beans.VetoableChangeSupport
vetoableChangeSupport
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, LOGIXNG_GLOBAL_VARIABLES, LOGIXNG_MODULES, LOGIXNG_STRING_ACTIONS, LOGIXNG_STRING_EXPRESSIONS, LOGIXNG_TABLES, LOGIXNGS, LOGIXS, MEMORIES, METERFRAMES, METERS, OBLOCKS, PANELFILES, PROPERTY_BEANS, PROPERTY_CAN_DELETE, PROPERTY_DISPLAY_LIST_NAME, PROPERTY_DO_DELETE, PROPERTY_DO_NOT_DELETE, PROPERTY_LENGTH, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
-
-
Constructor Summary
Constructors Constructor Description BlockManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BlockcreateNewBlock(java.lang.String userName)Create a new Block using an automatically incrementing system name.BlockcreateNewBlock(java.lang.String systemName, java.lang.String userName)Create a new Block, only if it does not exist.voiddispose()Free resources when no longer used.java.lang.StringgetBeanTypeHandled(boolean plural)Get the user-readable name of the type of NamedBean handled by this manager.BlockgetBlock(java.lang.String name)Get an existing Block.java.util.List<Block>getBlocksOccupiedByRosterEntry(BasicRosterEntry re)Get a list of blocks which the supplied roster entry appears to be occupying.BlockgetByDisplayName(java.lang.String key)java.lang.StringgetDefaultSpeed()java.lang.Class<Block>getNamedBeanClass()Get the class of NamedBean supported by this Manager.intgetXMLOrder()Determine the order that types should be written when storing panel files.booleanisSavedPathInfo()voidpropertyChange(java.beans.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.Blockprovide(java.lang.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.BlockprovideBlock(java.lang.String name)If the Block exists, return it, otherwise create a new one and return it.voidsetDefaultSpeed(java.lang.String speed)Set the Default Block Speed.voidsetSavedPathInfo(boolean save)longtimeSinceLastLayoutPowerOn()Get the amount of time since the layout was last powered up, in milliseconds.chartypeLetter()-
Methods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, createSystemName, deleteBean, deregister, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getBySystemName, getByUserName, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getOuterBean, 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, getBeanTypeHandled, getBySystemName, getByUserName, getEntryToolTip, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getSubSystemNamePrefix, getSystemNamePrefix, getSystemPrefix, isValidSystemNameFormat, makeSystemName, makeSystemName, makeSystemName, register, removeDataListener, setDataListenerMute, 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 Detail
-
shutDownTask
public final ShutDownTask shutDownTask
-
PROPERTY_DEFAULT_BLOCK_SPEED_CHANGE
public static final java.lang.String PROPERTY_DEFAULT_BLOCK_SPEED_CHANGE
String constant for property Default Block Speed Change- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BlockManager
public BlockManager()
-
-
Method Detail
-
dispose
public void dispose()
Description copied from class:AbstractManagerFree resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected.
-
getXMLOrder
@CheckReturnValue public int getXMLOrder()
Description copied from interface:ManagerDetermine 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:
getXMLOrderin interfaceManager<Block>- Returns:
- write order for this Manager; larger is later.
-
typeLetter
@CheckReturnValue public char typeLetter()
- Specified by:
typeLetterin interfaceManager<Block>- Returns:
- The type letter for a specific implementation
-
getNamedBeanClass
public java.lang.Class<Block> getNamedBeanClass()
Description copied from interface:ManagerGet the class of NamedBean supported by this Manager. This should be the generic class used in the Manager's class declaration.- Specified by:
getNamedBeanClassin interfaceManager<Block>- Returns:
- the class supported by this Manager.
-
isSavedPathInfo
@CheckReturnValue public boolean isSavedPathInfo()
-
setSavedPathInfo
public void setSavedPathInfo(boolean save)
-
createNewBlock
@CheckForNull public Block createNewBlock(@Nonnull java.lang.String systemName, @CheckForNull java.lang.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
@CheckForNull public Block createNewBlock(@CheckForNull java.lang.String userName)
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
@Nonnull public Block provideBlock(@Nonnull java.lang.String name)
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:
java.lang.IllegalArgumentException- if cannot create block or no name supplied; never returns null
-
getBlock
@CheckReturnValue @CheckForNull public Block getBlock(@Nonnull java.lang.String name)
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
@CheckReturnValue @CheckForNull public Block getByDisplayName(@Nonnull java.lang.String key)
-
setDefaultSpeed
public void setDefaultSpeed(@Nonnull java.lang.String speed)
Set the Default Block Speed.- Parameters:
speed- the speed- Throws:
java.lang.IllegalArgumentException- if provided speed is invalid
-
getDefaultSpeed
@CheckReturnValue @Nonnull public java.lang.String getDefaultSpeed()
-
getBeanTypeHandled
@CheckReturnValue @Nonnull public java.lang.String getBeanTypeHandled(boolean plural)
Description copied from interface:ManagerGet 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:
getBeanTypeHandledin 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 java.util.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
public void propertyChange(java.beans.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. 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:
propertyChangein interfacejava.beans.PropertyChangeListener- Overrides:
propertyChangein classAbstractManager<Block>- Parameters:
e- the change event
-
timeSinceLastLayoutPowerOn
public long 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
@Nonnull public Block provide(@Nonnull java.lang.String name)
Description copied from interface:ProvidingManagerGet 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:
providein interfaceProvidingManager<Block>- Parameters:
name- User name, system name, or address which can be promoted to system name- Returns:
- Never null
-
-