use of org.apache.geode.distributed.internal.tcpserver.TcpClient in project geode by apache.
the class InternalLocator method stop.
/**
* Stop this locator
*
* @param stopForReconnect - stopping for distributed system reconnect
* @param waitForDisconnect - wait up to 60 seconds for the locator to completely stop
*/
public void stop(boolean forcedDisconnect, boolean stopForReconnect, boolean waitForDisconnect) {
final boolean isDebugEnabled = logger.isDebugEnabled();
this.stoppedForReconnect = stopForReconnect;
this.forcedDisconnect = forcedDisconnect;
if (this.server.isShuttingDown()) {
// locator can be created, if desired, when this method returns
if (!stopForReconnect && waitForDisconnect) {
long endOfWait = System.currentTimeMillis() + 60000;
if (isDebugEnabled && this.server.isAlive()) {
logger.debug("sleeping to wait for the locator server to shut down...");
}
while (this.server.isAlive() && System.currentTimeMillis() < endOfWait) {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
return;
}
}
if (isDebugEnabled) {
if (this.server.isAlive()) {
logger.debug("60 seconds have elapsed waiting for the locator server to shut down - terminating wait and returning");
} else {
logger.debug("the locator server has shut down");
}
}
}
return;
}
if (this.locatorDiscoverer != null) {
this.locatorDiscoverer.stop();
this.locatorDiscoverer = null;
}
if (this.server.isAlive()) {
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_STOPPING__0, this));
try {
new TcpClient().stop(this.bindAddress, getPort());
} catch (ConnectException ignore) {
// must not be running
}
boolean interrupted = Thread.interrupted();
try {
this.server.join(TcpServer.SHUTDOWN_WAIT_TIME * 1000 + 10000);
} catch (InterruptedException ex) {
interrupted = true;
logger.warn(LocalizedMessage.create(LocalizedStrings.InternalLocator_INTERRUPTED_WHILE_STOPPING__0, this), ex);
// Continue running -- doing our best to stop everything...
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
if (this.server.isAlive()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.InternalLocator_COULD_NOT_STOP__0__IN_60_SECONDS, this));
}
}
removeLocator(this);
handleShutdown();
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_0__IS_STOPPED, this));
if (this.stoppedForReconnect) {
if (this.myDs != null) {
launchRestartThread();
}
}
}
use of org.apache.geode.distributed.internal.tcpserver.TcpClient in project geode by apache.
the class AutoConnectionSourceImplJUnitTest method testDiscoverLocators.
@Test
public void testDiscoverLocators() throws Exception {
startFakeLocator();
int secondPort = AvailablePortHelper.getRandomAvailableTCPPort();
TcpServer server2 = new TcpServer(secondPort, InetAddress.getLocalHost(), null, null, handler, new FakeHelper(), Thread.currentThread().getThreadGroup(), "tcp server");
server2.start();
try {
ArrayList locators = new ArrayList();
locators.add(new ServerLocation(InetAddress.getLocalHost().getHostName(), secondPort));
handler.nextLocatorListResponse = new LocatorListResponse(locators, false);
Thread.sleep(500);
try {
new TcpClient().stop(InetAddress.getLocalHost(), port);
} catch (ConnectException ignore) {
// must not be running
}
server.join(1000);
ServerLocation server1 = new ServerLocation("localhost", 10);
handler.nextConnectionResponse = new ClientConnectionResponse(server1);
assertEquals(server1, source.findServer(null));
} finally {
try {
new TcpClient().stop(InetAddress.getLocalHost(), secondPort);
} catch (ConnectException ignore) {
// must not be running
}
server.join(60 * 1000);
}
}
use of org.apache.geode.distributed.internal.tcpserver.TcpClient in project geode by apache.
the class JmxManagerLocatorRequest method send.
/**
* Send a request to the specified locator asking it to find (and start if needed) a jmx manager.
* A jmx manager will only be started
*
* @param locatorHost the name of the host the locator is on
* @param locatorPort the port the locator is listening on
* @param msTimeout how long in milliseconds to wait for a response from the locator
* @param sslConfigProps Map carrying SSL configuration that can be used by SocketCreator
* @return a response object that describes the jmx manager.
* @throws IOException if we can not connect to the locator, timeout waiting for a response, or
* have trouble communicating with it.
*/
public static JmxManagerLocatorResponse send(String locatorHost, int locatorPort, int msTimeout, Map<String, String> sslConfigProps) throws IOException {
Properties distributionConfigProps = new Properties();
InetAddress networkAddress = InetAddress.getByName(locatorHost);
InetSocketAddress inetSockAddr = new InetSocketAddress(networkAddress, locatorPort);
try {
if (sslConfigProps != null) {
distributionConfigProps.putAll(sslConfigProps);
}
TcpClient client = new TcpClient(new DistributionConfigImpl(distributionConfigProps));
Object responseFromServer = client.requestToServer(inetSockAddr, SINGLETON, msTimeout, true);
return (JmxManagerLocatorResponse) responseFromServer;
} catch (ClassNotFoundException unexpected) {
throw new IllegalStateException(unexpected);
} catch (ClassCastException unexpected) {
// locator meaningful message
throw new IllegalStateException(unexpected);
} finally {
distributionConfigProps.clear();
}
}
use of org.apache.geode.distributed.internal.tcpserver.TcpClient in project geode by apache.
the class LocatorJUnitTest method testBasicInfo.
@Test
public void testBasicInfo() throws Exception {
locator = Locator.startLocator(port, tmpFile);
int boundPort = (port == 0) ? locator.getPort() : port;
TcpClient client = new TcpClient();
String[] info = client.getInfo(InetAddress.getLocalHost(), boundPort);
assertNotNull(info);
assertTrue(info.length > 1);
}
use of org.apache.geode.distributed.internal.tcpserver.TcpClient in project geode by apache.
the class AbstractRemoteGatewaySender method initProxy.
public synchronized void initProxy() {
// return if it is being used for WBCL or proxy is already created
if (this.remoteDSId == DEFAULT_DISTRIBUTED_SYSTEM_ID || this.proxy != null && !this.proxy.isDestroyed()) {
return;
}
int locatorCount = 0;
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.setPRSingleHopEnabled(false);
if (this.locatorDiscoveryCallback != null) {
pf.setLocatorDiscoveryCallback(locatorDiscoveryCallback);
}
pf.setReadTimeout(this.socketReadTimeout);
pf.setIdleTimeout(connectionIdleTimeOut);
pf.setSocketBufferSize(socketBufferSize);
pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP);
RemoteLocatorRequest request = new RemoteLocatorRequest(this.remoteDSId, pf.getPoolAttributes().getServerGroup());
String locators = this.cache.getInternalDistributedSystem().getConfig().getLocators();
if (logger.isDebugEnabled()) {
logger.debug("Gateway Sender is attempting to configure pool with remote locator information");
}
StringTokenizer locatorsOnThisVM = new StringTokenizer(locators, ",");
while (locatorsOnThisVM.hasMoreTokens()) {
String localLocator = locatorsOnThisVM.nextToken();
DistributionLocatorId locatorID = new DistributionLocatorId(localLocator);
try {
RemoteLocatorResponse response = (RemoteLocatorResponse) new TcpClient().requestToServer(locatorID.getHost(), locatorID.getPort(), request, WanLocatorDiscoverer.WAN_LOCATOR_CONNECTION_TIMEOUT);
if (response != null) {
if (response.getLocators() == null) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_REMOTE_LOCATOR_FOR_REMOTE_SITE_0_IS_NOT_AVAILABLE_IN_LOCAL_LOCATOR_1, new Object[] { remoteDSId, localLocator }));
}
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("Received the remote site {} location information:", this.remoteDSId, response.getLocators());
}
Iterator<String> itr = response.getLocators().iterator();
while (itr.hasNext()) {
String remoteLocator = itr.next();
try {
DistributionLocatorId locatorId = new DistributionLocatorId(remoteLocator);
pf.addLocator(locatorId.getHost().getHostName(), locatorId.getPort());
locatorCount++;
} catch (Exception e) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PoolFactoryImpl_CAUGHT_EXCEPTION_ATTEMPTING_TO_ADD_REMOTE_LOCATOR_0, new Object[] { remoteLocator }), e);
}
}
}
break;
}
} catch (IOException ioe) {
if (logProxyFailure()) {
// don't print stack trace for connection failures
String ioeStr = "";
if (!logger.isDebugEnabled() && ioe instanceof ConnectException) {
ioeStr = ": " + ioe.toString();
ioe = null;
}
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_IS_NOT_ABLE_TO_CONNECT_TO_LOCAL_LOCATOR_1, new Object[] { this.id, localLocator + ioeStr }), ioe);
}
continue;
} catch (ClassNotFoundException e) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_IS_NOT_ABLE_TO_CONNECT_TO_LOCAL_LOCATOR_1, new Object[] { this.id, localLocator }), e);
}
continue;
}
}
if (locatorCount == 0) {
if (logProxyFailure()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_COULD_NOT_GET_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1, new Object[] { this.id, this.remoteDSId }));
}
this.proxyFailureTries++;
throw new GatewaySenderConfigurationException(LocalizedStrings.AbstractGatewaySender_SENDER_0_COULD_NOT_GET_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1.toLocalizedString(new Object[] { this.id, this.remoteDSId }));
}
pf.init(this);
this.proxy = ((PoolImpl) pf.create(this.getId()));
if (this.proxyFailureTries > 0) {
logger.info(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_GOT_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1, new Object[] { this.id, this.remoteDSId, this.proxyFailureTries }));
this.proxyFailureTries = 0;
}
}
Aggregations