use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class ObjectMultiMapProxy method aggregate.
@Override
public <SuppliedValue, Result> Result aggregate(Supplier<K, V, SuppliedValue> supplier, Aggregation<K, SuppliedValue, Result> aggregation, JobTracker jobTracker) {
try {
isNotNull(jobTracker, "jobTracker");
KeyValueSource<K, V> keyValueSource = KeyValueSource.fromMultiMap(this);
Job<K, V> job = jobTracker.newJob(keyValueSource);
Mapper mapper = aggregation.getMapper(supplier);
CombinerFactory combinerFactory = aggregation.getCombinerFactory();
ReducerFactory reducerFactory = aggregation.getReducerFactory();
Collator collator = aggregation.getCollator();
MappingJob mappingJob = job.mapper(mapper);
ReducingSubmittableJob reducingJob;
if (combinerFactory != null) {
reducingJob = mappingJob.combiner(combinerFactory).reducer(reducerFactory);
} else {
reducingJob = mappingJob.reducer(reducerFactory);
}
ICompletableFuture<Result> future = reducingJob.submit(collator);
return future.get();
} catch (Exception e) {
throw new HazelcastException(e);
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class IOUtil method copyDirectory.
private static void copyDirectory(File source, File target) {
if (target.exists() && !target.isDirectory()) {
throw new IllegalArgumentException("Cannot copy source directory since the target already exists " + "but it is not a directory");
}
final File targetSubDir = new File(target, source.getName());
if (!targetSubDir.exists() && !targetSubDir.mkdirs()) {
throw new HazelcastException("Could not create the target directory " + target);
}
final File[] sourceFiles = source.listFiles();
if (sourceFiles == null) {
throw new HazelcastException("Error occurred while listing directory contents for copy");
}
for (File file : sourceFiles) {
copy(file, targetSubDir);
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class RingbufferContainer method initRingbufferStore.
private void initRingbufferStore(String name, RingbufferConfig config, SerializationService serializationService, ClassLoader configClassLoader) {
this.store = RingbufferStoreWrapper.create(name, config.getRingbufferStoreConfig(), config.getInMemoryFormat(), serializationService, configClassLoader);
if (store.isEnabled()) {
try {
final long storeSequence = store.getLargestSequence();
ringbuffer.setTailSequence(storeSequence);
ringbuffer.setHeadSequence(storeSequence + 1);
} catch (Exception e) {
throw new HazelcastException(e);
}
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class DefaultDiscoveryService method buildProperties.
private Map<String, Comparable> buildProperties(DiscoveryStrategyFactory factory, DiscoveryStrategyConfig config, String className) {
Collection<PropertyDefinition> propertyDefinitions = factory.getConfigurationProperties();
if (propertyDefinitions == null) {
return Collections.emptyMap();
}
Map<String, Comparable> properties = config.getProperties();
Map<String, Comparable> mappedProperties = new HashMap<String, Comparable>();
for (PropertyDefinition propertyDefinition : propertyDefinitions) {
String propertyKey = propertyDefinition.key();
Comparable value = properties.get(propertyKey);
if (value == null) {
if (!propertyDefinition.optional()) {
throw new HazelcastException("Missing property '" + propertyKey + "' on discovery strategy '" + className + "' configuration");
}
continue;
}
TypeConverter typeConverter = propertyDefinition.typeConverter();
Comparable mappedValue = typeConverter.convert(value);
ValueValidator validator = propertyDefinition.validator();
if (validator != null) {
validator.validate(mappedValue);
}
mappedProperties.put(propertyKey, mappedValue);
}
return mappedProperties;
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class CacheThroughHazelcastInstanceTest method getCache_whenOtherHazelcastExceptionIsThrown_thenFail.
@Test
public void getCache_whenOtherHazelcastExceptionIsThrown_thenFail() {
// when one attempts to getCache but a HazelcastException other than ServiceNotFoundException is thrown
HazelcastInstanceImpl hzInstanceImpl = mock(HazelcastInstanceImpl.class);
when(hzInstanceImpl.getDistributedObject(anyString(), anyString())).thenThrow(new HazelcastException("mock hz exception"));
// then the thrown HazelcastException is rethrown by getCache
ICacheManager hzCacheManager = new HazelcastInstanceCacheManager(hzInstanceImpl);
thrown.expect(HazelcastException.class);
hzCacheManager.getCache("any-cache");
}
Aggregations