use of fish.payara.internal.notification.PayaraNotifierConfiguration in project Payara by payara.
the class NotificationService method initialize.
@PostConstruct
void initialize() {
// Get the config if it's not been injected
if (configuration == null) {
configuration = serviceLocator.getService(NotificationServiceConfiguration.class);
}
// Register an event listener
if (events != null) {
events.register(this);
}
// Is this service running on an instance?
final ServerEnvironment env = serviceLocator.getService(ServerEnvironment.class);
isInstance = env.isInstance();
// Find and register all notifier services
final List<ServiceHandle<PayaraNotifier>> notifierHandles = serviceLocator.getAllServiceHandles(PayaraNotifier.class);
for (ServiceHandle<PayaraNotifier> handle : notifierHandles) {
NotifierHandler handler;
final boolean isNotifierConfigurable = handle.getActiveDescriptor().getAdvertisedContracts().contains(PayaraConfiguredNotifier.class.getName());
if (isNotifierConfigurable) {
PayaraNotifierConfiguration notifierConfig = getOrCreateNotifierConfiguration(handle);
handler = new NotifierHandler(handle, notifierConfig);
} else {
handler = new NotifierHandler(handle);
}
notifiers.add(handler);
}
}
use of fish.payara.internal.notification.PayaraNotifierConfiguration in project Payara by payara.
the class GetNotificationConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext context) {
// Get the command report
final ActionReport report = context.getActionReport();
// Get the target configuration
final Config targetConfig = targetUtil.getConfig(target);
if (targetConfig == null) {
report.setMessage("No such config named: " + target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
final NotificationServiceConfiguration configuration = targetConfig.getExtensionByType(NotificationServiceConfiguration.class);
final String notificationServiceEnabled = configuration.getEnabled();
final List<ServiceHandle<PayaraNotifier>> notifierHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
if (notifierHandles.isEmpty()) {
report.setMessage("No notifiers defined");
report.setActionExitCode(ActionReport.ExitCode.WARNING);
return;
}
String[] headers = { "Notifier Name", "Enabled", "Notifier Enabled", "Notifier Noisy" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
Properties extraProps = new Properties();
for (ServiceHandle<PayaraNotifier> serviceHandle : notifierHandles) {
final Class<?> notifierClass = serviceHandle.getActiveDescriptor().getImplementationClass();
Object[] values = new Object[4];
values[0] = getNotifierName(serviceHandle.getActiveDescriptor());
values[1] = notificationServiceEnabled;
// Get the notifier config if applicable
PayaraNotifierConfiguration notifierConfig = null;
if (serviceHandle.getService() instanceof PayaraConfiguredNotifier) {
// Get the associated configuration
notifierConfig = configuration.getNotifierConfigurationByType(NotifierUtils.getConfigurationClass(notifierClass));
}
if (notifierConfig == null) {
values[2] = PayaraNotifierConfiguration.DEFAULT_ENABLED_VALUE;
values[3] = PayaraNotifierConfiguration.DEFAULT_NOISY_VALUE;
} else {
values[2] = notifierConfig.getEnabled();
values[3] = notifierConfig.getNoisy();
}
columnFormatter.addRow(values);
Map<String, Object> map = new HashMap<>(3);
map.put("enabled", values[1]);
map.put("notifierEnabled", values[2]);
map.put("noisy", values[3]);
if (notifierConfig != null && notifierConfig instanceof LogNotifierConfiguration) {
map.put("useSeparateLogFile", ((LogNotifierConfiguration) notifierConfig).getUseSeparateLogFile());
}
extraProps.put("getNotificationConfiguration" + notifierClass.getSimpleName(), map);
}
report.setMessage(columnFormatter.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setExtraProperties(extraProps);
}
use of fish.payara.internal.notification.PayaraNotifierConfiguration in project Payara by payara.
the class NotifierHandler method reconfigure.
protected void reconfigure() {
// Get the current configuration
PayaraNotifierConfiguration currentConfig = null;
if (config != null) {
currentConfig = PayaraConfiguredNotifier.class.cast(notifier).getConfiguration();
if (currentConfig == null) {
currentConfig = config;
}
}
final boolean enabled = config != null && valueOf(config.getEnabled());
final boolean wasEnabled = config != null && valueOf(currentConfig.getEnabled());
if (!enabled) {
if (wasEnabled) {
// If the notifier isn't enabled but was before
destroy();
}
} else {
if (wasEnabled) {
// If the notifier is enabled and was before
destroy();
bootstrap();
} else {
// If the notifier is enabled and wasn't before
bootstrap();
}
}
}
Aggregations