Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.apache.ignite.internal.processors.datastructures;

import java.io.Externalizable;
import javax.cache.processor.EntryProcessorException;
import org.apache.ignite.IgniteCacheRestartingException;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
Expand All @@ -30,6 +32,9 @@
import org.apache.ignite.internal.util.future.IgniteFutureImpl;
import org.apache.ignite.internal.util.typedef.internal.U;

/**
* Represents base class for atomic data structures.
*/
public abstract class AtomicDataStructureProxy<V extends AtomicDataStructureValue>
implements GridCacheRemovable,IgniteChangeGlobalStateSupport {
/** Logger. */
Expand All @@ -42,7 +47,7 @@ public abstract class AtomicDataStructureProxy<V extends AtomicDataStructureValu
private volatile GridFutureAdapter<Void> suspendFut;

/** Check removed flag. */
private boolean rmvCheck;
private volatile boolean rmvCheck;

/** Structure name. */
protected String name;
Expand Down Expand Up @@ -138,6 +143,35 @@ protected void checkRemoved() throws IllegalStateException {
}
}

/**
* Checks removed status after fail.
*
* @param cause Initial exception.
* @return Ignite runtime exception that corresponds the original {@code cause}.
*/
protected IgniteException checkRemovedAfterFail(Exception cause) {
assert cause != null: "The original cause must not be null.";

needCheckNotRemoved();

try {
checkRemoved();
}
catch (Exception e) {
// The original exception should be returned.
}

if (cause instanceof IgniteCheckedException)
return U.convertException((IgniteCheckedException) cause);
else if (cause instanceof EntryProcessorException)
return new IgniteException(cause.getMessage(), cause);
else {
assert cause instanceof IgniteException;

return (IgniteException)cause;
}
}

/**
* @return Error.
*/
Expand Down Expand Up @@ -188,6 +222,9 @@ private IllegalStateException suspendedError() {
// No-op.
}

/**
* Invalidates local state.
*/
protected void invalidateLocalState() {
// No-op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public GridCacheAtomicLongImpl(String name,

return val.get();
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -100,11 +100,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -119,11 +116,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -138,11 +132,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -157,11 +148,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -176,11 +164,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -195,11 +180,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -214,11 +196,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -233,11 +212,8 @@ public GridCacheAtomicLongImpl(String name,

return res.get() == expVal;
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -256,11 +232,8 @@ public long compareAndSetAndGet(long expVal, long newVal) {

return res.get();
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public GridCacheAtomicReferenceImpl(String name,
GridCacheAtomicReferenceValue<T> ref = cacheView.get(key);

if (ref == null)
throw new IgniteCheckedException("Failed to find atomic reference with given name: " + name);
throw new IgniteException("Failed to find atomic reference with given name: " + name);

return ref.get();
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -106,8 +106,13 @@ public GridCacheAtomicReferenceImpl(String name,
checkRemoved();

try {
if (ctx.dataStructures().knownType(val))
cacheView.invoke(key, new ReferenceSetEntryProcessor<>(val));
if (ctx.dataStructures().knownType(val)) {
EntryProcessorResult res = cacheView.invoke(key, new ReferenceSetEntryProcessor<>(val));

assert res != null;

res.get();
}
else {
CU.retryTopologySafe(new Callable<Void>() {
@Override public Void call() throws Exception {
Expand All @@ -127,11 +132,8 @@ public GridCacheAtomicReferenceImpl(String name,
});
}
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down Expand Up @@ -173,11 +175,8 @@ public GridCacheAtomicReferenceImpl(String name,
});
}
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down Expand Up @@ -225,11 +224,8 @@ public T compareAndSetAndGet(final T newVal, final T expVal) {
});
}
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public GridCacheAtomicStampedImpl(String name,

return stmp.get();
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -101,8 +101,13 @@ public GridCacheAtomicStampedImpl(String name,
checkRemoved();

try {
if (ctx.dataStructures().knownType(val) && ctx.dataStructures().knownType(stamp))
cacheView.invoke(key, new StampedSetEntryProcessor<>(val, stamp));
if (ctx.dataStructures().knownType(val) && ctx.dataStructures().knownType(stamp)) {
EntryProcessorResult res = cacheView.invoke(key, new StampedSetEntryProcessor<>(val, stamp));

assert res != null;

res.get();
}
else {
CU.retryTopologySafe(new Callable<Void>() {
@Override public Void call() throws Exception {
Expand All @@ -122,11 +127,8 @@ public GridCacheAtomicStampedImpl(String name,
});
}
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down Expand Up @@ -169,11 +171,8 @@ public GridCacheAtomicStampedImpl(String name,
});
}
}
catch (EntryProcessorException e) {
throw new IgniteException(e.getMessage(), e);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (EntryProcessorException | IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -185,12 +184,12 @@ public GridCacheAtomicStampedImpl(String name,
GridCacheAtomicStampedValue<T, S> stmp = cacheView.get(key);

if (stmp == null)
throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
throw new IgniteException("Failed to find atomic stamped with given name: " + name);

return stmp.stamp();
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand All @@ -206,8 +205,8 @@ public GridCacheAtomicStampedImpl(String name,

return stmp.value();
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
catch (IgniteException | IgniteCheckedException e) {
throw checkRemovedAfterFail(e);
}
}

Expand Down
Loading