Creating a transaction to update configuration data enables the data to be updated without the need to specify a dotted name in the set(1) subcommand. You can make the transaction available to system administrators in the following ways:
By adding an asadmin(1M) subcommand. If you are adding an asadmin subcommand, include the code for the transaction in the body of the subcommand's execute method. For more information, see Chapter 4, Extending the asadmin Utility.
By extending the Administration Console. For more information, see Chapter 3, Extending the Administration Console.
Any transaction that you create to modify configuration data must use a configuration change transaction to ensure that the change is atomic, consistent, isolated, and durable (ACID).
Set a dependency on the configuration object to update.
Define a method to invoke to perform the transaction.
Use the generic SimpleConfigCode interface to define the method that is to be invoked on a single configuration object, namely: SingleConfigCode<T extends ConfigBeanProxy>().
In the body of this method, implement the run method of the SingleConfigCode<T extends ConfigBeanProxy> interface.
In the body of the run method, invoke the setter methods that are defined for the attributes that you are setting.
These setter methods are defined in the interface that represents the element whose elements you are setting.
Invoke the static method org.jvnet.hk2.config.ConfigSupport.ConfigSupport.apply.
In the invocation, pass the following information as parameters to the method:
This example shows code in the execute method of an asadmin subcommand for updating the number-of-instances element of wombat-container-config element.
... import org.glassfish.api.Param; ... import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.config.Transactions; import org.jvnet.hk2.config.ConfigSupport; import org.jvnet.hk2.config.SingleConfigCode; import org.jvnet.hk2.config.TransactionFailure; ... @Param String instances; @Inject WombatContainerConfig config; public void execute(AdminCommandContext adminCommandContext) { try { ConfigSupport.apply(new SingleConfigCode<WombatContainerConfig>() { public Object run(WombatContainerConfig wombatContainerConfig) throws PropertyVetoException, TransactionFailure { wombatContainerConfig.setNumberOfInstances(instances); return null; } }, config); } catch(TransactionFailure e) { } } ...