Search in sources :

Example 66 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class LocatorLoadBalancingDUnitTest method checkConnectionCount.

private void checkConnectionCount(final int count) {
    Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
    final CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().get(0);
    Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS).pollInterval(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        int sz = server.getAcceptor().getStats().getCurrentClientConnections();
        if (Math.abs(sz - count) <= ALLOWABLE_ERROR_IN_COUNT) {
            return true;
        }
        System.out.println("Found " + sz + " connections, expected " + count);
        return false;
    });
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Cache(org.apache.geode.cache.Cache)

Example 67 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class InternalClientMembership method getConnectedClients.

/**
   * Caller must synchronize on cache.allClientServersLock
   * 
   * @return all the clients
   */
public static Map getConnectedClients() {
    // Get all clients
    Map allClients = new HashMap();
    for (Iterator bsii = CacheFactory.getAnyInstance().getCacheServers().iterator(); bsii.hasNext(); ) {
        CacheServerImpl bsi = (CacheServerImpl) bsii.next();
        AcceptorImpl ai = bsi.getAcceptor();
        if (ai != null && ai.getCacheClientNotifier() != null) {
            allClients.putAll(ai.getCacheClientNotifier().getAllClients());
        }
    }
    // Fill in the missing info, if HealthMonitor started
    if (ClientHealthMonitor.getInstance() != null)
        ClientHealthMonitor.getInstance().fillInClientInfo(allClients);
    return allClients;
}
Also used : HashMap(java.util.HashMap) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class InternalClientMembership method getClientQueueSizes.

public static Map getClientQueueSizes() {
    Map clientQueueSizes = new HashMap();
    InternalCache c = (InternalCache) CacheFactory.getAnyInstance();
    if (// Add a NULL Check
    c == null)
        return clientQueueSizes;
    for (Iterator bsii = c.getCacheServers().iterator(); bsii.hasNext(); ) {
        CacheServerImpl bsi = (CacheServerImpl) bsii.next();
        AcceptorImpl ai = bsi.getAcceptor();
        if (ai != null && ai.getCacheClientNotifier() != null) {
            clientQueueSizes.putAll(ai.getCacheClientNotifier().getClientQueueSizes());
        }
    }
    // for
    return clientQueueSizes;
}
Also used : HashMap(java.util.HashMap) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) Iterator(java.util.Iterator) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class BridgeServerResponse method create.

/**
   * Creates a {@code BridgeServerResponse} in response to the given request.
   */
static BridgeServerResponse create(DistributionManager dm, BridgeServerRequest request) {
    BridgeServerResponse m = new BridgeServerResponse();
    m.setRecipient(request.getSender());
    try {
        InternalCache cache = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem());
        if (request.getCacheId() != System.identityHashCode(cache)) {
            m.bridgeInfo = null;
        } else {
            int operation = request.getOperation();
            switch(operation) {
                case BridgeServerRequest.ADD_OPERATION:
                    {
                        CacheServerImpl bridge = (CacheServerImpl) cache.addCacheServer();
                        m.bridgeInfo = new RemoteBridgeServer(bridge);
                        break;
                    }
                case BridgeServerRequest.INFO_OPERATION:
                    {
                        int id = request.getBridgeId();
                        // it is not necessary to synchronize on allBridgeServersLock
                        for (CacheServer cacheServer : cache.getCacheServers()) {
                            CacheServerImpl bridge = (CacheServerImpl) cacheServer;
                            if (System.identityHashCode(bridge) == id) {
                                m.bridgeInfo = new RemoteBridgeServer(bridge);
                                break;
                            } else {
                                m.bridgeInfo = null;
                            }
                        }
                        break;
                    }
                case BridgeServerRequest.START_OPERATION:
                    {
                        RemoteBridgeServer config = request.getBridgeInfo();
                        for (CacheServer cacheServer : cache.getCacheServers()) {
                            CacheServerImpl bridge = (CacheServerImpl) cacheServer;
                            if (System.identityHashCode(bridge) == config.getId()) {
                                bridge.configureFrom(config);
                                bridge.start();
                                m.bridgeInfo = new RemoteBridgeServer(bridge);
                                break;
                            } else {
                                m.bridgeInfo = null;
                            }
                        }
                        break;
                    }
                case BridgeServerRequest.STOP_OPERATION:
                    {
                        RemoteBridgeServer config = request.getBridgeInfo();
                        for (CacheServer cacheServer : cache.getCacheServers()) {
                            CacheServerImpl bridge = (CacheServerImpl) cacheServer;
                            if (System.identityHashCode(bridge) == config.getId()) {
                                bridge.stop();
                                m.bridgeInfo = new RemoteBridgeServer(bridge);
                                break;
                            } else {
                                m.bridgeInfo = null;
                            }
                        }
                        break;
                    }
                default:
                    Assert.assertTrue(false, "Unknown bridge server operation: " + operation);
            }
        }
    } catch (CancelException ignore) {
        m.bridgeInfo = null;
    } catch (Exception ex) {
        m.exception = ex;
        m.bridgeInfo = null;
    }
    return m;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CancelException(org.apache.geode.CancelException)

Example 70 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class DurableClientInfoResponse method create.

/**
   * Returns a {@code DurableClientInfoResponse} that will be returned to the specified recipient.
   */
public static DurableClientInfoResponse create(DistributionManager dm, InternalDistributedMember recipient, DurableClientInfoRequest request) {
    DurableClientInfoResponse m = new DurableClientInfoResponse();
    m.setRecipient(recipient);
    try {
        InternalCache c = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem());
        if (!c.getCacheServers().isEmpty()) {
            CacheServerImpl server = (CacheServerImpl) c.getCacheServers().iterator().next();
            switch(request.action) {
                case DurableClientInfoRequest.HAS_DURABLE_CLIENT_REQUEST:
                    {
                        m.returnVal = server.getAcceptor().getCacheClientNotifier().hasDurableClient(request.durableId);
                        break;
                    }
                case DurableClientInfoRequest.IS_PRIMARY_FOR_DURABLE_CLIENT_REQUEST:
                    {
                        m.returnVal = server.getAcceptor().getCacheClientNotifier().hasPrimaryForDurableClient(request.durableId);
                        break;
                    }
            }
        }
    } catch (CacheClosedException ignore) {
    // do nothing
    }
    return m;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)76 Iterator (java.util.Iterator)23 Cache (org.apache.geode.cache.Cache)19 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)19 CacheServer (org.apache.geode.cache.server.CacheServer)14 IOException (java.io.IOException)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13 CacheException (org.apache.geode.cache.CacheException)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 Set (java.util.Set)7 InternalCache (org.apache.geode.internal.cache.InternalCache)7 Map (java.util.Map)6 Properties (java.util.Properties)6 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 HashMap (java.util.HashMap)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)5