Search in sources :

Example 6 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ClientServerRegisterInterestsDUnitTest method setupGemFireCacheServer.

private void setupGemFireCacheServer() {
    Host localhost = Host.getHost(0);
    gemfireServerVm = localhost.getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    gemfireServerVm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0").set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory();
                regionFactory.setDataPolicy(DataPolicy.REPLICATE);
                regionFactory.setKeyConstraint(String.class);
                regionFactory.setValueConstraint(String.class);
                Region<String, String> example = regionFactory.create("Example");
                assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
                assertEquals("/Example", example.getFullPath());
                assertEquals("Example", example.getName());
                assertTrue(example.isEmpty());
                example.put("1", "ONE");
                assertFalse(example.isEmpty());
                assertEquals(1, example.size());
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();
                clientSubscriptionConfig.setCapacity(100);
                clientSubscriptionConfig.setEvictionPolicy("entry");
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException(String.format("Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", serverPort.get()), e);
            }
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) RegionFactory(org.apache.geode.cache.RegionFactory) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 7 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class RemoveAllCacheListenerClientServerRegressionTest method setupGemFireCacheServer.

// ================================================================================
private void setupGemFireCacheServer(RegionShortcut shortcut, boolean concChecks) {
    serverVM = Host.getHost(0).getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    String serverName = this.getClass().getSimpleName() + "_server";
    serverVM.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", serverName).set(MCAST_PORT, "0").set(LOG_FILE, serverName + ".log").set(LOG_LEVEL, "config").set("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory(shortcut);
                regionFactory.addCacheListener(new TestListener());
                regionFactory.setConcurrencyChecksEnabled(concChecks);
                regionFactory.create(REGION_NAME);
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException("Failed to start cache server " + serverName + " on port " + serverPort.get() + ": " + e.getStackTrace());
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 8 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DescribeDiskStoreFunction method setCacheServerDetails.

protected void setCacheServerDetails(final InternalCache cache, final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) {
    for (CacheServer cacheServer : cache.getCacheServers()) {
        if (isUsingDiskStore(cacheServer, diskStore)) {
            DiskStoreDetails.CacheServerDetails cacheServerDetails = new DiskStoreDetails.CacheServerDetails(cacheServer.getBindAddress(), cacheServer.getPort());
            cacheServerDetails.setHostName(cacheServer.getHostnameForClients());
            diskStoreDetails.add(cacheServerDetails);
        }
    }
}
Also used : DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 9 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class GetMemberConfigInformationFunction method execute.

@Override
public void execute(FunctionContext context) {
    Object argsObject = context.getArguments();
    boolean hideDefaults = ((Boolean) argsObject).booleanValue();
    Cache cache = CacheFactory.getAnyInstance();
    InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
    DistributionConfig config = system.getConfig();
    DistributionConfigImpl distConfigImpl = ((DistributionConfigImpl) config);
    MemberConfigurationInfo memberConfigInfo = new MemberConfigurationInfo();
    memberConfigInfo.setJvmInputArguments(getJvmInputArguments());
    memberConfigInfo.setGfePropsRuntime(distConfigImpl.getConfigPropsFromSource(ConfigSource.runtime()));
    memberConfigInfo.setGfePropsSetUsingApi(distConfigImpl.getConfigPropsFromSource(ConfigSource.api()));
    if (!hideDefaults)
        memberConfigInfo.setGfePropsSetWithDefaults(distConfigImpl.getConfigPropsFromSource(null));
    memberConfigInfo.setGfePropsSetFromFile(distConfigImpl.getConfigPropsDefinedUsingFiles());
    // CacheAttributes
    Map<String, String> cacheAttributes = new HashMap<String, String>();
    cacheAttributes.put("copy-on-read", Boolean.toString(cache.getCopyOnRead()));
    cacheAttributes.put("is-server", Boolean.toString(cache.isServer()));
    cacheAttributes.put("lock-timeout", Integer.toString(cache.getLockTimeout()));
    cacheAttributes.put("lock-lease", Integer.toString(cache.getLockLease()));
    cacheAttributes.put("message-sync-interval", Integer.toString(cache.getMessageSyncInterval()));
    cacheAttributes.put("search-timeout", Integer.toString(cache.getSearchTimeout()));
    if (cache.getPdxDiskStore() == null) {
        cacheAttributes.put("pdx-disk-store", "");
    } else {
        cacheAttributes.put("pdx-disk-store", cache.getPdxDiskStore());
    }
    cacheAttributes.put("pdx-ignore-unread-fields", Boolean.toString(cache.getPdxIgnoreUnreadFields()));
    cacheAttributes.put("pdx-persistent", Boolean.toString(cache.getPdxPersistent()));
    cacheAttributes.put("pdx-read-serialized", Boolean.toString(cache.getPdxReadSerialized()));
    if (hideDefaults) {
        removeDefaults(cacheAttributes, getCacheAttributesDefaultValues());
    }
    memberConfigInfo.setCacheAttributes(cacheAttributes);
    List<Map<String, String>> cacheServerAttributesList = new ArrayList<Map<String, String>>();
    List<CacheServer> cacheServers = cache.getCacheServers();
    if (cacheServers != null)
        for (CacheServer cacheServer : cacheServers) {
            Map<String, String> cacheServerAttributes = new HashMap<String, String>();
            cacheServerAttributes.put("bind-address", cacheServer.getBindAddress());
            cacheServerAttributes.put("hostname-for-clients", cacheServer.getHostnameForClients());
            cacheServerAttributes.put("max-connections", Integer.toString(cacheServer.getMaxConnections()));
            cacheServerAttributes.put("maximum-message-count", Integer.toString(cacheServer.getMaximumMessageCount()));
            cacheServerAttributes.put("maximum-time-between-pings", Integer.toString(cacheServer.getMaximumTimeBetweenPings()));
            cacheServerAttributes.put("max-threads", Integer.toString(cacheServer.getMaxThreads()));
            cacheServerAttributes.put("message-time-to-live", Integer.toString(cacheServer.getMessageTimeToLive()));
            cacheServerAttributes.put("notify-by-subscription", Boolean.toString(cacheServer.getNotifyBySubscription()));
            cacheServerAttributes.put("port", Integer.toString(cacheServer.getPort()));
            cacheServerAttributes.put(SOCKET_BUFFER_SIZE, Integer.toString(cacheServer.getSocketBufferSize()));
            cacheServerAttributes.put("load-poll-interval", Long.toString(cacheServer.getLoadPollInterval()));
            cacheServerAttributes.put("tcp-no-delay", Boolean.toString(cacheServer.getTcpNoDelay()));
            if (hideDefaults)
                removeDefaults(cacheServerAttributes, getCacheServerAttributesDefaultValues());
            cacheServerAttributesList.add(cacheServerAttributes);
        }
    memberConfigInfo.setCacheServerAttributes(cacheServerAttributesList);
    context.getResultSender().lastResult(memberConfigInfo);
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) MemberConfigurationInfo(org.apache.geode.management.internal.cli.domain.MemberConfigurationInfo) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 10 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class GetMemberInformationFunction method execute.

@Override
public void execute(FunctionContext functionContext) {
    try {
        Cache cache = CacheFactory.getAnyInstance();
        /*
       * TODO: 1) Get the CPU usage%
       */
        InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
        DistributionConfig config = system.getConfig();
        String serverBindAddress = config.getServerBindAddress();
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemberInformation memberInfo = new MemberInformation();
        memberInfo.setGroups(config.getGroups());
        memberInfo.setLogFilePath(config.getLogFile().getCanonicalPath());
        memberInfo.setStatArchiveFilePath(config.getStatisticArchiveFile().getCanonicalPath());
        memberInfo.setWorkingDirPath(System.getProperty("user.dir"));
        memberInfo.setCacheXmlFilePath(config.getCacheXmlFile().getCanonicalPath());
        memberInfo.setLocators(config.getLocators());
        memberInfo.setServerBindAddress(serverBindAddress);
        memberInfo.setOffHeapMemorySize(config.getOffHeapMemorySize());
        MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
        memberInfo.setHeapUsage(Long.toString(bytesToMeg(memUsage.getUsed())));
        memberInfo.setMaxHeapSize(Long.toString(bytesToMeg(memUsage.getMax())));
        memberInfo.setInitHeapSize(Long.toString(bytesToMeg(memUsage.getInit())));
        memberInfo.setHostedRegions(CliUtil.getAllRegionNames());
        List<CacheServer> csList = cache.getCacheServers();
        // A member is a server only if it has a cacheserver
        if (csList != null) {
            memberInfo.setServer(true);
            Iterator<CacheServer> iters = csList.iterator();
            while (iters.hasNext()) {
                CacheServer cs = iters.next();
                String bindAddress = cs.getBindAddress();
                int port = cs.getPort();
                boolean isRunning = cs.isRunning();
                CacheServerInfo cacheServerInfo = new CacheServerInfo(bindAddress, port, isRunning);
                memberInfo.addCacheServerInfo(cacheServerInfo);
            }
            Map<ClientProxyMembershipID, CacheClientStatus> allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
            Iterator<ClientProxyMembershipID> it = allConnectedClients.keySet().iterator();
            int numConnections = 0;
            while (it.hasNext()) {
                CacheClientStatus status = allConnectedClients.get(it.next());
                numConnections = numConnections + status.getNumberOfConnections();
            }
            memberInfo.setClientCount(numConnections);
        } else {
            memberInfo.setServer(false);
        }
        functionContext.getResultSender().lastResult(memberInfo);
    } catch (CacheClosedException e) {
        functionContext.getResultSender().sendException(e);
    } catch (Exception e) {
        functionContext.getResultSender().sendException(e);
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) CacheClosedException(org.apache.geode.cache.CacheClosedException) MemoryUsage(java.lang.management.MemoryUsage) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) MemoryMXBean(java.lang.management.MemoryMXBean) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheServer (org.apache.geode.cache.server.CacheServer)323 AttributesFactory (org.apache.geode.cache.AttributesFactory)99 Properties (java.util.Properties)97 Test (org.junit.Test)77 Cache (org.apache.geode.cache.Cache)76 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)76 RegionAttributes (org.apache.geode.cache.RegionAttributes)60 IOException (java.io.IOException)53 ClientCache (org.apache.geode.cache.client.ClientCache)53 Region (org.apache.geode.cache.Region)50 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)49 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)33 Iterator (java.util.Iterator)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)30 Host (org.apache.geode.test.dunit.Host)27 VM (org.apache.geode.test.dunit.VM)25 DistributedSystem (org.apache.geode.distributed.DistributedSystem)20 CacheException (org.apache.geode.cache.CacheException)17 CacheFactory (org.apache.geode.cache.CacheFactory)17