Search in sources :

Example 1 with AttributesFactory

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());
}
Also used : UnknownHostException(java.net.UnknownHostException) AgentUtil(org.apache.geode.management.internal.AgentUtil) ServerLauncher(org.apache.geode.distributed.ServerLauncher) AttributesFactory(org.apache.geode.cache.AttributesFactory) JSONObject(org.json.JSONObject) InetAddress(java.net.InetAddress) Before(org.junit.Before)

Example 2 with AttributesFactory

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();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Example 3 with AttributesFactory

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();
}
Also used : GatewayDeltaForwarderCacheListener(org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener) RegionAttributes(org.apache.geode.cache.RegionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) SessionExpirationCacheListener(org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener) CacheWriter(org.apache.geode.cache.CacheWriter) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 4 with AttributesFactory

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;
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 5 with AttributesFactory

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);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1156 Region (org.apache.geode.cache.Region)565 Test (org.junit.Test)550 RegionAttributes (org.apache.geode.cache.RegionAttributes)471 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)468 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)356 VM (org.apache.geode.test.dunit.VM)304 Host (org.apache.geode.test.dunit.Host)288 Properties (java.util.Properties)244 CacheException (org.apache.geode.cache.CacheException)243 Cache (org.apache.geode.cache.Cache)229 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)206 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)201 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)199 LocalRegion (org.apache.geode.internal.cache.LocalRegion)173 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)156 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)139 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)129 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)126 IgnoredException (org.apache.geode.test.dunit.IgnoredException)125