[Minor] Code formatting

This commit is contained in:
Robert von Burg 2023-07-24 13:39:28 +02:00
parent cf9e7fb402
commit b1c5d05bbc
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 82 additions and 160 deletions

View File

@ -78,8 +78,7 @@ public abstract class PlcService implements PlcListener {
* Called to initialize this service, here one would read the model state of a given address using * Called to initialize this service, here one would read the model state of a given address using
* {@link #getAddressState(StrolchTransaction, String, String)} * {@link #getAddressState(StrolchTransaction, String, String)}
* *
* @param tx * @param tx the transaction giving access to the model
* the transaction giving access to the model
*/ */
public void start(StrolchTransaction tx) { public void start(StrolchTransaction tx) {
this.state = PlcServiceState.Started; this.state = PlcServiceState.Started;
@ -110,10 +109,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Register this service with the given resource and action * Register this service with the given resource and action
* *
* @param resource * @param resource the resource ID
* the resource ID * @param action the action
* @param action
* the action
*/ */
public void register(String resource, String action) { public void register(String resource, String action) {
this.plcHandler.register(resource, action, this); this.plcHandler.register(resource, action, this);
@ -123,10 +120,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Unregister this service with the given resource and action * Unregister this service with the given resource and action
* *
* @param resource * @param resource the resource ID
* the resource ID * @param action the action
* @param action
* the action
*/ */
public void unregister(String resource, String action) { public void unregister(String resource, String action) {
this.plcHandler.unregister(resource, action, this); this.plcHandler.unregister(resource, action, this);
@ -142,12 +137,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Returns the {@link Resource} of type #TYPE_PLC_ADDRESS for the given resource and action * Returns the {@link Resource} of type #TYPE_PLC_ADDRESS for the given resource and action
* *
* @param tx * @param tx the current TX
* the current TX * @param resource the resource
* @param resource * @param action the action
* the resource
* @param action
* the action
* *
* @return the {@link Resource} * @return the {@link Resource}
*/ */
@ -160,14 +152,10 @@ public abstract class PlcService implements PlcListener {
* Returns the value of a plc address by calling {@link #getPlcAddress(StrolchTransaction, String, String)} for the * Returns the value of a plc address by calling {@link #getPlcAddress(StrolchTransaction, String, String)} for the
* given resource and action * given resource and action
* *
* @param tx * @param tx the current TX
* the current TX * @param resource the resource
* @param resource * @param action the action
* the resource * @param <T> the type of value to return
* @param action
* the action
* @param <T>
* the type of value to return
* *
* @return the value of the given address * @return the value of the given address
*/ */
@ -179,12 +167,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Enables an operations log message to be seen by a user * Enables an operations log message to be seen by a user
* *
* @param addressKey * @param addressKey the address for which the message is enabled
* the address for which the message is enabled * @param bundle the resource bundle containing the message
* @param bundle * @param severity the severity of the message
* the resource bundle containing the message
* @param severity
* the severity of the message
*/ */
protected void enableMsg(PlcAddressKey addressKey, ResourceBundle bundle, LogSeverity severity) { protected void enableMsg(PlcAddressKey addressKey, ResourceBundle bundle, LogSeverity severity) {
sendMsg(logMessageFor(addressKey, bundle, severity, LogMessageState.Active)); sendMsg(logMessageFor(addressKey, bundle, severity, LogMessageState.Active));
@ -193,8 +178,7 @@ public abstract class PlcService implements PlcListener {
/** /**
* Disables an operations log message which was previously enabled * Disables an operations log message which was previously enabled
* *
* @param addressKey * @param addressKey the address for which the message was enabled
* the address for which the message was enabled
*/ */
protected void disableMsg(PlcAddressKey addressKey) { protected void disableMsg(PlcAddressKey addressKey) {
disableMsg(Locator.valueOf("Plc", this.plcHandler.getPlcId(), addressKey.resource, addressKey.action)); disableMsg(Locator.valueOf("Plc", this.plcHandler.getPlcId(), addressKey.resource, addressKey.action));
@ -203,12 +187,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Enables an operations log message to be seen by a user * Enables an operations log message to be seen by a user
* *
* @param i18nKey * @param i18nKey the key of the message in the resource bundle
* the key of the message in the resource bundle * @param bundle the resource bundle containing the message
* @param bundle * @param severity the severity of the message
* the resource bundle containing the message
* @param severity
* the severity of the message
*/ */
protected void enableMsg(String i18nKey, ResourceBundle bundle, LogSeverity severity) { protected void enableMsg(String i18nKey, ResourceBundle bundle, LogSeverity severity) {
sendMsg(logMessageFor(i18nKey, bundle, severity, LogMessageState.Active)); sendMsg(logMessageFor(i18nKey, bundle, severity, LogMessageState.Active));
@ -217,10 +198,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Disables an operations log message which was previously enabled * Disables an operations log message which was previously enabled
* *
* @param i18nKey * @param i18nKey the key of the message in the resource bundle for which the message was enabled
* the key of the message in the resource bundle for which the message was enabled * @param bundle the resource bundle containing the message
* @param bundle
* the resource bundle containing the message
*/ */
protected void disableMsg(String i18nKey, ResourceBundle bundle) { protected void disableMsg(String i18nKey, ResourceBundle bundle) {
disableMsg(Locator.valueOf("Plc", this.plcHandler.getPlcId(), bundle.getBaseBundleName(), i18nKey)); disableMsg(Locator.valueOf("Plc", this.plcHandler.getPlcId(), bundle.getBaseBundleName(), i18nKey));
@ -229,12 +208,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Sends a message created for the given properties to a remote listener * Sends a message created for the given properties to a remote listener
* *
* @param i18nKey * @param i18nKey the key of the message
* the key of the message * @param bundle the bundle containing the key
* @param bundle * @param severity the severity of the message
* the bundle containing the key
* @param severity
* the severity of the message
*/ */
protected void sendMsg(String i18nKey, ResourceBundle bundle, LogSeverity severity) { protected void sendMsg(String i18nKey, ResourceBundle bundle, LogSeverity severity) {
sendMsg(logMessageFor(i18nKey, bundle, severity)); sendMsg(logMessageFor(i18nKey, bundle, severity));
@ -243,12 +219,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Creates a {@link LogMessage} for the given fields * Creates a {@link LogMessage} for the given fields
* *
* @param addressKey * @param addressKey the address for the key
* the address for the key * @param bundle the bundle containing the message
* @param bundle * @param severity the severity of the message
* the bundle containing the message
* @param severity
* the severity of the message
* *
* @return the {@link LogMessage} instance * @return the {@link LogMessage} instance
*/ */
@ -259,14 +232,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Creates a {@link LogMessage} for the given fields * Creates a {@link LogMessage} for the given fields
* *
* @param addressKey * @param addressKey the address for the key
* the address for the key * @param bundle the bundle containing the message
* @param bundle * @param severity the severity of the message
* the bundle containing the message * @param state the state of the message
* @param severity
* the severity of the message
* @param state
* the state of the message
* *
* @return the {@link LogMessage} instance * @return the {@link LogMessage} instance
*/ */
@ -280,12 +249,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Creates a {@link LogMessage} for the given fields * Creates a {@link LogMessage} for the given fields
* *
* @param i18nKey * @param i18nKey the key of the message
* the key of the message * @param bundle the bundle containing the message
* @param bundle * @param severity the severity of the message
* the bundle containing the message
* @param severity
* the severity of the message
* *
* @return the {@link LogMessage} instance * @return the {@link LogMessage} instance
*/ */
@ -296,14 +262,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Creates a {@link LogMessage} for the given fields * Creates a {@link LogMessage} for the given fields
* *
* @param i18nKey * @param i18nKey the key of the message
* the key of the message * @param bundle the bundle containing the message
* @param bundle * @param severity the severity of the message
* the bundle containing the message * @param state the state of the message
* @param severity
* the severity of the message
* @param state
* the state of the message
* *
* @return the {@link LogMessage} instance * @return the {@link LogMessage} instance
*/ */
@ -317,14 +279,13 @@ public abstract class PlcService implements PlcListener {
/** /**
* Sends the given {@link LogMessage} to the remote listener * Sends the given {@link LogMessage} to the remote listener
* *
* @param logMessage * @param logMessage the message to send
* the message to send
*/ */
protected void sendMsg(LogMessage logMessage) { protected void sendMsg(LogMessage logMessage) {
switch (logMessage.getSeverity()) { switch (logMessage.getSeverity()) {
case Info, Notification -> logger.info(logMessage.toString()); case Info, Notification -> logger.info(logMessage.toString());
case Warning -> logger.warn(logMessage.toString()); case Warning -> logger.warn(logMessage.toString());
case Error, Exception -> logger.error(logMessage.toString()); case Error, Exception -> logger.error(logMessage.toString());
} }
this.plcHandler.sendMsg(logMessage); this.plcHandler.sendMsg(logMessage);
} }
@ -332,8 +293,7 @@ public abstract class PlcService implements PlcListener {
/** /**
* Disables a message with the given {@link Locator} * Disables a message with the given {@link Locator}
* *
* @param locator * @param locator the locator of the message
* the locator of the message
*/ */
protected void disableMsg(Locator locator) { protected void disableMsg(Locator locator) {
logger.info("Disabling message for locator " + locator); logger.info("Disabling message for locator " + locator);
@ -343,10 +303,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Causes the {@link PlcAddress} for the given resource and action to be sent as a telegram with its default value * Causes the {@link PlcAddress} for the given resource and action to be sent as a telegram with its default value
* *
* @param resource * @param resource the resource
* the resource * @param action the action
* @param action
* the action
*/ */
protected void send(String resource, String action) { protected void send(String resource, String action) {
this.plcHandler.send(resource, action); this.plcHandler.send(resource, action);
@ -355,12 +313,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Causes the {@link PlcAddress} for the given resource and action to be sent as a telegram with the given value * Causes the {@link PlcAddress} for the given resource and action to be sent as a telegram with the given value
* *
* @param resource * @param resource the resource
* the resource * @param action the action
* @param action * @param value the value to send with the {@link PlcAddress}
* the action
* @param value
* the value to send with the {@link PlcAddress}
*/ */
protected void send(String resource, String action, Object value) { protected void send(String resource, String action, Object value) {
this.plcHandler.send(resource, action, value); this.plcHandler.send(resource, action, value);
@ -369,12 +324,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Notifies listeners on the {@link PlcAddress} for the given resource and action, of the new value * Notifies listeners on the {@link PlcAddress} for the given resource and action, of the new value
* *
* @param resource * @param resource the resource
* the resource * @param action the action
* @param action * @param value the value to notify the listeners with
* the action
* @param value
* the value to notify the listeners with
*/ */
protected void notify(String resource, String action, Object value) { protected void notify(String resource, String action, Object value) {
this.plcHandler.notify(resource, action, value); this.plcHandler.notify(resource, action, value);
@ -383,8 +335,7 @@ public abstract class PlcService implements PlcListener {
/** /**
* Runs the given {@link PrivilegedRunnable} as the agent user * Runs the given {@link PrivilegedRunnable} as the agent user
* *
* @param runnable * @param runnable the runnable to run
* the runnable to run
*/ */
protected void run(PrivilegedRunnable runnable) throws Exception { protected void run(PrivilegedRunnable runnable) throws Exception {
this.container.getPrivilegeHandler().runAsAgent(runnable); this.container.getPrivilegeHandler().runAsAgent(runnable);
@ -393,10 +344,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Runs the given {@link PrivilegedRunnableWithResult} as the agent user, returning a value as the result * Runs the given {@link PrivilegedRunnableWithResult} as the agent user, returning a value as the result
* *
* @param runnable * @param runnable the runnable to run
* the runnable to run * @param <T> the type of object being returned in the runnable
* @param <T>
* the type of object being returned in the runnable
* *
* @return the result of the runnable * @return the result of the runnable
*/ */
@ -407,10 +356,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* Opens a new {@link StrolchTransaction} with the given {@link PrivilegeContext} * Opens a new {@link StrolchTransaction} with the given {@link PrivilegeContext}
* *
* @param ctx * @param ctx the {@link PrivilegeContext}
* the {@link PrivilegeContext} * @param readOnly true for the TX to be read only
* @param readOnly
* true for the TX to be read only
* *
* @return the new TX to be used in a try-with-resource block * @return the new TX to be used in a try-with-resource block
*/ */
@ -438,9 +385,8 @@ public abstract class PlcService implements PlcListener {
/** /**
* <p>Delays the execution of the given runnable by the given delay in milliseconds. Subsequent calls with the * <p>Delays the execution of the given runnable by the given delay in milliseconds. Subsequent calls with the
* given * given {@link PlcAddress} will cancel any previous calls with the same address, delaying the execution again by
* {@link PlcAddress} will cancel any previous calls with the same address, delaying the execution again by the * the given amount of time.</p>
* given amount of time.</p>
* *
* <p>This methods is used to handle hardware where the bits change often, before resting at a new state. E.g. a * <p>This methods is used to handle hardware where the bits change often, before resting at a new state. E.g. a
* light barrier where it might toggle between true and false a few times, before staying true when the light * light barrier where it might toggle between true and false a few times, before staying true when the light
@ -458,8 +404,7 @@ public abstract class PlcService implements PlcListener {
/** /**
* Submits the given runnable for asynchronous execution * Submits the given runnable for asynchronous execution
* *
* @param runnable * @param runnable the runnable to execute asynchronously
* the runnable to execute asynchronously
*/ */
protected void async(Runnable runnable) { protected void async(Runnable runnable) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
@ -474,12 +419,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Delay the execution of the given {@link Runnable} by the given delay * Delay the execution of the given {@link Runnable} by the given delay
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param delay the time to delay
* @param delay * @param delayUnit the unit of the time to delay
* the time to delay
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -496,12 +438,9 @@ public abstract class PlcService implements PlcListener {
/** /**
* Delay the execution of the given {@link PrivilegedRunnable} by the given delay * Delay the execution of the given {@link PrivilegedRunnable} by the given delay
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param delay the time to delay
* @param delay * @param delayUnit the unit of the time to delay
* the time to delay
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -518,14 +457,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Submit the given {@link Runnable} for repeated execution * Submit the given {@link Runnable} for repeated execution
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param initialDelay the initial delay
* @param initialDelay * @param period the delay between subsequent executions
* the initial delay * @param delayUnit the unit of the time to delay
* @param period
* the delay between subsequent executions
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -543,14 +478,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Submit the given {@link PrivilegedRunnable} for repeated execution * Submit the given {@link PrivilegedRunnable} for repeated execution
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param initialDelay the initial delay
* @param initialDelay * @param period the delay between subsequent executions
* the initial delay * @param delayUnit the unit of the time to delay
* @param period
* the delay between subsequent executions
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -568,14 +499,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Submit the given {@link Runnable} for repeated execution * Submit the given {@link Runnable} for repeated execution
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param initialDelay the initial delay
* @param initialDelay * @param period the delay between subsequent executions
* the initial delay * @param delayUnit the unit of the time to delay
* @param period
* the delay between subsequent executions
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -593,14 +520,10 @@ public abstract class PlcService implements PlcListener {
/** /**
* Submit the given {@link PrivilegedRunnable} for repeated execution * Submit the given {@link PrivilegedRunnable} for repeated execution
* *
* @param runnable * @param runnable the runnable to delay
* the runnable to delay * @param initialDelay the initial delay
* @param initialDelay * @param period the delay between subsequent executions
* the initial delay * @param delayUnit the unit of the time to delay
* @param period
* the delay between subsequent executions
* @param delayUnit
* the unit of the time to delay
* *
* @return a future to cancel the executor before execution * @return a future to cancel the executor before execution
*/ */
@ -618,8 +541,7 @@ public abstract class PlcService implements PlcListener {
/** /**
* Notifies the caller of one of the async, or schedule methods that the execution of a runnable failed * Notifies the caller of one of the async, or schedule methods that the execution of a runnable failed
* *
* @param e * @param e the exception which occurred
* the exception which occurred
*/ */
protected void handleFailedAsync(Exception e) { protected void handleFailedAsync(Exception e) {
logger.error("Failed to execute " + getClass().getSimpleName(), e); logger.error("Failed to execute " + getClass().getSimpleName(), e);