http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicReference.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicReference.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicReference.java new file mode 100644 index 0000000..ec0d827 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicReference.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; + +/** + * This interface provides a rich API for working with distributed atomic reference. + * <p> + * <h1 class="header">Functionality</h1> + * Distributed atomic reference includes the following main functionality: + * <ul> + * <li> + * Method {@link #get()} synchronously gets current value of an atomic reference. + * </li> + * <li> + * Method {@link #set(Object)} synchronously and unconditionally sets the value in the an atomic reference. + * </li> + * <li> + * Methods {@code compareAndSet(...)} synchronously and conditionally set the value in the an atomic reference. + * </li> + * </ul> + * All previously described methods have asynchronous analogs. + * <ul> + * <li> + * Method {@link #name()} gets name of atomic reference. + * </li> + * </ul> + * <h1 class="header">Creating Distributed Atomic Reference</h1> + * Instance of distributed atomic reference can be created by calling the following method: + * <ul> + * <li>{@link CacheDataStructures#atomicReference(String, Object, boolean)}</li> + * </ul> + * @see CacheDataStructures#atomicReference(String, Object, boolean) + * @see CacheDataStructures#removeAtomicReference(String) + */ +public interface CacheAtomicReference<T> { + /** + * Name of atomic reference. + * + * @return Name of an atomic reference. + */ + public String name(); + + /** + * Gets current value of an atomic reference. + * + * @return current value of an atomic reference. + * @throws IgniteCheckedException If operation failed. + */ + public T get() throws IgniteCheckedException; + + /** + * Unconditionally sets the value. + * + * @param val Value. + * @throws IgniteCheckedException If operation failed. + */ + public void set(T val) throws IgniteCheckedException; + + /** + * Conditionally sets the new value. That will be set if {@code expVal} is equal + * to current value respectively. + * + * @param expVal Expected value. + * @param newVal New value. + * @return Result of operation execution. If {@code true} than value have been updated. + * @throws IgniteCheckedException If operation failed. + */ + public boolean compareAndSet(T expVal, T newVal) throws IgniteCheckedException; + + /** + * Gets status of atomic. + * + * @return {@code true} if an atomic reference was removed from cache, {@code false} otherwise. + */ + public boolean removed(); +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicSequence.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicSequence.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicSequence.java new file mode 100644 index 0000000..09ef416 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicSequence.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; + +/** + * This interface provides a rich API for working with distributed atomic sequence. + * <p> + * <h1 class="header">Functionality</h1> + * Distributed atomic sequence includes the following main functionality: + * <ul> + * <li> + * Method {@link #get()} synchronously gets current value from atomic sequence. + * </li> + * <li> + * Various {@code get..(..)} methods synchronously get current value from atomic sequence + * and increase atomic sequences value. + * </li> + * <li> + * Various {@code add..(..)} {@code increment(..)} methods synchronously increase atomic sequences value + * and return increased value. + * </li> + * </ul> + * All previously described methods have asynchronous analogs. + * <ul> + * <li> + * Method {@link #batchSize(int size)} sets batch size of current atomic sequence. + * </li> + * <li> + * Method {@link #batchSize()} gets current batch size of atomic sequence. + * </li> + * <li> + * Method {@link #name()} gets name of atomic sequence. + * </li> + * </ul> + * <h1 class="header">Creating Distributed Atomic Sequence</h1> + * Instance of distributed atomic sequence can be created by calling the following method: + * <ul> + * <li>{@link CacheDataStructures#atomicSequence(String, long, boolean)}</li> + * </ul> + * @see CacheDataStructures#atomicSequence(String, long, boolean) + * @see CacheDataStructures#removeAtomicSequence(String) + */ +public interface CacheAtomicSequence { + /** + * Name of atomic sequence. + * + * @return Name of atomic sequence. + */ + public String name(); + + /** + * Gets current value of atomic sequence. + * + * @return Value of atomic sequence. + * @throws IgniteCheckedException If operation failed. + */ + public long get() throws IgniteCheckedException; + + /** + * Increments and returns the value of atomic sequence. + * + * @return Value of atomic sequence after increment. + * @throws IgniteCheckedException If operation failed. + */ + public long incrementAndGet() throws IgniteCheckedException; + + /** + * Gets and increments current value of atomic sequence. + * + * @return Value of atomic sequence before increment. + * @throws IgniteCheckedException If operation failed. + */ + public long getAndIncrement() throws IgniteCheckedException; + + /** + * Adds {@code l} elements to atomic sequence and gets value of atomic sequence. + * + * @param l Number of added elements. + * @return Value of atomic sequence. + * @throws IgniteCheckedException If operation failed. + */ + public long addAndGet(long l) throws IgniteCheckedException; + + /** + * Gets current value of atomic sequence and adds {@code l} elements. + * + * @param l Number of added elements. + * @return Value of atomic sequence. + * @throws IgniteCheckedException If operation failed. + */ + public long getAndAdd(long l) throws IgniteCheckedException; + + /** + * Gets local batch size for this atomic sequence. + * + * @return Sequence batch size. + */ + public int batchSize(); + + /** + * Sets local batch size for atomic sequence. + * + * @param size Sequence batch size. Must be more then 0. + */ + public void batchSize(int size); + + /** + * Gets status of atomic sequence. + * + * @return {@code true} if atomic sequence was removed from cache, {@code false} otherwise. + */ + public boolean removed(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicStamped.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicStamped.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicStamped.java new file mode 100644 index 0000000..ab70f24 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheAtomicStamped.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.apache.ignite.lang.*; + +/** + * This interface provides a rich API for working with distributed atomic stamped value. + * <p> + * <h1 class="header">Functionality</h1> + * Distributed atomic stamped includes the following main functionality: + * <ul> + * <li> + * Method {@link #get()} synchronously gets both value and stamp of atomic. + * </li> + * <li> + * Method {@link #value()} synchronously gets current value of atomic. + * </li> + * <li> + * Method {@link #stamp()} synchronously gets current stamp of atomic. + * </li> + * <li> + * Method {@link #set(Object, Object)} synchronously and unconditionally sets the value + * and the stamp in the atomic. + * </li> + * <li> + * Methods {@code compareAndSet(...)} synchronously and conditionally set the value + * and the stamp in the atomic. + * </li> + * </ul> + * All previously described methods have asynchronous analogs. + * <ul> + * <li> + * Method {@link #name()} gets name of atomic stamped. + * </li> + * </ul> + * <h1 class="header">Creating Distributed Atomic Stamped</h1> + * Instance of distributed atomic stamped can be created by calling the following method: + * <ul> + * <li>{@link CacheDataStructures#atomicLong(String, long, boolean)}</li> + * </ul> + * @see CacheDataStructures#atomicStamped(String, Object, Object, boolean) + * @see CacheDataStructures#removeAtomicStamped(String) + */ +public interface CacheAtomicStamped<T, S> { + /** + * Name of atomic stamped. + * + * @return Name of atomic stamped. + */ + public String name(); + + /** + * Gets both current value and current stamp of atomic stamped. + * + * @return both current value and current stamp of atomic stamped. + * @throws IgniteCheckedException If operation failed. + */ + public IgniteBiTuple<T, S> get() throws IgniteCheckedException; + + /** + * Unconditionally sets the value and the stamp. + * + * @param val Value. + * @param stamp Stamp. + * @throws IgniteCheckedException If operation failed. + */ + public void set(T val, S stamp) throws IgniteCheckedException; + + /** + * Conditionally sets the new value and new stamp. They will be set if {@code expVal} + * and {@code expStamp} are equal to current value and current stamp respectively. + * + * @param expVal Expected value. + * @param newVal New value. + * @param expStamp Expected stamp. + * @param newStamp New stamp. + * @return Result of operation execution. If {@code true} than value and stamp will be updated. + * @throws IgniteCheckedException If operation failed. + */ + public boolean compareAndSet(T expVal, T newVal, S expStamp, S newStamp) throws IgniteCheckedException; + + /** + * Gets current stamp. + * + * @return Current stamp. + * @throws IgniteCheckedException If operation failed. + */ + public S stamp() throws IgniteCheckedException; + + /** + * Gets current value. + * + * @return Current value. + * @throws IgniteCheckedException If operation failed. + */ + public T value() throws IgniteCheckedException; + + /** + * Gets status of atomic. + * + * @return {@code true} if atomic stamped was removed from cache, {@code false} otherwise. + */ + public boolean removed(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheCountDownLatch.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheCountDownLatch.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheCountDownLatch.java new file mode 100644 index 0000000..0f4aae0 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheCountDownLatch.java @@ -0,0 +1,226 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; + +import java.util.concurrent.*; + +/** + * This interface provides a rich API for working with distributed count down latch. + * <p> + * <h1 class="header">Functionality</h1> + * Distributed count down latch provides functionality similar to {@code java.util.CountDownLatch}. + * Note that you cannot remove count down latch having count greater that zero. It should be + * counted down to zero first. + * <h1 class="header">Creating Distributed Count Down Latch</h1> + * Instance of cache count down latch can be created by calling the following method: + * {@link CacheDataStructures#countDownLatch(String, int, boolean, boolean)}. + * @see CacheDataStructures#countDownLatch(String, int, boolean, boolean) + * @see CacheDataStructures#removeCountDownLatch(String) + */ +public interface CacheCountDownLatch { + /** + * Gets name of the latch. + * + * @return Name of the latch. + */ + public String name(); + + /** + * Gets current count value of the latch. + * + * @return Current count. + */ + public int count(); + + /** + * Gets initial count value of the latch. + * + * @return Initial count. + */ + public int initialCount(); + + /** + * Gets {@code autoDelete} flag. If this flag is {@code true} latch is removed + * from cache when it has been counted down to 0. + * + * @return Value of {@code autoDelete} flag. + */ + public boolean autoDelete(); + + /** + * Causes the current thread to wait until the latch has counted down to + * zero, unless current thread is interrupted. + * <p> + * If the current count of the latch is zero then this method returns immediately. + * <p> + * If the current count is greater than zero then the current + * thread becomes disabled for thread scheduling purposes and lies + * dormant until one of two things happen: + * <ul> + * <li>The count reaches zero due to invocations of the + * {@link #countDown} method on any node; or + * <li>Some other thread interrupts the current thread. + * </ul> + * <p> + * If the current thread: + * <ul> + * <li>has its interrupted status set on entry to this method; or + * <li>is interrupted while waiting, + * </ul> + * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's + * interrupted status is cleared. + * + * @throws IgniteCheckedException If operation failed. + * @throws org.apache.ignite.IgniteInterruptedException if the current thread is interrupted + * while waiting + */ + public void await() throws IgniteCheckedException; + + /** + * Causes the current thread to wait until the latch has counted down to + * zero, unless the thread is interrupted, or the specified waiting time elapses. + * <p> + * If the current count is zero then this method returns immediately + * with the value {@code true}. + * <p> + * If the current count is greater than zero then the current + * thread becomes disabled for thread scheduling purposes and lies + * dormant until one of three things happen: + * <ul> + * <li>The count reaches zero due to invocations of the + * {@link #countDown} method on any node; or + * <li>Some other thread interrupts the current thread; or + * <li>The specified waiting time elapses. + * </ul> + * <p> + * If the count reaches zero then the method returns with the + * value {@code true}. + * <p> + * If the current thread: + * <ul> + * <li>has its interrupted status set on entry to this method; or + * <li>is interrupted while waiting, + * </ul> + * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's + * interrupted status is cleared. + * <p> + * If the specified waiting time elapses then the value {@code false} + * is returned. If the time is less than or equal to zero, the method + * will not wait at all. + * + * @param timeout The maximum time to wait in milliseconds. + * @return {@code True} if the count reached zero and {@code false} + * if the waiting time elapsed before the count reached zero. + * @throws org.apache.ignite.IgniteInterruptedException If the current thread is interrupted + * while waiting. + * @throws IgniteCheckedException If operation failed. + */ + public boolean await(long timeout) throws IgniteCheckedException; + + /** + * Causes the current thread to wait until the latch has counted down to + * zero, unless the thread is interrupted, or the specified waiting time elapses. + * <p> + * If the current count is zero then this method returns immediately + * with the value {@code true}. + * <p> + * If the current count is greater than zero then the current + * thread becomes disabled for thread scheduling purposes and lies + * dormant until one of three things happen: + * <ul> + * <li>The count reaches zero due to invocations of the + * {@link #countDown} method on any node; or + * <li>Some other thread interrupts the current thread; or + * <li>The specified waiting time elapses. + * </ul> + * <p> + * If the count reaches zero then the method returns with the + * value {@code true}. + * <p> + * If the current thread: + * <ul> + * <li>has its interrupted status set on entry to this method; or + * <li>is interrupted while waiting, + * </ul> + * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's + * interrupted status is cleared. + * <p> + * If the specified waiting time elapses then the value {@code false} + * is returned. If the time is less than or equal to zero, the method + * will not wait at all. + * + * + * @param timeout The maximum time to wait. + * @param unit The time unit of the {@code timeout} argument. + * @return {@code True} if the count reached zero and {@code false} + * if the waiting time elapsed before the count reached zero. + * @throws org.apache.ignite.IgniteInterruptedException If the current thread is interrupted + * while waiting. + * @throws IgniteCheckedException If operation failed. + */ + public boolean await(long timeout, TimeUnit unit) throws IgniteCheckedException; + + /** + * Decrements the count of the latch, releasing all waiting threads + * on all nodes if the count reaches zero. + * <p> + * If the current count is greater than zero then it is decremented. + * If the new count is zero then all waiting threads are re-enabled for + * thread scheduling purposes. + * <p> + * If the current count equals zero then nothing happens. + * + * @return Count after decrement. + * @throws IgniteCheckedException If operation failed. + */ + public int countDown() throws IgniteCheckedException; + + /** + * Decreases the count of the latch using passed in value, + * releasing all waiting threads on all nodes if the count reaches zero. + * <p> + * If the current count is greater than zero then it is decreased. + * If the new count is zero then all waiting threads are re-enabled for + * thread scheduling purposes. + * <p> + * If the current count equals zero then nothing happens. + * + * @param val Value to decrease counter on. + * @return Count after decreasing. + * @throws IgniteCheckedException If operation failed. + */ + public int countDown(int val) throws IgniteCheckedException; + + /** + * Counts down this latch to zero, releasing all waiting threads on all nodes. + * <p> + * If the current count equals zero then nothing happens. + * + * @throws IgniteCheckedException If operation failed. + */ + public void countDownAll() throws IgniteCheckedException; + + /** + * Gets {@code removed} status of the latch. + * + * @return {@code True} if latch was removed from cache, {@code false} otherwise. + */ + public boolean removed(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidException.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidException.java new file mode 100644 index 0000000..f5b1e11 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidException.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * This checked exception gets thrown if attempt to access an invalid data structure has been made. + * Data structure may become invalid if communication with remote nodes has been lost or + * any other error condition happened that prevented from insuring consistent state. + * <p> + * The best way to handle this error is to discard the invalid data structure instance and try + * getting the underlying data structure from cache again. + * <p> + * Note that data structures throw runtime exceptions out of methods that don't have + * checked exceptions in the signature. + */ +public class CacheDataStructureInvalidException extends IgniteCheckedException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates new exception with given error message. + * + * @param msg Error message. + */ + public CacheDataStructureInvalidException(String msg) { + super(msg); + } + + /** + * Creates new exception with given throwable as a nested cause and + * source of error message. + * + * @param cause Non-null throwable cause. + */ + public CacheDataStructureInvalidException(Throwable cause) { + this(cause.getMessage(), cause); + } + + /** + * Creates a new exception with given error message and optional nested cause exception. + * + * @param msg Error message. + * @param cause Optional nested exception (can be {@code null}). + */ + public CacheDataStructureInvalidException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidRuntimeException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidRuntimeException.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidRuntimeException.java new file mode 100644 index 0000000..3fcf528 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureInvalidRuntimeException.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * This runtime exception gets thrown if attempt to access an invalid data structure has been made. + * Data structure may become invalid if communication with remote nodes has been lost or + * any other error condition happened that prevented from insuring consistent state. + * <p> + * The best way to handle this error is to discard the invalid data structure instance and try + * getting the underlying data structure from cache again. + * <p> + * Note that data structures throw runtime exceptions out of methods that don't have + * checked exceptions in the signature. + */ +public class CacheDataStructureInvalidRuntimeException extends IgniteException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates new exception with given error message. + * + * @param msg Error message. + */ + public CacheDataStructureInvalidRuntimeException(String msg) { + super(msg); + } + + /** + * Creates new exception with given throwable as a nested cause and + * source of error message. + * + * @param cause Non-null throwable cause. + */ + public CacheDataStructureInvalidRuntimeException(Throwable cause) { + this(cause.getMessage(), cause); + } + + /** + * Creates a new exception with given error message and optional nested cause exception. + * + * @param msg Error message. + * @param cause Optional nested exception (can be {@code null}). + */ + public CacheDataStructureInvalidRuntimeException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedException.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedException.java new file mode 100644 index 0000000..5be9e13 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedException.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * This checked exception gets thrown if attempt to access a removed data structure has been made. + * <p> + * Note that data structures throw runtime exceptions out of methods that don't have + * checked exceptions in the signature. + */ +public class CacheDataStructureRemovedException extends IgniteCheckedException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates new exception with given error message. + * + * @param msg Error message. + */ + public CacheDataStructureRemovedException(String msg) { + super(msg); + } + + /** + * Creates new exception with given throwable as a nested cause and + * source of error message. + * + * @param cause Non-null throwable cause. + */ + public CacheDataStructureRemovedException(Throwable cause) { + this(cause.getMessage(), cause); + } + + /** + * Creates a new exception with given error message and optional nested cause exception. + * + * @param msg Error message. + * @param cause Optional nested exception (can be {@code null}). + */ + public CacheDataStructureRemovedException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedRuntimeException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedRuntimeException.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedRuntimeException.java new file mode 100644 index 0000000..dbacaf9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructureRemovedRuntimeException.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * This runtime exception gets thrown if attempt to access a removed data structure has been made. + * <p> + * Note that data structures throw runtime exceptions out of methods that don't have + * checked exceptions in the signature. + */ +public class CacheDataStructureRemovedRuntimeException extends IgniteException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates new exception with given error message. + * + * @param msg Error message. + */ + public CacheDataStructureRemovedRuntimeException(String msg) { + super(msg); + } + + /** + * Creates new exception with given throwable as a nested cause and + * source of error message. + * + * @param cause Non-null throwable cause. + */ + public CacheDataStructureRemovedRuntimeException(Throwable cause) { + this(cause.getMessage(), cause); + } + + /** + * Creates a new exception with given error message and optional nested cause exception. + * + * @param msg Error message. + * @param cause Optional nested exception (can be {@code null}). + */ + public CacheDataStructureRemovedRuntimeException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructures.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructures.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructures.java new file mode 100644 index 0000000..fd2df8a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheDataStructures.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * Facade for working with distributed cache data structures. All cache data structures are similar + * in APIs to {@code 'java.util.concurrent'} package, but all operations on them are grid-aware. + * For example, if you increment {@link CacheAtomicLong} on one node, another node will + * know about the change. Or if you add an element to {@link CacheQueue} on one node, + * you can poll it on another node. + * <p> + * You can get data structures facade by calling {@link org.apache.ignite.cache.Cache#dataStructures()} method. + */ +public interface CacheDataStructures { + /** + * Will get an atomic sequence from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * + * @param name Sequence name. + * @param initVal Initial value for sequence. If sequence already cached, {@code initVal} will be ignored. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Sequence for the given name. + * @throws IgniteCheckedException If sequence could not be fetched or created. + */ + @Nullable public CacheAtomicSequence atomicSequence(String name, long initVal, boolean create) + throws IgniteCheckedException; + + /** + * Remove sequence from cache. + * + * @param name Sequence name. + * @return {@code True} if sequence has been removed, {@code false} otherwise. + * @throws IgniteCheckedException If remove failed. + */ + public boolean removeAtomicSequence(String name) throws IgniteCheckedException; + + /** + * Will get a atomic long from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * + * @param name Name of atomic long. + * @param initVal Initial value for atomic long. If atomic long already cached, {@code initVal} + * will be ignored. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Atomic long. + * @throws IgniteCheckedException If atomic long could not be fetched or created. + */ + @Nullable public CacheAtomicLong atomicLong(String name, long initVal, boolean create) throws IgniteCheckedException; + + /** + * Remove atomic long from cache. + * + * @param name Name of atomic long. + * @return {@code True} if atomic long has been removed, {@code false} otherwise. + * @throws IgniteCheckedException If removing failed. + */ + public boolean removeAtomicLong(String name) throws IgniteCheckedException; + + /** + * Will get a named queue from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * If queue is present in cache already, queue properties will not be changed. Use + * collocation for {@link org.apache.ignite.cache.CacheMode#PARTITIONED} caches if you have lots of relatively + * small queues as it will make fetching, querying, and iteration a lot faster. If you have + * few very large queues, then you should consider turning off collocation as they simply + * may not fit in a single node's memory. However note that in this case + * to get a single element off the queue all nodes may have to be queried. + * + * @param name Name of queue. + * @param cap Capacity of queue, {@code 0} for unbounded queue. + * @param collocated If {@code true} then all items within the same queue will be collocated on the same node. + * Otherwise elements of the same queue maybe be cached on different nodes. If you have lots of relatively + * small queues, then you should use collocation. If you have few large queues, then you should turn off + * collocation. This parameter works only for {@link org.apache.ignite.cache.CacheMode#PARTITIONED} cache. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Queue with given properties. + * @throws IgniteCheckedException If remove failed. + */ + @Nullable public <T> CacheQueue<T> queue(String name, int cap, boolean collocated, + boolean create) throws IgniteCheckedException; + + /** + * Remove queue from cache. Internally one transaction will be created for all elements + * in the queue. If you anticipate that queue may be large, then it's better to use + * {@link #removeQueue(String, int)} which allows to specify batch size. In that case + * transaction will be split into multiple transactions which will have upto {@code batchSize} + * elements in it. + * + * @param name Name queue. + * @return {@code True} if queue has been removed and false if it's not cached. + * @throws IgniteCheckedException If remove failed. + */ + public boolean removeQueue(String name) throws IgniteCheckedException; + + /** + * Remove queue from cache. Internally multiple transactions will be created + * with no more than {@code batchSize} elements in them. For larger queues, this + * method is preferrable over {@link #removeQueue(String)} which will create only + * one transaction for the whole operation. + * + * @param name Name queue. + * @param batchSize Batch size. + * @return {@code True} if queue has been removed and false if it's not cached. + * @throws IgniteCheckedException If remove failed. + */ + public boolean removeQueue(String name, int batchSize) throws IgniteCheckedException; + + /** + * Will get a named set from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * + * @param name Set name. + * @param collocated If {@code true} then all items within the same set will be collocated on the same node. + * Otherwise elements of the same set maybe be cached on different nodes. This parameter works only + * for {@link org.apache.ignite.cache.CacheMode#PARTITIONED} cache. + * @param create Flag indicating whether set should be created if does not exist. + * @return Set with given properties. + * @throws IgniteCheckedException If failed. + */ + @Nullable public <T> CacheSet<T> set(String name, boolean collocated, boolean create) throws IgniteCheckedException; + + /** + * Removes set from cache. + * + * @param name Set name. + * @return {@code True} if set has been removed and false if it's not cached. + * @throws IgniteCheckedException If failed. + */ + public boolean removeSet(String name) throws IgniteCheckedException; + + /** + * Will get a atomic reference from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * + * @param name Atomic reference name. + * @param initVal Initial value for atomic reference. If atomic reference already cached, + * {@code initVal} will be ignored. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Atomic reference for the given name. + * @throws IgniteCheckedException If atomic reference could not be fetched or created. + */ + @Nullable public <T> CacheAtomicReference<T> atomicReference(String name, @Nullable T initVal, boolean create) + throws IgniteCheckedException; + + /** + * Remove atomic reference from cache. + * + * @param name Atomic reference name. + * @return {@code True} if atomic reference has been removed, {@code false} otherwise. + * @throws IgniteCheckedException If remove failed. + */ + public boolean removeAtomicReference(String name) throws IgniteCheckedException; + + /** + * Will get a atomic stamped from cache and create one if it has not been created yet and {@code create} flag + * is {@code true}. + * + * @param name Atomic stamped name. + * @param initVal Initial value for atomic stamped. If atomic stamped already cached, + * {@code initVal} will be ignored. + * @param initStamp Initial stamp for atomic stamped. If atomic stamped already cached, + * {@code initStamp} will be ignored. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Atomic stamped for the given name. + * @throws IgniteCheckedException If atomic stamped could not be fetched or created. + */ + @Nullable public <T, S> CacheAtomicStamped<T, S> atomicStamped(String name, @Nullable T initVal, + @Nullable S initStamp, boolean create) throws IgniteCheckedException; + + /** + * Remove atomic stamped from cache. + * + * @param name Atomic stamped name. + * @return {@code True} if atomic stamped has been removed, {@code false} otherwise. + * @throws IgniteCheckedException If remove failed. + */ + public boolean removeAtomicStamped(String name) throws IgniteCheckedException; + + /** + * Gets or creates count down latch. If count down latch is not found in cache and {@code create} flag + * is {@code true}, it is created using provided name and count parameter. + * + * @param name Name of the latch. + * @param cnt Count for new latch creation. + * @param autoDel {@code True} to automatically delete latch from cache + * when its count reaches zero. + * @param create Boolean flag indicating whether data structure should be created if does not exist. + * @return Count down latch for the given name. + * @throws IgniteCheckedException If operation failed. + */ + @Nullable public CacheCountDownLatch countDownLatch(String name, int cnt, boolean autoDel, boolean create) + throws IgniteCheckedException; + + /** + * Removes count down latch from cache. + * + * @param name Name of the latch. + * @return Count down latch for the given name. + * @throws IgniteCheckedException If operation failed. + */ + public boolean removeCountDownLatch(String name) throws IgniteCheckedException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheQueue.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheQueue.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheQueue.java new file mode 100644 index 0000000..c47b185 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheQueue.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * This interface provides a rich API for working with distributed queues based on In-Memory Data Grid. + * <p> + * <h1 class="header">Overview</h1> + * Cache queue provides an access to cache elements using typical queue API. Cache queue also implements + * {@link Collection} interface and provides all methods from collections including + * {@link Collection#addAll(Collection)}, {@link Collection#removeAll(Collection)}, and + * {@link Collection#retainAll(Collection)} methods for bulk operations. Note that all + * {@link Collection} methods in the queue may throw {@link IgniteException} in case + * of failure. + * <p> + * All queue operations have synchronous and asynchronous counterparts. + * <h1 class="header">Bounded vs Unbounded</h1> + * Queues can be {@code unbounded} or {@code bounded}. {@code Bounded} queues can + * have maximum capacity. Queue capacity can be set at creation time and cannot be + * changed later. Here is an example of how to create {@code bounded} {@code LIFO} queue with + * capacity of {@code 1000} items. + * <pre name="code" class="java"> + * CacheQueue<String> queue = cache().queue("anyName", LIFO, 1000); + * ... + * queue.add("item"); + * </pre> + * For {@code bounded} queues <b>blocking</b> operations, such as {@link #take()} or {@link #put(Object)} + * are available. These operations will block until queue capacity changes to make the operation + * possible. + * <h1 class="header">Collocated vs Non-collocated</h1> + * Queue items can be placed on one node or distributed throughout grid nodes + * (governed by {@code collocated} parameter). {@code Non-collocated} mode is provided only + * for partitioned caches. If {@code collocated} parameter is {@code true}, then all queue items + * will be collocated on one node, otherwise items will be distributed through all grid nodes. + * Unless explicitly specified, by default queues are {@code collocated}. + * <p> + * Here is an example of how create {@code unbounded} queue + * in non-collocated mode. + * <pre name="code" class="java"> + * CacheQueue<String> queue = cache().queue("anyName", 0 /*unbounded*/, false /*non-collocated*/); + * ... + * queue.add("item"); + * </pre> + * <h1 class="header">Creating Cache Queues</h1> + * Instances of distributed cache queues can be created by calling the following method + * on {@link CacheDataStructures} API: + * <ul> + * <li>{@link CacheDataStructures#queue(String, int, boolean, boolean)}</li> + * </ul> + * @see CacheDataStructures#queue(String, int, boolean, boolean) + * @see CacheDataStructures#removeQueue(String) + * @see CacheDataStructures#removeQueue(String, int) + */ +public interface CacheQueue<T> extends BlockingQueue<T> { + /** + * Gets queue name. + * + * @return Queue name. + */ + public String name(); + + /** {@inheritDoc} */ + @Override public boolean add(T item) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean offer(T item) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean addAll(Collection<? extends T> items) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean contains(Object item) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean containsAll(Collection<?> items) throws IgniteException; + + /** {@inheritDoc} */ + @Override public void clear() throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean remove(Object item) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean removeAll(Collection<?> items) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean isEmpty() throws IgniteException; + + /** {@inheritDoc} */ + @Override public Iterator<T> iterator() throws IgniteException; + + /** {@inheritDoc} */ + @Override public Object[] toArray() throws IgniteException; + + /** {@inheritDoc} */ + @Override public <T> T[] toArray(T[] a) throws IgniteException; + + /** {@inheritDoc} */ + @Override public boolean retainAll(Collection<?> items) throws IgniteException; + + /** {@inheritDoc} */ + @Override public int size() throws IgniteException; + + /** {@inheritDoc} */ + @Override @Nullable public T poll() throws IgniteException; + + /** {@inheritDoc} */ + @Override @Nullable public T peek() throws IgniteException; + + /** {@inheritDoc} */ + @Override public void put(T item) throws IgniteException; + + /** {@inheritDoc} */ + @Override @Nullable public T take() throws IgniteException; + + /** {@inheritDoc} */ + @Override @Nullable public T poll(long timeout, TimeUnit unit) throws IgniteException; + + /** + * Removes all of the elements from this queue. Method is used in massive queues with huge numbers of elements. + * + * @param batchSize Batch size. + * @throws IgniteException if operation failed. + */ + public void clear(int batchSize) throws IgniteException; + + /** + * Gets maximum number of elements of the queue. + * + * @return Maximum number of elements. If queue is unbounded {@code Integer.MAX_SIZE} will return. + * @throws IgniteCheckedException If operation failed. + */ + public int capacity() throws IgniteCheckedException; + + /** + * Returns {@code true} if this queue is bounded. + * + * @return {@code true} if this queue is bounded. + * @throws IgniteCheckedException If operation failed. + */ + public boolean bounded() throws IgniteCheckedException; + + /** + * Returns {@code true} if this queue can be kept on the one node only. + * Returns {@code false} if this queue can be kept on the many nodes. + * + * @return {@code true} if this queue is in {@code collocated} mode {@code false} otherwise. + * @throws IgniteCheckedException If operation failed. + */ + public boolean collocated() throws IgniteCheckedException; + + /** + * Gets status of queue. + * + * @return {@code true} if queue was removed from cache {@code false} otherwise. + */ + public boolean removed(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheSet.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheSet.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheSet.java new file mode 100644 index 0000000..b049922 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/CacheSet.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.datastructures; + +import org.apache.ignite.*; + +import java.util.*; + +/** + * Set implementation based on on In-Memory Data Grid. + * <h1 class="header">Overview</h1> + * Cache set implements {@link Set} interface and provides all methods from collections. + * Note that all {@link Collection} methods in the set may throw {@link IgniteException} in case of failure + * or if set was removed. + * <h1 class="header">Collocated vs Non-collocated</h1> + * Set items can be placed on one node or distributed throughout grid nodes + * (governed by {@code collocated} parameter). {@code Non-collocated} mode is provided only + * for partitioned caches. If {@code collocated} parameter is {@code true}, then all set items + * will be collocated on one node, otherwise items will be distributed through all grid nodes. + * @see CacheDataStructures#set(String, boolean, boolean) + * @see CacheDataStructures#removeSet(String) + */ +public interface CacheSet<T> extends Set<T> { + /** + * Gets set name. + * + * @return Set name. + */ + public String name(); + + /** + * Returns {@code true} if this set can be kept on the one node only. + * Returns {@code false} if this set can be kept on the many nodes. + * + * @return {@code True} if this set is in {@code collocated} mode {@code false} otherwise. + * @throws IgniteCheckedException If operation failed. + */ + public boolean collocated() throws IgniteCheckedException; + + /** + * Gets status of set. + * + * @return {@code True} if set was removed from cache {@code false} otherwise. + */ + public boolean removed(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicLong.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicLong.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicLong.java deleted file mode 100644 index ac49a54..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicLong.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.datastructures; - -import org.apache.ignite.*; - -/** - * This interface provides a rich API for working with distributedly cached atomic long value. - * <p> - * <h1 class="header">Functionality</h1> - * Distributed atomic long includes the following main functionality: - * <ul> - * <li> - * Method {@link #get()} synchronously gets current value of atomic long. - * </li> - * <li> - * Various {@code get..(..)} methods synchronously get current value of atomic long - * and increase or decrease value of atomic long. - * </li> - * <li> - * Method {@link #addAndGet(long l)} synchronously sums {@code l} with current value of atomic long - * and returns result. - * </li> - * <li> - * Method {@link #incrementAndGet()} synchronously increases value of atomic long and returns result. - * </li> - * <li> - * Method {@link #decrementAndGet()} synchronously decreases value of atomic long and returns result. - * </li> - * <li> - * Method {@link #getAndSet(long l)} synchronously gets current value of atomic long and sets {@code l} - * as value of atomic long. - * </li> - * </ul> - * All previously described methods have asynchronous analogs. - * <ul> - * <li> - * Method {@link #name()} gets name of atomic long. - * </li> - * </ul> - * <p> - * <h1 class="header">Creating Distributed Atomic Long</h1> - * Instance of distributed atomic long can be created by calling the following method: - * <ul> - * <li>{@link GridCacheDataStructures#atomicLong(String, long, boolean)}</li> - * </ul> - * @see GridCacheDataStructures#atomicLong(String, long, boolean) - * @see GridCacheDataStructures#removeAtomicLong(String) - */ -public interface GridCacheAtomicLong { - /** - * Name of atomic long. - * - * @return Name of atomic long. - */ - public String name(); - - /** - * Gets current value of atomic long. - * - * @return Current value of atomic long. - * @throws IgniteCheckedException If operation failed. - */ - public long get() throws IgniteCheckedException; - - /** - * Increments and gets current value of atomic long. - * - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long incrementAndGet() throws IgniteCheckedException; - - /** - * Gets and increments current value of atomic long. - * - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndIncrement() throws IgniteCheckedException; - - /** - * Adds {@code l} and gets current value of atomic long. - * - * @param l Number which will be added. - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long addAndGet(long l) throws IgniteCheckedException; - - /** - * Gets current value of atomic long and adds {@code l}. - * - * @param l Number which will be added. - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndAdd(long l) throws IgniteCheckedException; - - /** - * Decrements and gets current value of atomic long. - * - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long decrementAndGet() throws IgniteCheckedException; - - /** - * Gets and decrements current value of atomic long. - * - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndDecrement() throws IgniteCheckedException; - - /** - * Gets current value of atomic long and sets new value {@code l} of atomic long. - * - * @param l New value of atomic long. - * @return Value. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndSet(long l) throws IgniteCheckedException; - - /** - * Atomically compares current value to the expected value, and if they are equal, sets current value - * to new value. - * - * @param expVal Expected atomic long's value. - * @param newVal New atomic long's value to set if current value equal to expected value. - * @return {@code True} if comparison succeeded, {@code false} otherwise. - * @throws IgniteCheckedException If failed. - */ - public boolean compareAndSet(long expVal, long newVal) throws IgniteCheckedException; - - /** - * Gets status of atomic. - * - * @return {@code true} if atomic was removed from cache, {@code false} in other case. - */ - public boolean removed(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicReference.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicReference.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicReference.java deleted file mode 100644 index 9d3d69a..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicReference.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.datastructures; - -import org.apache.ignite.*; - -/** - * This interface provides a rich API for working with distributed atomic reference. - * <p> - * <h1 class="header">Functionality</h1> - * Distributed atomic reference includes the following main functionality: - * <ul> - * <li> - * Method {@link #get()} synchronously gets current value of an atomic reference. - * </li> - * <li> - * Method {@link #set(Object)} synchronously and unconditionally sets the value in the an atomic reference. - * </li> - * <li> - * Methods {@code compareAndSet(...)} synchronously and conditionally set the value in the an atomic reference. - * </li> - * </ul> - * All previously described methods have asynchronous analogs. - * <ul> - * <li> - * Method {@link #name()} gets name of atomic reference. - * </li> - * </ul> - * <h1 class="header">Creating Distributed Atomic Reference</h1> - * Instance of distributed atomic reference can be created by calling the following method: - * <ul> - * <li>{@link GridCacheDataStructures#atomicReference(String, Object, boolean)}</li> - * </ul> - * @see GridCacheDataStructures#atomicReference(String, Object, boolean) - * @see GridCacheDataStructures#removeAtomicReference(String) - */ -public interface GridCacheAtomicReference<T> { - /** - * Name of atomic reference. - * - * @return Name of an atomic reference. - */ - public String name(); - - /** - * Gets current value of an atomic reference. - * - * @return current value of an atomic reference. - * @throws IgniteCheckedException If operation failed. - */ - public T get() throws IgniteCheckedException; - - /** - * Unconditionally sets the value. - * - * @param val Value. - * @throws IgniteCheckedException If operation failed. - */ - public void set(T val) throws IgniteCheckedException; - - /** - * Conditionally sets the new value. That will be set if {@code expVal} is equal - * to current value respectively. - * - * @param expVal Expected value. - * @param newVal New value. - * @return Result of operation execution. If {@code true} than value have been updated. - * @throws IgniteCheckedException If operation failed. - */ - public boolean compareAndSet(T expVal, T newVal) throws IgniteCheckedException; - - /** - * Gets status of atomic. - * - * @return {@code true} if an atomic reference was removed from cache, {@code false} otherwise. - */ - public boolean removed(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicSequence.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicSequence.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicSequence.java deleted file mode 100644 index 051d2e3..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicSequence.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.datastructures; - -import org.apache.ignite.*; - -/** - * This interface provides a rich API for working with distributed atomic sequence. - * <p> - * <h1 class="header">Functionality</h1> - * Distributed atomic sequence includes the following main functionality: - * <ul> - * <li> - * Method {@link #get()} synchronously gets current value from atomic sequence. - * </li> - * <li> - * Various {@code get..(..)} methods synchronously get current value from atomic sequence - * and increase atomic sequences value. - * </li> - * <li> - * Various {@code add..(..)} {@code increment(..)} methods synchronously increase atomic sequences value - * and return increased value. - * </li> - * </ul> - * All previously described methods have asynchronous analogs. - * <ul> - * <li> - * Method {@link #batchSize(int size)} sets batch size of current atomic sequence. - * </li> - * <li> - * Method {@link #batchSize()} gets current batch size of atomic sequence. - * </li> - * <li> - * Method {@link #name()} gets name of atomic sequence. - * </li> - * </ul> - * <h1 class="header">Creating Distributed Atomic Sequence</h1> - * Instance of distributed atomic sequence can be created by calling the following method: - * <ul> - * <li>{@link GridCacheDataStructures#atomicSequence(String, long, boolean)}</li> - * </ul> - * @see GridCacheDataStructures#atomicSequence(String, long, boolean) - * @see GridCacheDataStructures#removeAtomicSequence(String) - */ -public interface GridCacheAtomicSequence { - /** - * Name of atomic sequence. - * - * @return Name of atomic sequence. - */ - public String name(); - - /** - * Gets current value of atomic sequence. - * - * @return Value of atomic sequence. - * @throws IgniteCheckedException If operation failed. - */ - public long get() throws IgniteCheckedException; - - /** - * Increments and returns the value of atomic sequence. - * - * @return Value of atomic sequence after increment. - * @throws IgniteCheckedException If operation failed. - */ - public long incrementAndGet() throws IgniteCheckedException; - - /** - * Gets and increments current value of atomic sequence. - * - * @return Value of atomic sequence before increment. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndIncrement() throws IgniteCheckedException; - - /** - * Adds {@code l} elements to atomic sequence and gets value of atomic sequence. - * - * @param l Number of added elements. - * @return Value of atomic sequence. - * @throws IgniteCheckedException If operation failed. - */ - public long addAndGet(long l) throws IgniteCheckedException; - - /** - * Gets current value of atomic sequence and adds {@code l} elements. - * - * @param l Number of added elements. - * @return Value of atomic sequence. - * @throws IgniteCheckedException If operation failed. - */ - public long getAndAdd(long l) throws IgniteCheckedException; - - /** - * Gets local batch size for this atomic sequence. - * - * @return Sequence batch size. - */ - public int batchSize(); - - /** - * Sets local batch size for atomic sequence. - * - * @param size Sequence batch size. Must be more then 0. - */ - public void batchSize(int size); - - /** - * Gets status of atomic sequence. - * - * @return {@code true} if atomic sequence was removed from cache, {@code false} otherwise. - */ - public boolean removed(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicStamped.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicStamped.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicStamped.java deleted file mode 100644 index 8480708..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheAtomicStamped.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.datastructures; - -import org.apache.ignite.*; -import org.apache.ignite.lang.*; - -/** - * This interface provides a rich API for working with distributed atomic stamped value. - * <p> - * <h1 class="header">Functionality</h1> - * Distributed atomic stamped includes the following main functionality: - * <ul> - * <li> - * Method {@link #get()} synchronously gets both value and stamp of atomic. - * </li> - * <li> - * Method {@link #value()} synchronously gets current value of atomic. - * </li> - * <li> - * Method {@link #stamp()} synchronously gets current stamp of atomic. - * </li> - * <li> - * Method {@link #set(Object, Object)} synchronously and unconditionally sets the value - * and the stamp in the atomic. - * </li> - * <li> - * Methods {@code compareAndSet(...)} synchronously and conditionally set the value - * and the stamp in the atomic. - * </li> - * </ul> - * All previously described methods have asynchronous analogs. - * <ul> - * <li> - * Method {@link #name()} gets name of atomic stamped. - * </li> - * </ul> - * <h1 class="header">Creating Distributed Atomic Stamped</h1> - * Instance of distributed atomic stamped can be created by calling the following method: - * <ul> - * <li>{@link GridCacheDataStructures#atomicLong(String, long, boolean)}</li> - * </ul> - * @see GridCacheDataStructures#atomicStamped(String, Object, Object, boolean) - * @see GridCacheDataStructures#removeAtomicStamped(String) - */ -public interface GridCacheAtomicStamped<T, S> { - /** - * Name of atomic stamped. - * - * @return Name of atomic stamped. - */ - public String name(); - - /** - * Gets both current value and current stamp of atomic stamped. - * - * @return both current value and current stamp of atomic stamped. - * @throws IgniteCheckedException If operation failed. - */ - public IgniteBiTuple<T, S> get() throws IgniteCheckedException; - - /** - * Unconditionally sets the value and the stamp. - * - * @param val Value. - * @param stamp Stamp. - * @throws IgniteCheckedException If operation failed. - */ - public void set(T val, S stamp) throws IgniteCheckedException; - - /** - * Conditionally sets the new value and new stamp. They will be set if {@code expVal} - * and {@code expStamp} are equal to current value and current stamp respectively. - * - * @param expVal Expected value. - * @param newVal New value. - * @param expStamp Expected stamp. - * @param newStamp New stamp. - * @return Result of operation execution. If {@code true} than value and stamp will be updated. - * @throws IgniteCheckedException If operation failed. - */ - public boolean compareAndSet(T expVal, T newVal, S expStamp, S newStamp) throws IgniteCheckedException; - - /** - * Gets current stamp. - * - * @return Current stamp. - * @throws IgniteCheckedException If operation failed. - */ - public S stamp() throws IgniteCheckedException; - - /** - * Gets current value. - * - * @return Current value. - * @throws IgniteCheckedException If operation failed. - */ - public T value() throws IgniteCheckedException; - - /** - * Gets status of atomic. - * - * @return {@code true} if atomic stamped was removed from cache, {@code false} otherwise. - */ - public boolean removed(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cafee25f/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheCountDownLatch.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheCountDownLatch.java b/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheCountDownLatch.java deleted file mode 100644 index e2c621c..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/datastructures/GridCacheCountDownLatch.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.datastructures; - -import org.apache.ignite.*; - -import java.util.concurrent.*; - -/** - * This interface provides a rich API for working with distributed count down latch. - * <p> - * <h1 class="header">Functionality</h1> - * Distributed count down latch provides functionality similar to {@code java.util.CountDownLatch}. - * Note that you cannot remove count down latch having count greater that zero. It should be - * counted down to zero first. - * <h1 class="header">Creating Distributed Count Down Latch</h1> - * Instance of cache count down latch can be created by calling the following method: - * {@link GridCacheDataStructures#countDownLatch(String, int, boolean, boolean)}. - * @see GridCacheDataStructures#countDownLatch(String, int, boolean, boolean) - * @see GridCacheDataStructures#removeCountDownLatch(String) - */ -public interface GridCacheCountDownLatch { - /** - * Gets name of the latch. - * - * @return Name of the latch. - */ - public String name(); - - /** - * Gets current count value of the latch. - * - * @return Current count. - */ - public int count(); - - /** - * Gets initial count value of the latch. - * - * @return Initial count. - */ - public int initialCount(); - - /** - * Gets {@code autoDelete} flag. If this flag is {@code true} latch is removed - * from cache when it has been counted down to 0. - * - * @return Value of {@code autoDelete} flag. - */ - public boolean autoDelete(); - - /** - * Causes the current thread to wait until the latch has counted down to - * zero, unless current thread is interrupted. - * <p> - * If the current count of the latch is zero then this method returns immediately. - * <p> - * If the current count is greater than zero then the current - * thread becomes disabled for thread scheduling purposes and lies - * dormant until one of two things happen: - * <ul> - * <li>The count reaches zero due to invocations of the - * {@link #countDown} method on any node; or - * <li>Some other thread interrupts the current thread. - * </ul> - * <p> - * If the current thread: - * <ul> - * <li>has its interrupted status set on entry to this method; or - * <li>is interrupted while waiting, - * </ul> - * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's - * interrupted status is cleared. - * - * @throws IgniteCheckedException If operation failed. - * @throws org.apache.ignite.IgniteInterruptedException if the current thread is interrupted - * while waiting - */ - public void await() throws IgniteCheckedException; - - /** - * Causes the current thread to wait until the latch has counted down to - * zero, unless the thread is interrupted, or the specified waiting time elapses. - * <p> - * If the current count is zero then this method returns immediately - * with the value {@code true}. - * <p> - * If the current count is greater than zero then the current - * thread becomes disabled for thread scheduling purposes and lies - * dormant until one of three things happen: - * <ul> - * <li>The count reaches zero due to invocations of the - * {@link #countDown} method on any node; or - * <li>Some other thread interrupts the current thread; or - * <li>The specified waiting time elapses. - * </ul> - * <p> - * If the count reaches zero then the method returns with the - * value {@code true}. - * <p> - * If the current thread: - * <ul> - * <li>has its interrupted status set on entry to this method; or - * <li>is interrupted while waiting, - * </ul> - * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's - * interrupted status is cleared. - * <p> - * If the specified waiting time elapses then the value {@code false} - * is returned. If the time is less than or equal to zero, the method - * will not wait at all. - * - * @param timeout The maximum time to wait in milliseconds. - * @return {@code True} if the count reached zero and {@code false} - * if the waiting time elapsed before the count reached zero. - * @throws org.apache.ignite.IgniteInterruptedException If the current thread is interrupted - * while waiting. - * @throws IgniteCheckedException If operation failed. - */ - public boolean await(long timeout) throws IgniteCheckedException; - - /** - * Causes the current thread to wait until the latch has counted down to - * zero, unless the thread is interrupted, or the specified waiting time elapses. - * <p> - * If the current count is zero then this method returns immediately - * with the value {@code true}. - * <p> - * If the current count is greater than zero then the current - * thread becomes disabled for thread scheduling purposes and lies - * dormant until one of three things happen: - * <ul> - * <li>The count reaches zero due to invocations of the - * {@link #countDown} method on any node; or - * <li>Some other thread interrupts the current thread; or - * <li>The specified waiting time elapses. - * </ul> - * <p> - * If the count reaches zero then the method returns with the - * value {@code true}. - * <p> - * If the current thread: - * <ul> - * <li>has its interrupted status set on entry to this method; or - * <li>is interrupted while waiting, - * </ul> - * then {@link org.apache.ignite.IgniteInterruptedException} is thrown and the current thread's - * interrupted status is cleared. - * <p> - * If the specified waiting time elapses then the value {@code false} - * is returned. If the time is less than or equal to zero, the method - * will not wait at all. - * - * - * @param timeout The maximum time to wait. - * @param unit The time unit of the {@code timeout} argument. - * @return {@code True} if the count reached zero and {@code false} - * if the waiting time elapsed before the count reached zero. - * @throws org.apache.ignite.IgniteInterruptedException If the current thread is interrupted - * while waiting. - * @throws IgniteCheckedException If operation failed. - */ - public boolean await(long timeout, TimeUnit unit) throws IgniteCheckedException; - - /** - * Decrements the count of the latch, releasing all waiting threads - * on all nodes if the count reaches zero. - * <p> - * If the current count is greater than zero then it is decremented. - * If the new count is zero then all waiting threads are re-enabled for - * thread scheduling purposes. - * <p> - * If the current count equals zero then nothing happens. - * - * @return Count after decrement. - * @throws IgniteCheckedException If operation failed. - */ - public int countDown() throws IgniteCheckedException; - - /** - * Decreases the count of the latch using passed in value, - * releasing all waiting threads on all nodes if the count reaches zero. - * <p> - * If the current count is greater than zero then it is decreased. - * If the new count is zero then all waiting threads are re-enabled for - * thread scheduling purposes. - * <p> - * If the current count equals zero then nothing happens. - * - * @param val Value to decrease counter on. - * @return Count after decreasing. - * @throws IgniteCheckedException If operation failed. - */ - public int countDown(int val) throws IgniteCheckedException; - - /** - * Counts down this latch to zero, releasing all waiting threads on all nodes. - * <p> - * If the current count equals zero then nothing happens. - * - * @throws IgniteCheckedException If operation failed. - */ - public void countDownAll() throws IgniteCheckedException; - - /** - * Gets {@code removed} status of the latch. - * - * @return {@code True} if latch was removed from cache, {@code false} otherwise. - */ - public boolean removed(); -}