Search in sources :

Example 1 with TransportView

use of org.apache.synapse.transport.passthru.jmx.TransportView in project wso2-synapse by wso2.

the class PassThroughHttpSender method init.

public void init(ConfigurationContext configurationContext, TransportOutDescription transportOutDescription) throws AxisFault {
    log.info("Initializing Pass-through HTTP/S Sender...");
    this.configurationContext = configurationContext;
    namePrefix = transportOutDescription.getName().toUpperCase(Locale.US);
    scheme = getScheme();
    WorkerPool workerPool = null;
    Object obj = configurationContext.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
    if (obj != null) {
        workerPool = (WorkerPool) obj;
    }
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(false, scheme.getName());
    proxyConfig = new ProxyConfigBuilder().build(transportOutDescription);
    if (log.isDebugEnabled()) {
        log.debug(proxyConfig.logProxyConfig());
    }
    targetConfiguration = new TargetConfiguration(configurationContext, transportOutDescription, workerPool, metrics, proxyConfig.createProxyAuthenticator());
    targetConfiguration.build();
    PassThroughSenderManager.registerPassThroughHttpSender(this);
    configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, targetConfiguration.getWorkerPool());
    ClientConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportOutDescription, configurationContext);
    connFactory = connFactoryBuilder.createConnFactory(targetConfiguration.getHttpParams());
    try {
        String prefix = namePrefix + "-Sender I/O dispatcher";
        ioReactor = new DefaultConnectingIOReactor(targetConfiguration.getIOReactorConfig(), new NativeThreadFactory(new ThreadGroup(prefix + " Thread Group"), prefix));
        ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {

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

            public boolean handle(RuntimeException runtimeException) {
                log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
                return true;
            }
        });
    } catch (IOReactorException e) {
        handleException("Error starting " + namePrefix + " ConnectingIOReactor", e);
    }
    ConnectCallback connectCallback = new ConnectCallback();
    targetConnections = new TargetConnections(ioReactor, targetConfiguration, connectCallback);
    targetConfiguration.setConnections(targetConnections);
    TransportView view = new TransportView(null, this, metrics, targetConfiguration.getWorkerPool());
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-sender");
    // create the delivery agent to hand over messages
    deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections, proxyConfig);
    // we need to set the delivery agent
    connectCallback.setDeliveryAgent(deliveryAgent);
    interceptors = StreamInterceptorsLoader.getInterceptors();
    handler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration, interceptors);
    ioEventDispatch = new ClientIODispatch(handler, connFactory);
    // start the sender in a separate thread
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                ioReactor.execute(ioEventDispatch);
            } catch (Exception ex) {
                log.fatal("Exception encountered in the " + namePrefix + " Sender. " + "No more connections will be initiated by this transport", ex);
            }
            log.info(namePrefix + " Sender shutdown");
        }
    }, "PassThrough" + namePrefix + "Sender");
    t.start();
    state = BaseConstants.STARTED;
    log.info("Pass-through " + namePrefix + " Sender started...");
}
Also used : IOReactorExceptionHandler(org.apache.http.nio.reactor.IOReactorExceptionHandler) ProxyConfigBuilder(org.apache.synapse.transport.nhttp.config.ProxyConfigBuilder) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) ClientConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ClientConnFactoryBuilder) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) IOException(java.io.IOException) InvalidConfigurationException(org.apache.synapse.transport.exceptions.InvalidConfigurationException) XMLStreamException(javax.xml.stream.XMLStreamException) RemoteException(java.rmi.RemoteException) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException) DefaultConnectingIOReactor(org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor) IOReactorException(org.apache.http.nio.reactor.IOReactorException) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) TransportView(org.apache.synapse.transport.passthru.jmx.TransportView) TargetConnections(org.apache.synapse.transport.passthru.connections.TargetConnections)

Example 2 with TransportView

use of org.apache.synapse.transport.passthru.jmx.TransportView in project wso2-synapse by wso2.

the class PassThroughHttpListener method init.

public void init(ConfigurationContext cfgCtx, TransportInDescription transportInDescription) throws AxisFault {
    log.info("Initializing Pass-through HTTP/S Listener...");
    this.configurationContext = cfgCtx;
    pttInDescription = transportInDescription;
    namePrefix = transportInDescription.getName().toUpperCase(Locale.US);
    scheme = initScheme();
    int portOffset = Integer.parseInt(System.getProperty("portOffset", "0"));
    Parameter portParam = transportInDescription.getParameter("port");
    int port = Integer.parseInt(portParam.getValue().toString());
    operatingPort = port + portOffset;
    portParam.setValue(String.valueOf(operatingPort));
    portParam.getParameterElement().setText(String.valueOf(operatingPort));
    System.setProperty(transportInDescription.getName() + ".nio.port", String.valueOf(operatingPort));
    Object obj = cfgCtx.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
    WorkerPool workerPool = null;
    if (obj != null) {
        workerPool = (WorkerPool) obj;
    }
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, scheme.getName());
    sourceConfiguration = new SourceConfiguration(cfgCtx, transportInDescription, scheme, workerPool, metrics);
    sourceConfiguration.build();
    HttpHost host = new HttpHost(sourceConfiguration.getHostname(), sourceConfiguration.getPort(), sourceConfiguration.getScheme().getName());
    ServerConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportInDescription, host, cfgCtx);
    connFactory = connFactoryBuilder.build(sourceConfiguration.getHttpParams());
    interceptors = StreamInterceptorsLoader.getInterceptors();
    handler = new SourceHandler(sourceConfiguration, interceptors);
    passThroughListeningIOReactorManager = PassThroughListeningIOReactorManager.getInstance();
    // register to receive updates on services for lifetime management
    // cfgCtx.getAxisConfiguration().addObservers(axisObserver);
    String prefix = namePrefix + "-Listener I/O dispatcher";
    try {
        ioReactor = (DefaultListeningIOReactor) passThroughListeningIOReactorManager.initIOReactor(operatingPort, handler, new PassThroughSharedListenerConfiguration(new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix), connFactory, sourceConfiguration));
    } catch (IOReactorException e) {
        handleException("Error initiating " + namePrefix + " ListeningIOReactor", e);
    }
    Map<String, String> o = (Map<String, String>) cfgCtx.getProperty(PassThroughConstants.EPR_TO_SERVICE_NAME_MAP);
    if (o != null) {
        this.eprToServiceNameMap = o;
    } else {
        eprToServiceNameMap = new HashMap<String, String>();
        cfgCtx.setProperty(PassThroughConstants.EPR_TO_SERVICE_NAME_MAP, eprToServiceNameMap);
    }
    cfgCtx.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, sourceConfiguration.getWorkerPool());
    /* register to receive updates on services */
    serviceTracker = new AxisServiceTracker(cfgCtx.getAxisConfiguration(), new AxisServiceFilter() {

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

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

        public void serviceRemoved(AxisService service) {
            removeServiceFfromURIMap(service);
        }
    });
    TransportView view = new TransportView(this, null, metrics, sourceConfiguration.getWorkerPool());
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-receiver");
}
Also used : PassThroughSharedListenerConfiguration(org.apache.synapse.transport.passthru.core.PassThroughSharedListenerConfiguration) AxisServiceFilter(org.apache.axis2.transport.base.tracker.AxisServiceFilter) AxisServiceTrackerListener(org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) AxisService(org.apache.axis2.description.AxisService) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) IOReactorException(org.apache.http.nio.reactor.IOReactorException) AxisServiceTracker(org.apache.axis2.transport.base.tracker.AxisServiceTracker) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) HttpHost(org.apache.http.HttpHost) TransportView(org.apache.synapse.transport.passthru.jmx.TransportView) SourceConfiguration(org.apache.synapse.transport.passthru.config.SourceConfiguration) Parameter(org.apache.axis2.description.Parameter) Map(java.util.Map) HashMap(java.util.HashMap) ServerConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ServerConnFactoryBuilder)

Aggregations

NativeThreadFactory (org.apache.axis2.transport.base.threads.NativeThreadFactory)2 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)2 IOReactorException (org.apache.http.nio.reactor.IOReactorException)2 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)2 TransportView (org.apache.synapse.transport.passthru.jmx.TransportView)2 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 AxisService (org.apache.axis2.description.AxisService)1 Parameter (org.apache.axis2.description.Parameter)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 HttpException (org.apache.http.HttpException)1 HttpHost (org.apache.http.HttpHost)1 DefaultConnectingIOReactor (org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor)1 IOReactorExceptionHandler (org.apache.http.nio.reactor.IOReactorExceptionHandler)1 InvalidConfigurationException (org.apache.synapse.transport.exceptions.InvalidConfigurationException)1