Search in sources :

Example 1 with TransportMBeanSupport

use of org.apache.axis2.transport.base.TransportMBeanSupport in project wso2-axis2-transports by wso2.

the class AbstractTransportListener method init.

/**
 * Initialize the generic transport. Sets up the transport and the thread pool to be used
 * for message processing. Also creates an AxisObserver that gets notified of service
 * life cycle events for the transport to act on
 * @param cfgCtx the axis configuration context
 * @param transportIn the transport-in description
 * @throws AxisFault on error
 */
public void init(ConfigurationContext cfgCtx, TransportInDescription transportIn) throws AxisFault {
    this.cfgCtx = cfgCtx;
    this.transportIn = transportIn;
    this.transportOut = cfgCtx.getAxisConfiguration().getTransportOut(getTransportName());
    this.config = TransportConfiguration.getConfiguration(getTransportName());
    if (useAxis2ThreadPool) {
        // this.workerPool = cfgCtx.getThreadPool(); not yet implemented
        throw new AxisFault("Unsupported thread pool for task execution - Axis2 thread pool");
    } else {
        if (this.workerPool == null) {
            // FIXME <-- workaround for AXIS2-4552
            this.workerPool = WorkerPoolFactory.getWorkerPool(config.getServerCoreThreads(), config.getServerMaxThreads(), config.getServerKeepalive(), config.getServerQueueLen(), getTransportName() + "Server Worker thread group", getTransportName() + "-Worker");
        }
    }
    // register to receive updates on services for lifetime management
    serviceTracker = new AxisServiceTracker(cfgCtx.getAxisConfiguration(), new AxisServiceFilter() {

        public boolean matches(AxisService service) {
            return // these are "private" services
            !service.getName().startsWith("__") && BaseUtils.isUsingTransport(service, getTransportName());
        }
    }, new AxisServiceTrackerListener() {

        public void serviceAdded(AxisService service) {
            internalStartListeningForService(service);
        }

        public void serviceRemoved(AxisService service) {
            internalStopListeningForService(service);
        }
    });
    // register with JMX
    if (mbeanSupport == null) {
        // FIXME <-- workaround for AXIS2-4552
        mbeanSupport = new TransportMBeanSupport(this, getTransportName());
        mbeanSupport.register();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisServiceTracker(org.apache.axis2.transport.base.tracker.AxisServiceTracker) AxisServiceFilter(org.apache.axis2.transport.base.tracker.AxisServiceFilter) AxisServiceTrackerListener(org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)

Example 2 with TransportMBeanSupport

use of org.apache.axis2.transport.base.TransportMBeanSupport in project wso2-synapse by wso2.

the class HttpCoreNIOSender method init.

/**
 * Initialize the transport sender, and execute reactor in new separate thread
 * @param cfgCtx the Axis2 configuration context
 * @param transportOut the description of the http/s transport from Axis2 configuration
 * @throws AxisFault thrown on an error
 */
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    this.configurationContext = cfgCtx;
    cfg = NHttpConfiguration.getInstance();
    params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_SENDER, 60000)).setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)).setParameter(CoreProtocolPNames.USER_AGENT, "Synapse-HttpComponents-NIO");
    // .setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,
    // cfg.getStringValue(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,HTTP.DEFAULT_PROTOCOL_CHARSET)); //TODO:This does not works with HTTPCore 4.3
    name = transportOut.getName().toUpperCase(Locale.US) + " Sender";
    ClientConnFactoryBuilder contextBuilder = initConnFactoryBuilder(transportOut, cfgCtx);
    connFactory = contextBuilder.createConnFactory(params);
    connpool = new ConnectionPool();
    proxyConfig = new ProxyConfigBuilder().build(transportOut);
    if (log.isDebugEnabled()) {
        log.debug(proxyConfig.logProxyConfig());
    }
    Parameter param = transportOut.getParameter("warnOnHTTP500");
    if (param != null) {
        String[] warnOnHttp500 = ((String) param.getValue()).split("\\|");
        cfgCtx.setNonReplicableProperty("warnOnHTTP500", warnOnHttp500);
    }
    IOReactorConfig ioReactorConfig = new IOReactorConfig();
    ioReactorConfig.setIoThreadCount(NHttpConfiguration.getInstance().getClientIOWorkers());
    ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000));
    ioReactorConfig.setConnectTimeout(cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000));
    ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1);
    if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) {
        ioReactorConfig.setInterestOpQueued(true);
    }
    try {
        String prefix = name + " I/O dispatcher";
        ioReactor = new DefaultConnectingIOReactor(ioReactorConfig, new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix));
        ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {

            public boolean handle(IOException ioException) {
                log.warn("System may be unstable: IOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
                return true;
            }

            public boolean handle(RuntimeException runtimeException) {
                log.warn("System may be unstable: IOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
                return true;
            }
        });
    } catch (IOException e) {
        log.error("Error starting the IOReactor", e);
        throw new AxisFault(e.getMessage(), e);
    }
    metrics = new NhttpMetricsCollector(false, transportOut.getName());
    handler = new ClientHandler(connpool, connFactory, proxyConfig, cfgCtx, params, metrics);
    iodispatch = new ClientIODispatch(handler, connFactory);
    final IOEventDispatch ioEventDispatch = iodispatch;
    // start the Sender in a new seperate thread
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                ioReactor.execute(ioEventDispatch);
            } catch (InterruptedIOException ex) {
                log.fatal("Reactor Interrupted");
            } catch (IOException e) {
                log.fatal("Encountered an I/O error: " + e.getMessage(), e);
            }
            log.info(name + " Shutdown");
        }
    }, "HttpCoreNIOSender");
    t.start();
    log.info(name + " starting");
    // register with JMX
    mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportOut.getName());
    mbeanSupport.register();
    state = BaseConstants.STARTED;
}
Also used : IOReactorExceptionHandler(org.apache.http.nio.reactor.IOReactorExceptionHandler) AxisFault(org.apache.axis2.AxisFault) InterruptedIOException(java.io.InterruptedIOException) ProxyConfigBuilder(org.apache.synapse.transport.nhttp.config.ProxyConfigBuilder) ClientConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ClientConnFactoryBuilder) NhttpMetricsCollector(org.apache.synapse.transport.nhttp.util.NhttpMetricsCollector) TransportMBeanSupport(org.apache.axis2.transport.base.TransportMBeanSupport) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) IOReactorConfig(org.apache.http.impl.nio.reactor.IOReactorConfig) DefaultConnectingIOReactor(org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor) Parameter(org.apache.axis2.description.Parameter) IOEventDispatch(org.apache.http.nio.reactor.IOEventDispatch) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 3 with TransportMBeanSupport

use of org.apache.axis2.transport.base.TransportMBeanSupport in project wso2-synapse by wso2.

the class HttpCoreNIOListener method init.

/**
 * Initialize the transport listener, and execute reactor in new separate thread
 * @param "cfgCtx" the Axis2 configuration context
 * @param transportIn the description of the http/s transport from Axis2 configuration
 * @throws AxisFault on error
 */
public void init(ConfigurationContext ctx, TransportInDescription transportIn) throws AxisFault {
    cfgCtx = ctx;
    Map<String, String> o = (Map<String, String>) cfgCtx.getProperty(NhttpConstants.EPR_TO_SERVICE_NAME_MAP);
    if (o != null) {
        this.eprToServiceNameMap = o;
    } else {
        eprToServiceNameMap = new HashMap<String, String>();
        cfgCtx.setProperty(NhttpConstants.EPR_TO_SERVICE_NAME_MAP, eprToServiceNameMap);
    }
    NHttpConfiguration cfg = NHttpConfiguration.getInstance();
    // Initialize connection factory
    params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000)).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Synapse-HttpComponents-NIO");
    // .setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,
    // cfg.getStringValue(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, HTTP.DEFAULT_PROTOCOL_CHARSET)); //TODO:This does not works with HTTPCore 4.3
    name = transportIn.getName().toUpperCase(Locale.US) + " Listener";
    scheme = initScheme();
    // Setup listener context
    listenerContext = new ListenerContextBuilder(transportIn).parse().build();
    System.setProperty(transportIn.getName() + ".nio.port", String.valueOf(listenerContext.getPort()));
    // Setup connection factory
    HttpHost host = new HttpHost(listenerContext.getHostname(), listenerContext.getPort(), scheme.getName());
    connFactory = initConnFactoryBuilder(transportIn, host, ctx).build(params);
    // configure the IO reactor on the specified port
    try {
        String prefix = name + " I/O dispatcher";
        IOReactorConfig ioReactorConfig = new IOReactorConfig();
        ioReactorConfig.setIoThreadCount(cfg.getServerIOWorkers());
        ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000));
        ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1);
        if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) {
            ioReactorConfig.setInterestOpQueued(true);
        }
        ioReactorConfig.setSoReuseAddress(cfg.getBooleanValue(CoreConnectionPNames.SO_REUSEADDR, false));
        ioReactor = new DefaultListeningIOReactor(ioReactorConfig, new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix));
        ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {

            public boolean handle(IOException ioException) {
                log.warn("System may be unstable: IOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
                return true;
            }

            public boolean handle(RuntimeException runtimeException) {
                log.warn("System may be unstable: IOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
                return true;
            }
        });
    } catch (IOException e) {
        handleException("Error creating IOReactor", e);
    }
    metrics = new NhttpMetricsCollector(true, transportIn.getName());
    handler = new ServerHandler(cfgCtx, scheme, listenerContext, metrics);
    iodispatch = new ServerIODispatch(handler, connFactory);
    Parameter param = transportIn.getParameter(NhttpConstants.WSDL_EPR_PREFIX);
    if (param != null) {
        serviceEPRPrefix = getServiceEPRPrefix(cfgCtx, (String) param.getValue());
        customEPRPrefix = (String) param.getValue();
        EPRPrefixCheck = false;
    } else {
        serviceEPRPrefix = getServiceEPRPrefix(cfgCtx, listenerContext.getHostname(), listenerContext.getPort());
        customEPRPrefix = scheme.getName() + "://" + listenerContext.getHostname() + ":" + (listenerContext.getPort() == scheme.getDefaultPort() ? "" : listenerContext.getPort()) + "/";
    }
    // register to receive updates on services for lifetime management
    cfgCtx.getAxisConfiguration().addObservers(axisObserver);
    // register with JMX
    mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportIn.getName());
    mbeanSupport.register();
}
Also used : IOReactorExceptionHandler(org.apache.http.nio.reactor.IOReactorExceptionHandler) NhttpMetricsCollector(org.apache.synapse.transport.nhttp.util.NhttpMetricsCollector) TransportMBeanSupport(org.apache.axis2.transport.base.TransportMBeanSupport) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) IOReactorConfig(org.apache.http.impl.nio.reactor.IOReactorConfig) HttpHost(org.apache.http.HttpHost) Parameter(org.apache.axis2.description.Parameter) BasicHttpParams(org.apache.http.params.BasicHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 AxisFault (org.apache.axis2.AxisFault)2 Parameter (org.apache.axis2.description.Parameter)2 TransportMBeanSupport (org.apache.axis2.transport.base.TransportMBeanSupport)2 NativeThreadFactory (org.apache.axis2.transport.base.threads.NativeThreadFactory)2 IOReactorConfig (org.apache.http.impl.nio.reactor.IOReactorConfig)2 IOReactorExceptionHandler (org.apache.http.nio.reactor.IOReactorExceptionHandler)2 BasicHttpParams (org.apache.http.params.BasicHttpParams)2 NhttpMetricsCollector (org.apache.synapse.transport.nhttp.util.NhttpMetricsCollector)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AxisServiceFilter (org.apache.axis2.transport.base.tracker.AxisServiceFilter)1 AxisServiceTracker (org.apache.axis2.transport.base.tracker.AxisServiceTracker)1 AxisServiceTrackerListener (org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)1 HttpHost (org.apache.http.HttpHost)1 DefaultConnectingIOReactor (org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor)1 DefaultListeningIOReactor (org.apache.http.impl.nio.reactor.DefaultListeningIOReactor)1 IOEventDispatch (org.apache.http.nio.reactor.IOEventDispatch)1 ClientConnFactoryBuilder (org.apache.synapse.transport.nhttp.config.ClientConnFactoryBuilder)1