use of fish.payara.service.example.config.ExampleServiceConfiguration in project Payara by payara.
the class GetExampleServiceMessageCommand method execute.
/**
* This method is called when the command is executed
* @param context
*/
@Override
public void execute(AdminCommandContext context) {
// obtain the correct configuration
Config configNode = targetUtil.getConfig(config);
ExampleServiceConfiguration serviceConfig = configNode.getExtensionByType(ExampleServiceConfiguration.class);
// add return message
context.getActionReport().setMessage("Example Service message is " + serviceConfig.getMessage());
}
use of fish.payara.service.example.config.ExampleServiceConfiguration in project Payara by payara.
the class ExampleConfigUpdateOnlyOnDAS method execute.
@Override
public void execute(AdminCommandContext context) {
// obtain the correct configuration
Config configVal = targetUtil.getConfig(target);
ExampleServiceConfiguration serviceConfig = configVal.getExtensionByType(ExampleServiceConfiguration.class);
if (serviceConfig != null) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<ExampleServiceConfiguration>() {
@Override
public Object run(ExampleServiceConfiguration config) {
config.setMessage(message);
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
// set failure
context.getActionReport().failure(Logger.getLogger(SetExampleServiceMessage.class.getName()), "Failed to update message", ex);
}
} else {
context.getActionReport().failure(Logger.getLogger(this.getClass().getCanonicalName()), "No configuration with name " + target);
}
}
use of fish.payara.service.example.config.ExampleServiceConfiguration in project Payara by payara.
the class SetExampleServiceMessage method execute.
@Override
public void execute(AdminCommandContext context) {
// obtain the correct configuration
Config configVal = targetUtil.getConfig(target);
ExampleServiceConfiguration serviceConfig = configVal.getExtensionByType(ExampleServiceConfiguration.class);
if (serviceConfig != null) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<ExampleServiceConfiguration>() {
@Override
public Object run(ExampleServiceConfiguration config) {
config.setMessage(message);
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
// set failure
context.getActionReport().failure(Logger.getLogger(SetExampleServiceMessage.class.getName()), "Failed to update message", ex);
}
}
// was targetted explicitly via the following code
if (server.isDas()) {
// you would need to do this if you now want to manipulate the service based on the command parameters
if (targetUtil.getConfig(target).isDas()) {
// this command was also targetted at the DAS
service.doSomethingDirectly("Set message command was targetted at the DAS");
// as below you can now directly manipulate the service as needed
}
} else {
// if you are not the DAS then impoicitly this command was targeted to this instance
service.doSomethingDirectly("Set config command targeted at the instance");
// you can now directly manipulate the service remember though
// if it is a config listener it has already been notified of the config change
// however if it is not a config listener you can manipulate the service now
}
}
Aggregations