use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class PortManager method changeSystemProperty.
private void changeSystemProperty(List<SystemProperty> sps, String name, String port) throws PropertyVetoException, TransactionFailure {
for (SystemProperty sp : sps) {
if (name.equals(sp.getName())) {
sp.setValue(port);
return;
}
}
// does not exist -- let's add one!
SystemProperty sp = newServer.createChild(SystemProperty.class);
sp.setName(name);
sp.setValue(port);
sps.add(sp);
}
use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class PortUtils method checkInternalConsistency.
/**
* Make sure all ports that are specified by the user make sense.
* @param server The new Server element
* @return null if all went OK. Otherwise return a String with the error message.
*/
static void checkInternalConsistency(Server server) throws TransactionFailure {
// Make sure all the system properties for ports have different numbers.
List<SystemProperty> sysProps = server.getSystemProperty();
Set<Integer> ports = new TreeSet<Integer>();
for (SystemProperty sp : sysProps) {
String name = sp.getName();
if (PORTSLIST.contains(name)) {
String val = sp.getValue();
try {
boolean wasAdded = ports.add(Integer.parseInt(val));
if (// TODO unit test
!wasAdded)
throw new TransactionFailure(Strings.get("PortUtils.duplicate_port", val, server.getName()));
} catch (TransactionFailure tf) {
// don't re-wrap the same Exception type!
throw tf;
} catch (Exception e) {
// TODO unit test
throw new TransactionFailure(Strings.get("PortUtils.non_int_port", val, server.getName()));
}
}
}
checkForLegalPorts(ports, server.getName());
}
use of com.sun.enterprise.config.serverbeans.SystemProperty 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 com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class CreateSystemProperties method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
String sysPropName = "";
try {
for (final Object key : properties.keySet()) {
final String propName = (String) key;
sysPropName = propName;
// value of an existing property
try {
TranslatedConfigView.doSubstitution.set(Boolean.FALSE);
if (spb.containsProperty(sysPropName) && spb.getSystemProperty(sysPropName).getValue().equals(properties.getProperty(propName))) {
continue;
}
} finally {
TranslatedConfigView.doSubstitution.set(Boolean.TRUE);
}
ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {
@Override
public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
// update existing system property
for (SystemProperty sysProperty : param.getSystemProperty()) {
if (sysProperty.getName().equals(propName)) {
Transaction t = Transaction.getTransaction(param);
sysProperty = t.enroll(sysProperty);
sysProperty.setValue(properties.getProperty(propName));
return sysProperty;
}
}
// create system-property
SystemProperty newSysProp = param.createChild(SystemProperty.class);
newSysProp.setName(propName);
newSysProp.setValue(properties.getProperty(propName));
param.getSystemProperty().add(newSysProp);
return newSysProp;
}
}, spb);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class CombinedJavaConfigSystemPropertyListener method changed.
/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
// ignore a REMOVE and an ADD of the same value
final UnprocessedChangeEvents unp = ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tc, T t) {
NotProcessed result = null;
if (tc == Profiler.class) {
result = new NotProcessed("Creation or changes to a profiler require restart");
} else if (tc == Property.class && t.getParent().getClass() == JavaConfig.class) {
result = new NotProcessed("Addition of properties to JavaConfig requires restart");
} else if (tc == JavaConfig.class && t instanceof JavaConfig) {
final JavaConfig njc = (JavaConfig) t;
logFine(type, njc);
// we must *always* check the jvm options, no way to know except by comparing,
// plus we should send an appropriate message back for each removed/added item
final List<String> curProps = new ArrayList<String>(njc.getJvmOptions());
final boolean jvmOptionsWereChanged = !oldProps.equals(curProps);
final List<String> reasons = handle(oldProps, curProps);
oldProps = curProps;
// something in the JavaConfig itself changed
// to do this well, we ought to keep a list of attributes, so we can make a good message
// saying exactly which attribute what changed
final Map<String, String> curAttrs = collectAttrs(njc);
reasons.addAll(handleAttrs(oldAttrs, curAttrs));
oldAttrs = curAttrs;
result = reasons.isEmpty() ? null : new NotProcessed(CombinedJavaConfigSystemPropertyListener.toString(reasons));
} else if (tc == SystemProperty.class && t instanceof SystemProperty) {
final SystemProperty sp = (SystemProperty) t;
// check to see if this system property is for this instance
ConfigBeanProxy proxy = sp.getParent();
ConfigView p = ConfigSupport.getImpl(proxy);
if (p == ConfigSupport.getImpl(server) || p == ConfigSupport.getImpl(config) || (cluster != null && p == ConfigSupport.getImpl(cluster)) || p == ConfigSupport.getImpl(domain)) {
// check to see if this system property is referenced by any of the options
String pname = sp.getName();
if (referencesProperty(pname, oldProps) || referencesProperty(pname, oldAttrs.values())) {
result = new NotProcessed("The system-property, " + pname + ", that is referenced by the Java configuration, was modified");
}
}
if (type == TYPE.ADD || type == TYPE.CHANGE) {
// create-system-properties
if (proxy instanceof Domain) {
return addToDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return addToConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return addToCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return addToServer(sp);
}
} else if (type == TYPE.REMOVE) {
if (proxy instanceof Domain) {
return removeFromDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return removeFromConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return removeFromCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return removeFromServer(sp);
}
}
} else {
// ignore other changes that are reported
}
return result;
}
}, logger);
return unp;
}
Aggregations