use of org.apache.geode.internal.cache.wan.GatewaySenderEventImpl in project geode by apache.
the class ParallelGatewaySenderQueue method peek.
public List peek(int batchSize, int timeToWait) throws InterruptedException, CacheException {
final boolean isDebugEnabled = logger.isDebugEnabled();
PartitionedRegion prQ = getRandomShadowPR();
List<GatewaySenderEventImpl> batch = new ArrayList<>();
if (prQ == null || prQ.getLocalMaxMemory() == 0) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
blockProcessorThreadIfRequired();
return batch;
}
long start = System.currentTimeMillis();
long end = start + timeToWait;
// Add peeked events
addPeekedEvents(batch, batchSize);
int bId = -1;
while (batch.size() < batchSize) {
if (areLocalBucketQueueRegionsPresent() && ((bId = getRandomPrimaryBucket(prQ)) != -1)) {
GatewaySenderEventImpl object = (GatewaySenderEventImpl) peekAhead(prQ, bId);
if (object != null) {
GatewaySenderEventImpl copy = object.makeHeapCopyIfOffHeap();
if (copy == null) {
if (stats != null) {
stats.incEventsNotQueuedConflated();
}
continue;
}
object = copy;
}
// Conflate here
if (object != null) {
if (isDebugEnabled) {
logger.debug("The gatewayEventImpl in peek is {}", object);
}
batch.add(object);
peekedEvents.add(object);
} else {
// If time to wait is -1 (don't wait) or time interval has elapsed
long currentTime = System.currentTimeMillis();
if (isDebugEnabled) {
logger.debug("{}: Peeked object was null. Peek current time: {}", this, currentTime);
}
if (timeToWait == -1 || (end <= currentTime)) {
if (isDebugEnabled) {
logger.debug("{}: Peeked object was null.. Peek breaking", this);
}
break;
}
if (isDebugEnabled) {
logger.debug("{}: Peeked object was null. Peek continuing", this);
}
continue;
}
} else {
// If time to wait is -1 (don't wait) or time interval has elapsed
long currentTime = System.currentTimeMillis();
if (isDebugEnabled) {
logger.debug("{}: Peek current time: {}", this, currentTime);
}
if (timeToWait == -1 || (end <= currentTime)) {
if (isDebugEnabled) {
logger.debug("{}: Peek breaking", this);
}
break;
}
if (isDebugEnabled) {
logger.debug("{}: Peek continuing", this);
}
// Sleep a bit before trying again.
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
continue;
}
}
if (isDebugEnabled) {
logger.debug("{}: Peeked a batch of {} entries. The size of the queue is {}. localSize is {}", this, batch.size(), size(), localSize());
}
if (batch.size() == 0) {
blockProcessorThreadIfRequired();
}
return batch;
}
use of org.apache.geode.internal.cache.wan.GatewaySenderEventImpl in project geode by apache.
the class SerialGatewaySenderEventProcessor method enqueueEvent.
/**
* Add the input object to the event queue
*/
@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue) throws IOException, CacheException {
// There is a case where the event is serialized for processing. The
// region is not
// serialized along with the event since it is a transient field. I
// created an
// intermediate object (GatewayEventImpl) to avoid this since the region
// name is
// used in the sendBatch method, and it can't be null. See EntryEventImpl
// for details.
GatewaySenderEventImpl senderEvent = null;
boolean isPrimary = sender.isPrimary();
if (!isPrimary) {
// over while we're processing an event as a secondaryEvent.
synchronized (unprocessedEventsLock) {
// Test whether this gateway is the primary.
if (sender.isPrimary()) {
isPrimary = true;
} else {
// If it is not, create an uninitialized GatewayEventImpl and
// put it into the map of unprocessed events.
// OFFHEAP
senderEvent = new GatewaySenderEventImpl(operation, event, substituteValue, false);
// ok
handleSecondaryEvent(senderEvent);
}
}
}
if (isPrimary) {
Region region = event.getRegion();
boolean isPDXRegion = (region instanceof DistributedRegion && region.getName().equals(PeerTypeRegistration.REGION_NAME));
if (!isPDXRegion) {
waitForFailoverCompletion();
}
// If it is, create and enqueue an initialized GatewayEventImpl
// OFFHEAP ok
senderEvent = new GatewaySenderEventImpl(operation, event, substituteValue);
boolean queuedEvent = false;
try {
queuedEvent = queuePrimaryEvent(senderEvent);
} finally {
// when the event is accessed through the region queue.
if (!queuedEvent) {
GatewaySenderEventImpl.release(senderEvent);
}
}
}
}
Aggregations