Search in sources :

Example 1 with AxisServiceTrackerListener

use of org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener 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 AxisServiceTrackerListener

use of org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener 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

AxisServiceFilter (org.apache.axis2.transport.base.tracker.AxisServiceFilter)2 AxisServiceTracker (org.apache.axis2.transport.base.tracker.AxisServiceTracker)2 AxisServiceTrackerListener (org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AxisFault (org.apache.axis2.AxisFault)1 AxisService (org.apache.axis2.description.AxisService)1 Parameter (org.apache.axis2.description.Parameter)1 NativeThreadFactory (org.apache.axis2.transport.base.threads.NativeThreadFactory)1 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)1 HttpHost (org.apache.http.HttpHost)1 IOReactorException (org.apache.http.nio.reactor.IOReactorException)1 ServerConnFactoryBuilder (org.apache.synapse.transport.nhttp.config.ServerConnFactoryBuilder)1 SourceConfiguration (org.apache.synapse.transport.passthru.config.SourceConfiguration)1 PassThroughSharedListenerConfiguration (org.apache.synapse.transport.passthru.core.PassThroughSharedListenerConfiguration)1 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)1 TransportView (org.apache.synapse.transport.passthru.jmx.TransportView)1