Search in sources :

Example 1 with RemoteLocatorRequest

use of org.apache.geode.cache.client.internal.locator.wan.RemoteLocatorRequest 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;
    }
}
Also used : DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) RemoteLocatorResponse(org.apache.geode.cache.client.internal.locator.wan.RemoteLocatorResponse) IOException(java.io.IOException) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) IOException(java.io.IOException) ConnectException(java.net.ConnectException) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) StringTokenizer(java.util.StringTokenizer) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) RemoteLocatorRequest(org.apache.geode.cache.client.internal.locator.wan.RemoteLocatorRequest) ConnectException(java.net.ConnectException)

Aggregations

IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 StringTokenizer (java.util.StringTokenizer)1 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)1 RemoteLocatorRequest (org.apache.geode.cache.client.internal.locator.wan.RemoteLocatorRequest)1 RemoteLocatorResponse (org.apache.geode.cache.client.internal.locator.wan.RemoteLocatorResponse)1 TcpClient (org.apache.geode.distributed.internal.tcpserver.TcpClient)1 DistributionLocatorId (org.apache.geode.internal.admin.remote.DistributionLocatorId)1 PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)1