use of org.jvnet.hk2.config.UnprocessedChangeEvent in project Payara by payara.
the class AddLibraryCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = Logger.getLogger("org.glassfish.deployment.admin");
File libDir = env.getLibPath();
if (type.equals("ext")) {
libDir = new File(libDir, "ext");
} else if (type.equals("app")) {
libDir = new File(libDir, "applibs");
}
// library directory
try {
List<UnprocessedChangeEvent> unprocessed = new ArrayList<UnprocessedChangeEvent>();
StringBuilder msg = new StringBuilder();
ClassLoader commonLoader = commonClsLdr.getCommonClassLoader();
CurrentBeforeParentClassLoader loader = null;
if (commonLoader instanceof CurrentBeforeParentClassLoader) {
loader = (CurrentBeforeParentClassLoader) commonLoader;
}
for (File libraryFile : files) {
if (libraryFile.exists()) {
logger.log(Level.FINER, "ready to add new library");
File result = DeploymentCommandUtils.renameUploadedFileOrCopyInPlaceFile(libDir, libraryFile, logger, env);
// Applib is its own classloader which does not have a method to load files,
if (loader != null && !type.equals("applibs")) {
loader.addURL(result.toURI().toURL());
logger.log(Level.FINE, "added library to classloader", loader);
} else {
PropertyChangeEvent pe = new PropertyChangeEvent(libDir, "add-library", null, libraryFile);
UnprocessedChangeEvent uce = new UnprocessedChangeEvent(pe, "add-library");
unprocessed.add(uce);
logger.log(Level.FINER, "library not added to classloader");
}
} else {
msg.append(localStrings.getLocalString("lfnf", "Library file not found", libraryFile.getAbsolutePath()));
}
}
if (msg.length() > 0) {
logger.log(Level.WARNING, msg.toString());
report.setActionExitCode(ActionReport.ExitCode.WARNING);
report.setMessage(msg.toString());
}
if (!unprocessed.isEmpty()) {
// set the restart required flag
UnprocessedChangeEvents uces = new UnprocessedChangeEvents(unprocessed);
List<UnprocessedChangeEvents> ucesList = new ArrayList<UnprocessedChangeEvents>();
ucesList.add(uces);
ucl.unprocessedTransactedEvents(ucesList);
}
// touch the domain.xml so instances restart will synch
// over the libraries.
dxp.touch();
} catch (Exception e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
use of org.jvnet.hk2.config.UnprocessedChangeEvent in project Payara by payara.
the class DynamicReloadService method changed.
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
/*
* Deal with any changes to the DasConfig that might affect whether
* the reloader should be stopped or started or rescheduled with a
* different frequency. Those change are handled here, by this
* class.
*/
/* Record any events we tried to process but could not. */
List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
Boolean newEnabled = null;
Integer newPollIntervalInSeconds = null;
for (PropertyChangeEvent event : events) {
String propName = event.getPropertyName();
if (event.getSource() instanceof DasConfig) {
if (configPropertyNames.contains(propName) && (event.getOldValue().equals(event.getNewValue()))) {
logger.fine("[DynamicReload] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
continue;
}
if (propName.equals("dynamic-reload-enabled")) {
/*
* Either start the currently stopped reloader or stop the
* currently running one.
*/
newEnabled = Boolean.valueOf((String) event.getNewValue());
} else if (propName.equals("dynamic-reload-poll-interval-in-seconds")) {
try {
newPollIntervalInSeconds = new Integer((String) event.getNewValue());
} catch (NumberFormatException ex) {
String reason = ex.getClass().getName() + " " + ex.getLocalizedMessage();
logger.log(Level.WARNING, reason);
}
}
}
}
if (newEnabled != null) {
if (newEnabled) {
start(newPollIntervalInSeconds == null ? getPollIntervalInSeconds(activeDasConfig) : newPollIntervalInSeconds);
} else {
stop();
}
} else {
if (newPollIntervalInSeconds != null && isEnabled(activeDasConfig)) {
/*
* There is no change in whether the reloader should be running, only
* in how often it should run. If it is not running now don't
* start it. If it is running now, restart it to use the new
* polling interval.
*/
reschedule(newPollIntervalInSeconds);
}
}
return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
use of org.jvnet.hk2.config.UnprocessedChangeEvent in project Payara by payara.
the class SetNetworkListenerConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
NetworkListener listener = config.getNetworkConfig().getNetworkListener(listenerName);
if (!validate(actionReport)) {
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
@Override
public Object run(final NetworkListener listenerProxy) throws PropertyVetoException, TransactionFailure {
if (enabled != null) {
listenerProxy.setEnabled(enabled.toString());
}
if (address != null) {
listenerProxy.setAddress(address);
}
if (port != null && !ADMIN_LISTENER.equals(listenerName)) {
listenerProxy.setPort(port.toString());
}
if (portRange != null) {
listenerProxy.setPortRange(portRange);
}
if (protocol != null) {
listenerProxy.setProtocol(protocol);
}
if (threadPool != null) {
listenerProxy.setThreadPool(threadPool);
}
if (transport != null) {
listenerProxy.setTransport(transport);
}
if (jkEnabled != null) {
listenerProxy.setJkEnabled(jkEnabled.toString());
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return null;
}
}, listener);
String oldPort = listener.getPort();
if (port != null && ADMIN_LISTENER.equals(listenerName)) {
UnprocessedChangeEvent unprocessed = new UnprocessedChangeEvent(new PropertyChangeEvent(this, "port", oldPort, port), listener.getName() + " port changed from " + oldPort + " to " + port);
LOGGER.log(Level.INFO, MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port));
actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port.toString()));
List<UnprocessedChangeEvents> unprocessedList = new ArrayList<>();
unprocessedList.add(new UnprocessedChangeEvents(unprocessed));
ucl.unprocessedTransactedEvents(unprocessedList);
}
} catch (TransactionFailure e) {
LOGGER.log(Level.SEVERE, null, e);
actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
actionReport.setFailureCause(e);
return;
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.UnprocessedChangeEvent in project Payara by payara.
the class GetRestartRequiredCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ActionReport.MessagePart mp = report.getTopMessagePart();
Properties extraProperties = new Properties();
Map<String, Object> entity = new HashMap<String, Object>();
mp.setMessage(Boolean.toString(ucl.serverRequiresRestart()));
entity.put("restartRequired", Boolean.toString(ucl.serverRequiresRestart()));
List<String> unprocessedChanges = new ArrayList<String>();
for (UnprocessedChangeEvents es : ucl.getUnprocessedChangeEvents()) {
for (UnprocessedChangeEvent e : es.getUnprocessed()) {
if (why) {
mp.addChild().setMessage(e.getReason());
}
unprocessedChanges.add(e.getReason());
}
}
if (!unprocessedChanges.isEmpty()) {
entity.put("unprocessedChanges", unprocessedChanges);
}
extraProperties.put("entity", entity);
((ActionReport) report).setExtraProperties(extraProperties);
}
use of org.jvnet.hk2.config.UnprocessedChangeEvent in project Payara by payara.
the class LogManagerService method generateAttributeChangeEvent.
public void generateAttributeChangeEvent(String property, String propertyDetail, Map props) {
PropertyChangeEvent pce = new PropertyChangeEvent(this, property, propertyDetail, props.get(property));
UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log file attribute " + property + " changed."));
List<UnprocessedChangeEvents> b = new ArrayList();
b.add(ucel);
ucl.unprocessedTransactedEvents(b);
}
Aggregations