001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.context;
006:
007: import com.tc.async.api.Sink;
008: import com.tc.net.groups.ClientID;
009: import com.tc.object.ObjectID;
010: import com.tc.object.ObjectRequestID;
011: import com.tc.objectserver.api.ObjectManagerLookupResults;
012: import com.tc.text.PrettyPrintable;
013: import com.tc.text.PrettyPrinter;
014:
015: import java.util.Collection;
016: import java.util.Collections;
017: import java.util.Date;
018: import java.util.HashSet;
019: import java.util.Map;
020: import java.util.Set;
021:
022: /**
023: * This is the context needed to make a request to the server for a specific Managed root.
024: */
025: public class ManagedObjectRequestContext implements
026: ObjectManagerResultsContext, PrettyPrintable {
027: private final long timestamp;
028: private final ClientID clientID;
029: private final Set requestedObjectIDs;
030: private Map objects;
031: private final ObjectRequestID requestID;
032: private boolean moreObjects = false;
033: private int batchCount = 0;
034: private Set lookupPendingObjectIDs;
035: private final int maxRequestDepth;
036: private final Sink sink;
037: private final Set missingObjects = new HashSet();
038: private final String requestingThreadName;
039:
040: public ManagedObjectRequestContext(ClientID clientID,
041: ObjectRequestID requestID, Set ids, int maxRequestDepth,
042: Sink sink, String requestingThreadName) {
043: this .maxRequestDepth = maxRequestDepth;
044: this .sink = sink;
045: this .requestingThreadName = requestingThreadName;
046: this .timestamp = System.currentTimeMillis();
047: this .clientID = clientID;
048: this .requestID = requestID;
049: this .requestedObjectIDs = ids;
050: }
051:
052: public int getMaxRequestDepth() {
053: return this .maxRequestDepth;
054: }
055:
056: public boolean hasMoreObjects() {
057: return moreObjects;
058: }
059:
060: public ClientID getRequestedNodeID() {
061: return clientID;
062: }
063:
064: public int getBatchCount() {
065: return batchCount;
066: }
067:
068: public ObjectRequestID getRequestID() {
069: return this .requestID;
070: }
071:
072: public Set getLookupIDs() {
073: return requestedObjectIDs;
074: }
075:
076: public Collection getObjects() {
077: return objects.values();
078: }
079:
080: public Set getLookupPendingObjectIDs() {
081: return this .lookupPendingObjectIDs;
082: }
083:
084: public PrettyPrinter prettyPrint(PrettyPrinter out) {
085: out.println("ManagedObjectRequestContext");
086: PrettyPrinter rv = out;
087: out = out.duplicateAndIndent();
088: out.indent().println(new Date(timestamp));
089: out.indent().println("channelID: " + clientID);
090: out.indent().println("requestID: " + requestID);
091: out.indent().print("requestedObjectIDs: ").println(
092: requestedObjectIDs);
093: return rv;
094: }
095:
096: public String toString() {
097: return "ManagedObjectRequestContext@"
098: + System.identityHashCode(this ) + " [ " + clientID
099: + " , " + requestID + " , " + requestedObjectIDs
100: + ", requestingThread = " + requestingThreadName + " ]";
101: }
102:
103: public String getRequestingThreadName() {
104: return requestingThreadName;
105: }
106:
107: public void setResults(ObjectManagerLookupResults results) {
108: this .objects = results.getObjects();
109: this .lookupPendingObjectIDs = results
110: .getLookupPendingObjectIDs();
111: this .sink.add(this ); // Add to next stage
112: }
113:
114: public Sink getSink() {
115: return this .sink;
116: }
117:
118: public Set getNewObjectIDs() {
119: return Collections.EMPTY_SET;
120: }
121:
122: public void missingObject(ObjectID oid) {
123: missingObjects.add(oid);
124: }
125:
126: public Set getMissingObjectIDs() {
127: return missingObjects;
128: }
129:
130: }
|