1717
1818package org .apache .ignite .internal .processors .cache .transactions ;
1919
20- import java .nio .ByteBuffer ;
2120import org .apache .ignite .IgniteCheckedException ;
22- import org .apache .ignite .internal .GridDirectTransient ;
23- import org .apache .ignite .internal .IgniteCodeGeneratingFail ;
21+ import org .apache .ignite .internal .Order ;
22+ import org .apache .ignite .internal .managers . communication . GridCacheOperationMessage ;
2423import org .apache .ignite .internal .processors .cache .CacheObject ;
2524import org .apache .ignite .internal .processors .cache .CacheObjectValueContext ;
2625import org .apache .ignite .internal .processors .cache .GridCacheContext ;
2928import org .apache .ignite .internal .util .tostring .GridToStringInclude ;
3029import org .apache .ignite .internal .util .typedef .internal .S ;
3130import org .apache .ignite .plugin .extensions .communication .Message ;
32- import org .apache .ignite .plugin .extensions .communication .MessageReader ;
33- import org .apache .ignite .plugin .extensions .communication .MessageWriter ;
3431import org .jetbrains .annotations .Nullable ;
3532
3633import static org .apache .ignite .internal .processors .cache .GridCacheOperation .CREATE ;
4239/**
4340 * Auxiliary class to hold value, value-has-been-set flag, value update operation, value bytes.
4441 */
45- @ IgniteCodeGeneratingFail // Need to handle 'hasWriteVal' flag during write.
4642public class TxEntryValueHolder implements Message {
47- /** */
43+ /** Stored value. */
44+ @ Order (value = 0 , method = "value" )
4845 @ GridToStringInclude (sensitive = true )
49- private CacheObject val ;
46+ private @ Nullable CacheObject val ;
5047
5148 /** */
5249 @ GridToStringInclude
5350 private GridCacheOperation op = NOOP ;
5451
52+ /** Cache operation stub for serialization. */
53+ @ Order (value = 1 , method = "operationMessage" )
54+ @ SuppressWarnings ("unused" )
55+ private GridCacheOperationMessage opMsg ;
56+
5557 /** Flag indicating that value has been set for write. */
58+ @ Order (value = 2 , method = "hasWriteValue" )
5659 @ GridToStringExclude
5760 private boolean hasWriteVal ;
5861
5962 /** Flag indicating that value has been set for read. */
6063 @ GridToStringExclude
61- @ GridDirectTransient
6264 private boolean hasReadVal ;
6365
6466 /**
@@ -67,7 +69,7 @@ public class TxEntryValueHolder implements Message {
6769 * @param hasWriteVal Write value presence flag.
6870 * @param hasReadVal Read value presence flag.
6971 */
70- public void value (GridCacheOperation op , CacheObject val , boolean hasWriteVal , boolean hasReadVal ) {
72+ public void updateValue (GridCacheOperation op , CacheObject val , boolean hasWriteVal , boolean hasReadVal ) {
7173 if (hasReadVal && this .hasWriteVal )
7274 return ;
7375
@@ -86,16 +88,14 @@ public boolean hasValue() {
8688 }
8789
8890 /**
89- * Gets stored value.
90- *
91- * @return Value.
91+ * @return Stored value.
9292 */
9393 public CacheObject value () {
9494 return val ;
9595 }
9696
9797 /**
98- * @param val Stored value.
98+ * @param val New stored value.
9999 */
100100 public void value (@ Nullable CacheObject val ) {
101101 this .val = val ;
@@ -120,19 +120,40 @@ public void op(GridCacheOperation op) {
120120 }
121121
122122 /**
123- * @return {@code True} if write value was set.
123+ * @return Flag indicating that value has been set for write .
124124 */
125125 public boolean hasWriteValue () {
126126 return hasWriteVal ;
127127 }
128128
129+ /**
130+ * @param hasWriteVal New flag indicating that value has been set for write.
131+ */
132+ public void hasWriteValue (boolean hasWriteVal ) {
133+ this .hasWriteVal = hasWriteVal ;
134+ }
135+
129136 /**
130137 * @return {@code True} if read value was set.
131138 */
132139 public boolean hasReadValue () {
133140 return hasReadVal ;
134141 }
135142
143+ /**
144+ * @return Cache operation message.
145+ */
146+ public GridCacheOperationMessage operationMessage () {
147+ return new GridCacheOperationMessage (op );
148+ }
149+
150+ /**
151+ * @param opMsg New cache operation message.
152+ */
153+ public void operationMessage (GridCacheOperationMessage opMsg ) {
154+ op = opMsg != null ? opMsg .value () : null ;
155+ }
156+
136157 /**
137158 * @param ctx Cache context.
138159 * @throws org.apache.ignite.IgniteCheckedException If marshaling failed.
@@ -158,79 +179,6 @@ public void unmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws Ignit
158179 return S .toString (TxEntryValueHolder .class , this );
159180 }
160181
161- /** {@inheritDoc} */
162- @ Override public boolean writeTo (ByteBuffer buf , MessageWriter writer ) {
163- writer .setBuffer (buf );
164-
165- if (!writer .isHeaderWritten ()) {
166- if (!writer .writeHeader (directType ()))
167- return false ;
168-
169- writer .onHeaderWritten ();
170- }
171-
172- switch (writer .state ()) {
173- case 0 :
174- if (!writer .writeBoolean (hasWriteVal ))
175- return false ;
176-
177- writer .incrementState ();
178-
179- case 1 :
180- if (!writer .writeByte (op != null ? (byte )op .ordinal () : -1 ))
181- return false ;
182-
183- writer .incrementState ();
184-
185- case 2 :
186- if (!writer .writeCacheObject (hasWriteVal ? val : null ))
187- return false ;
188-
189- writer .incrementState ();
190-
191- }
192-
193- return true ;
194- }
195-
196- /** {@inheritDoc} */
197- @ Override public boolean readFrom (ByteBuffer buf , MessageReader reader ) {
198- reader .setBuffer (buf );
199-
200- switch (reader .state ()) {
201- case 0 :
202- hasWriteVal = reader .readBoolean ();
203-
204- if (!reader .isLastRead ())
205- return false ;
206-
207- reader .incrementState ();
208-
209- case 1 :
210- byte opOrd ;
211-
212- opOrd = reader .readByte ();
213-
214- if (!reader .isLastRead ())
215- return false ;
216-
217- op = GridCacheOperation .fromOrdinal (opOrd );
218-
219- reader .incrementState ();
220-
221- case 2 :
222- val = reader .readCacheObject ();
223-
224- if (!reader .isLastRead ())
225- return false ;
226-
227- reader .incrementState ();
228-
229- }
230-
231- return true ;
232- }
233-
234182 /** {@inheritDoc} */
235183 @ Override public short directType () {
236184 return 101 ;
0 commit comments