001: /**
002: * $Id: ResponseBufferEntry.java,v 1.3 2004/03/03 19:31:28 batchu Exp $
003: * Copyright 2003 Sun Microsystems, Inc.
004: * All rights reserved.
005: * Use of this product is subject to license terms.
006: * Federal Acquisitions: Commercial Software -- Government Users
007: * Subject to Standard License Terms and Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
010: * registered trademarks of Sun Microsystems, Inc. in the
011: * United States and other countries.
012: */package com.sun.mobile.responsebuffer;
013:
014: import com.aligo.util.Cache;
015:
016: /**
017: * ResponseBufferEntry is a wrapper for Aligo's Cache (com.aligo.util.Cache)
018: * objects. The only utility it provides is storage management and
019: * lifecycle management.
020: *
021: * Aligo's Cache objects are populated by the RenderingEngine when
022: * the data to be rendered is much too big for the device.
023: */
024: public class ResponseBufferEntry {
025: /**
026: * Creates a ResponseBufferEntry in a given ResponseBufferGroup with a
027: * given entry number for buffering the data generated by the given
028: * request url.
029: *
030: * Nobody other than ResponseBufferService should be calling this. Every
031: * other caller should be using the following method instead.
032: *
033: * @see com.sun.portal.wireless.cache.ResponseBufferService
034: */
035: ResponseBufferEntry(ResponseBufferGroup response_buffer_group,
036: Integer response_buffer_entry_number, Cache buffer) {
037: _group = response_buffer_group;
038: _entry_number = response_buffer_entry_number;
039: _buffer = buffer;
040:
041: if (buffer != null) {
042: _request_url = buffer.getRequestUrl();
043: }
044: }
045:
046: private ResponseBufferEntry() {
047: // Disallow this constructor
048: }
049:
050: /**
051: * To get reference to the wrapped com.aligo.util.Cache object
052: */
053: public Cache getCache() throws StaleResponseBufferDataException {
054: if (!isValid()) {
055: throw new StaleResponseBufferDataException();
056: }
057:
058: return (_buffer);
059: }
060:
061: /**
062: * Returns the validity of this ResponseBufferEntry
063: */
064: public synchronized boolean isValid() {
065: return (_is_valid);
066: }
067:
068: /**
069: * Marks this entry invalid. Throws StaleResponseBufferDataException on further calls
070: * to getCache method.
071: *
072: * @see com.sun.portal.wireless.cache.StaleResponseBufferDataException
073: */
074: synchronized void setInvalid() {
075: if (_is_valid) {
076: _is_valid = false;
077: }
078: }
079:
080: public synchronized void invalidate() {
081: if (isValid()) {
082: setInvalid();
083:
084: // Tell the parent if necessary
085: if (_group != null) {
086: _group.invalidate(_entry_number);
087: }
088: }
089: }
090:
091: /**
092: * Gets the request url which generated the data buffered and managed by this
093: * ResponseBufferEntry.
094: */
095: public String getRequestURL() {
096: return (_request_url);
097: }
098:
099: /**
100: * Gets the ResponseBufferGroup managing this ResponseBufferEntry.
101: */
102: public ResponseBufferGroup getGroup() {
103: return (_group);
104: }
105:
106: /**
107: * Gets the number assigned to this ResponseBufferEntry by its parent
108: * ResponseBufferGroup.
109: */
110: public Integer getEntryNumber() {
111: return (_entry_number);
112: }
113:
114: /**
115: * Holds the reference to ResponseBufferGroup responsible for managing this entry
116: */
117: private ResponseBufferGroup _group = null;
118:
119: /**
120: * Holds the number by which ResponseBufferGroup refers to this entry
121: */
122: private Integer _entry_number = null;
123:
124: /**
125: * Holds the url which generated the content buffered response by this entry
126: */
127: private String _request_url = null;
128:
129: /**
130: * To mark whether or not the data buffered response is still valid.
131: */
132: private boolean _is_valid = true;
133:
134: /**
135: * To hold the Aligo's Cache object which actually holds the buffered response
136: * content.
137: */
138: private Cache _buffer = null;
139: }
|