Search in sources :

Example 11 with HazelcastException

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

the class QueueContainer method txnPeek.

/**
     * Retrieves, but does not remove, the head of the queue. If the queue is empty checks if there is a reserved item with
     * the associated {@code offerId} and returns it.
     * If the item was retrieved from the queue but does not contain any data and the queue store is enabled, this method will
     * try load the data from the data store.
     *
     * @param offerId       the ID of the reserved item to be returned if the queue is empty
     * @param transactionId currently ignored
     * @return the head of the queue or a reserved item associated with the {@code offerId} if the queue is empty
     * @throws HazelcastException if there is an exception while loading the data from the queue store
     */
public QueueItem txnPeek(long offerId, String transactionId) {
    QueueItem item = getItemQueue().peek();
    if (item == null) {
        if (offerId == -1) {
            return null;
        }
        TxQueueItem txItem = txMap.get(offerId);
        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);
        }
    }
    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 12 with HazelcastException

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

the class QueueContainer method mapIterateAndRemove.

/**
     * Deletes items from the queue which have IDs contained in the key set of the given map. 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 map the map of items which to be removed.
     */
public void mapIterateAndRemove(Map<Long, Data> map) {
    if (map.size() <= 0) {
        return;
    }
    if (store.isEnabled()) {
        try {
            store.deleteAll(map.keySet());
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    final Iterator<QueueItem> iter = getItemQueue().iterator();
    while (iter.hasNext()) {
        final QueueItem item = iter.next();
        if (map.containsKey(item.getItemId())) {
            iter.remove();
            //For Stats
            age(item, Clock.currentTimeMillis());
        }
    }
    scheduleEvictionIfEmpty();
}
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 13 with HazelcastException

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

the class QueueContainer method offer.

//TX Methods Ends
public long offer(Data data) {
    QueueItem item = new QueueItem(this, nextId(), null);
    if (store.isEnabled()) {
        try {
            store.store(item.getItemId(), data);
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    if (!store.isEnabled() || store.getMemoryLimit() > getItemQueue().size()) {
        item.setData(data);
    }
    getItemQueue().offer(item);
    cancelEvictionIfExists();
    return item.getItemId();
}
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 14 with HazelcastException

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

the class QueueContainer method clear.

public Map<Long, Data> clear() {
    long current = Clock.currentTimeMillis();
    LinkedHashMap<Long, Data> map = new LinkedHashMap<Long, Data>(getItemQueue().size());
    for (QueueItem item : getItemQueue()) {
        map.put(item.getItemId(), item.getData());
        // For stats
        age(item, current);
    }
    if (store.isEnabled() && !map.isEmpty()) {
        try {
            store.deleteAll(map.keySet());
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    getItemQueue().clear();
    dataMap.clear();
    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 15 with HazelcastException

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

the class QueueContainer method poll.

/**
     * Retrieves and removes the head of the queue (in other words, the first item), or returns {@code null} if it is empty.
     * Also calls the queue store for item deletion by item ID.
     *
     * @return the first item in the queue
     */
public QueueItem poll() {
    final QueueItem item = peek();
    if (item == null) {
        return null;
    }
    if (store.isEnabled()) {
        try {
            store.delete(item.getItemId());
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    getItemQueue().poll();
    age(item, Clock.currentTimeMillis());
    scheduleEvictionIfEmpty();
    return item;
}
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)

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