use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class TransactionServiceConfigListener method postConstruct.
@Override
public void postConstruct() {
// Listen to monitoring level changes
Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
ts = c.getExtensionByType(TransactionService.class);
ModuleMonitoringLevels mml = c.getMonitoringService().getModuleMonitoringLevels();
((ObservableBean) ConfigSupport.getImpl(mml)).addListener(this);
}
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 (micro) {
return;
}
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 ParentConfigListenerTest method addHttpListenerTest.
@Test
public void addHttpListenerTest() throws TransactionFailure {
NetworkListenersContainer container = habitat.getService(NetworkListenersContainer.class);
ConfigSupport.apply(new SingleConfigCode<NetworkListeners>() {
public Object run(NetworkListeners param) throws TransactionFailure {
NetworkListener newListener = param.createChild(NetworkListener.class);
newListener.setName("Funky-Listener");
newListener.setPort("8078");
param.getNetworkListener().add(newListener);
return null;
}
}, container.httpService);
getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
assertTrue(container.received);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpService);
// let's check that my newly added listener is available in the habitat.
List<ServiceHandle<NetworkListener>> networkListeners = habitat.getAllServiceHandles(NetworkListener.class);
boolean found = false;
for (ServiceHandle<NetworkListener> nlSH : networkListeners) {
NetworkListener nl = (NetworkListener) nlSH.getService();
if (nl.getName().equals("Funky-Listener")) {
found = true;
}
}
Assert.assertTrue("Newly added listener not found", found);
// direct access.
NetworkListener nl = habitat.getService(NetworkListener.class, "Funky-Listener");
Assert.assertTrue("Direct access to newly added listener failed", nl != null);
bean.removeListener(container);
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class GrizzlyService method postConstruct.
/**
* The component has been injected with any dependency and
* will be placed into commission by the subsystem.
*/
@Override
public void postConstruct() {
events.register(this);
final NetworkConfig networkConfig = config.getNetworkConfig();
configListener = new DynamicConfigListener(config, LOGGER);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkConfig.getNetworkListeners());
bean.addListener(configListener);
bean = (ObservableBean) ConfigSupport.getImpl(config.getHttpService());
bean.addListener(configListener);
transactions.addListenerForType(SystemProperty.class, configListener);
configListener.setGrizzlyService(this);
try {
boolean isAtLeastOneProxyStarted = false;
futures = new ArrayList<>();
// Record how long it took for the listeners to start up
final long startTime = System.currentTimeMillis();
// Keep a list of successfully started listeners
List<NetworkListener> startedListeners = new ArrayList<>();
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (createNetworkProxy(listener) != null) {
isAtLeastOneProxyStarted = true;
startedListeners.add(listener);
}
}
if (isAtLeastOneProxyStarted) {
// Get the startup time
final long startupTime = System.currentTimeMillis() - startTime;
// Log the listeners which started.
String boundAddresses = Arrays.toString(startedListeners.stream().map(listener -> listener.getName() + ":" + getRealPort(listener)).collect(Collectors.toList()).toArray());
LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyStarted, new Object[] { Grizzly.getDotedVersion(), startupTime, boundAddresses });
registerContainerAdapters();
}
} catch (RuntimeException e) {
// So far postConstruct can not throw any other exception type
LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCantStart, e);
for (NetworkProxy proxy : proxies) {
try {
proxy.stop();
} catch (Exception proxyStopException) {
LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCloseException, new Object[] { proxy.getPort(), proxyStopException });
}
}
throw e;
}
registerMonitoringStatsProviders();
}
use of org.jvnet.hk2.config.ObservableBean in project Payara by payara.
the class WebContainer method createHost.
/**
* Creates a Host from a virtual-server config bean.
*
* @param vsBean The virtual-server configuration bean
* @param httpService The http-service element.
* @param securityService The security-service element
* @return
*/
public VirtualServer createHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean, HttpService httpService, SecurityService securityService) {
String virtualServerId = vsBean.getId();
String docroot = vsBean.getPropertyValue("docroot");
if (docroot == null) {
docroot = vsBean.getDocroot();
}
validateDocroot(docroot, virtualServerId, vsBean.getDefaultWebModule());
VirtualServer virtualServer = createHost(virtualServerId, vsBean, docroot, null);
// cache control
Property cacheProp = vsBean.getProperty("setCacheControl");
if (cacheProp != null) {
virtualServer.configureCacheControl(cacheProp.getValue());
}
PEAccessLogValve accessLogValve = virtualServer.getAccessLogValve();
boolean startAccessLog = accessLogValve.configure(virtualServerId, vsBean, httpService, domain, serviceLocator, webContainerFeatureFactory, globalAccessLogBufferSize, globalAccessLogWriteInterval, globalAccessLogPrefix);
if (startAccessLog && virtualServer.isAccessLoggingEnabled(globalAccessLoggingEnabled)) {
virtualServer.addValve((GlassFishValve) accessLogValve);
}
logger.log(FINEST, VIRTUAL_SERVER_CREATED, virtualServerId);
/*
* We must configure the Host with its associated port numbers and alias names before adding it as an engine child and
* thereby starting it, because a MapperListener, which is associated with an HTTP listener and receives notifications
* about Host registrations, relies on these Host properties in order to determine whether a new Host needs to be added
* to the HTTP listener's Mapper.
*/
configureHost(virtualServer, securityService);
virtualServer.setDomain(domain);
virtualServer.setServices(serviceLocator);
virtualServer.setClassLoaderHierarchy(classLoaderHierarchy);
// Add Host to Engine
engine.addChild(virtualServer);
ObservableBean virtualServerBean = (ObservableBean) ConfigSupport.getImpl(vsBean);
virtualServerBean.addListener(configListener);
return virtualServer;
}
Aggregations