Search in sources :

Example 1 with SenderProxy

use of org.apache.geode.cache.client.internal.SenderProxy in project geode by apache.

the class GatewaySenderEventRemoteDispatcher method readAcknowledgement.

protected GatewayAck readAcknowledgement() {
    SenderProxy sp = new SenderProxy(this.processor.getSender().getProxy());
    GatewayAck ack = null;
    Exception ex;
    try {
        connection = getConnection(false);
        if (logger.isDebugEnabled()) {
            logger.debug(" Receiving ack on the thread {}", connection);
        }
        this.connectionLifeCycleLock.readLock().lock();
        try {
            if (connection != null && !processor.isStopped()) {
                ack = (GatewayAck) sp.receiveAckFromReceiver(connection);
            }
        } finally {
            this.connectionLifeCycleLock.readLock().unlock();
        }
    } catch (Exception e) {
        Throwable t = e.getCause();
        if (t instanceof BatchException70) {
            // A BatchException has occurred.
            // Do not process the connection as dead since it is not dead.
            ex = (BatchException70) t;
        } else if (e instanceof GatewaySenderException) {
            // This Exception is thrown from
            // getConnection
            ex = (Exception) e.getCause();
        } else {
            ex = e;
            // keep using the connection if we had a batch exception. Else, destroy
            // it
            destroyConnection();
        }
        if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
        // if our pool is shutdown then just be silent
        } else if (ex instanceof IOException || (ex instanceof ServerConnectivityException && !(ex.getCause() instanceof PdxRegistryMismatchException)) || ex instanceof ConnectionDestroyedException) {
            // Sleep for a bit and recheck.
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
        } else {
            if (!(ex instanceof CancelException)) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_STOPPING_THE_PROCESSOR_BECAUSE_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_PROCESSING_A_BATCH), ex);
            }
            this.processor.setIsStopped(true);
        }
    }
    return ack;
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException) CancelException(org.apache.geode.CancelException) SenderProxy(org.apache.geode.cache.client.internal.SenderProxy) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) GemFireIOException(org.apache.geode.GemFireIOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException) IOException(java.io.IOException) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 2 with SenderProxy

use of org.apache.geode.cache.client.internal.SenderProxy in project geode by apache.

the class GatewaySenderEventRemoteDispatcher method _dispatchBatch.

private boolean _dispatchBatch(List events, boolean isRetry) {
    Exception ex = null;
    int currentBatchId = this.processor.getBatchId();
    connection = getConnection(true);
    int batchIdForThisConnection = this.processor.getBatchId();
    GatewaySenderStats statistics = this.sender.getStatistics();
    // i.e The connection has been reset. It also resets the batchId.
    if (currentBatchId != batchIdForThisConnection || this.processor.isConnectionReset()) {
        return false;
    }
    try {
        if (this.processor.isConnectionReset()) {
            isRetry = true;
        }
        SenderProxy sp = new SenderProxy(this.sender.getProxy());
        this.connectionLifeCycleLock.readLock().lock();
        try {
            if (connection != null) {
                sp.dispatchBatch_NewWAN(connection, events, currentBatchId, sender.isRemoveFromQueueOnException(), isRetry);
                if (logger.isDebugEnabled()) {
                    logger.debug("{} : Dispatched batch (id={}) of {} events, queue size: {} on connection {}", this.processor.getSender(), currentBatchId, events.size(), this.processor.getQueue().size(), connection);
                }
            } else {
                throw new ConnectionDestroyedException();
            }
        } finally {
            this.connectionLifeCycleLock.readLock().unlock();
        }
        return true;
    } catch (ServerOperationException e) {
        Throwable t = e.getCause();
        if (t instanceof BatchException70) {
            // A BatchException has occurred.
            // Do not process the connection as dead since it is not dead.
            ex = (BatchException70) t;
        } else {
            ex = e;
            // keep using the connection if we had a batch exception. Else, destroy it
            destroyConnection();
        }
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher_0_EXCEPTION_DURING_PROCESSING_BATCH_1_ON_CONNECTION_2.toLocalizedString(new Object[] { this, Integer.valueOf(currentBatchId), connection }), ex);
    } catch (GemFireIOException e) {
        Throwable t = e.getCause();
        if (t instanceof MessageTooLargeException) {
            // A MessageTooLargeException has occurred.
            // Do not process the connection as dead since it is not dead.
            ex = (MessageTooLargeException) t;
            // Reduce the batch size by half of the configured batch size or number of events in the
            // current batch (whichever is less)
            int newBatchSize = Math.min(events.size(), this.processor.getBatchSize()) / 2;
            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySenderEventRemoteDispatcher_MESSAGE_TOO_LARGE_EXCEPTION, new Object[] { events.size(), newBatchSize }), e);
            this.processor.setBatchSize(newBatchSize);
            statistics.incBatchesResized();
        } else {
            ex = e;
            // keep using the connection if we had a MessageTooLargeException. Else, destroy it
            destroyConnection();
        }
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher_0_EXCEPTION_DURING_PROCESSING_BATCH_1_ON_CONNECTION_2.toLocalizedString(new Object[] { this, Integer.valueOf(currentBatchId), connection }), ex);
    } catch (IllegalStateException e) {
        this.processor.setException(new GatewaySenderException(e));
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher_0_EXCEPTION_DURING_PROCESSING_BATCH_1_ON_CONNECTION_2.toLocalizedString(new Object[] { this, Integer.valueOf(currentBatchId), connection }), e);
    } catch (Exception e) {
        // An Exception has occurred. Get its cause.
        Throwable t = e.getCause();
        if (t instanceof IOException) {
            // An IOException has occurred.
            ex = (IOException) t;
        } else {
            ex = e;
        }
        // the cause is not going to be BatchException70. So, destroy the connection
        destroyConnection();
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher_0_EXCEPTION_DURING_PROCESSING_BATCH_1_ON_CONNECTION_2.toLocalizedString(new Object[] { this, Integer.valueOf(currentBatchId), connection }), ex);
    }
}
Also used : GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) GemFireIOException(org.apache.geode.GemFireIOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException) IOException(java.io.IOException) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) SenderProxy(org.apache.geode.cache.client.internal.SenderProxy) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) GemFireIOException(org.apache.geode.GemFireIOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)

Aggregations

IOException (java.io.IOException)2 CancelException (org.apache.geode.CancelException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)2 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)2 SenderProxy (org.apache.geode.cache.client.internal.SenderProxy)2 ConnectionDestroyedException (org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)2 MessageTooLargeException (org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException)2 PdxRegistryMismatchException (org.apache.geode.pdx.PdxRegistryMismatchException)2 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2