Search in sources :

Example 6 with HazelcastException

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);
    }
}
Also used : MappingJob(com.hazelcast.mapreduce.MappingJob) HazelcastException(com.hazelcast.core.HazelcastException) ReducerFactory(com.hazelcast.mapreduce.ReducerFactory) HazelcastException(com.hazelcast.core.HazelcastException) Collator(com.hazelcast.mapreduce.Collator) CombinerFactory(com.hazelcast.mapreduce.CombinerFactory) Mapper(com.hazelcast.mapreduce.Mapper) ReducingSubmittableJob(com.hazelcast.mapreduce.ReducingSubmittableJob)

Example 7 with HazelcastException

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);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) File(java.io.File)

Example 8 with HazelcastException

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);
        }
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Example 9 with HazelcastException

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;
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) HazelcastException(com.hazelcast.core.HazelcastException) HashMap(java.util.HashMap) ValueValidator(com.hazelcast.config.properties.ValueValidator) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition)

Example 10 with HazelcastException

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");
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) HazelcastException(com.hazelcast.core.HazelcastException) ICacheManager(com.hazelcast.core.ICacheManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)57 IOException (java.io.IOException)18 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)11 TransactionException (com.hazelcast.transaction.TransactionException)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 File (java.io.File)8 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 OCallable (com.orientechnologies.common.util.OCallable)6 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 Collator (com.hazelcast.mapreduce.Collator)4 CombinerFactory (com.hazelcast.mapreduce.CombinerFactory)4 Mapper (com.hazelcast.mapreduce.Mapper)4