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