Search in sources :

Example 16 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class QueueContainer method drain.

/**
     * Removes items from the queue and the queue store (if configured), up to {@code maxSize} or the size of the queue,
     * whichever is smaller. Also schedules the queue for destruction if it is empty or destroys it immediately if it is
     * empty and {@link QueueConfig#getEmptyQueueTtl()} is 0.
     *
     * @param maxSize the maximum number of items to be removed
     * @return the map of IDs and removed (drained) items
     */
public Map<Long, Data> drain(int maxSize) {
    int maxSizeParam = maxSize;
    if (maxSizeParam < 0 || maxSizeParam > getItemQueue().size()) {
        maxSizeParam = getItemQueue().size();
    }
    final LinkedHashMap<Long, Data> map = new LinkedHashMap<Long, Data>(maxSizeParam);
    mapDrainIterator(maxSizeParam, map);
    if (store.isEnabled() && maxSizeParam != 0) {
        try {
            store.deleteAll(map.keySet());
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    long current = Clock.currentTimeMillis();
    for (int i = 0; i < maxSizeParam; i++) {
        final QueueItem item = getItemQueue().poll();
        //For Stats
        age(item, current);
    }
    if (maxSizeParam != 0) {
        scheduleEvictionIfEmpty();
    }
    return map;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Data(com.hazelcast.nio.serialization.Data) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TransactionException(com.hazelcast.transaction.TransactionException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class QueueContainer method remove.

/**
     * iterates all items, checks equality with data
     * This method does not trigger store load.
     */
public long remove(Data data) {
    Iterator<QueueItem> iter = getItemQueue().iterator();
    while (iter.hasNext()) {
        QueueItem item = iter.next();
        if (data.equals(item.getData())) {
            if (store.isEnabled()) {
                try {
                    store.delete(item.getItemId());
                } catch (Exception e) {
                    throw new HazelcastException(e);
                }
            }
            iter.remove();
            //For Stats
            age(item, Clock.currentTimeMillis());
            scheduleEvictionIfEmpty();
            return item.getItemId();
        }
    }
    return -1;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TransactionException(com.hazelcast.transaction.TransactionException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException)

Example 18 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class QueueContainer method txnPollReserve.

//TX Poll
/**
     * Retrieves and removes the head of the queue and loads the data from the queue store if the data is not stored in-memory
     * and the queue store is configured and enabled. If the queue is empty returns an item which was previously reserved with
     * the {@code reservedOfferId} by invoking {@code {@link #txnOfferReserve(String)}}.
     *
     * @param reservedOfferId the ID of the reserved item to be returned if the queue is empty
     * @param transactionId   the transaction ID for which this poll is invoked
     * @return the head of the queue or a reserved item with the {@code reservedOfferId} if there is any
     */
public QueueItem txnPollReserve(long reservedOfferId, String transactionId) {
    QueueItem item = getItemQueue().peek();
    if (item == null) {
        TxQueueItem txItem = txMap.remove(reservedOfferId);
        if (txItem == null) {
            return null;
        }
        item = new QueueItem(this, txItem.getItemId(), txItem.getData());
        return item;
    }
    if (store.isEnabled() && item.getData() == null) {
        try {
            load(item);
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    getItemQueue().poll();
    txMap.put(item.getItemId(), new TxQueueItem(item).setPollOperation(true).setTransactionId(transactionId));
    return item;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TransactionException(com.hazelcast.transaction.TransactionException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException)

Example 19 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class XmlConfigBuilder method attachChildConfig.

private static void attachChildConfig(Object parent, Object child) throws Exception {
    String targetName = child.getClass().getSimpleName();
    Method attacher = getMethod(parent, "set" + targetName, false);
    if (attacher == null) {
        attacher = getMethod(parent, "add" + targetName, false);
    }
    if (attacher == null) {
        throw new HazelcastException(String.format("%s doesn't accept %s as child", parent.getClass().getSimpleName(), targetName));
    }
    attacher.invoke(parent, child);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Method(java.lang.reflect.Method)

Example 20 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class XmlConfigBuilder method invokeSetter.

private static void invokeSetter(Object target, Node node, String argument) {
    Method method = getMethod(target, "set" + toPropertyName(cleanNodeName(node)), true);
    if (method == null) {
        throw new InvalidConfigurationException("Invalid element/attribute name in XML configuration: " + node);
    }
    Class<?> arg = method.getParameterTypes()[0];
    Object coercedArg = arg == String.class ? argument : arg == int.class ? Integer.valueOf(argument) : arg == long.class ? Long.valueOf(argument) : arg == boolean.class ? getBooleanValue(argument) : null;
    if (coercedArg == null) {
        throw new HazelcastException(String.format("Method %s has unsupported argument type %s", method.getName(), arg.getSimpleName()));
    }
    try {
        method.invoke(target, coercedArg);
    } catch (Exception e) {
        throw new HazelcastException(e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Method(java.lang.reflect.Method) HazelcastException(com.hazelcast.core.HazelcastException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

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