Search in sources :

Example 1 with InvalidValueException

use of org.apache.geode.InvalidValueException in project geode by apache.

the class CacheServerImpl method getAttribFactoryForClientMessagesRegion.

public static AttributesFactory getAttribFactoryForClientMessagesRegion(InternalCache cache, String ePolicy, int capacity, String overflowDir, boolean isDiskStore) throws InvalidValueException, GemFireIOException {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    if (isDiskStore) {
        // overflowDir parameter is actually diskstore name
        factory.setDiskStoreName(overflowDir);
        // client subscription queue is always overflow to disk, so do async
        // see feature request #41479
        factory.setDiskSynchronous(true);
    } else if (overflowDir == null || overflowDir.equals(ClientSubscriptionConfig.DEFAULT_OVERFLOW_DIRECTORY)) {
        factory.setDiskStoreName(null);
        // client subscription queue is always overflow to disk, so do async
        // see feature request #41479
        factory.setDiskSynchronous(true);
    } else {
        File dir = new File(overflowDir + File.separatorChar + generateNameForClientMsgsRegion(OSProcess.getId()));
        // This will delete the overflow directory when virtual machine terminates.
        dir.deleteOnExit();
        if (!dir.mkdirs() && !dir.isDirectory()) {
            throw new GemFireIOException("Could not create client subscription overflow directory: " + dir.getAbsolutePath());
        }
        File[] dirs = { dir };
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        dsf.setAutoCompact(true).setDiskDirsAndSizes(dirs, new int[] { MAX_VALUE }).create("bsi");
        factory.setDiskStoreName("bsi");
        // backward compatibility, it was sync
        factory.setDiskSynchronous(true);
    }
    factory.setDataPolicy(DataPolicy.NORMAL);
    // enable statistics
    factory.setStatisticsEnabled(true);
    /* setting LIFO related eviction attributes */
    if (HARegionQueue.HA_EVICTION_POLICY_ENTRY.equals(ePolicy)) {
        factory.setEvictionAttributes(EvictionAttributes.createLIFOEntryAttributes(capacity, EvictionAction.OVERFLOW_TO_DISK));
    } else if (HARegionQueue.HA_EVICTION_POLICY_MEMORY.equals(ePolicy)) {
        // condition refinement
        factory.setEvictionAttributes(EvictionAttributes.createLIFOMemoryAttributes(capacity, EvictionAction.OVERFLOW_TO_DISK));
    } else {
        // throw invalid eviction policy exception
        throw new InvalidValueException(LocalizedStrings.CacheServerImpl__0_INVALID_EVICTION_POLICY.toLocalizedString(ePolicy));
    }
    return factory;
}
Also used : InvalidValueException(org.apache.geode.InvalidValueException) AttributesFactory(org.apache.geode.cache.AttributesFactory) GemFireIOException(org.apache.geode.GemFireIOException) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 2 with InvalidValueException

use of org.apache.geode.InvalidValueException in project geode by apache.

the class AbstractDistributionConfig method setAttributeObject.

public void setAttributeObject(String attName, Object attValue, ConfigSource source) {
    // TODO: the setters is already checking the parameter type, do we still need to do this?
    Class validValueClass = getAttributeType(attName);
    if (attValue != null) {
        // null is a "valid" value for any class
        if (!validValueClass.isInstance(attValue)) {
            throw new InvalidValueException(LocalizedStrings.AbstractDistributionConfig_0_VALUE_1_MUST_BE_OF_TYPE_2.toLocalizedString(new Object[] { attName, attValue, validValueClass.getName() }));
        }
    }
    if (attName.startsWith(USERDEFINED_PREFIX_NAME)) {
        // Do nothing its user defined property.
        return;
    }
    // accepts int
    if (attName.equalsIgnoreCase(LOG_LEVEL) || attName.equalsIgnoreCase(SECURITY_LOG_LEVEL)) {
        if (attValue instanceof String) {
            attValue = LogLevel.getLogWriterLevel((String) attValue);
        }
    }
    if (attName.startsWith(SECURITY_PREFIX)) {
        this.setSecurity(attName, attValue.toString());
    }
    if (attName.startsWith(SSL_SYSTEM_PROPS_NAME) || attName.startsWith(SYS_PROP_NAME)) {
        this.setSSLProperty(attName, attValue.toString());
    }
    Method setter = setters.get(attName);
    if (setter == null) {
        // return
        if (attName.startsWith(SECURITY_PREFIX) || attName.startsWith(SSL_SYSTEM_PROPS_NAME) || attName.startsWith(SYS_PROP_NAME)) {
            getAttSourceMap().put(attName, source);
            return;
        }
        throw new InternalGemFireException(LocalizedStrings.AbstractDistributionConfig_UNHANDLED_ATTRIBUTE_NAME_0.toLocalizedString(attName));
    }
    Class[] pTypes = setter.getParameterTypes();
    if (pTypes.length != 1) {
        throw new InternalGemFireException("the attribute setter must have one and only one parametter");
    }
    checkAttribute(attName, attValue);
    try {
        setter.invoke(this, attValue);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        } else {
            throw new InternalGemFireException("error invoking " + setter.getName() + " with " + attValue, e);
        }
    }
    getAttSourceMap().put(attName, source);
}
Also used : InvalidValueException(org.apache.geode.InvalidValueException) InternalGemFireException(org.apache.geode.InternalGemFireException) Method(java.lang.reflect.Method) InvalidValueException(org.apache.geode.InvalidValueException) UnmodifiableException(org.apache.geode.UnmodifiableException) InternalGemFireException(org.apache.geode.InternalGemFireException) UnknownHostException(java.net.UnknownHostException)

Aggregations

InvalidValueException (org.apache.geode.InvalidValueException)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 UnknownHostException (java.net.UnknownHostException)1 GemFireIOException (org.apache.geode.GemFireIOException)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 UnmodifiableException (org.apache.geode.UnmodifiableException)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)1