KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > beanflow > State


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.beanflow;
18
19 /**
20  * Represents a piece of state which can be accessed in a multi threaded way
21  * rather like {@link java.util.concurrent.atomic.AtomicReference} but which
22  * also supports the use of listeners to be notified when the state changes.
23  *
24  * @version $Revision: $
25  */

26 public interface State<T> {
27
28     /**
29      * Returns the current value of the state
30      */

31     public T get();
32
33     /**
34      * Sets the current value
35      */

36     public void set(T value);
37
38     /**
39      * Sets the state to a new value and return the old value
40      */

41     public T getAndSet(T value);
42
43     /**
44      * If the current state is the expected value then set it to the given new
45      * value and return true otherwise return false
46      */

47     public boolean compareAndSet(T expected, T newValue);
48
49     /**
50      * Add a task to be executed if the state changes
51      */

52     public void addRunnable(Runnable JavaDoc listener);
53
54     /**
55      * Remove a task
56      */

57     public void removeRunnable(Runnable JavaDoc listener);
58
59     /**
60      * Returns true if the current value is equal to the given value
61      */

62     public boolean is(T that);
63
64     /**
65      * Return true if the current value is equal to any of the given values
66      */

67     public boolean isAny(T... values);
68
69 }
70
Popular Tags