Search in sources :

Example 1 with StringPrintWriter

use of org.apache.geode.internal.shared.StringPrintWriter in project geode by apache.

the class GMSMembershipManager method saveCacheXmlForReconnect.

/** generate XML from the cache before shutting down due to forced disconnect */
public void saveCacheXmlForReconnect(boolean sharedConfigEnabled) {
    // first save the current cache description so reconnect can rebuild the cache
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null) {
        if (!Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "autoReconnect-useCacheXMLFile") && !sharedConfigEnabled) {
            try {
                logger.info("generating XML to rebuild the cache after reconnect completes");
                StringPrintWriter pw = new StringPrintWriter();
                CacheXmlGenerator.generate((Cache) cache, pw, true, false);
                String cacheXML = pw.toString();
                cache.getCacheConfig().setCacheXMLDescription(cacheXML);
                logger.info("XML generation completed: {}", cacheXML);
            } catch (CancelException e) {
                logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_PROBLEM_GENERATING_CACHE_XML), e);
            }
        } else if (sharedConfigEnabled && !cache.getCacheServers().isEmpty()) {
            // we need to retain a cache-server description if this JVM was started by gfsh
            List<CacheServerCreation> list = new ArrayList<>(cache.getCacheServers().size());
            for (final Object o : cache.getCacheServers()) {
                CacheServerImpl cs = (CacheServerImpl) o;
                if (cs.isDefaultServer()) {
                    CacheServerCreation bsc = new CacheServerCreation(cache, cs);
                    list.add(bsc);
                }
            }
            cache.getCacheConfig().setCacheServerCreation(list);
            logger.info("CacheServer configuration saved");
        }
    }
}
Also used : StringPrintWriter(org.apache.geode.internal.shared.StringPrintWriter) CacheServerCreation(org.apache.geode.internal.cache.xmlcache.CacheServerCreation) InternalCache(org.apache.geode.internal.cache.InternalCache) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CancelException (org.apache.geode.CancelException)1 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 CacheServerCreation (org.apache.geode.internal.cache.xmlcache.CacheServerCreation)1 StringPrintWriter (org.apache.geode.internal.shared.StringPrintWriter)1