@Override void endElement(Stack<Object> stack) { RegionMapping mapping = (RegionMapping) stack.pop(); RegionCreation regionCreation = (RegionCreation) stack.peek(); regionCreation.getExtensionPoint().addExtension(new RegionMappingConfiguration(mapping)); } };
@Override public Region createSubregion(String subregionName, RegionAttributes attrs) throws RegionExistsException, TimeoutException { RegionCreation subregion = new RegionCreation(this.cache, this, subregionName, null); subregion.setAttributes(attrs); this.addSubregion(subregionName, subregion); return subregion; }
void initializeRegions(Map<String, Region<?, ?>> declarativeRegions, Cache cache) { for (Region region : declarativeRegions.values()) { RegionCreation regionCreation = (RegionCreation) region; regionCreation.createRoot(cache); } }
/** * After popping the current <code>RegionCreation</code> off the stack, if the element on top of * the stack is a <code>RegionCreation</code>, then it is the parent region. */ private void endRegion() throws RegionExistsException { RegionCreation region = (RegionCreation) stack.pop(); boolean isRoot = false; if (stack.isEmpty()) { isRoot = true; } else if (!(stack.peek() instanceof RegionCreation)) { isRoot = true; } if (isRoot) { this.cache.addRootRegion(region); } else { RegionCreation parent = (RegionCreation) stack.peek(); parent.addSubregion(region.getName(), region); } }
private void startIndex(Attributes atts) { if (!(stack.peek() instanceof RegionCreation)) { throw new CacheXmlException("lucene <index> elements must occur within <region> elements"); } final RegionCreation region = (RegionCreation) stack.peek(); String name = atts.getValue(NAME); LuceneIndexCreation indexCreation = new LuceneIndexCreation(); indexCreation.setName(name); indexCreation.setRegion(region); region.getExtensionPoint().addExtension(indexCreation); stack.push(indexCreation); cache = (CacheCreation) region.getCache(); }
@Before public void setUp() { this.parser = new LuceneXmlParser(); CacheCreation cache = Mockito.mock(CacheCreation.class); RegionCreation regionCreation = Mockito.mock(RegionCreation.class); RegionAttributesCreation rac = Mockito.mock(RegionAttributesCreation.class); Mockito.when(regionCreation.getFullPath()).thenReturn("/region"); Mockito.when(regionCreation.getAttributes()).thenReturn(rac); Mockito.when(regionCreation.getExtensionPoint()) .thenReturn(new SimpleExtensionPoint(this.rc, this.rc)); this.rc = regionCreation; this.stack = new Stack<Object>(); stack.push(cache); stack.push(rc); this.parser.setStack(stack); }
@Before public void setup() { attributes = mock(Attributes.class); regionCreation = mock(RegionCreation.class); when(regionCreation.getFullPath()).thenReturn("/region"); extensionPoint = mock(ExtensionPoint.class); when(regionCreation.getExtensionPoint()).thenReturn(extensionPoint); stack = new Stack<>(); }
/** * Test method for {@link RegionCreation#getExtensionPoint()}. * * Assert that method returns a {@link SimpleExtensionPoint} instance and assume that * {@link SimpleExtensionPointJUnitTest} has covered the rest. */ @Test public void testGetExtensionPoint() { final CacheCreation cache = new CacheCreation(); final RegionCreation region = new RegionCreation(cache, "test"); final ExtensionPoint<Region<?, ?>> extensionPoint = region.getExtensionPoint(); assertNotNull(extensionPoint); assertEquals(extensionPoint.getClass(), SimpleExtensionPoint.class); }
@Override void startElement(Stack<Object> stack, Attributes attributes) { if (!(stack.peek() instanceof RegionCreation)) { throw new CacheXmlException( "<jdbc:mapping> elements must occur within <region> elements"); } RegionCreation regionCreation = (RegionCreation) stack.peek(); RegionMapping mapping = new RegionMapping(); mapping.setRegionName(regionCreation.getFullPath().substring(1)); mapping.setDataSourceName( attributes.getValue(JdbcConnectorServiceXmlParser.DATA_SOURCE)); mapping.setTableName(attributes.getValue(JdbcConnectorServiceXmlParser.TABLE)); mapping.setPdxName(attributes.getValue(JdbcConnectorServiceXmlParser.PDX_NAME)); mapping.setIds(attributes.getValue(JdbcConnectorServiceXmlParser.IDS)); mapping.setCatalog(attributes.getValue(JdbcConnectorServiceXmlParser.CATALOG)); mapping.setSchema(attributes.getValue(JdbcConnectorServiceXmlParser.SCHEMA)); stack.push(mapping); }
/** * Note: hydra invokes this with setRefid=false. */ public void setAttributes(RegionAttributes attrs, boolean setRefid) { this.hasAttributes = true; if (attrs instanceof RegionAttributesCreation) { this.attrs = (RegionAttributesCreation) attrs; } else { this.attrs = new RegionAttributesCreation(this.cache, attrs, false); } if ((setRefid && (this.attrs.getRefid() == null))) { this.attrs.setRefid(getRefid()); } if (attrs.getPartitionAttributes() != null && attrs.getEvictionAttributes() != null && attrs.getEvictionAttributes().getAlgorithm().isLRUMemory() && attrs.getPartitionAttributes().getLocalMaxMemory() != 0 && attrs.getEvictionAttributes() .getMaximum() != attrs.getPartitionAttributes().getLocalMaxMemory()) { getCache().getLogger().warning(String.format( "For region %s with data policy PARTITION, memory LRU eviction attribute maximum has been reset from %sMB to local-max-memory %sMB", new Object[] {this.getName(), attrs.getEvictionAttributes().getMaximum(), attrs.getPartitionAttributes().getLocalMaxMemory()})); this.attrs.setEvictionAttributes(attrs.getEvictionAttributes().createLRUMemoryAttributes( attrs.getPartitionAttributes().getLocalMaxMemory(), attrs.getEvictionAttributes().getObjectSizer(), attrs.getEvictionAttributes().getAction())); } }
@Test public void declarativeRegionIsCreated() { CacheCreation cacheCreation = new CacheCreation(); RegionCreation declarativeRegion = mock(RegionCreation.class); when(declarativeRegion.getName()).thenReturn("testRegion"); Map<String, Region<?, ?>> declarativeRegions = new HashMap<>(); declarativeRegions.put("testRegion", declarativeRegion); when(this.cache.getRegion("testRegion")).thenReturn(null); cacheCreation.initializeRegions(declarativeRegions, this.cache); verify(declarativeRegion, times(1)).createRoot(this.cache); }
/** * After popping the current <code>RegionAttributesCreation</code> off the stack, we add it to the * <code>RegionCreation</code> that should be on the top of the stack. */ private void endRegionAttributes() { RegionAttributesCreation attrs = (RegionAttributesCreation) stack.pop(); CacheCreation cache; Object top = stack.peek(); if (top instanceof RegionCreation) { RegionCreation region = (RegionCreation) top; region.setAttributes(attrs); cache = (CacheCreation) region.getCache(); } else if (top instanceof CacheCreation) { cache = (CacheCreation) top; } else { String s = "Did not expected a " + top.getClass().getName() + " on top of the stack."; Assert.assertTrue(false, s); cache = null; // Dead code } String id = attrs.getId(); if (id != null) { cache.setRegionAttributes(id, attrs); } }
/** * When a <code>region</code> element is first encountered, we create a {@link RegionCreation}and * push it on the stack. */ private void startRegion(Attributes atts) { String name = atts.getValue(NAME); String refid = atts.getValue(REFID); Assert.assertTrue(name != null); RegionCreation region = new RegionCreation(this.cache, name, refid); stack.push(region); }
@Override public Region createRegion(String name, RegionAttributes aRegionAttributes) throws RegionExistsException, TimeoutException { if (aRegionAttributes instanceof RegionAttributesCreation) { ((RegionAttributesCreation) aRegionAttributes).inheritAttributes(this); ((RegionAttributesCreation) aRegionAttributes).prepareForValidation(); } AttributesFactory.validateAttributes(aRegionAttributes); RegionCreation region = new RegionCreation(this, name, null); region.setAttributes(aRegionAttributes); this.addRootRegion(region); return region; }
if (!this.getName().equals(other.getName())) { throw new RuntimeException(String.format("region names differ: this: %s other: %s", new Object[] {this.getName(), other.getName()})); Collection myEntries = this.basicEntries(false); Collection otherEntries = ((LocalRegion) other).basicEntries(false); if (myEntries.size() != otherEntries.size()) {
/** * Sets the attributes of the root region * * @throws RegionExistsException If this cache already contains a region with the same name as * {@code root}. */ void addRootRegion(RegionCreation root) throws RegionExistsException { String name = root.getName(); RegionCreation existing = (RegionCreation) this.roots.get(name); if (existing != null) { throw new RegionExistsException(existing); } else { this.roots.put(root.getName(), root); } }
/** * Creates a new <code>RegionCreation</code> with the given name and with the default * <code>RegionAttributes</code>. */ public RegionCreation(CacheCreation cache, RegionCreation parent, String name, String refid) { this.cache = cache; if (parent != null) { this.fullPath = parent.getFullPath() + SEPARATOR + name; } else { this.fullPath = SEPARATOR + name; } this.name = name; this.refid = refid; this.attrs = new RegionAttributesCreation(this.cache); if (refid != null) { this.attrs.setRefid(refid); this.attrs.inheritAttributes(cache); } }
public Region createRegion(String name, String refid) throws RegionExistsException, TimeoutException { RegionCreation region = new RegionCreation(this, name, refid); this.addRootRegion(region); return region; }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { switch (localName) { case ELEMENT_CACHE: { MockCacheExtension extension = (MockCacheExtension) stack.pop(); CacheCreation cache = (CacheCreation) stack.peek(); cache.getExtensionPoint().addExtension(extension); break; } case ELEMENT_REGION: { MockRegionExtension extension = (MockRegionExtension) stack.pop(); RegionCreation region = (RegionCreation) stack.peek(); region.getExtensionPoint().addExtension(extension); break; } default: throw new SAXParseException("Unexpected element '" + localName + "'.", documentLocator); } }