Search in sources :

Example 11 with CancelCriterion

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;
}
Also used : HashMap(java.util.HashMap) DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) CancelCriterion(org.apache.geode.CancelCriterion) ArrayList(java.util.ArrayList) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) IOException(java.io.IOException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) BigInteger(java.math.BigInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with CancelCriterion

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);
        }
    }
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion)

Example 13 with CancelCriterion

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;
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion)

Example 14 with CancelCriterion

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;
        }
    };
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) Before(org.junit.Before)

Example 15 with CancelCriterion

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);
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MetaRegionFactory(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue.MetaRegionFactory) Before(org.junit.Before)

Aggregations

CancelCriterion (org.apache.geode.CancelCriterion)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Socket (java.net.Socket)2 Iterator (java.util.Iterator)2 SSLSocket (javax.net.ssl.SSLSocket)2 Statistics (org.apache.geode.Statistics)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 DM (org.apache.geode.distributed.internal.DM)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2