Search in sources :

Example 6 with WorkerPool

use of org.apache.axis2.transport.base.threads.WorkerPool 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...");
    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());
    TransportView view = new TransportView(null, this, metrics, null);
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-sender");
    proxyConfig = new ProxyConfigBuilder().build(transportOutDescription);
    log.info(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);
    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);
    // create the delivery agent to hand over messages
    deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections, proxyConfig);
    // we need to set the delivery agent
    connectCallback.setDeliveryAgent(deliveryAgent);
    handler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    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) 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 7 with WorkerPool

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

the class JMSEndpoint method loadConfiguration.

@Override
public boolean loadConfiguration(ParameterInclude params) throws AxisFault {
    // We only support endpoints configured at service level
    if (!(params instanceof AxisService)) {
        return false;
    }
    AxisService service = (AxisService) params;
    cf = listener.getConnectionFactory(service);
    if (cf == null) {
        return false;
    }
    Parameter destParam = service.getParameter(JMSConstants.PARAM_DESTINATION);
    if (destParam != null) {
        jndiDestinationName = (String) destParam.getValue();
    } else {
        // Assume that the JNDI destination name is the same as the service name
        jndiDestinationName = service.getName();
    }
    Parameter destTypeParam = service.getParameter(JMSConstants.PARAM_DEST_TYPE);
    if (destTypeParam != null) {
        String paramValue = (String) destTypeParam.getValue();
        if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(paramValue) || JMSConstants.DESTINATION_TYPE_TOPIC.equals(paramValue)) {
            setDestinationType(paramValue);
        } else {
            throw new AxisFault("Invalid destinaton type value " + paramValue);
        }
    } else {
        log.debug("JMS destination type not given. default queue");
        destinationType = JMSConstants.QUEUE;
    }
    Parameter replyDestTypeParam = service.getParameter(JMSConstants.PARAM_REPLY_DEST_TYPE);
    if (replyDestTypeParam != null) {
        String paramValue = (String) replyDestTypeParam.getValue();
        if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(paramValue) || JMSConstants.DESTINATION_TYPE_TOPIC.equals(paramValue)) {
            setReplyDestinationType(paramValue);
        } else {
            throw new AxisFault("Invalid destination type value " + paramValue);
        }
    } else {
        log.debug("JMS reply destination type not given. default queue");
        replyDestinationType = JMSConstants.DESTINATION_TYPE_QUEUE;
    }
    jndiReplyDestinationName = ParamUtils.getOptionalParam(service, JMSConstants.PARAM_REPLY_DESTINATION);
    Parameter contentTypeParam = service.getParameter(JMSConstants.CONTENT_TYPE_PARAM);
    if (contentTypeParam == null) {
        contentTypeRuleSet = new ContentTypeRuleSet();
        contentTypeRuleSet.addRule(new PropertyRule(BaseConstants.CONTENT_TYPE));
        contentTypeRuleSet.addRule(new MessageTypeRule(BytesMessage.class, "application/octet-stream"));
        contentTypeRuleSet.addRule(new MessageTypeRule(TextMessage.class, "text/plain"));
    } else {
        contentTypeRuleSet = ContentTypeRuleFactory.parse(contentTypeParam);
    }
    // compute service EPR and keep for later use
    computeEPRs();
    serviceTaskManager = ServiceTaskManagerFactory.createTaskManagerForService(cf, service, workerPool);
    serviceTaskManager.setJmsMessageReceiver(new JMSMessageReceiver(listener, cf, this));
    // Fix for ESBJAVA-3687, retrieve JMS transport property transport.jms.MessagePropertyHyphens and set this
    // into the msgCtx
    Parameter paramHyphenSupport = service.getParameter(JMSConstants.PARAM_JMS_HYPHEN_MODE);
    if (paramHyphenSupport != null) {
        if (((String) paramHyphenSupport.getValue()).equals(JMSConstants.HYPHEN_MODE_REPLACE)) {
            hyphenSupport = JMSConstants.HYPHEN_MODE_REPLACE;
        } else if (((String) paramHyphenSupport.getValue()).equals(JMSConstants.HYPHEN_MODE_DELETE)) {
            hyphenSupport = JMSConstants.HYPHEN_MODE_DELETE;
        }
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) PropertyRule(org.apache.axis2.transport.jms.ctype.PropertyRule) AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) ContentTypeRuleSet(org.apache.axis2.transport.jms.ctype.ContentTypeRuleSet) BytesMessage(javax.jms.BytesMessage) MessageTypeRule(org.apache.axis2.transport.jms.ctype.MessageTypeRule) TextMessage(javax.jms.TextMessage)

Example 8 with WorkerPool

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

the class XMPPListener method start.

/**
 * Start a pool of Workers. For each connection in connectionFactories,
 * assign a packer listener. This packet listener will trigger when a
 * message arrives.
 */
public void start() throws AxisFault {
    // create thread pool of workers
    ExecutorService workerPool = new ThreadPoolExecutor(1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue(), new org.apache.axis2.util.threadpool.DefaultThreadFactory(new ThreadGroup("XMPP Worker thread group"), "XMPPWorker"));
    Iterator iter = connectionFactories.values().iterator();
    while (iter.hasNext()) {
        XMPPConnectionFactory connectionFactory = (XMPPConnectionFactory) iter.next();
        XMPPPacketListener xmppPacketListener = new XMPPPacketListener(connectionFactory, this.configurationContext, workerPool);
        connectionFactory.listen(xmppPacketListener);
    }
}
Also used : XMPPConnectionFactory(org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory) XMPPPacketListener(org.apache.axis2.transport.xmpp.util.XMPPPacketListener) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 9 with WorkerPool

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

the class MSMQEndpoint method loadConfiguration.

@Override
public boolean loadConfiguration(ParameterInclude params) {
    // only support endpoints configured at service level
    if (!(params instanceof AxisService)) {
        return false;
    }
    AxisService service = (AxisService) params;
    // we just assume that the service name==queue name
    Parameter destParam = service.getParameter(MSMQConstants.PARAM_DESTINATION);
    if (destParam != null) {
        msmqDestinationQueueName = (String) destParam.getValue();
    } else {
        msmqDestinationQueueName = service.getName();
    }
    endpointReferences.add(new EndpointReference(MSMQConnectionManager.getReceiverQueueFullName(getServiceName())));
    // TODO: improve MSMQ transport for two way messaging..
    Parameter contentTypeParam = service.getParameter(MSMQConstants.PARAM_CONTENT_TYPE);
    serviceTaskManager = ServiceTaskManagerFactory.createTaskManagerForService(service, workerPool);
    serviceTaskManager.setMsmqMessageReceiver(new MSMQMessageReceiver(listener, msmqDestinationQueueName, this));
    // Deal with content type
    if (contentTypeParam.getValue() != null && !"".equals(String.valueOf(contentTypeParam.getValue()).trim())) {
        serviceTaskManager.setContentType(String.valueOf(contentTypeParam.getValue()));
    }
    return true;
}
Also used : AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 10 with WorkerPool

use of org.apache.axis2.transport.base.threads.WorkerPool 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...");
    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());
    TransportView view = new TransportView(this, null, metrics, null);
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-receiver");
    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);
    connFactory = connFactoryBuilder.build(sourceConfiguration.getHttpParams());
    handler = new SourceHandler(sourceConfiguration);
    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);
        }
    });
}
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

WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)15 Test (org.junit.Test)12 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)11 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)11 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)8 TargetConfiguration (org.apache.synapse.transport.passthru.config.TargetConfiguration)6 AxisService (org.apache.axis2.description.AxisService)5 Parameter (org.apache.axis2.description.Parameter)5 NHttpClientConnection (org.apache.http.nio.NHttpClientConnection)5 HttpResponse (org.apache.http.HttpResponse)3 TargetConnections (org.apache.synapse.transport.passthru.connections.TargetConnections)3 Message (quickfix.Message)3 SessionID (quickfix.SessionID)3 BeginString (quickfix.field.BeginString)3 MsgSeqNum (quickfix.field.MsgSeqNum)3 MsgType (quickfix.field.MsgType)3 SenderCompID (quickfix.field.SenderCompID)3 TargetCompID (quickfix.field.TargetCompID)3