Search in sources :

Example 1 with GenericGrizzlyListener

use of org.glassfish.grizzly.config.GenericGrizzlyListener in project Payara by payara.

the class VirtualServer method addProbes.

/**
 * Sets all the monitoring probes used in the virtual server
 * @param globalAccessLoggingEnabled
 * @see org.glassfish.grizzly.http.HttpProbe
 */
void addProbes(boolean globalAccessLoggingEnabled) {
    for (final NetworkListener listener : getGrizzlyNetworkListeners()) {
        try {
            final GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
            if (proxy != null) {
                GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) proxy.getUnderlyingListener();
                List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
                if (codecFilters == null || codecFilters.isEmpty()) {
                    // if it's AJP listener - it's ok if we didn't find HttpCodecFilter
                    if (grizzlyListener.isAjpEnabled()) {
                        continue;
                    }
                    _logger.log(Level.SEVERE, LogFacade.CODE_FILTERS_NULL, new Object[] { listener.getName(), codecFilters });
                } else {
                    for (HttpCodecFilter codecFilter : codecFilters) {
                        if (codecFilter.getMonitoringConfig().getProbes().length == 0) {
                            HttpProbeImpl httpProbe = new HttpProbeImpl(listener, isAccessLoggingEnabled(globalAccessLoggingEnabled));
                            codecFilter.getMonitoringConfig().addProbes(httpProbe);
                        }
                    }
                }
                grizzlyListener.getTransport().getConnectionMonitoringConfig().addProbes(new ConnectionProbe.Adapter() {

                    RequestProbeProvider requestProbeProvider = webContainer.getRequestProbeProvider();

                    @Override
                    public void onReadEvent(Connection connection, Buffer data, int size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataReceivedEvent(size, _id);
                        }
                    }

                    @Override
                    public void onWriteEvent(Connection connection, Buffer data, long size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataSentEvent(size, _id);
                        }
                    }
                });
            } else {
                // check the listener is enabled before spitting out the SEVERE log
                if (Boolean.parseBoolean(listener.getEnabled())) {
                    _logger.log(Level.SEVERE, LogFacade.PROXY_NULL, new Object[] { listener.getName() });
                }
            }
        } catch (Exception ex) {
            _logger.log(Level.SEVERE, LogFacade.ADD_HTTP_PROBES_ERROR, ex);
        }
    }
}
Also used : Buffer(org.glassfish.grizzly.Buffer) GrizzlyProxy(com.sun.enterprise.v3.services.impl.GrizzlyProxy) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Connection(org.glassfish.grizzly.Connection) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) ConfigException(org.glassfish.embeddable.web.ConfigException) IOException(java.io.IOException) GlassFishException(org.glassfish.embeddable.GlassFishException) ConnectionProbe(org.glassfish.grizzly.ConnectionProbe) RequestProbeProvider(org.glassfish.web.admin.monitor.RequestProbeProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with GenericGrizzlyListener

use of org.glassfish.grizzly.config.GenericGrizzlyListener in project Payara by payara.

the class VirtualServer method getHttpProbeImpl.

private List<HttpProbeImpl> getHttpProbeImpl() {
    List<HttpProbeImpl> httpProbes = new ArrayList<>();
    for (final NetworkListener listener : getGrizzlyNetworkListeners()) {
        final GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
        if (proxy != null) {
            GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) proxy.getUnderlyingListener();
            List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
            if (codecFilters != null && !codecFilters.isEmpty()) {
                for (HttpCodecFilter codecFilter : codecFilters) {
                    HttpProbe[] probes = codecFilter.getMonitoringConfig().getProbes();
                    if (probes != null) {
                        for (HttpProbe probe : probes) {
                            if (probe instanceof HttpProbeImpl) {
                                httpProbes.add((HttpProbeImpl) probe);
                            }
                        }
                    }
                }
            }
        }
    }
    return httpProbes;
}
Also used : GrizzlyProxy(com.sun.enterprise.v3.services.impl.GrizzlyProxy) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) HttpProbe(org.glassfish.grizzly.http.HttpProbe) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 3 with GenericGrizzlyListener

use of org.glassfish.grizzly.config.GenericGrizzlyListener in project Payara by payara.

the class GrizzlyService method restartNetworkListener.

/**
 * Restart {@link NetworkListener}.
 *
 * @param networkListener {@link NetworkListener}
 * @param timeout restart timeout, if timeout value is negative - then no timeout will be applied.
 * @param timeUnit restart timeout unit
 *
 * @throws TimeoutException thrown if timeout had expired before server succeeded to restart
 * @throws IOException
 */
public void restartNetworkListener(NetworkListener networkListener, long timeout, TimeUnit timeUnit) throws IOException, TimeoutException {
    // Restart GrizzlyProxy on the address/port
    // Address/port/id could have been changed - so try to find
    // corresponding proxy both ways
    NetworkProxy proxy = lookupNetworkProxy(networkListener);
    Map<Class<? extends HttpCodecFilter>, List<HttpProbe>> filterToProbeMapping = new HashMap<>();
    if (proxy == null) {
        proxy = getNetworkProxy(networkListener.getName());
    }
    if (proxy != null) {
        if (proxy instanceof GrizzlyProxy) {
            GrizzlyProxy grizzlyProxy = (GrizzlyProxy) proxy;
            GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) grizzlyProxy.getUnderlyingListener();
            List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
            if (codecFilters != null && !codecFilters.isEmpty()) {
                for (HttpCodecFilter codecFilter : codecFilters) {
                    HttpProbe[] probes = codecFilter.getMonitoringConfig().getProbes();
                    if (probes != null) {
                        List<HttpProbe> probesForType = filterToProbeMapping.get(codecFilter.getClass());
                        if (probesForType == null) {
                            probesForType = new ArrayList<>(4);
                            filterToProbeMapping.put(codecFilter.getClass(), probesForType);
                        }
                        Collections.addAll(probesForType, probes);
                    }
                }
            }
        }
        removeNetworkProxy(proxy);
    }
    final Future future = createNetworkProxy(networkListener);
    if (future == null) {
        LOGGER.log(Level.FINE, "Skipping proxy registration for the listener {0}", networkListener.getName());
        return;
    }
    try {
        if (timeout <= 0) {
            future.get();
        } else {
            future.get(timeout, timeUnit);
        }
        NetworkProxy newNetworkProxy = getNetworkProxy(networkListener.getName());
        if (newNetworkProxy instanceof GrizzlyProxy) {
            GrizzlyProxy grizzlyProxy = (GrizzlyProxy) newNetworkProxy;
            GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) grizzlyProxy.getUnderlyingListener();
            if (!filterToProbeMapping.isEmpty()) {
                for (Class<? extends HttpCodecFilter> aClass : filterToProbeMapping.keySet()) {
                    List<? extends HttpCodecFilter> filters = grizzlyListener.getFilters(aClass);
                    if (filters != null && !filters.isEmpty()) {
                        if (filters.size() != 1) {
                            throw new IllegalStateException();
                        }
                        final List<HttpProbe> probes = filterToProbeMapping.get(aClass);
                        filters.get(0).getMonitoringConfig().addProbes(probes.toArray(new HttpProbe[probes.size()]));
                    }
                }
            }
        }
    } catch (ExecutionException e) {
        throw new IOException(e.getCause());
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    registerContainerAdapters();
}
Also used : GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IOException(java.io.IOException) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) Future(java.util.concurrent.Future) List(java.util.List) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) HttpProbe(org.glassfish.grizzly.http.HttpProbe)

Aggregations

GenericGrizzlyListener (org.glassfish.grizzly.config.GenericGrizzlyListener)3 HttpCodecFilter (org.glassfish.grizzly.http.HttpCodecFilter)3 GrizzlyProxy (com.sun.enterprise.v3.services.impl.GrizzlyProxy)2 IOException (java.io.IOException)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 HttpProbe (org.glassfish.grizzly.http.HttpProbe)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 ConfigException (org.glassfish.embeddable.web.ConfigException)1 Buffer (org.glassfish.grizzly.Buffer)1 Connection (org.glassfish.grizzly.Connection)1 ConnectionProbe (org.glassfish.grizzly.ConnectionProbe)1 RequestProbeProvider (org.glassfish.web.admin.monitor.RequestProbeProvider)1