Example usage for java.util ConcurrentModificationException ConcurrentModificationException

List of usage examples for java.util ConcurrentModificationException ConcurrentModificationException

Introduction

In this page you can find the example usage for java.util ConcurrentModificationException ConcurrentModificationException.

Prototype

public ConcurrentModificationException() 

Source Link

Document

Constructs a ConcurrentModificationException with no detail message.

Usage

From source file:org.apache.openejb.math.MathRuntimeException.java

/**
 * Constructs a new <code>ConcurrentModificationException</code> with specified formatted detail message.
 * Message formatting is delegated to {@link MessageFormat}.
 *
 * @param pattern   format specifier//from  w  w w .j a v  a 2s  . c om
 * @param arguments format arguments
 * @return built exception
 */
public static ConcurrentModificationException createConcurrentModificationException(final String pattern,
        final Object... arguments) {
    return new ConcurrentModificationException() {

        /** Serializable version identifier. */
        private static final long serialVersionUID = 6134247282754009421L;

        /** {@inheritDoc} */
        @Override
        public String getMessage() {
            return buildMessage(Locale.US, pattern, arguments);
        }

        /** {@inheritDoc} */
        @Override
        public String getLocalizedMessage() {
            return buildMessage(Locale.getDefault(), pattern, arguments);
        }

    };
}

From source file:jp.co.nemuzuka.service.impl.TicketServiceImpl.java

@Override
public void deleteComment(String keyString, String commentKeyString, Long commentVersionNo,
        String projectKeyString) {

    Key ticketModelKey = Datastore.stringToKey(keyString);
    Key projectKey = Datastore.stringToKey(projectKeyString);

    //Key???//from  w  ww. j  a v  a2s.c om
    TicketModel model = ticketDao.getWithProjectKey(ticketModelKey, projectKey);
    if (model == null) {
        //??????Exceptionthrow
        throw new ConcurrentModificationException();
    }
    //
    commentService.delete(ticketModelKey, commentKeyString, commentVersionNo);

}

From source file:org.apache.hadoop.test.system.AbstractDaemonClient.java

/**
 * Number of times ConcurrentModificationException present in log file. 
 * <br/>/*from w w w .ja v a  2 s  .com*/
 * @param excludeExpList list of exceptions to exclude.
 * @return number of times exception in log file.
 * @throws IOException is thrown on RPC error. 
 */
public int getNumberOfConcurrentModificationExceptionsInLog(String[] excludeExpList) throws IOException {
    return getNumberOfExceptionsInLog(new ConcurrentModificationException(), excludeExpList);
}

From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java

public Iterator<PConnection> iterator() {
    return new Iterator<PConnection>() {
        Iterator<Node> iter = nodemap.values().iterator();
        Node next;// w  w w.j  a va 2 s .  c om
        int expectedModCount = modCount;

        void align() {
            if (next == null) {
                Node n;
                while (iter.hasNext()) {
                    n = iter.next();
                    if (n.p != null) {
                        next = n;
                        break;
                    }
                }
            }
        }

        public boolean hasNext() {
            align();
            return next != null;
        }

        public PConnection next() {
            if (expectedModCount != modCount)
                throw new ConcurrentModificationException();

            if (!hasNext())
                throw new NoSuchElementException();
            PConnection c = new PConnection(next.c, next.parent());
            next = null;
            return c;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.alfresco.repo.transaction.RetryingTransactionHelperTest.java

public void testZeroAndNegativeRetries() {
    final MutableInt callCount = new MutableInt(0);
    RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>() {
        public Long execute() throws Throwable {
            callCount.setValue(callCount.intValue() + 1);
            throw new ConcurrentModificationException();
        }/*from w  w  w .ja  v a  2 s .  c  om*/
    };
    // No retries
    callCount.setValue(0);
    txnHelper.setMaxRetries(0);
    try {
        txnHelper.doInTransaction(callback);
    } catch (ConcurrentModificationException e) {
        // Expected
    }
    assertEquals("Should have been called exactly once", 1, callCount.intValue());

    // Negative retries
    callCount.setValue(0);
    txnHelper.setMaxRetries(-1);
    try {
        txnHelper.doInTransaction(callback);
    } catch (ConcurrentModificationException e) {
        // Expected
    }
    assertEquals("Should have been called exactly once", 1, callCount.intValue());
}

From source file:com.workplacesystems.utilsj.collections.TransactionalBidiTreeMap.java

/**
 * common remove logic (remove by key or remove by value)
 *
 * @param o the key, or value, that we're looking for
 * @param index KEY or VALUE/*www  .  j av  a 2  s .  c  om*/
 *
 * @return the key, if remove by value, or the value, if remove by
 *         key. null if the specified key or value could not be
 *         found
 *
 * @throws ConcurrentModificationException if the node has been
 *                                     removed by another thread
 */
private Object doRemove(final Object o, final int index) throws ConcurrentModificationException {

    checkNonNullComparable(o, index);

    String thread_id = getCurrentThreadId();

    Node<K, V> node = lookupValid(o, index, thread_id);
    Object rval = null;

    if (validNode(node, thread_id)) {
        if (node != null && node.is(Node.DELETED, null) && !node.is(Node.DELETED, thread_id))
            throw new ConcurrentModificationException();

        rval = node.getData(oppositeIndex(index));

        if (auto_commit || node.is(Node.ADDED, thread_id))
            doRedBlackDelete(node);
        else {
            node.setStatus(Node.DELETED, thread_id);
        }
    }

    return rval;
}

From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

/**
 * Test to see if my underlying list has been modified
 * by some other process.  If it has, throws a
 * {@link ConcurrentModificationException}, otherwise
 * quietly returns.//from   ww w.jav  a 2 s  . com
 *
 * @throws ConcurrentModificationException
 */
protected void checkForComod() throws ConcurrentModificationException {
    if (_modCount != _list._modCount) {
        throw new ConcurrentModificationException();
    }
}

From source file:com.workplacesystems.utilsj.collections.TransactionalBidiTreeMap.java

/**
 * insert a node by its value//w  w w. ja  va  2s  . com
 *
 * @param newNode the node to be inserted
 *
 * @throws IllegalArgumentException if the node already exists
 *                                     in the value mapping
 */
private void insertValue(final Node<K, V> newNode, final String thread_id) throws IllegalArgumentException {

    Node<K, V> node = rootNode[VALUE];

    while (true) {
        int cmp = compare(Node.ADDED, newNode.getData(VALUE), node.getStatus(), node.getData(VALUE), VALUE);

        if (cmp == 0) {
            if (nextEqualValid(getFloorEqualNode(node, VALUE), VALUE, thread_id) != null) {
                String debug_message = "Cannot store a duplicate value (\"" + newNode.getData(VALUE)
                        + "\") in this Map. Value already exists for key " + node.getKey();
                log.debug(debug_message);

                throw new IllegalArgumentException(debug_message);
            }

            if (node.is(Node.ADDED, null))
                throw new ConcurrentModificationException();

            if (node.getRight(VALUE) != null) {
                node = node.getRight(VALUE);
            } else if (node.getLeft(VALUE) != null) {
                node = node.getLeft(VALUE);
            } else {
                node.setRight(newNode, VALUE);
                newNode.setParent(node, VALUE);
                doRedBlackInsert(newNode, VALUE);

                break;
            }
        } else if (cmp < 0) {
            if (node.getLeft(VALUE) != null) {
                node = node.getLeft(VALUE);
            } else {
                node.setLeft(newNode, VALUE);
                newNode.setParent(node, VALUE);
                doRedBlackInsert(newNode, VALUE);

                break;
            }
        } else { // cmp > 0
            if (node.getRight(VALUE) != null) {
                node = node.getRight(VALUE);
            } else {
                node.setRight(newNode, VALUE);
                newNode.setParent(node, VALUE);
                doRedBlackInsert(newNode, VALUE);

                break;
            }
        }
    }
}

From source file:com.workplacesystems.utilsj.collections.TransactionalBidiTreeMap.java

/**
 * Associates the specified value with the specified key in this
 * map.//  w  w  w .  j  a va2s.c  om
 *
 * @param key key with which the specified value is to be
 *            associated.
 * @param value value to be associated with the specified key.
 *
 * @return null
 *
 * @throws ClassCastException if the class of the specified key
 *                               or value prevents it from being
 *                               stored in this map.
 * @throws NullPointerException if the specified key or value
 *                                 is null
 * @throws IllegalArgumentException if the key duplicates an
 *                                     existing key, or if the
 *                                     value duplicates an
 *                                     existing value
 */
@Override
public V put(final K key, final V value) throws ClassCastException, NullPointerException,
        IllegalArgumentException, ConcurrentModificationException {

    checkKeyAndValue(key, value);

    Node<K, V> node = rootNode[KEY];

    String thread_id = getCurrentThreadId();

    if (node == null) {
        Node<K, V> root = new Node<K, V>(key, value);

        rootNode[KEY] = root;
        rootNode[VALUE] = root;

        if (!auto_commit)
            root.setStatus(Node.ADDED, thread_id);

        grow();
    } else {
        while (true) {
            int cmp = compare(Node.ADDED, key, node.getStatus(), node.getData(KEY), KEY);

            if (cmp == 0) {
                if (nextEqualValid(getFloorEqualNode(node, KEY), KEY, thread_id) != null) {
                    String debug_message = "Cannot store a duplicate key (\"" + key + "\") in this Map";
                    log.debug(debug_message);
                    throw new IllegalArgumentException(debug_message);
                }

                if (node.is(Node.ADDED, null))
                    throw new ConcurrentModificationException();

                if (node.getRight(KEY) != null) {
                    node = node.getRight(KEY);
                } else if (node.getLeft(KEY) != null) {
                    node = node.getLeft(KEY);
                } else {
                    Node<K, V> newNode = new Node<K, V>(key, value);

                    insertValue(newNode, thread_id);
                    node.setRight(newNode, KEY);
                    newNode.setParent(node, KEY);
                    doRedBlackInsert(newNode, KEY);
                    grow();

                    if (!auto_commit)
                        newNode.setStatus(Node.ADDED, thread_id);

                    break;
                }
            } else if (cmp < 0) {
                if (node.getLeft(KEY) != null) {
                    node = node.getLeft(KEY);
                } else {
                    Node<K, V> newNode = new Node<K, V>(key, value);

                    insertValue(newNode, thread_id);
                    node.setLeft(newNode, KEY);
                    newNode.setParent(node, KEY);
                    doRedBlackInsert(newNode, KEY);
                    grow();

                    if (!auto_commit)
                        newNode.setStatus(Node.ADDED, thread_id);

                    break;
                }
            } else { // cmp > 0
                if (node.getRight(KEY) != null) {
                    node = node.getRight(KEY);
                } else {
                    Node<K, V> newNode = new Node<K, V>(key, value);

                    insertValue(newNode, thread_id);
                    node.setRight(newNode, KEY);
                    newNode.setParent(node, KEY);
                    doRedBlackInsert(newNode, KEY);
                    grow();

                    if (!auto_commit)
                        newNode.setStatus(Node.ADDED, thread_id);

                    break;
                }
            }
        }
    }

    return null;
}