Search in sources :

Example 21 with CacheServer

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

the class CacheXml66DUnitTest method testBridgeAttributesRelatedToClientQueuesHA.

/**
   * Tests the bridge-server attributes ({@code maximum-message-count} and
   * {@code message-time-to-live}) related to HA of client-queues in gemfire cache-server framework
   */
@Test
public void testBridgeAttributesRelatedToClientQueuesHA() throws Exception {
    CacheCreation cache = new CacheCreation();
    cache.setMessageSyncInterval(3445);
    CacheServer bs = cache.addCacheServer();
    bs.setMaximumMessageCount(12345);
    bs.setMessageTimeToLive(56789);
    bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setDataPolicy(DataPolicy.NORMAL);
    cache.createVMRegion("rootNORMAL", attrs);
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
    assertNotNull(server);
    assertEquals(12345, server.getMaximumMessageCount());
    assertEquals(56789, server.getMessageTimeToLive());
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 22 with CacheServer

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

the class CacheXml66DUnitTest method testBridgeLoadProbe.

@Test
public void testBridgeLoadProbe() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheServer server = cache.addCacheServer();
    server.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
    server.setLoadProbe(new MyLoadProbe());
    testXml(cache);
    Cache c = getCache();
    server = c.getCacheServers().get(0);
    assertEquals(MyLoadProbe.class, server.getLoadProbe().getClass());
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 23 with CacheServer

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

the class CacheServerLauncher method createCache.

protected InternalCache createCache(InternalDistributedSystem system, Map<String, Object> options) throws IOException {
    InternalCache cache = (InternalCache) CacheFactory.create(system);
    float threshold = getCriticalHeapPercent(options);
    if (threshold > 0.0f) {
        cache.getResourceManager().setCriticalHeapPercentage(threshold);
    }
    threshold = getEvictionHeapPercent(options);
    if (threshold > 0.0f) {
        cache.getResourceManager().setEvictionHeapPercentage(threshold);
    }
    threshold = getCriticalOffHeapPercent(options);
    getCriticalOffHeapPercent(options);
    if (threshold > 0.0f) {
        cache.getResourceManager().setCriticalOffHeapPercentage(threshold);
    }
    threshold = getEvictionOffHeapPercent(options);
    if (threshold > 0.0f) {
        cache.getResourceManager().setEvictionOffHeapPercentage(threshold);
    }
    // Create and start a default cache server
    // If (disableDefaultServer is not set or it is set but false) AND (the number of cacheservers
    // is 0)
    Boolean disable = disableDefaultServer;
    if ((disable == null || !disable) && cache.getCacheServers().size() == 0) {
        // Create and add a cache server
        CacheServer server = cache.addCacheServer();
        CacheServerHelper.setIsDefaultServer(server);
        // Set its port if necessary
        Integer serverPort = CacheServerLauncher.getServerPort();
        if (serverPort != null) {
            server.setPort(serverPort);
        }
        // Set its bind address if necessary
        String serverBindAddress = getServerBindAddress();
        if (serverBindAddress != null) {
            server.setBindAddress(serverBindAddress.trim());
        }
        // Start it
        server.start();
    }
    return cache;
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer)

Example 24 with CacheServer

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

the class CacheXmlParser method startCacheServer.

/**
   * When a <code>cache-server</code> element is first encountered, we create a new
   * {@link CacheCreation#addCacheServer() CacheServer} in the cache.
   *
   * @since GemFire 4.0
   */
private void startCacheServer(Attributes atts) {
    CacheServer bridge = this.cache.addCacheServer();
    String port = atts.getValue(PORT);
    if (port != null) {
        bridge.setPort(parseInt(port));
    }
    String bindAddress = atts.getValue(BIND_ADDRESS);
    if (bindAddress != null) {
        bridge.setBindAddress(bindAddress.trim());
    }
    String hostnameForClients = atts.getValue(HOSTNAME_FOR_CLIENTS);
    if (hostnameForClients != null) {
        bridge.setHostnameForClients(hostnameForClients.trim());
    }
    String maxConnections = atts.getValue(MAX_CONNECTIONS);
    if (maxConnections != null) {
        bridge.setMaxConnections(parseInt(maxConnections));
    }
    String maxThreads = atts.getValue(MAX_THREADS);
    if (maxThreads != null) {
        bridge.setMaxThreads(parseInt(maxThreads));
    }
    String notifyBySubscription = atts.getValue(NOTIFY_BY_SUBSCRIPTION);
    if (notifyBySubscription != null) {
        boolean b = Boolean.valueOf(notifyBySubscription).booleanValue();
        bridge.setNotifyBySubscription(b);
    }
    String socketBufferSize = atts.getValue(SOCKET_BUFFER_SIZE);
    if (socketBufferSize != null) {
        bridge.setSocketBufferSize(Integer.parseInt(socketBufferSize));
    }
    String tcpDelay = atts.getValue(TCP_NO_DELAY);
    if (tcpDelay != null) {
        bridge.setTcpNoDelay(Boolean.valueOf(tcpDelay).booleanValue());
    }
    String maximumTimeBetweenPings = atts.getValue(MAXIMUM_TIME_BETWEEN_PINGS);
    if (maximumTimeBetweenPings != null) {
        bridge.setMaximumTimeBetweenPings(Integer.parseInt(maximumTimeBetweenPings));
    }
    String maximumMessageCount = atts.getValue(MAXIMUM_MESSAGE_COUNT);
    if (maximumMessageCount != null) {
        bridge.setMaximumMessageCount(Integer.parseInt(maximumMessageCount));
    }
    String messageTimeToLive = atts.getValue(MESSAGE_TIME_TO_LIVE);
    if (messageTimeToLive != null) {
        bridge.setMessageTimeToLive(Integer.parseInt(messageTimeToLive));
    }
    String loadPollInterval = atts.getValue(LOAD_POLL_INTERVAL);
    if (loadPollInterval != null) {
        bridge.setLoadPollInterval(Long.parseLong(loadPollInterval));
    }
    this.stack.push(bridge);
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer)

Example 25 with CacheServer

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

the class CacheXmlGenerator method parse.

/**
   * Called by the transformer to parse the "input source". We ignore the input source and, instead,
   * generate SAX events to the {@link #setContentHandler ContentHandler}.
   */
public void parse(InputSource input) throws SAXException {
    Assert.assertTrue(this.handler != null);
    boolean isClientCache = this.creation instanceof ClientCacheCreation;
    handler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    if (this.useSchema) {
        if (null == version.getSchemaLocation()) {
            // TODO jbarrett - localize
            throw new IllegalStateException("No schema for version " + version.getVersion());
        }
        // add schema location for cache schema.
        handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
        addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
        // add cache schema to default prefix.
        handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
        addAttribute(atts, VERSION, this.version.getVersion());
    }
    if (creation.hasLockLease()) {
        atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
    }
    if (creation.hasLockTimeout()) {
        atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
    }
    if (creation.hasSearchTimeout()) {
        atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
        if (creation.hasMessageSyncInterval()) {
            atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
        if (creation.hasServer()) {
            atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
        }
        if (creation.hasCopyOnRead()) {
            atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
        }
    }
    if (isClientCache) {
        handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
    } else {
        handler.startElement("", CACHE, CACHE, atts);
    }
    if (this.cache != null) {
        if (!isClientCache) {
            generate(this.cache.getCacheTransactionManager());
        } else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generate(this.cache.getCacheTransactionManager());
        }
        generateDynamicRegionFactory(this.cache);
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
                Set<GatewaySender> senderSet = cache.getGatewaySenders();
                for (GatewaySender sender : senderSet) {
                    generateGatewaySender(sender);
                }
                generateGatewayReceiver(this.cache);
                generateAsyncEventQueue(this.cache);
            }
        }
        if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
            if (this.cache.getGatewayConflictResolver() != null) {
                generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
            }
        }
        if (!isClientCache) {
            for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
                CacheServer bridge = (CacheServer) iter.next();
                generate(bridge);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
            Iterator pools;
            if (this.cache instanceof GemFireCacheImpl) {
                pools = PoolManager.getAll().values().iterator();
            } else {
                pools = this.creation.getPools().values().iterator();
            }
            while (pools.hasNext()) {
                Pool cp = (Pool) pools.next();
                generate(cp);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
            if (this.cache instanceof GemFireCacheImpl) {
                InternalCache gfc = (InternalCache) this.cache;
                for (DiskStore ds : gfc.listDiskStores()) {
                    generate(ds);
                }
            } else {
                for (DiskStore ds : this.creation.listDiskStores()) {
                    generate(ds);
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generatePdx();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
            Map namedAttributes = this.cache.listRegionAttributes();
            for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                String id = (String) entry.getKey();
                RegionAttributes attrs = (RegionAttributes) entry.getValue();
                // Since CacheCreation predefines these even in later versions
                // we need to exclude them in all versions.
                // It would be better if CacheCreation could only predefine them
                // for versions 6.5 and later but that is not easy to do
                {
                    if (this.creation instanceof ClientCacheCreation) {
                        try {
                            ClientRegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    } else {
                        try {
                            RegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    }
                }
                generate(id, attrs);
            }
        }
        if (cache instanceof GemFireCacheImpl) {
            generateRegions();
        } else {
            TreeSet rSet = new TreeSet(new RegionComparator());
            rSet.addAll(this.cache.rootRegions());
            Iterator it = rSet.iterator();
            while (it.hasNext()) {
                Region root = (Region) it.next();
                generateRegion(root);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
            generateFunctionService();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
            generateResourceManager();
            generateSerializerRegistration();
        }
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
                if (this.cache instanceof GemFireCacheImpl) {
                    InternalCache internalCache = (InternalCache) this.cache;
                    for (File file : internalCache.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                } else {
                    for (File file : this.creation.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generateInitializer();
        }
    }
    if (cache instanceof Extensible) {
        @SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
        generate(extensible);
    }
    if (isClientCache) {
        handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
    } else {
        handler.endElement("", CACHE, CACHE);
    }
    handler.endDocument();
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Pool(org.apache.geode.cache.client.Pool) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Extensible(org.apache.geode.internal.cache.extension.Extensible) DiskStore(org.apache.geode.cache.DiskStore) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Map(java.util.Map) File(java.io.File) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache)

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