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...");
}
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;
}
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);
}
}
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;
}
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);
}
});
}
Aggregations