Please,
Forgive me if this topic has been discussed earlier. I'm quite new with
Turbine and just started more serious work with modules.
The RunData object is a key object all around Turbine and I think that its
correct use could be clarified and its internal state better protected by
making it an interface instead of an object. Now it contains fields that are
partly public and partly private. In addition, also most public fields have
both getters and setters. Yet some of the fields are quite clearly meant to
be initialized only by the factory and should not be changed during
processing.
Examples of interfaces used for corresponding purposes are
HttpServletRequest, HttpServletResponse and HttpSession. An additional
benefit from the change would be the possibility to make implementations
support new functionality, e.g. pooling. As Tomcat pools connectors, request
and response implementations and Turbine caches modules, RunData is one of
the base objects, which is allocated again for every request. For heavy
loaded applications, balancing of memory usage is a key issue.
I tried this by creating a RunData interface, renaming the original RunData
to TurbineRunData and making all of its fields private. I added pooling
support both to TurbineRunData and RunDataFactory. Only five classes in
Turbine (01/31/2001) were referencing the public fields, otherwise
compilation was OK and running some basic Velocity modules worked without
problems.
The classes that required changes were related to error handling (Error,
VelocityErrorScreen, WebMacroErrorScreen) using the stackTrace and
stackTraceException fields. I changed the classes to use getters/setters
instead. In addition, DefaultBottomNavigation used the varDebug field, which
I also moved behind a getter. The Turbine class was changed to return the
used RunData back to the factory to be recycled. For pooling support, I
added a Recyclable interface and a RecyclableSupport class for objects to be
pooled and a BoundedBuffer class for implementing the pool.
The RunData interface is attached and I would be happy to provide the rest,
if this gets support. Comments?
-- Ilkka
--
Nokia Networks
http://www.nokia.com/networks
mail: [EMAIL PROTECTED]
*************************************************************
package org.apache.turbine.util;
// Java Core Classes
import java.util.Hashtable;
import java.io.PrintWriter;
import java.io.IOException;
// Java Servlet Classes
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Turbine Utility Classes
import org.apache.turbine.util.security.AccessControlList;
import org.apache.turbine.util.template.TemplateInfo;
import org.apache.turbine.om.security.User;
// ECS Classes
import org.apache.ecs.Document;
import org.apache.ecs.Element;
import org.apache.ecs.StringElement;
/**
* RunData is an interface for run-time information that is
* passed within Turbine. This provides the threading mechanism
* for the entire system because multiple requests can potentially
* come in at the same time. Thus, there is only one RunData implementation
* for each request that is being serviced.
*
* <p>RunData caches a lot of frequently used data, such as a
* database connection, the queryTable and other important
* information.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Bernie Hoeneisen</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
* @version draft
*/
public interface RunData
{
/**
* Gets the parameters.
*
* @return A ParameterParser.
*/
public ParameterParser getParameters();
/**
* Gets the HttpServletRequest object.
*
* @return An HttpServletRequest.
*/
public HttpServletRequest getRequest();
/**
* Gets the HttpServletResponse object.
*
* @return An HttpServletResponse.
*/
public HttpServletResponse getResponse();
/**
* Gets the Servlet Session information.
*
* @return An HttpSession.
*/
public HttpSession getSession();
/**
* Get the Servlet Configuration used during servlet init.
*
* @return A ServletConfig.
*/
public ServletConfig getServletConfig();
/**
* Get the Servlet Context used during servlet init.
*
* @return A ServletContext.
*/
public ServletContext getServletContext();
/**
* Get the AccessControl object.
*
* @return An AccessControlList.
*/
public AccessControlList getACL();
/**
* Set the AccessControl object.
*
* @param acl An AccessControlList.
*/
public void setACL(AccessControlList acl);
/**
* Check to see if page is set.
*
* @return True if page is set.
*/
public boolean isPageSet();
/**
* Gets the page.
*
* @return A Document.
*/
public Document getPage();
/**
* Whether or not an action has been defined.
*
* @return True if an action has been defined.
*/
public boolean hasAction();
/**
* Get the ACTION= value. It returns an empty string if null so
* that it is easy to do conditionals on it based on the
* equalsIgnoreCase() method.
*
* @return A String, "" if null.
*/
public String getAction();
/**
* Set the action for the request.
*
* @param action A String.
*/
public void setAction(String action);
/**
* If the Layout has not been defined by the Screen then set the
* layout to be "DefaultLayout". The Screen object can also
* override this method to provide intelligent determination of
* the Layout to execute. You can also define that logic here as
* well if you want it to apply on a global scale. For example,
* if you wanted to allow someone to define Layout "preferences"
* where they could dynamicially change the Layout for the entire
* site.
*
* @return A String.
*/
public String getLayout();
/**
* Set the layout for the request.
*
* @param layout A String.
*/
public void setLayout(String layout);
/**
* Convenience method for TemplateInfo Object that
* returns the layout template being used.
*
* @return A String.
*/
public String getLayoutTemplate();
/**
* Modifies the Layout Template for the Screen. This convenience
* method allows for a layout to be modified from within a
* template. For example;
*
* $data.setLayoutTemplate("/NewLayout.vm")
*
* @param layout A layout template.
*/
public void setLayoutTemplate(String layout);
/**
* Whether or not a screen has been defined.
*
* @return True if a screen has been defined.
*/
public boolean hasScreen();
/**
* The screen to execute.
*
* @return A String.
*/
public String getScreen();
/**
* Set the screen for the request.
*
* @param screen A String.
*/
public void setScreen(String screen);
/**
* Convenience method for TemplateInfo Object that
* returns the name of the template being used.
*
* @return A String.
*/
public String getScreenTemplate();
/**
* Sets the Screen Template for the request. For
* example;
* $data.setScreenTemplate("NewScreen.vm")
*
* @param screen A screen template.
*/
public void setScreenTemplate(String screen);
/**
* Return the TemplateInfo object. Create a new one if needed.
*
* @return A TemplateInfo.
*/
public TemplateInfo getTemplateInfo();
/**
* Whether or not a message has been defined.
*
* @return True if a message has been defined.
*/
public boolean hasMessage();
/**
* The results of an Action or other message to be displayed
* should be placed here.
*
* @return A String.
*/
public String getMessage();
/**
* The results of an Action or other message to be displayed
* should be placed here.
*
* @return A StringElement.
*/
public StringElement getMessageAsHTML();
/**
* Set the message for the request.
*
* @param msg A String.
*/
public void setMessage(String msg);
/**
* Set the message for the request.
*
* @param msg An Element.
*/
public void setMessage(Element msg);
/**
* Adds the string to message. If message has prior messages from
* other Actions or Screens, this method can be used to chain
* them.
*
* @param msg A String.
*/
public void addMessage(String msg);
/**
* Adds the ECS Element to message. If message has prior messages
* from other Actions or Screens, this method can be used to chain
* them.
*
* @param msg An Element.
*/
public void addMessage(Element msg);
/**
* Unset the message for the request.
*/
public void unsetMessage();
/**
* Returns a FormMessages object where all the messages to the
* user should be stored.
*
* @return A FormMessages.
*/
public FormMessages getMessages();
/**
* Set the FormMessages object for the request.
*
* @param msgs A FormMessages.
*/
public void setMessages(FormMessages msgs);
/**
* Gets the title of the page.
*
* @return A String.
*/
public String getTitle();
/**
* Set the title for the request.
*
* @param title A String.
*/
public void setTitle(String title);
/**
* See if a User object exists in this session.
*
* @return True if a User object exists in this session.
*/
public boolean userExists();
/**
* Return the user object.
*
* @return A User.
*/
public User getUser();
/**
* Set the user object.
*
* @param user A User.
*/
public void setUser(User user);
/**
* Attempts to get the User object from the session. If it does
* not exist, it returns null.
*
* @return A User.
*/
public User getUserFromSession();
/**
* Allows one to invalidate the user in the default session.
*
* @return True if user was invalidated.
*/
public boolean removeUserFromSession();
/**
* Gets the PrintWriter. First time calling this will set the
* PrintWriter via res.getWriter().
*
* @return A PrintWriter.
* @exception IOException.
*/
public PrintWriter getOut()
throws IOException;
/**
* Check to see if out is set.
*
* @return True if out is set.
*/
public boolean isOutSet();
/**
* Declare that output will be direct to the response stream,
* even though getOut() may never be called. Useful for response
* mechanisms that may call res.getWriter() themselves
* (such as JSP.)
*/
public void declareDirectResponse();
/**
* Get the charset. If it has not already been defined with
* setCharSet(), then attempt to get it from the
* TurbineResources.properties file under the property name of
* "locale.default.charset".
*
* @return A String.
*/
public String getCharSet();
/**
* Set the charset.
*
* @param lcharset A String.
*/
public void setCharSet(String lcharset);
/**
* Gets the HTTP content type to return.
*
* @return A String.
*/
public String getContentType();
/**
* Sets the HTTP content type to return.
*
* @param ct A String.
*/
public void setContentType(String ct);
/**
* Get the redirect URI. If this is set, also make sure to set
* the status code to 302.
*
* @return A String, "" if null.
*/
public String getRedirectURI();
/**
* Sets the redirect uri. If this is set, also make sure to set
* the status code to 302.
*
* @param ruri A String.
*/
public void setRedirectURI(String ruri);
/**
* Returns an array of system errors.
*
* @return A SystemError[].
*/
public SystemError[] getSystemErrors();
/**
* Add critical system error.
*
* @param err A SystemError.
*/
public void setSystemError(SystemError err);
/**
* Gets the HTTP status code to return.
*
* @return An int.
*/
public int getStatusCode();
/**
* Sets the HTTP status code to return.
*
* @param sc An int.
*/
public void setStatusCode(int sc);
/**
* Gets JNDI Contexts.
*
* @return A Hashtable.
*/
public Hashtable getJNDIContexts();
/**
* Sets JNDI Contexts.
*
* @param contexts A Hashtable.
*/
public void setJNDIContexts(Hashtable contexts);
/**
* Gets the cached serverScheme that is stored in the ServerData
* object.
*
* @return A String.
*/
public String getServerScheme();
/**
* Sets the cached serverScheme that is stored in the ServerData
* object.
*
* @param ss A String.
*/
public void setServerScheme(String ss);
/**
* Gets the cached serverName that is stored in the ServerData
* object.
*
* @return A String.
*/
public String getServerName();
/**
* Sets the cached serverName that is stored in the ServerData
* object.
*
* @param sn A String.
*/
public void setServerName(String sn);
/**
* Gets the cached serverPort that is stored in the ServerData
* object.
*
* @return An int.
*/
public int getServerPort();
/**
* Sets the cached serverPort that is stored in the ServerData
* object.
*
* @param port An int.
*/
public void setServerPort(int port);
/**
* Gets the cached context path that is stored in the ServerData
* object.
*
* @return A String.
*/
public String getContextPath();
/**
* Sets the cached script name that is stored in the ServerData
* object.
*
* @param sn A String.
*/
public void setContextPath(String cp);
/**
* Gets the cached script name that is stored in the ServerData
* object.
*
* @return A String.
*/
public String getScriptName();
/**
* Sets the cached script name that is stored in the ServerData
* object.
*
* @param sn A String.
*/
public void setScriptName(String sn);
/**
* Get the ServerData used by this RunData.
*
* @return A ServerData.
*/
public ServerData getServerData();
/**
* Returns the Internet Protocol (IP) address of the client that
* sent the request.
*
* @return A String.
*/
public String getRemoteAddr();
/**
* Returns the fully qualified name of the client that sent the
* request.
*
* @return A String.
*/
public String getRemoteHost();
/**
* Get the user agent for this RunData.
*
* @return A String.
*/
public String getUserAgent();
/**
* Pulls a User object from the session and increments the access
* counter and sets the last access date for the object.
*/
public void populate();
/**
* Saves a User object into the session.
*/
public void save();
/**
* Gets the stack trace if set.
*
* @return A String.
*/
public String getStackTrace();
/**
* Gets the stack trace exception if set.
*
* @return A Throwable.
*/
public Throwable getStackTraceException();
/**
* Sets the stack trace.
*
* @param trace A String.
* @param exp A Throwable.
*/
public void setStackTrace(String trace,
Throwable exp);
/**
* Gets a table of debug variables.
*
* @return A Hashtable for debug variables.
*/
public Hashtable getVarDebug();
}
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]