KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > l2 > context > ManagedObjectSyncContext


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.l2.context;
6
7 import com.tc.async.api.Sink;
8 import com.tc.bytes.TCByteBuffer;
9 import com.tc.net.groups.NodeID;
10 import com.tc.object.dna.impl.ObjectStringSerializer;
11 import com.tc.objectserver.api.ObjectManagerLookupResults;
12 import com.tc.objectserver.context.ObjectManagerResultsContext;
13 import com.tc.util.Assert;
14
15 import java.util.Collections JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.HashSet JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Set JavaDoc;
20
21 public class ManagedObjectSyncContext implements ObjectManagerResultsContext {
22
23   private final NodeID nodeID;
24   private final Set JavaDoc oids;
25   private final boolean more;
26   private final Sink nextSink;
27   private final Map JavaDoc rootsMap;
28
29   private ObjectManagerLookupResults result;
30   private TCByteBuffer[] dnas;
31   private int dnaCount;
32   private ObjectStringSerializer serializer;
33
34   public ManagedObjectSyncContext(NodeID nodeID, Set JavaDoc oids, boolean more, Sink sink) {
35     this.nodeID = nodeID;
36     this.oids = oids;
37     this.more = more;
38     this.nextSink = sink;
39     this.rootsMap = Collections.EMPTY_MAP;
40   }
41
42   public ManagedObjectSyncContext(NodeID nodeID, HashMap JavaDoc rootsMap, boolean more, Sink sink) {
43     this.nodeID = nodeID;
44     this.oids = new HashSet JavaDoc(rootsMap.values());
45     this.more = more;
46     this.nextSink = sink;
47     this.rootsMap = rootsMap;
48   }
49
50   public void setResults(ObjectManagerLookupResults results) {
51     this.result = results;
52     nextSink.add(this);
53   }
54
55   public Set JavaDoc getLookupIDs() {
56     return oids;
57   }
58   
59   public Map JavaDoc getRootsMap() {
60     return rootsMap;
61   }
62
63   public Map JavaDoc getObjects() {
64     Assert.assertNotNull(result);
65     return result.getObjects();
66   }
67
68   public void setDehydratedBytes(TCByteBuffer[] buffers, int count, ObjectStringSerializer os) {
69     this.dnas = buffers;
70     this.dnaCount = count;
71     this.serializer = os;
72   }
73
74   public NodeID getNodeID() {
75     return nodeID;
76   }
77
78   public void close() {
79     // TODO::change state
80
}
81
82   public ObjectStringSerializer getObjectSerializer() {
83     Assert.assertNotNull(serializer);
84     return serializer;
85   }
86
87   public TCByteBuffer[] getSerializedDNAs() {
88     Assert.assertNotNull(dnas);
89     return dnas;
90   }
91
92   public int getDNACount() {
93     Assert.assertTrue(dnaCount > 0);
94     return dnaCount;
95   }
96
97   public boolean hasMore() {
98     return more;
99   }
100
101   public Set JavaDoc getNewObjectIDs() {
102     return Collections.EMPTY_SET;
103   }
104
105
106 }
107
Popular Tags