use of com.sun.enterprise.config.serverbeans.SystemProperty 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 com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class OSGIConsoleHandlers method getConsoleUrl.
@Handler(id = "getConsoleUrl", input = { @HandlerInput(name = "instanceName", type = String.class, required = true) }, output = { @HandlerOutput(name = "consoleUrl", type = String.class) })
public static void getConsoleUrl(HandlerContext handlerCtx) {
String instanceName = (String) handlerCtx.getInputValue("instanceName");
Domain domain = Globals.get(Domain.class);
Server server = domain.getServerNamed(instanceName);
String port = null;
SystemProperty httpPort = server.getSystemProperty(http_port);
if (httpPort != null) {
port = httpPort.getValue();
} else {
// if port is not set as system property, get it from config
Config cfg = server.getConfig();
SystemProperty httpConfigPort = cfg.getSystemProperty(http_port);
if (httpConfigPort != null) {
port = httpConfigPort.getValue();
}
}
if (port == null) {
throw new RuntimeException("Not able to get HTTP_LISTENER_PORT " + "for instance : " + instanceName);
}
Node node = domain.getNodeNamed(server.getNodeRef());
String host = node.getNodeHost();
String consoleUrl = "http://" + host + ":" + port + consolePath;
handlerCtx.setOutputValue("consoleUrl", consoleUrl);
}
use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class TypedListenerTest method multipleListeners.
@Test
public void multipleListeners() throws TransactionFailure {
final Domain domain = getHabitat().getService(Domain.class);
final ConfigListener configListener1 = new ConfigListener() {
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
listenersInvoked.incrementAndGet();
return null;
}
};
final ConfigListener configListener2 = new ConfigListener() {
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
listenersInvoked.incrementAndGet();
return null;
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addListenerForType(SystemProperty.class, configListener1);
transactions.addListenerForType(SystemProperty.class, configListener2);
assertTrue(domain != null);
// adding
ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
SystemProperty prop = domain.createChild(SystemProperty.class);
domain.getSystemProperty().add(prop);
prop.setName("Jerome");
prop.setValue("was here");
return prop;
}
}, domain);
transactions.waitForDrain();
assertTrue(listenersInvoked.intValue() == 2);
} finally {
assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener1));
assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener2));
}
}
use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class TypedListenerTest method addElementTest.
@Test
public void addElementTest() throws TransactionFailure {
final Domain domain = getHabitat().getService(Domain.class);
final ConfigListener configListener = new ConfigListener() {
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
events = Arrays.asList(propertyChangeEvents);
return null;
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addListenerForType(SystemProperty.class, configListener);
assertTrue(domain != null);
// adding
ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
SystemProperty prop = domain.createChild(SystemProperty.class);
domain.getSystemProperty().add(prop);
prop.setName("Jerome");
prop.setValue("was here");
return prop;
}
}, domain);
transactions.waitForDrain();
assertTrue(events != null);
logger.log(Level.FINE, "Number of events {0}", events.size());
assertTrue(events.size() == 3);
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
events = null;
// modification
for (SystemProperty prop : domain.getSystemProperty()) {
if (prop.getName().equals("Jerome")) {
ConfigSupport.apply(new SingleConfigCode<SystemProperty>() {
@Override
public Object run(SystemProperty param) throws PropertyVetoException, TransactionFailure {
param.setValue("was also here");
return null;
}
}, prop);
break;
}
}
assertTrue(events != null);
logger.log(Level.FINE, "Number of events {0}", events.size());
assertTrue(events.size() == 1);
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
events = null;
// removal
assertNotNull(ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
for (SystemProperty prop : domain.getSystemProperty()) {
if (prop.getName().equals("Jerome")) {
domain.getSystemProperty().remove(prop);
return prop;
}
}
return null;
}
}, domain));
transactions.waitForDrain();
assertTrue(events != null);
logger.log(Level.FINE, "Number of events {0}", events.size());
assertTrue(events.size() == 1);
for (PropertyChangeEvent event : events) {
logger.fine(event.toString());
}
} finally {
assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener));
}
}
use of com.sun.enterprise.config.serverbeans.SystemProperty in project Payara by payara.
the class PortBaseHelper method setSystemProperty.
private void setSystemProperty(String name, String value) throws TransactionFailure, PropertyVetoException {
SystemProperty sp = _server.getSystemProperty(name);
if (sp == null) {
SystemProperty newSP = _server.createChild(SystemProperty.class);
newSP.setName(name);
newSP.setValue(value);
_server.getSystemProperty().add(newSP);
} else {
// Don't change the system property if it already exists - leave the original port assignment
// sp.setName(name);
// sp.setValue(value);
}
}
Aggregations