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