Search in sources :

Example 1 with ObservableBean

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);
}
Also used : TransactionService(com.sun.enterprise.transaction.config.TransactionService) ModuleMonitoringLevels(com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels) Config(com.sun.enterprise.config.serverbeans.Config) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 2 with ObservableBean

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);
}
Also used : ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 3 with ObservableBean

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);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transactions(org.jvnet.hk2.config.Transactions) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 4 with ObservableBean

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();
}
Also used : Arrays(java.util.Arrays) RestrictTo(org.glassfish.api.event.RestrictTo) KernelLoggerInfo(org.glassfish.kernel.KernelLoggerInfo) Events(org.glassfish.api.event.Events) TimeoutException(java.util.concurrent.TimeoutException) RequestDispatcher(org.glassfish.api.container.RequestDispatcher) InetAddress(java.net.InetAddress) Protocol(org.glassfish.grizzly.config.dom.Protocol) Future(java.util.concurrent.Future) GrizzlyNetworkListenerRestartAdapter(org.glassfish.api.container.GrizzlyNetworkListenerRestartAdapter) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) Adapter(org.glassfish.api.container.Adapter) Map(java.util.Map) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Futures(org.glassfish.grizzly.utils.Futures) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Method(java.lang.reflect.Method) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Logger(java.util.logging.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Transactions(org.jvnet.hk2.config.Transactions) Entry(java.util.Map.Entry) HttpService(com.sun.enterprise.config.serverbeans.HttpService) MonitoringDataCollection(fish.payara.monitoring.collect.MonitoringDataCollection) Queue(java.util.Queue) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Result(com.sun.enterprise.util.Result) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) FutureImpl(org.glassfish.grizzly.impl.FutureImpl) ObservableBean(org.jvnet.hk2.config.ObservableBean) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Constants(org.glassfish.common.util.Constants) GrizzlyMonitoring(com.sun.enterprise.v3.services.impl.monitor.GrizzlyMonitoring) Rank(org.glassfish.hk2.api.Rank) EventTypes(org.glassfish.api.event.EventTypes) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) HttpProbe(org.glassfish.grizzly.http.HttpProbe) StringUtils(com.sun.enterprise.util.StringUtils) FutureProvider(org.glassfish.api.FutureProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Named(javax.inject.Named) EventListener(org.glassfish.api.event.EventListener) PreDestroy(org.glassfish.hk2.api.PreDestroy) RunLevel(org.glassfish.hk2.runlevel.RunLevel) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) Mapper(org.glassfish.grizzly.http.server.util.Mapper) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) IOException(java.io.IOException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) UnknownHostException(java.net.UnknownHostException) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Grizzly(org.glassfish.grizzly.Grizzly) PostConstruct(org.glassfish.hk2.api.PostConstruct) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) InvocationHandler(java.lang.reflect.InvocationHandler) Config(com.sun.enterprise.config.serverbeans.Config) Collections(java.util.Collections) CountStatistic(org.glassfish.external.statistics.CountStatistic) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with ObservableBean

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;
}
Also used : ObservableBean(org.jvnet.hk2.config.ObservableBean) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Aggregations

ObservableBean (org.jvnet.hk2.config.ObservableBean)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Test (org.junit.Test)6 Transactions (org.jvnet.hk2.config.Transactions)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)4 Config (com.sun.enterprise.config.serverbeans.Config)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 ManagedJobConfig (com.sun.enterprise.config.serverbeans.ManagedJobConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 PropertyVetoException (java.beans.PropertyVetoException)2 MalformedURLException (java.net.MalformedURLException)2 LifecycleException (org.apache.catalina.LifecycleException)2 HTMLActionReporter (com.sun.enterprise.admin.report.HTMLActionReporter)1 ModuleMonitoringLevels (com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels)1 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)1 TransactionService (com.sun.enterprise.transaction.config.TransactionService)1 Result (com.sun.enterprise.util.Result)1