KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > config > Option


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.config;
8
9 import org.jboss.cache.optimistic.DataVersion;
10
11 /**
12  * Used to override characteristics of specific calls to the cache. The javadocs of each of the setters below detail functionality and behaviour.
13  *
14  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
15  * @since 1.3.0
16  */

17 public class Option implements Cloneable JavaDoc
18 {
19    private boolean failSilently;
20    private boolean cacheModeLocal;
21    private DataVersion dataVersion;
22    private boolean suppressLocking;
23    private boolean forceDataGravitation;
24    private boolean bypassInterceptorChain;
25
26    /**
27     * @since 2.0.0
28     * @deprecated This is very kludgy and ugly. If you need to work on a {@link Node} directly, use the XXXDirect() methods on {@link NodeSPI}. This method will disappear before BETA1
29     */

30    public boolean isBypassInterceptorChain()
31    {
32       return bypassInterceptorChain;
33    }
34
35    /**
36     * Bypasses the entire interceptor chain and talks to the cache directly. Use with extreme care, may cause a lot of data corruption and in certain cache configurations, my cause
37     * the cache not to function at all. Intended strictly for internal use only.
38     *
39     * @deprecated This is very kludgy and ugly. If you need to work on a {@link Node} directly, use the XXXDirect() methods on {@link NodeSPI}. This method will disappear before BETA1
40     */

41    public void setBypassInterceptorChain(boolean bypassInterceptorChain)
42    {
43       this.bypassInterceptorChain = bypassInterceptorChain;
44    }
45
46    /**
47     * @since 1.4.0
48     */

49    public boolean isSuppressLocking()
50    {
51       return suppressLocking;
52    }
53
54    /**
55     * Suppresses acquiring locks for the given invocation. Used with pessimistic locking only. Use with extreme care, may lead to a breach in data integrity!
56     *
57     * @since 1.4.0
58     */

59    public void setSuppressLocking(boolean suppressLocking)
60    {
61       this.suppressLocking = suppressLocking;
62    }
63
64
65    /**
66     * @since 1.3.0
67     */

68    public boolean isFailSilently()
69    {
70       return failSilently;
71    }
72
73    /**
74     * suppress any failures in your cache operation, including version mismatches with optimistic locking, timeouts obtaining locks, transaction rollbacks. If this is option is set, the method invocation will __never fail or throw an exception__, although it may not succeed. With this option enabled the call will <b>not</b> participate in any ongoing transactions even if a transaction is running.
75     *
76     * @since 1.3.0
77     */

78    public void setFailSilently(boolean failSilently)
79    {
80       this.failSilently = failSilently;
81    }
82
83    /**
84     * only applies to put() and remove() methods on the cache.
85     *
86     * @since 1.3.0
87     */

88    public boolean isCacheModeLocal()
89    {
90       return cacheModeLocal;
91    }
92
93    /**
94     * overriding CacheMode from REPL_SYNC, REPL_ASYNC, INVALIDATION_SYNC, INVALIDATION_ASYNC to LOCAL. Only applies to put() and remove() methods on the cache.
95     *
96     * @param cacheModeLocal
97     * @since 1.3.0
98     */

99    public void setCacheModeLocal(boolean cacheModeLocal)
100    {
101       this.cacheModeLocal = cacheModeLocal;
102    }
103
104    /**
105     * @since 1.3.0
106     */

107    public DataVersion getDataVersion()
108    {
109       return dataVersion;
110    }
111
112    /**
113     * Passing in an {@link org.jboss.cache.optimistic.DataVersion} instance when using optimistic locking will override the default behaviour of internally generated version info and allow the caller to handle data versioning.
114     *
115     * @since 1.3.0
116     */

117    public void setDataVersion(DataVersion dataVersion)
118    {
119       this.dataVersion = dataVersion;
120    }
121
122    /**
123     * @since 1.4.0
124     */

125    public boolean getForceDataGravitation()
126    {
127       return forceDataGravitation;
128    }
129
130    /**
131     * Enables data gravitation calls if a cache miss is detected when using <a HREF="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheBuddyReplicationDesign">Buddy Replication</a>.
132     * Enabled only for a given invocation, and only useful if <code>autoDataGravitation</code> is set to <code>false</code>.
133     * See <a HREF="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheBuddyReplicationDesign">Buddy Replication</a> documentation for more details.
134     *
135     * @since 1.4.0
136     */

137    public void setForceDataGravitation(boolean enableDataGravitation)
138    {
139       this.forceDataGravitation = enableDataGravitation;
140    }
141
142
143    public String JavaDoc toString()
144    {
145       return "Option{" +
146               "failSilently=" + failSilently +
147               ", cacheModeLocal=" + cacheModeLocal +
148               ", dataVersion=" + dataVersion +
149               ", suppressLocking=" + suppressLocking +
150               ", forceDataGravitation=" + forceDataGravitation +
151               ", bypassInterceptorChain=" + bypassInterceptorChain +
152               '}';
153    }
154
155    public Option clone() throws CloneNotSupportedException JavaDoc
156    {
157       return (Option) super.clone();
158    }
159
160
161    public boolean equals(Object JavaDoc o)
162    {
163       if (this == o) return true;
164       if (o == null || getClass() != o.getClass()) return false;
165
166       final Option option = (Option) o;
167
168       if (bypassInterceptorChain != option.bypassInterceptorChain) return false;
169       if (cacheModeLocal != option.cacheModeLocal) return false;
170       if (failSilently != option.failSilently) return false;
171       if (forceDataGravitation != option.forceDataGravitation) return false;
172       if (suppressLocking != option.suppressLocking) return false;
173       if (dataVersion != null ? !dataVersion.equals(option.dataVersion) : option.dataVersion != null) return false;
174
175       return true;
176    }
177
178    public int hashCode()
179    {
180       int result;
181       result = (failSilently ? 1 : 0);
182       result = 29 * result + (cacheModeLocal ? 1 : 0);
183       result = 29 * result + (dataVersion != null ? dataVersion.hashCode() : 0);
184       result = 29 * result + (suppressLocking ? 1 : 0);
185       result = 29 * result + (forceDataGravitation ? 1 : 0);
186       result = 29 * result + (bypassInterceptorChain ? 1 : 0);
187       return result;
188    }
189
190    /**
191     * Resets this option to defaults.
192     */

193    public void reset()
194    {
195       this.bypassInterceptorChain = false;
196       this.cacheModeLocal = false;
197       this.failSilently = false;
198       this.forceDataGravitation = false;
199       this.suppressLocking = false;
200       this.dataVersion = null;
201    }
202 }
203
Popular Tags