01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.applicator;
06:
07: import com.tc.exception.TCNotSupportedMethodException;
08: import com.tc.object.ClientObjectManager;
09: import com.tc.object.TCObject;
10: import com.tc.object.TraversedReferences;
11: import com.tc.object.bytecode.AtomicLongAdapter;
12: import com.tc.object.dna.api.DNA;
13: import com.tc.object.dna.api.DNACursor;
14: import com.tc.object.dna.api.DNAWriter;
15: import com.tc.object.dna.api.DNAEncoding;
16: import com.tc.object.dna.api.PhysicalAction;
17: import com.tc.object.tx.optimistic.OptimisticTransactionManager;
18: import com.tc.util.Assert;
19:
20: import java.io.IOException;
21: import java.util.Map;
22: import java.util.concurrent.atomic.AtomicLong;
23:
24: public class AtomicLongApplicator extends BaseApplicator {
25: public AtomicLongApplicator(DNAEncoding encoding) {
26: super (encoding);
27: }
28:
29: public TraversedReferences getPortableObjects(Object pojo,
30: TraversedReferences addTo) {
31: addTo.addAnonymousReference(pojo);
32: return addTo;
33: }
34:
35: public void hydrate(ClientObjectManager objectManager,
36: TCObject tcObject, DNA dna, Object po) throws IOException,
37: IllegalArgumentException, ClassNotFoundException {
38: DNACursor cursor = dna.getCursor();
39: Assert.eval(cursor.getActionCount() <= 1);
40:
41: if (po instanceof AtomicLong) {
42: if (cursor.next(encoding)) {
43: PhysicalAction a = (PhysicalAction) cursor.getAction();
44: Long value = (Long) a.getObject();
45: ((AtomicLong) po).set(value.longValue());
46: }
47: }
48: }
49:
50: public void dehydrate(ClientObjectManager objectManager,
51: TCObject tcObject, DNAWriter writer, Object pojo) {
52: AtomicLong ai = (AtomicLong) pojo;
53: long value = ai.get();
54:
55: writer.addPhysicalAction(AtomicLongAdapter.VALUE_FIELD_NAME,
56: new Long(value));
57: }
58:
59: public Object getNewInstance(ClientObjectManager objectManager,
60: DNA dna) {
61: throw new UnsupportedOperationException();
62: }
63:
64: public Map connectedCopy(Object source, Object dest, Map visited,
65: ClientObjectManager objectManager,
66: OptimisticTransactionManager txManager) {
67: throw new TCNotSupportedMethodException();
68: }
69: }
|