use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class MemberDomConfigProcessor method getEvictionConfig.
private EvictionConfig getEvictionConfig(Node node, boolean isNearCache, boolean isIMap) {
EvictionConfig evictionConfig = new EvictionConfig();
if (isIMap) {
// Set IMap defaults
evictionConfig.setEvictionPolicy(MapConfig.DEFAULT_EVICTION_POLICY).setMaxSizePolicy(MapConfig.DEFAULT_MAX_SIZE_POLICY).setSize(MapConfig.DEFAULT_MAX_SIZE);
}
Node size = getNamedItemNode(node, "size");
Node maxSizePolicy = getNamedItemNode(node, "max-size-policy");
Node evictionPolicy = getNamedItemNode(node, "eviction-policy");
Node comparatorClassName = getNamedItemNode(node, "comparator-class-name");
if (size != null) {
evictionConfig.setSize(parseInt(getTextContent(size)));
if (isIMap && evictionConfig.getSize() == 0) {
evictionConfig.setSize(MapConfig.DEFAULT_MAX_SIZE);
}
}
if (maxSizePolicy != null) {
evictionConfig.setMaxSizePolicy(MaxSizePolicy.valueOf(upperCaseInternal(getTextContent(maxSizePolicy))));
}
if (evictionPolicy != null) {
evictionConfig.setEvictionPolicy(EvictionPolicy.valueOf(upperCaseInternal(getTextContent(evictionPolicy))));
}
if (comparatorClassName != null) {
String className = getTextContent(comparatorClassName);
if (!StringUtil.isNullOrEmptyAfterTrim(className)) {
evictionConfig.setComparatorClassName(className);
}
}
try {
doEvictionConfigChecks(evictionConfig, isIMap, isNearCache);
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException(e.getMessage());
}
return evictionConfig;
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class XmlClientConfigBuilder method handleConfig.
private void handleConfig(Element docElement) throws Exception {
for (Node node : childElements(docElement)) {
String nodeName = cleanNodeName(node);
if (occurrenceSet.contains(nodeName)) {
throw new InvalidConfigurationException("Duplicate '" + nodeName + "' definition found in XML configuration. ");
}
handleXmlNode(node, nodeName);
if (!canOccurMultipleTimes(nodeName)) {
occurrenceSet.add(nodeName);
}
}
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class SPIAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Set<MemberGroup> memberGroups = new HashSet<MemberGroup>();
for (Member member : allMembers) {
try {
if (member.localMember()) {
DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
// If no discovery strategy is found fail-fast
if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
} else {
for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
checkNotNull(discoveryStrategy.getPartitionGroupStrategy());
Iterable<MemberGroup> spiGroupsIterator = discoveryStrategy.getPartitionGroupStrategy().getMemberGroups();
for (MemberGroup group : spiGroupsIterator) {
memberGroups.add(group);
}
return memberGroups;
}
}
}
} catch (Exception e) {
if (e instanceof ValidationException) {
throw new InvalidConfigurationException("Invalid configuration", e);
} else {
throw new RuntimeException("Failed to configure discovery strategies", e);
}
}
}
return memberGroups;
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast-jet by hazelcast.
the class XmlJetConfigBuilder method parse.
@Override
protected Document parse(InputStream inputStream) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = dbf.newDocumentBuilder();
try {
return builder.parse(inputStream);
} catch (Exception e) {
String msg = "Failed to parse config" + LINE_SEPARATOR + "Exception: " + e.getMessage() + LINE_SEPARATOR + "Hazelcast Jet startup interrupted.";
LOGGER.severe(msg);
throw new InvalidConfigurationException(e.getMessage(), e);
} finally {
IOUtil.closeResource(inputStream);
}
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class MemberDomConfigProcessor method getTimedExpiryPolicyFactoryConfig.
private CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig getTimedExpiryPolicyFactoryConfig(Node node) {
String expiryPolicyTypeStr = getAttribute(node, "expiry-policy-type");
String durationAmountStr = getAttribute(node, "duration-amount");
String timeUnitStr = getAttribute(node, "time-unit");
ExpiryPolicyType expiryPolicyType = ExpiryPolicyType.valueOf(upperCaseInternal(expiryPolicyTypeStr));
if (expiryPolicyType != ExpiryPolicyType.ETERNAL && (isNullOrEmpty(durationAmountStr) || isNullOrEmpty(timeUnitStr))) {
throw new InvalidConfigurationException("Both of the \"duration-amount\" or \"time-unit\" attributes " + "are required for expiry policy factory configuration " + "(except \"ETERNAL\" expiry policy type)");
}
CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig durationConfig = null;
if (expiryPolicyType != ExpiryPolicyType.ETERNAL) {
long durationAmount;
try {
durationAmount = parseLong(durationAmountStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("Invalid value for duration amount: " + durationAmountStr, e);
}
if (durationAmount <= 0) {
throw new InvalidConfigurationException("Duration amount must be positive: " + durationAmount);
}
TimeUnit timeUnit;
try {
timeUnit = TimeUnit.valueOf(upperCaseInternal(timeUnitStr));
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException("Invalid value for time unit: " + timeUnitStr, e);
}
durationConfig = new CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig(durationAmount, timeUnit);
}
return new CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig(expiryPolicyType, durationConfig);
}
Aggregations