use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.
the class HttpCoreNIOListener method startSpecificEndpoints.
/**
* Start specific end points given by InetSockeAddress list
*
* @param endpointsClosed InetSocketAddresses of endpoints to be started
* @throws AxisFault
*/
private void startSpecificEndpoints(List<InetSocketAddress> endpointsClosed) throws AxisFault {
Queue<ListenerEndpoint> endpoints = new LinkedList<ListenerEndpoint>();
// Ensure simple but stable order
List<InetSocketAddress> addressList = endpointsClosed;
Collections.sort(addressList, new Comparator<InetSocketAddress>() {
public int compare(InetSocketAddress a1, InetSocketAddress a2) {
String s1 = a1.toString();
String s2 = a2.toString();
return s1.compareTo(s2);
}
});
for (InetSocketAddress address : addressList) {
endpoints.add(ioReactor.listen(address));
}
// requests.
while (!endpoints.isEmpty()) {
ListenerEndpoint endpoint = endpoints.remove();
try {
endpoint.waitFor();
if (log.isInfoEnabled()) {
InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
if (!address.isUnresolved()) {
log.info(name + " started on " + address.getHostName() + ":" + address.getPort());
} else {
log.info(name + " started on " + address);
}
}
} catch (InterruptedException e) {
log.warn("Listener startup was interrupted");
break;
}
}
}
use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method closeAllPTTListenerEndpoints.
/**
* Close all endpoints started by PTT Listeners.
*
* @param port Port of the Endpoint for PTT axis2 Listener
* @return is all Endpoints closed
*/
public boolean closeAllPTTListenerEndpoints(int port) {
try {
ListeningIOReactor listeningIOReactor = passThroughListenerIOReactorMapper.get(port);
if (listeningIOReactor != null) {
Set<ListenerEndpoint> endpoints = listeningIOReactor.getEndpoints();
// If it is shared IO Reactor then only close endpoints related to PTT Listener
if (passThroughListenerServerIODispatchMapper.get(port) instanceof MultiListenerServerIODispatch) {
for (ListenerEndpoint listenerEndpoint : endpoints) {
if (listenerEndpoint.getAddress() instanceof InetSocketAddress) {
int endPointPort = ((InetSocketAddress) listenerEndpoint.getAddress()).getPort();
if (dynamicPTTListeningEndpointMapper.containsKey(endPointPort)) {
continue;
}
log.info("Closing Endpoint Listener for port " + port);
listenerEndpoint.close();
log.info("Successfully closed Endpoint Listener for port " + port);
}
}
} else {
for (ListenerEndpoint listenerEndpoint : endpoints) {
log.info("Closing Endpoint Listener for port " + port);
listenerEndpoint.close();
log.info("Successfully closed Endpoint Listener for port " + port);
}
}
}
return true;
} catch (Exception e) {
log.error("Error occurred when closing Endpoint in PassThrough Transport Related to port " + port, e);
return false;
}
}
use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method startDynamicPTTSSLEndpoint.
/**
* Start SSL endpoint in IO reactor which is external to PTT Axis Listeners started at server startup
* @param inetSocketAddress InetSocketAddress
* @param nHttpServerEventHandler ServerHandler responsible for handle events of port
* @param endpointName Endpoint Name
* @param sslConfiguration SSL information for create secure connection
* @return
*/
public boolean startDynamicPTTSSLEndpoint(InetSocketAddress inetSocketAddress, NHttpServerEventHandler nHttpServerEventHandler, String endpointName, SSLConfiguration sslConfiguration) {
try {
// get Shared IO Reactor and Start Endpoint
ListenerEndpoint endpoint = startEndpoint(inetSocketAddress, getSharedSSLIOReactor(nHttpServerEventHandler, endpointName, inetSocketAddress.getPort(), sslConfiguration), endpointName);
if (endpoint != null) {
portServerHandlerMapper.put(inetSocketAddress.getPort(), nHttpServerEventHandler);
dynamicPTTListeningEndpointMapper.put(inetSocketAddress.getPort(), endpoint);
return true;
} else {
return false;
}
} catch (Exception e) {
log.error("Cannot Start Endpoint for " + endpointName, e);
return false;
}
}
use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method startEndpoint.
private ListenerEndpoint startEndpoint(InetSocketAddress inetSocketAddress, ListeningIOReactor defaultListeningIOReactor, String endPointName) throws Exception {
ListenerEndpoint endpoint = defaultListeningIOReactor.listen(inetSocketAddress);
try {
endpoint.waitFor();
InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
if (!address.isUnresolved()) {
log.info((endPointName != null ? "Pass-through " + endPointName : " Pass-through Http ") + " Listener started on " + address.getHostName() + ":" + address.getPort());
} else {
log.info((endPointName != null ? "Pass-through " + endPointName : " Pass-through Http ") + " Listener started on " + address);
}
} catch (Exception e) {
throw new Exception("Endpoint does not start for port " + inetSocketAddress.getPort() + "May be IO Reactor not started or endpoint binding exception ", e);
}
return endpoint;
}
use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method startDynamicPTTEndpoint.
/**
* Start Endpoint in IOReactor which is external to PTT Axis2 Listeners started at server startup
*
* @param inetSocketAddress Socket Address of starting endpoint
* @param nHttpServerEventHandler ServerHandler responsible for handle events of port
* @param endpointName Endpoint Name
* @return Is Endpoint started
*/
public boolean startDynamicPTTEndpoint(InetSocketAddress inetSocketAddress, NHttpServerEventHandler nHttpServerEventHandler, String endpointName) {
try {
// get Shared IO Reactor and Start Endpoint
ListenerEndpoint endpoint = startEndpoint(inetSocketAddress, getSharedIOReactor(nHttpServerEventHandler, endpointName), endpointName);
if (endpoint != null) {
portServerHandlerMapper.put(inetSocketAddress.getPort(), nHttpServerEventHandler);
dynamicPTTListeningEndpointMapper.put(inetSocketAddress.getPort(), endpoint);
return true;
} else {
return false;
}
} catch (Exception e) {
log.error("Cannot Start Endpoint for " + endpointName, e);
return false;
}
}
Aggregations