Search in sources :

Example 1 with CacheServerImpl

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

the class InternalDistributedSystem method createAndStartCacheServers.

/**
   * after an auto-reconnect we may need to recreate a cache server and start it
   */
public void createAndStartCacheServers(List<CacheServerCreation> cacheServerCreation, InternalCache cache) {
    List<CacheServer> servers = cache.getCacheServers();
    // to recreate it.
    if (servers.isEmpty() && cacheServerCreation != null) {
        for (CacheServerCreation bridge : cacheServerCreation) {
            CacheServerImpl impl = (CacheServerImpl) cache.addCacheServer();
            impl.configureFrom(bridge);
        }
    }
    servers = cache.getCacheServers();
    for (CacheServer server : servers) {
        try {
            if (!server.isRunning()) {
                server.start();
            }
        } catch (IOException ex) {
            throw new GemFireIOException(LocalizedStrings.CacheCreation_WHILE_STARTING_CACHE_SERVER_0.toLocalizedString(server), ex);
        }
    }
}
Also used : CacheServerCreation(org.apache.geode.internal.cache.xmlcache.CacheServerCreation) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireIOException(org.apache.geode.GemFireIOException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException)

Example 2 with CacheServerImpl

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

the class CacheServerBridge method getClientVersion.

public Version getClientVersion(ClientConnInfo connInfo) {
    InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
    if (cache.getCacheServers().size() == 0) {
        return null;
    }
    CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
    if (server == null) {
        return null;
    }
    AcceptorImpl acceptorImpl = server.getAcceptor();
    if (acceptorImpl == null) {
        return null;
    }
    ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
    boolean flag = false;
    if (connInfo.toString().contains("primary=true")) {
        flag = true;
    }
    for (ServerConnection conn : serverConnections) {
        ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
        ClientConnInfo cci = new ClientConnInfo(conn.getProxyID(), conn.getSocketHost(), conn.getSocketPort(), flag);
        if (connInfo.toString().equals(cci.toString())) {
            return cliIdFrmProxy.getClientVersion();
        }
    }
    // check form ccp
    ClientProxyMembershipID proxyId = connInfo.getClientId();
    CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
    if (proxy != null) {
        return proxy.getVersion();
    } else {
        return null;
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 3 with CacheServerImpl

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

the class GatewayReceiverMBeanBridge method getConnectedGatewaySenders.

public String[] getConnectedGatewaySenders() {
    Set<String> uniqueIds = null;
    AcceptorImpl acceptor = ((CacheServerImpl) rcv.getServer()).getAcceptor();
    Set<ServerConnection> serverConnections = acceptor.getAllServerConnections();
    if (serverConnections != null && serverConnections.size() > 0) {
        uniqueIds = new HashSet<String>();
        for (ServerConnection conn : serverConnections) {
            uniqueIds.add(conn.getMembershipID());
        }
        String[] allConnectedClientStr = new String[uniqueIds.size()];
        return uniqueIds.toArray(allConnectedClientStr);
    }
    return new String[0];
}
Also used : AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 4 with CacheServerImpl

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

the class ContunuousQueryFunction method execute.

@Override
public void execute(FunctionContext context) {
    try {
        String clientID = (String) context.getArguments();
        InternalCache cache = getCache();
        if (cache.getCacheServers().size() > 0) {
            CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
            if (server != null) {
                AcceptorImpl acceptorImpl = server.getAcceptor();
                if (acceptorImpl != null) {
                    CacheClientNotifier cacheClientNotifier = acceptorImpl.getCacheClientNotifier();
                    if (cacheClientNotifier != null) {
                        Collection<CacheClientProxy> cacheClientProxySet = cacheClientNotifier.getClientProxies();
                        ClientInfo clientInfo = null;
                        boolean foundClientinCCP = false;
                        Iterator<CacheClientProxy> it = cacheClientProxySet.iterator();
                        while (it.hasNext()) {
                            CacheClientProxy ccp = it.next();
                            if (ccp != null) {
                                String clientIdFromProxy = ccp.getProxyID().getDSMembership();
                                if (clientIdFromProxy != null && clientIdFromProxy.equals(clientID)) {
                                    foundClientinCCP = true;
                                    String durableId = ccp.getProxyID().getDurableId();
                                    boolean isPrimary = ccp.isPrimary();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), (isPrimary == true ? cache.getDistributedSystem().getDistributedMember().getId() : ""), (isPrimary == false ? cache.getDistributedSystem().getDistributedMember().getId() : ""));
                                    break;
                                }
                            }
                        }
                        // try getting from server connections
                        if (foundClientinCCP == false) {
                            ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
                            for (ServerConnection conn : serverConnections) {
                                ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
                                if (clientID.equals(cliIdFrmProxy.getDSMembership())) {
                                    String durableId = cliIdFrmProxy.getDurableId();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), "N.A.", "N.A.");
                                }
                            }
                        }
                        context.getResultSender().lastResult(clientInfo);
                    }
                }
            }
        }
    } catch (Exception e) {
        context.getResultSender().lastResult("Exception in ContunuousQueryFunction =" + e.getMessage());
    }
    context.getResultSender().lastResult(null);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 5 with CacheServerImpl

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

the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.

@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
    final String regionName1 = this.getName() + "-1";
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM client = host.getVM(2);
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.REPLICATE);
            factory.setConcurrencyChecksEnabled(false);
            createRegion(regionName1, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    // Create server1.
    server1.invoke(createServer);
    final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getLonerSystem();
            getCache();
            Region region1 = null;
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            regionFactory.setConcurrencyChecksEnabled(false);
            ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
            region1 = createRegion(regionName1, regionFactory.create());
            region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
        }
    };
    // Create client.
    client.invoke(createPool);
    // Init values at server.
    server1.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 20; i++) {
                region1.put("key-string-" + i, "value-" + i);
            }
        }
    });
    // Put some values on the client.
    client.invoke(new CacheSerializableRunnable("Put values client") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 10; i++) {
                region1.put("key-string-" + i, "client-value-" + i);
            }
        }
    });
    SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            String pName = region1.getAttributes().getPoolName();
            region1.localDestroyRegion();
            PoolImpl p = (PoolImpl) PoolManager.find(pName);
            p.destroy();
        }
    };
    client.invoke(closePool);
    SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {

        public void run2() throws CacheException {
            for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
                CacheServerImpl bsi = (CacheServerImpl) bi.next();
                final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
                WaitCriterion ev = new WaitCriterion() {

                    public boolean done() {
                        return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 62 * 1000, 200, true);
                assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
            }
        }
    };
    server1.invoke(validateClientRegisterUnRegister);
    server1.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) CacheClientNotifierStats(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifierStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

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