KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > context > ManagedObjectRequestContext


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

5 package com.tc.objectserver.context;
6
7 import com.tc.async.api.Sink;
8 import com.tc.net.protocol.tcm.ChannelID;
9 import com.tc.object.ObjectRequestID;
10 import com.tc.objectserver.api.ObjectManagerLookupResults;
11 import com.tc.text.PrettyPrintable;
12 import com.tc.text.PrettyPrinter;
13
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
19
20 /**
21  * @author steve This is the context needed to make a request to the server for a specific Managed root.
22  */

23 public class ManagedObjectRequestContext implements ObjectManagerResultsContext, PrettyPrintable {
24   private final long timestamp;
25   private final ChannelID channelID;
26   private final Set JavaDoc requestedObjectIDs;
27   private Map JavaDoc objects;
28   private final ObjectRequestID requestID;
29   private boolean moreObjects = false;
30   private int batchCount = 0;
31   private Set JavaDoc lookupPendingObjectIDs;
32   private final int maxRequestDepth;
33   private final Sink sink;
34
35   public ManagedObjectRequestContext(ChannelID channelID, ObjectRequestID requestID, Set JavaDoc ids, int maxRequestDepth,
36                                      Sink sink) {
37     this.maxRequestDepth = maxRequestDepth;
38     this.sink = sink;
39     this.timestamp = System.currentTimeMillis();
40     this.channelID = channelID;
41     this.requestID = requestID;
42     this.requestedObjectIDs = ids;
43   }
44
45   public int getMaxRequestDepth() {
46     return this.maxRequestDepth;
47   }
48
49   public boolean hasMoreObjects() {
50     return moreObjects;
51   }
52
53   public ChannelID getChannelID() {
54     return channelID;
55   }
56
57   public int getBatchCount() {
58     return batchCount;
59   }
60
61   public ObjectRequestID getRequestID() {
62     return this.requestID;
63   }
64
65   public Set JavaDoc getLookupIDs() {
66     return requestedObjectIDs;
67   }
68
69   public Collection JavaDoc getObjects() {
70     return objects.values();
71   }
72
73   public Set JavaDoc getLookupPendingObjectIDs() {
74     return this.lookupPendingObjectIDs;
75   }
76
77   public PrettyPrinter prettyPrint(PrettyPrinter out) {
78     out.println("ManagedObjectRequestContext");
79     PrettyPrinter rv = out;
80     out = out.duplicateAndIndent();
81     out.indent().println(new Date JavaDoc(timestamp));
82     out.indent().println("channelID: " + channelID);
83     out.indent().println("requestID: " + requestID);
84     out.indent().print("requestedObjectIDs: ").println(requestedObjectIDs);
85     return rv;
86   }
87
88   public void setResults(ObjectManagerLookupResults results) {
89     this.objects = results.getObjects();
90     this.lookupPendingObjectIDs = results.getLookupPendingObjectIDs();
91     this.sink.add(this); // Add to next stage
92
}
93
94   public Sink getSink() {
95     return this.sink;
96   }
97
98   public Set JavaDoc getNewObjectIDs() {
99     return Collections.EMPTY_SET;
100   }
101
102 }
103
Popular Tags