use of org.apache.geode.CancelCriterion in project geode by apache.
the class HandShake method handshakeWithSubscriptionFeed.
/**
* Used by client-side CacheClientUpdater to handshake with a server in order to receive messages
* generated by subscriptions (register-interest, continuous query)
*/
public ServerQueueStatus handshakeWithSubscriptionFeed(Socket sock, boolean isPrimary) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException, ClassNotFoundException {
ServerQueueStatus sqs = null;
try {
DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
final InputStream in = sock.getInputStream();
DataInputStream dis = new DataInputStream(in);
DistributedMember member = getIDForSocket(sock);
if (!this.multiuserSecureMode) {
this.credentials = getCredentials(member);
}
byte mode = isPrimary ? Acceptor.PRIMARY_SERVER_TO_CLIENT : Acceptor.SECONDARY_SERVER_TO_CLIENT;
write(dos, dis, mode, REPLY_OK, 0, new ArrayList(), this.credentials, member, true);
// Wait here for a reply before continuing. This ensures that the client
// updater is registered with the server before continuing.
byte acceptanceCode = dis.readByte();
if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) {
// SSL
throw new AuthenticationRequiredException(LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString());
}
// No need to check for return value since DataInputStream already throws
// EOFException in case of EOF
byte qType = dis.readByte();
// read and ignore qSize flag
int qSize = dis.readInt();
sqs = new ServerQueueStatus(qType, qSize, member);
// Read the message (if any)
readMessage(dis, dos, acceptanceCode, member);
// clients but that is not used in tests
if (currentClientVersion.compareTo(Version.GFE_61) < 0) {
return sqs;
}
HashMap instantiatorMap = DataSerializer.readHashMap(dis);
for (Iterator itr = instantiatorMap.entrySet().iterator(); itr.hasNext(); ) {
Map.Entry instantiator = (Map.Entry) itr.next();
Integer id = (Integer) instantiator.getKey();
ArrayList instantiatorArguments = (ArrayList) instantiator.getValue();
InternalInstantiator.register((String) instantiatorArguments.get(0), (String) instantiatorArguments.get(1), id, false);
}
HashMap dataSerializersMap = DataSerializer.readHashMap(dis);
for (Iterator itr = dataSerializersMap.entrySet().iterator(); itr.hasNext(); ) {
Map.Entry dataSerializer = (Map.Entry) itr.next();
Integer id = (Integer) dataSerializer.getKey();
InternalDataSerializer.register((String) dataSerializer.getValue(), false, null, null, id);
}
HashMap<Integer, ArrayList<String>> dsToSupportedClassNames = DataSerializer.readHashMap(dis);
InternalDataSerializer.updateSupportedClassesMap(dsToSupportedClassNames);
} catch (IOException ex) {
CancelCriterion stopper = this.system.getCancelCriterion();
stopper.checkCancelInProgress(null);
throw ex;
} catch (ClassNotFoundException ex) {
CancelCriterion stopper = this.system.getCancelCriterion();
stopper.checkCancelInProgress(null);
throw ex;
}
return sqs;
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class ColocationLogger method run.
public void run() {
CancelCriterion stopper = region.getGemFireCache().getDistributedSystem().getCancelCriterion();
DistributedSystem.setThreadsSocketPolicy(true);
SystemFailure.checkFailure();
if (stopper.cancelInProgress() != null) {
return;
}
try {
run2();
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
if (logger.isDebugEnabled()) {
logger.debug("Unexpected exception in colocation", t);
}
}
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class RegionVersionVector method waitToDominate.
/**
* wait for this vector to dominate the given vector. This means that the receiver has seen all
* version changes that the given vector has seen.
*
* @param otherVector the vector, usually from another member, that we want to dominate
* @param region the region owning this vector
* @return true if dominance was achieved
*/
public boolean waitToDominate(RegionVersionVector<T> otherVector, LocalRegion region) {
if (otherVector == this) {
return true;
}
boolean result = false;
long waitTimeRemaining = 0;
long startTime = System.currentTimeMillis();
boolean interrupted = false;
CancelCriterion stopper = region.getCancelCriterion();
try {
do {
stopper.checkCancelInProgress(null);
result = dominates(otherVector);
if (!result) {
long now = System.currentTimeMillis();
waitTimeRemaining = MAX_DOMINANCE_WAIT_TIME - (now - startTime);
if (logger.isTraceEnabled()) {
logger.trace("Waiting up to {} ms to achieve dominance", waitTimeRemaining);
}
if (waitTimeRemaining > 0) {
long waitTime = Math.min(DOMINANCE_PAUSE_TIME, waitTimeRemaining);
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
stopper.checkCancelInProgress(e);
interrupted = true;
break;
}
}
}
} while (waitTimeRemaining > 0 && !result);
} finally {
if (interrupted) {
if (logger.isTraceEnabled()) {
logger.trace("waitForDominance has been interrupted");
}
Thread.currentThread().interrupt();
}
}
return result;
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class OpExecutorImplJUnitTest method setUp.
@Before
public void setUp() {
this.logger = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
this.endpointManager = new DummyEndpointManager();
this.queueManager = new DummyQueueManager();
this.manager = new DummyManager();
riTracker = new RegisterInterestTracker();
cancelCriterion = new CancelCriterion() {
@Override
public String cancelInProgress() {
return null;
}
@Override
public RuntimeException generateCancelledException(Throwable e) {
return null;
}
};
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class ParallelGatewaySenderQueueJUnitTest method createParallelGatewaySenderQueue.
@Before
public void createParallelGatewaySenderQueue() {
cache = mock(GemFireCacheImpl.class);
sender = mock(AbstractGatewaySender.class);
CancelCriterion cancelCriterion = mock(CancelCriterion.class);
when(sender.getCancelCriterion()).thenReturn(cancelCriterion);
when(sender.getCache()).thenReturn(cache);
when(sender.getMaximumQueueMemory()).thenReturn(100);
when(sender.getLifeCycleLock()).thenReturn(new ReentrantReadWriteLock());
metaRegionFactory = mock(MetaRegionFactory.class);
queue = new ParallelGatewaySenderQueue(sender, Collections.emptySet(), 0, 1, metaRegionFactory);
}
Aggregations