use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class JobCleanUpService method scheduleCleanUp.
/**
* This will schedule a cleanup of expired jobs based on configurable values
*/
private void scheduleCleanUp() {
if (managedJobConfig == null) {
managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
bean.addListener(this);
}
logger.fine(KernelLoggerInfo.schedulingCleanup);
// default values to 20 minutes for delayBetweenRuns and initialDelay
long delayBetweenRuns = 1200000;
long initialDelay = 1200000;
delayBetweenRuns = jobManagerService.convert(managedJobConfig.getPollInterval());
initialDelay = jobManagerService.convert(managedJobConfig.getInitialDelay());
ScheduledFuture<?> cleanupFuture = scheduler.scheduleAtFixedRate(new JobCleanUpTask(), initialDelay, delayBetweenRuns, TimeUnit.MILLISECONDS);
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class WebContainerStarter method postConstruct.
/**
* Scans the domain.xml to see if it specifies any configuration
* that can be handled only by the web container, and if so, starts
* the web container
*/
public void postConstruct() {
domainProvider.get();
Config serverConfig = serverConfigProvider.get();
boolean isStartNeeded = false;
if (serverConfig != null) {
if (isStartNeeded(serverConfig.getHttpService())) {
isStartNeeded = true;
}
if (!isStartNeeded && isStartNeeded(serverConfig.getNetworkConfig())) {
isStartNeeded = true;
}
}
if (isStartNeeded) {
startWebContainer();
} else {
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
bean.addListener(this);
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
bean.addListener(this);
}
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class WebContainer method createHttpListener.
protected WebConnector createHttpListener(NetworkListener listener, HttpService httpService, Mapper mapper) {
if (!Boolean.valueOf(listener.getEnabled())) {
return null;
}
int port = 8080;
WebConnector connector;
checkHostnameUniqueness(listener.getName(), httpService);
try {
port = Integer.parseInt(listener.getPort());
} catch (NumberFormatException nfe) {
String msg = rb.getString(LogFacade.HTTP_LISTENER_INVALID_PORT);
msg = MessageFormat.format(msg, listener.getPort(), listener.getName());
throw new IllegalArgumentException(msg);
}
if (mapper == null) {
for (Mapper m : habitat.<Mapper>getAllServices(Mapper.class)) {
if (m.getPort() == port && m instanceof ContextMapper) {
ContextMapper cm = (ContextMapper) m;
if (listener.getName().equals(cm.getId())) {
mapper = m;
break;
}
}
}
}
String defaultVS = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
if (!defaultVS.equals(org.glassfish.api.web.Constants.ADMIN_VS)) {
// Before we start a WebConnector, let's makes sure there is
// not another Container already listening on that port
DataChunk host = DataChunk.newInstance();
char[] c = defaultVS.toCharArray();
host.setChars(c, 0, c.length);
DataChunk mb = DataChunk.newInstance();
mb.setChars(new char[] { '/' }, 0, 1);
MappingData md = new MappingData();
try {
mapper.map(host, mb, md);
} catch (Exception e) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "", e);
}
}
if (md.context != null && md.context instanceof ContextRootInfo) {
ContextRootInfo r = (ContextRootInfo) md.context;
if (!(r.getHttpHandler() instanceof ContainerMapper)) {
new BindException("Port " + port + " is already used by Container: " + r.getHttpHandler() + " and will not get started.").printStackTrace();
return null;
}
}
}
/*
* Create Connector. Connector is SSL-enabled if
* 'security-enabled' attribute in <http-listener>
* element is set to TRUE.
*/
boolean isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
if (isSecure && defaultRedirectPort == -1) {
defaultRedirectPort = port;
}
String address = listener.getAddress();
if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
address = null;
/*
* Setting 'address' to NULL will cause Tomcat to pass a
* NULL InetAddress argument to the java.net.ServerSocket
* constructor, meaning that the server socket will accept
* connections on any/all local addresses.
*/
}
connector = (WebConnector) _embedded.createConnector(address, port, isSecure);
connector.setMapper(mapper);
connector.setJvmRoute(engine.getJvmRoute());
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, LogFacade.HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
}
connector.setDefaultHost(listener.findHttpProtocol().getHttp().getDefaultVirtualServer());
connector.setName(listener.getName());
connector.setInstanceName(instanceName);
connector.configure(listener, isSecure, httpService);
_embedded.addConnector(connector);
connectorMap.put(listener.getName(), connector);
// If we already know the redirect port, then set it now
// This situation will occurs when dynamic reconfiguration occurs
String redirectPort = listener.findHttpProtocol().getHttp().getRedirectPort();
if (redirectPort != null) {
connector.setRedirectPort(Integer.parseInt(redirectPort));
} else if (defaultRedirectPort != -1) {
connector.setRedirectPort(defaultRedirectPort);
}
ObservableBean httpListenerBean = (ObservableBean) ConfigSupport.getImpl(listener);
httpListenerBean.addListener(configListener);
return connector;
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class WebContainer method postConstruct.
@Override
public void postConstruct() {
final ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
mapperLock.writeLock().lock();
try {
createProbeProviders();
injectionMgr = habitat.getService(InjectionManager.class);
invocationMgr = habitat.getService(InvocationManager.class);
tldProviders = habitat.getAllServices(TldProvider.class);
createStatsProviders();
setJspFactory();
_appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
_modulesRoot = instance.getApplicationRepositoryPath();
// START S1AS 6178005
appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
// END S1AS 6178005
// TODO: ParserUtils should become a @Service and it should initialize itself.
// TODO: there should be only one EntityResolver for both DigesterFactory
// and ParserUtils
File root = _serverContext.getInstallRoot();
File libRoot = new File(root, "lib");
File schemas = new File(libRoot, "schemas");
File dtds = new File(libRoot, "dtds");
try {
ParserUtils.setSchemaResourcePrefix(schemas.toURI().toURL().toString());
ParserUtils.setDtdResourcePrefix(dtds.toURI().toURL().toString());
ParserUtils.setEntityResolver(habitat.<EntityResolver>getService(EntityResolver.class, "web"));
} catch (MalformedURLException e) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_SET_SCHEMAS_DTDS_LOCATION, e);
}
instanceName = _serverContext.getInstanceName();
webContainerFeatureFactory = getWebContainerFeatureFactory();
configureDynamicReloadingSettings();
setDebugLevel();
String maxDepth = null;
org.glassfish.web.config.serverbeans.WebContainer configWC = serverConfig.getExtensionByType(org.glassfish.web.config.serverbeans.WebContainer.class);
if (configWC != null)
maxDepth = configWC.getPropertyValue(DISPATCHER_MAX_DEPTH);
if (maxDepth != null) {
int depth = -1;
try {
depth = Integer.parseInt(maxDepth);
} catch (NumberFormatException e) {
}
if (depth > 0) {
Request.setMaxDispatchDepth(depth);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.MAX_DISPATCH_DEPTH_SET, maxDepth);
}
}
}
File currentLogFile = loggingRuntime.getCurrentLogFile();
if (currentLogFile != null) {
logServiceFile = currentLogFile.getAbsolutePath();
}
Level level = Logger.getLogger("org.apache.catalina.level").getLevel();
if (level != null) {
logLevel = level.getName();
}
_embedded = habitat.getService(EmbeddedWebContainer.class);
_embedded.setWebContainer(this);
_embedded.setLogServiceFile(logServiceFile);
_embedded.setLogLevel(logLevel);
_embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
_embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
_embedded.setCatalinaHome(instance.getDomainRoot().getAbsolutePath());
_embedded.setCatalinaBase(instance.getDomainRoot().getAbsolutePath());
_embedded.setUseNaming(false);
if (_debug > 1)
_embedded.setDebug(_debug);
_embedded.setLogger(new IASLogger(logger));
engine = _embedded.createEngine();
engine.setParentClassLoader(EmbeddedWebContainer.class.getClassLoader());
engine.setService(_embedded);
_embedded.addEngine(engine);
((StandardEngine) engine).setDomain(_serverContext.getDefaultDomainName());
engine.setName(_serverContext.getDefaultDomainName());
/*
* Set the server info.
* By default, the server info is taken from Version#getVersion.
* However, customers may override it via the product.name system
* property.
* Some customers prefer not to disclose the server info
* for security reasons, in which case they would set the value of the
* product.name system property to the empty string. In this case,
* the server name will not be publicly disclosed via the "Server"
* HTTP response header (which will be suppressed) or any container
* generated error pages. However, it will still appear in the
* server logs (see IT 6900).
*/
String serverInfo = System.getProperty("product.name");
if (serverInfo == null) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(Version.getVersion());
} else if (serverInfo.isEmpty()) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(serverInfo);
} else {
ServerInfo.setServerInfo(serverInfo);
ServerInfo.setPublicServerInfo(serverInfo);
}
initInstanceSessionProperties();
configListener = addAndGetWebConfigListener();
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
bean.addListener(configListener);
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
bean.addListener(configListener);
if (serverConfig.getAvailabilityService() != null) {
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getAvailabilityService());
bean.addListener(configListener);
}
transactions.addListenerForType(SystemProperty.class, configListener);
configListener.setNetworkConfig(serverConfig.getNetworkConfig());
// embedded mode does not have manager-propertie in domain.xml
if (configListener.managerProperties != null) {
ObservableBean managerBean = (ObservableBean) ConfigSupport.getImpl(configListener.managerProperties);
managerBean.addListener(configListener);
}
if (serverConfig.getJavaConfig() != null) {
((ObservableBean) ConfigSupport.getImpl(serverConfig.getJavaConfig())).addListener(configListener);
}
configListener.setContainer(this);
configListener.setLogger(logger);
events.register(this);
grizzlyService.addMapperUpdateListener(configListener);
HttpService httpService = serverConfig.getHttpService();
NetworkConfig networkConfig = serverConfig.getNetworkConfig();
if (networkConfig != null) {
// continue;
securityService = serverConfig.getSecurityService();
// Configure HTTP listeners
NetworkListeners networkListeners = networkConfig.getNetworkListeners();
if (networkListeners != null) {
List<NetworkListener> listeners = networkListeners.getNetworkListener();
for (NetworkListener listener : listeners) {
createHttpListener(listener, httpService);
}
}
setDefaultRedirectPort(defaultRedirectPort);
// Configure virtual servers
createHosts(httpService, securityService);
}
loadSystemDefaultWebModules();
// _lifecycle.fireLifecycleEvent(START_EVENT, null);
_started = true;
/*
* Start the embedded container.
* Make sure to set the thread's context classloader to the
* classloader of this class (see IT 8866 for details)
*/
ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
/*
* Trigger a call to sun.awt.AppContext.getAppContext().
* This will pin the classloader of this class in memory
* and fix a memory leak affecting instances of WebappClassLoader
* that was caused by a JRE implementation change in 1.6.0_15
* onwards. See IT 11110
*/
ImageIO.getCacheDirectory();
_embedded.start();
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.UNABLE_TO_START_WEB_CONTAINER, le);
return;
} finally {
// Restore original context classloader
Thread.currentThread().setContextClassLoader(current);
}
} finally {
mapperLock.writeLock().unlock();
}
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class ConfigAttributeSetTest method simpleAttributeSetTest.
@Test
public void simpleAttributeSetTest() {
CommandRunnerImpl runner = habitat.getService(CommandRunnerImpl.class);
assertNotNull(runner);
// let's find our target
NetworkListener listener = null;
NetworkListeners service = habitat.getService(NetworkListeners.class);
for (NetworkListener l : service.getNetworkListener()) {
if ("http-listener-1".equals(l.getName())) {
listener = l;
break;
}
}
assertNotNull(listener);
// Let's register a listener
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
bean.addListener(this);
// parameters to the command
ParameterMap parameters = new ParameterMap();
parameters.set("value", "8090");
parameters.set("DEFAULT", "configs.config.server-config.http-service.http-listener.http-listener-1.port");
// execute the set command.
runner.getCommandInvocation("set", new HTMLActionReporter(), adminSubject()).parameters(parameters).execute();
// check the result.
String port = listener.getPort();
assertEquals(port, "8090");
// ensure events are delivered.
habitat.<Transactions>getService(Transactions.class).waitForDrain();
// finally
bean.removeListener(this);
// check we recevied the event
assertNotNull(event);
assertEquals("8080", event.getOldValue());
assertEquals("8090", event.getNewValue());
assertEquals("port", event.getPropertyName());
}
Aggregations