use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class QueryResultData method setUp.
@Before
public void setUp() throws Exception {
AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
if (agentUtil.findWarLocation("geode-web-api") == null) {
fail("unable to locate geode-web-api WAR file");
}
this.restServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
try {
InetAddress addr = SocketCreator.getLocalHost();
this.hostName = addr.getHostName();
} catch (UnknownHostException ex) {
this.hostName = ManagementConstants.DEFAULT_HOST_NAME;
}
String workingDirectory = System.getProperty("geode.build.dir", System.getProperty("user.dir"));
ServerLauncher serverLauncher = new ServerLauncher.Builder().set(MCAST_PORT, "0").setServerBindAddress(this.hostName).setServerPort(0).set(START_DEV_REST_API, "true").set(HTTP_SERVICE_PORT, String.valueOf(this.restServicePort)).set(HTTP_SERVICE_BIND_ADDRESS, this.hostName).setPdxReadSerialized(true).setWorkingDirectory(workingDirectory).build();
serverLauncher.start();
this.baseURL = "http://" + this.hostName + ":" + this.restServicePort;
this.c = CacheFactory.getAnyInstance();
final AttributesFactory<String, String> attributesFactory = new AttributesFactory<>();
attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
// Create region, customers
final RegionAttributes<String, String> regionAttributes = attributesFactory.create();
c.createRegion(CUSTOMER_REGION, regionAttributes);
// Create region, items
attributesFactory.setDataPolicy(DataPolicy.PARTITION);
c.createRegion(ITEM_REGION, regionAttributes);
// Create region, /orders
final AttributesFactory<Object, Object> af2 = new AttributesFactory<>();
af2.setDataPolicy(DataPolicy.PARTITION);
final RegionAttributes<Object, Object> rAttributes2 = af2.create();
c.createRegion(ORDER_REGION, rAttributes2);
// Create region, primitiveKVStore
final AttributesFactory<Object, Object> af1 = new AttributesFactory<>();
af1.setDataPolicy(DataPolicy.PARTITION);
final RegionAttributes<Object, Object> rAttributes = af1.create();
c.createRegion(PRIMITIVE_KV_STORE_REGION, rAttributes);
RegionFactory<String, Object> rf = c.createRegionFactory(RegionShortcut.REPLICATE);
rf.setDataPolicy(DataPolicy.EMPTY);
rf.setCacheLoader(new SimpleCacheLoader());
rf.setCacheWriter(new SampleCacheWriter());
rf.create(EMPTY_REGION);
// Register functions here
FunctionService.registerFunction(new GetAllEntries());
FunctionService.registerFunction(new GetRegions());
FunctionService.registerFunction(new PutKeyFunction());
FunctionService.registerFunction(new GetDeliveredOrders());
FunctionService.registerFunction(new AddFreeItemToOrders());
FunctionService.registerFunction(new NoArgumentFunction());
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class RestAPIsWithSSLDUnitTest method startBridgeServer.
@SuppressWarnings("deprecation")
protected int startBridgeServer(String hostName, int restServicePort, final String locators, final String[] regions, final Properties sslProperties, boolean clusterLevel) {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(restServicePort));
System.setProperty("javax.net.debug", "ssl,handshake");
props = configureSSL(props, sslProperties, clusterLevel);
DistributedSystem ds = getSystem(props);
InternalCache cache = (InternalCache) CacheFactory.create(ds);
cache.setReadSerialized(true);
AttributesFactory factory = new AttributesFactory();
factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
CacheServer server = cache.addCacheServer();
server.setPort(0);
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
remoteObjects.put(CACHE_KEY, cache);
return server.getPort();
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class RegionHelper method getRegionAttributes.
private static RegionAttributes getRegionAttributes(Cache cache, RegionConfiguration configuration) {
// Create the requested attributes
RegionAttributes baseRequestedAttributes = cache.getRegionAttributes(configuration.getRegionAttributesId());
if (baseRequestedAttributes == null) {
throw new IllegalArgumentException("No region attributes named " + configuration.getRegionAttributesId() + " are defined.");
}
AttributesFactory requestedFactory = new AttributesFactory(baseRequestedAttributes);
// Set the expiration time and action if necessary
int maxInactiveInterval = configuration.getMaxInactiveInterval();
if (maxInactiveInterval != RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) {
requestedFactory.setStatisticsEnabled(true);
if (configuration.getCustomExpiry() == null) {
requestedFactory.setEntryIdleTimeout(new ExpirationAttributes(maxInactiveInterval, ExpirationAction.DESTROY));
} else {
requestedFactory.setCustomEntryIdleTimeout(configuration.getCustomExpiry());
}
}
// Add the gateway delta region cache listener if necessary
if (configuration.getEnableGatewayDeltaReplication()) {
// Add the listener that forwards created/destroyed deltas to the gateway
requestedFactory.addCacheListener(new GatewayDeltaForwarderCacheListener(cache));
}
// Add the debug cache listener if necessary
if (configuration.getEnableDebugListener()) {
requestedFactory.addCacheListener(new DebugCacheListener());
}
if (configuration.getSessionExpirationCacheListener()) {
requestedFactory.addCacheListener(new SessionExpirationCacheListener());
}
// Add the cacheWriter if necessary
if (configuration.getCacheWriterName() != null) {
try {
CacheWriter writer = (CacheWriter) Class.forName(configuration.getCacheWriterName()).newInstance();
requestedFactory.setCacheWriter(writer);
} catch (InstantiationException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
}
}
return requestedFactory.create();
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class CreateRegionFunction method createRegionConfigurationMetadataRegion.
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() {
// a sessionFactory in hibernate could have been re-started
// so, it is possible that this region exists already
Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION);
if (r != null) {
return r;
}
GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache;
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true);
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.LOCAL);
af.addCacheListener(new RegionConfigurationCacheListener());
RegionAttributes ra = af.create();
try {
return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira);
} catch (IOException | ClassNotFoundException e) {
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class ClientHealthMonitoringRegion method initialize.
/**
* This method creates the client health monitoring region.
* <p>
* GuardedBy ClientHealthMonitoringRegion.class
*
* @param cache The current GemFire Cache
*/
private static void initialize(InternalCache cache) {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEntryTimeToLive(new ExpirationAttributes(ADMIN_REGION_EXPIRY_INTERVAL, ExpirationAction.DESTROY));
cache.getLogger().fine("ClientHealthMonitoringRegion, setting TTL for entry....");
factory.addCacheListener(prepareCacheListener());
factory.setStatisticsEnabled(true);
RegionAttributes regionAttrs = factory.create();
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
internalArgs.setIsUsedForPartitionedRegionAdmin(false);
currentInstance = cache.createVMRegion(ADMIN_REGION_NAME, regionAttrs, internalArgs);
} catch (Exception ex) {
cache.getLoggerI18n().error(LocalizedStrings.ClientHealthMonitoringRegion_ERROR_WHILE_CREATING_AN_ADMIN_REGION, ex);
}
}
Aggregations