use of org.jvnet.hk2.config.UnprocessedChangeEvents 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.UnprocessedChangeEvents in project Payara by payara.
the class WebConfigListener method changed.
/**
* Handles HttpService change events
* @param events the PropertyChangeEvent
*/
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
}
try {
if (tClass == HttpService.class) {
container.updateHttpService((HttpService) t);
} else if (tClass == NetworkListener.class) {
if (type == TYPE.ADD) {
container.addConnector((NetworkListener) t, httpService, true);
} else if (type == TYPE.REMOVE) {
container.deleteConnector((NetworkListener) t);
} else if (type == TYPE.CHANGE) {
container.updateConnector((NetworkListener) t, httpService);
}
} else if (tClass == VirtualServer.class) {
if (type == TYPE.ADD) {
container.createHost((VirtualServer) t, httpService, null);
container.loadDefaultWebModule((VirtualServer) t);
} else if (type == TYPE.REMOVE) {
container.deleteHost(httpService);
} else if (type == TYPE.CHANGE) {
container.updateHost((VirtualServer) t);
}
} else if (tClass == AccessLog.class) {
container.updateAccessLog(httpService);
} else if (tClass == ManagerProperties.class) {
return new NotProcessed("ManagerProperties requires restart");
} else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
// container.updateHttpService handles SingleSignOn valve configuration
container.updateHttpService(httpService);
} else if (tClass == NetworkListeners.class) {
// skip updates
} else if (tClass == Property.class) {
ConfigBeanProxy config = ((Property) t).getParent();
if (config instanceof HttpService) {
container.updateHttpService((HttpService) config);
} else if (config instanceof VirtualServer) {
container.updateHost((VirtualServer) config);
} else if (config instanceof NetworkListener) {
container.updateConnector((NetworkListener) config, httpService);
} else {
container.updateHttpService(httpService);
}
} else if (tClass == SystemProperty.class) {
if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
container.updateConnector(listener, httpService);
}
}
}
} else if (tClass == JavaConfig.class) {
JavaConfig jc = (JavaConfig) t;
final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
for (String jvmOption : jvmOptions) {
if (jvmOption.startsWith("-DjvmRoute=")) {
container.updateJvmRoute(httpService, jvmOption);
}
}
} else {
// Ignore other unrelated events
}
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
}
return null;
}
}, logger);
}
use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.
the class DynamicConfigListener method changed.
@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
}
if (tClass == NetworkListener.class && t instanceof NetworkListener) {
return processNetworkListener(type, (NetworkListener) t, events);
} else if (tClass == Http.class && t instanceof Http) {
return processProtocol(type, (Protocol) t.getParent(), events);
} else if (tClass == FileCache.class && t instanceof FileCache) {
return processProtocol(type, (Protocol) t.getParent().getParent(), null);
} else if (tClass == Ssl.class && t instanceof Ssl) {
/*
* Make sure the SSL parent is in fact a protocol. It could
* be a jmx-connector.
*/
final ConfigBeanProxy parent = t.getParent();
if (parent instanceof Protocol) {
return processProtocol(type, (Protocol) parent, null);
}
} else if (tClass == Protocol.class && t instanceof Protocol) {
return processProtocol(type, (Protocol) t, null);
} else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
NotProcessed notProcessed = null;
ThreadPool threadPool = (ThreadPool) t;
for (NetworkListener listener : threadPool.findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
// Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
MonitoringService ms = config.getMonitoringService();
String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
}
return notProcessed;
} else if (tClass == Transport.class && t instanceof Transport) {
NotProcessed notProcessed = null;
for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
return notProcessed;
} else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
return processVirtualServer(type, (VirtualServer) t);
} else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
NetworkConfig networkConfig = config.getNetworkConfig();
if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
}
}
}
return null;
}
return null;
}
}, logger);
}
use of org.jvnet.hk2.config.UnprocessedChangeEvents 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.UnprocessedChangeEvents 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);
}
Aggregations