Search in sources :

Example 11 with Connection

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

the class DestroyEntryPropagationDUnitTest method acquireConnectionsAndDestroyEntriesK1andK2.

private void acquireConnectionsAndDestroyEntriesK1andK2() {
    try {
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
        assertNotNull(r1);
        String poolName = r1.getAttributes().getPoolName();
        assertNotNull(poolName);
        PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
        assertNotNull(pool);
        Connection conn = pool.acquireConnection();
        final Connection conn1;
        if (conn.getServer().getPort() != PORT2) {
            // Ensure we have a server with the proper port
            conn1 = pool.acquireConnection();
        } else {
            conn1 = conn;
        }
        assertNotNull(conn1);
        assertEquals(PORT2, conn1.getServer().getPort());
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.destroyOnForTestsOnly(conn1, "key1", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 1)), null);
        srp.destroyOnForTestsOnly(conn1, "key2", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 2)), null);
    } catch (Exception ex) {
        throw new AssertionError("Failed while setting acquireConnectionsAndDestroyEntry  ", ex);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) Connection(org.apache.geode.cache.client.internal.Connection) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheException(org.apache.geode.cache.CacheException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 12 with Connection

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

the class GatewaySenderEventRemoteDispatcher method destroyConnection.

public void destroyConnection() {
    this.connectionLifeCycleLock.writeLock().lock();
    try {
        Connection con = this.connection;
        if (con != null) {
            if (!con.isDestroyed()) {
                con.destroy();
                this.sender.getProxy().returnConnection(con);
            }
            // Reset the connection so the next time through a new one will be
            // obtained
            this.connection = null;
            this.sender.setServerLocation(null);
        }
    } finally {
        this.connectionLifeCycleLock.writeLock().unlock();
    }
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection)

Example 13 with Connection

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

the class WANLocatorServerDUnitTest method createClient.

public static void createClient(Integer port1, Integer port2, Integer port3) {
    ClientCacheFactory cf = new ClientCacheFactory();
    cache = (Cache) cf.create();
    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
    pf.setReadTimeout(0);
    pf.setIdleTimeout(-1);
    pf.setMinConnections(4);
    pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP);
    pf.addLocator("localhost", port1);
    pf.addLocator("localhost", port2);
    pf.addLocator("localhost", port3);
    pf.init((GatewaySender) null);
    proxy = ((PoolImpl) pf.create("KISHOR_POOL"));
    Connection con1 = proxy.acquireConnection();
    try {
        con1.close(true);
    } catch (Exception e) {
        fail("createClient failed", e);
    }
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) IOException(java.io.IOException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 14 with Connection

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

the class PooledConnection method switchConnection.

public synchronized boolean switchConnection(Connection newCon) throws InterruptedException {
    Connection oldCon = null;
    synchronized (this) {
        if (shouldDestroy())
            return false;
        if (this.active && !shouldDestroy()) {
            this.waitingToSwitch = true;
            try {
                while (this.active && !shouldDestroy()) {
                    wait();
                }
            } finally {
                this.waitingToSwitch = false;
                notifyAll();
            }
        }
        if (shouldDestroy())
            return false;
        assert !this.active;
        final long now = System.nanoTime();
        oldCon = this.connection;
        this.connection = newCon;
        this.endpoint = newCon.getEndpoint();
        this.birthDate = now;
    }
    if (oldCon != null) {
        try {
            // do this outside of sync
            oldCon.close(false);
        } catch (Exception e) {
        // ignore
        }
    }
    return true;
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection) SocketException(java.net.SocketException) InternalGemFireException(org.apache.geode.InternalGemFireException)

Example 15 with Connection

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

the class PooledConnection method internalDestroy.

public void internalDestroy() {
    // probably already set but make sure
    this.shouldDestroy.set(true);
    synchronized (this) {
        this.active = false;
        notifyAll();
        Connection myCon = connection;
        if (myCon != null) {
            myCon.destroy();
            connection = null;
        }
    }
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection)

Aggregations

Connection (org.apache.geode.cache.client.internal.Connection)21 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)10 EventID (org.apache.geode.internal.cache.EventID)7 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)6 Region (org.apache.geode.cache.Region)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 CacheException (org.apache.geode.cache.CacheException)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 GemFireIOException (org.apache.geode.GemFireIOException)2 Statistics (org.apache.geode.Statistics)2 StatisticsType (org.apache.geode.StatisticsType)2 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)2 ConnectionDestroyedException (org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2