|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jvnet.hk2.config.ConfigSupport
@Service public class ConfigSupport
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 }
Nested Class Summary | |
---|---|
static class |
ConfigSupport.AttributeChanges
|
static class |
ConfigSupport.MultipleAttributeChanges
|
static class |
ConfigSupport.SingleAttributeChange
|
static interface |
ConfigSupport.TransactionCallBack<T>
|
Field Summary | |
---|---|
static int |
lockTimeOutInSeconds
|
Constructor Summary | |
---|---|
ConfigSupport()
|
Method Summary | ||
---|---|---|
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. |
|
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
|
apply(SingleConfigCode<T> code,
T param)
Execute some logic on one config bean of type T protected by a transaction |
|
ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
List<ConfigSupport.AttributeChanges> attributes)
|
|
static ConfigBean |
createAndSet(ConfigBean parent,
Class<? extends ConfigBeanProxy> childType,
List<ConfigSupport.AttributeChanges> attributes,
ConfigSupport.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,
ConfigSupport.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 |
|
|
getWriteableView(T source)
Returns a writeable view of a configuration object |
|
static
|
proxyType(T element)
Returns the type of configuration object this config proxy represents. |
|
static UnprocessedChangeEvents |
sortAndDispatch(PropertyChangeEvent[] events,
Changed target,
Logger logger)
sort events and dispatch the changes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int lockTimeOutInSeconds
Constructor Detail |
---|
public ConfigSupport()
Method Detail |
---|
public static <T extends ConfigBeanProxy> Object apply(SingleConfigCode<T> code, T param) throws TransactionFailure
code
- code to executeparam
- config object participating in the transaction
TransactionFailure
- when code did not run successfullypublic static Object apply(ConfigCode code, ConfigBeanProxy... objects) throws TransactionFailure
code
- code to executeobjects
- config beans participating to the transaction
TransactionFailure
- 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 transaction
TransactionFailure
- when the code did run successfully due to a
transaction exceptionpublic <T extends ConfigBeanProxy> T getWriteableView(T source) throws TransactionFailure
source
- the configured interface implementation
TransactionFailure
- if the object cannot be enrolled (probably already enrolled in
another transaction).public static ConfigView getImpl(ConfigBeanProxy source)
source
- configuration interface proxy
public static <T extends ConfigBeanProxy> Class<T> proxyType(T element)
element
- is the configuration object
public 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, ConfigSupport.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 child
TransactionFailure
- if the creation or attribute settings failedpublic static ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, List<ConfigSupport.AttributeChanges> attributes, ConfigSupport.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 type
TransactionFailure
- 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 child
TransactionFailure
- if the creation or attribute settings failedpublic ConfigBean createAndSet(ConfigBean parent, Class<? extends ConfigBeanProxy> childType, List<ConfigSupport.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 delete
TransactionFailure
- if something goes wrong.public static Class<? extends ConfigBeanProxy> getElementTypeByName(ConfigBeanProxy parent, String elementName) throws ClassNotFoundException
ClassNotFoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |