@Service public class ConfigSupport extends Object implements ConfigurationUtilities
Helper class to execute some code on configuration objects while taking care of the transaction boiler plate code.
Programmers that wish to apply some changes to configuration objects can use these convenience methods to reduce the complexity of handling transactions.
For instance, say a programmer need to change the HttpListener port from 8080 to 8989, it just needs to do :
... in his code somewhere ... HttpListener httpListener = domain.get... // If the programmer tries to modify the httpListener directly // it will get an exception httpListener.setPort("8989"); // will generate a PropertyVetoException // instead he needs to use a transaction and can use the helper services ConfigSupport.apply(new SingleConfigCode() { public Object run(HttpListener okToChange) throws PropertyException { okToChange.setPort("8989"); // good... httpListener.setPort("7878"); // not good, exceptions still raised... return null; }); // Note that after this code System.out.println("Port is " + httpListener.getPort()); // will display 8989 }
Modifier and Type | Class and Description |
---|---|
static class |
ConfigSupport.MultipleAttributeChanges |
static class |
ConfigSupport.SingleAttributeChange |
Modifier and Type | Field and Description |
---|---|
static int |
lockTimeOutInSeconds |
Constructor and Description |
---|
ConfigSupport() |
Modifier and Type | Method and Description |
---|---|
Object |
_apply(ConfigCode code,
ConfigBeanProxy... objects)
Executes some logic on some config beans protected by a transaction.
|
static void |
_deleteChild(ConfigBean parent,
WriteableView writeableParent,
ConfigBean child)
Unprotected child deletion, caller must start a transaction before calling this
method.
|
Object |
addChildWithAttributes(ConfigBeanProxy param,
ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
List<AttributeChanges> attributes,
TransactionCallBack<WriteableView> runnable)
Adds this child bean to the parent with the given attributes.
|
static Object |
apply(ConfigCode code,
ConfigBeanProxy... objects)
Executes some logic on some config beans protected by a transaction.
|
void |
apply(Map<ConfigBean,Map<String,String>> mapOfChanges) |
static <T extends ConfigBeanProxy> |
apply(SingleConfigCode<T> code,
T param)
Execute some logic on one config bean of type T protected by a transaction
|
static List<AttributeChanges> |
convertMapToAttributeChanges(Map<String,String> values) |
ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
List<AttributeChanges> attributes) |
static ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
List<AttributeChanges> attributes,
TransactionCallBack<WriteableView> runnable)
Creates a new child of the passed child and add it to the parent's live
list of elements.
|
static ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
Map<String,String> attributes)
Creates a new child of the passed child and add it to the parent's live
list of elements.
|
static ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
Map<String,String> attributes,
TransactionCallBack<WriteableView> runnable)
Creates a new child of the passed child and add it to the parent's live
list of elements.
|
static void |
deleteChild(ConfigBean parent,
ConfigBean child) |
String[] |
getAttributesNames(ConfigBean bean)
Returns the list of attributes names by the passed ConfigBean
|
String[] |
getElementsNames(ConfigBean bean)
Returns the list of elements names by the passed ConfigBean
|
static Class<? extends ConfigBeanProxy> |
getElementTypeByName(ConfigBeanProxy parent,
String elementName) |
static ConfigView |
getImpl(ConfigBeanProxy source)
Return the main implementation bean for a proxy.
|
static Class<?>[] |
getSubElementsTypes(ConfigBean bean)
Returns the list of sub-elements supported by a ConfigBean
|
<T extends ConfigBeanProxy> |
getWriteableView(T source)
Returns a writeable view of a configuration object
|
static <T extends ConfigBeanProxy> |
proxyType(T element)
Returns the type of configuration object this config proxy represents.
|
static <T extends ConfigBeanProxy> |
revealProxy(T proxy)
Unwrap HK2 proxy to ConfigBeanProxy.
|
static UnprocessedChangeEvents |
sortAndDispatch(PropertyChangeEvent[] events,
Changed target,
Logger logger)
sort events and dispatch the changes.
|
public static <T extends ConfigBeanProxy> Object apply(SingleConfigCode<T> code, T param) throws TransactionFailure
code
- code to executeparam
- config object participating in the transactionTransactionFailure
- when code did not run successfullypublic static Object apply(ConfigCode code, ConfigBeanProxy... objects) throws TransactionFailure
code
- code to executeobjects
- config beans participating to the transactionTransactionFailure
- when the code did run successfully due to a
transaction exceptionpublic Object _apply(ConfigCode code, ConfigBeanProxy... objects) throws TransactionFailure
code
- code to executeobjects
- config beans participating to the transactionTransactionFailure
- when the code did run successfully due to a
transaction exceptionpublic <T extends ConfigBeanProxy> T getWriteableView(T source) throws TransactionFailure
source
- the configured interface implementationTransactionFailure
- if the object cannot be enrolled (probably already enrolled in
another transaction).public static ConfigView getImpl(ConfigBeanProxy source)
source
- configuration interface proxypublic static <T extends ConfigBeanProxy> Class<T> proxyType(T element)
element
- is the configuration objectpublic static UnprocessedChangeEvents sortAndDispatch(PropertyChangeEvent[] events, Changed target, Logger logger)
events
- of events that resulted of a successful configuration transactiontarget
- the intended receiver of the changes notificationlogger
- to log any issues.public void apply(Map<ConfigBean,Map<String,String>> mapOfChanges) throws TransactionFailure
TransactionFailure
public static Class<?>[] getSubElementsTypes(ConfigBean bean) throws ClassNotFoundException
ClassNotFoundException
- for severe errors with the model associated
with the passed config bean.public String[] getAttributesNames(ConfigBean bean)
public String[] getElementsNames(ConfigBean bean)
public static ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, Map<String,String> attributes, TransactionCallBack<WriteableView> runnable) throws TransactionFailure
parent
- parent config bean to which the child will be added.childType
- child typeattributes
- map of key value pair to set on the newly created childTransactionFailure
- if the creation or attribute settings failedpublic static ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, List<AttributeChanges> attributes, TransactionCallBack<WriteableView> runnable) throws TransactionFailure
parent
- parent config bean to which the child will be added.childType
- child typeattributes
- list of attribute changes to apply to the newly created childrunnable
- code that will be invoked as part of the transaction to add
more attributes or elements to the newly create typeTransactionFailure
- if the creation or attribute settings failedpublic static ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, Map<String,String> attributes) throws TransactionFailure
parent
- parent config bean to which the child will be added.childType
- child typeattributes
- list of attributes changes to apply to the new created childTransactionFailure
- if the creation or attribute settings failedpublic ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, List<AttributeChanges> attributes) throws TransactionFailure
TransactionFailure
public static void deleteChild(ConfigBean parent, ConfigBean child) throws TransactionFailure
TransactionFailure
public static void _deleteChild(ConfigBean parent, WriteableView writeableParent, ConfigBean child) throws TransactionFailure
parent
- the parent elementwriteableParent
- the writeable view of the parent elementchild
- the child to deleteTransactionFailure
- if something goes wrong.public static List<AttributeChanges> convertMapToAttributeChanges(Map<String,String> values)
public static Class<? extends ConfigBeanProxy> getElementTypeByName(ConfigBeanProxy parent, String elementName) throws ClassNotFoundException
ClassNotFoundException
public static <T extends ConfigBeanProxy> T revealProxy(T proxy)
ConfigBeanProxy
- probably proxied by HK2.org.glassfish.hk2.api.MultiException
- If there was an error resolving the proxy.public Object addChildWithAttributes(ConfigBeanProxy param, ConfigBean parent, Class<? extends ConfigBeanProxy> childType, List<AttributeChanges> attributes, TransactionCallBack<WriteableView> runnable) throws TransactionFailure
ConfigurationUtilities
addChildWithAttributes
in interface ConfigurationUtilities
TransactionFailure
Copyright © 2021. All rights reserved.