com.google.code.rees.scope.conversation.context
Class DefaultConversationContextManager

java.lang.Object
  extended by com.google.code.rees.scope.conversation.context.DefaultConversationContextManager
All Implemented Interfaces:
ConversationContextManager, Serializable
Direct Known Subclasses:
TimeoutConversationContextManager

public class DefaultConversationContextManager
extends Object
implements ConversationContextManager

The default implementation of the ConversationContextManager.

Author:
rees.byars
See Also:
Serialized Form

Field Summary
protected  ConversationContextFactory contextFactory
           
protected  Map<String,Map<String,ConversationContext>> conversations
           
protected  int maxInstances
           
protected  long nextId
           
 
Constructor Summary
DefaultConversationContextManager()
           
 
Method Summary
 ConversationContext createContext(String conversationName, long maxIdleTimeMillis)
          Creates a new context for the given conversation name, using the given idle time
 void destroy()
          Cleanup and release the manager's resources
 ConversationContext getContext(String conversationName, String conversationId)
          Retrieve the context identified by the given information, creating a new one if none exists.
protected  String getNextId()
           
 ConversationContext remove(String conversationName, String conversationId)
          Remove the context identified by the given information, returning the context being removed
protected  void removeMostStaleConversation(Map<String,ConversationContext> conversationContexts, String conversationName, long defaultDuration)
          Recursively removes the least-recently accessed conversations until the number of remaining conversations equals maxInstances
 void setContextFactory(ConversationContextFactory contextFactory)
          Set the ConversationContextFactory to be used by this manager
 void setMaxInstances(int maxInstances)
          Set the max number of cached ConversationContexts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contextFactory

protected ConversationContextFactory contextFactory

conversations

protected Map<String,Map<String,ConversationContext>> conversations

maxInstances

protected int maxInstances

nextId

protected long nextId
Constructor Detail

DefaultConversationContextManager

public DefaultConversationContextManager()
Method Detail

setMaxInstances

public void setMaxInstances(int maxInstances)
Set the max number of cached ConversationContexts.

Specified by:
setMaxInstances in interface ConversationContextManager

setContextFactory

public void setContextFactory(ConversationContextFactory contextFactory)
Set the ConversationContextFactory to be used by this manager

Specified by:
setContextFactory in interface ConversationContextManager

createContext

public ConversationContext createContext(String conversationName,
                                         long maxIdleTimeMillis)
Creates a new context for the given conversation name, using the given idle time

Specified by:
createContext in interface ConversationContextManager
Returns:

getContext

public ConversationContext getContext(String conversationName,
                                      String conversationId)
Retrieve the context identified by the given information, creating a new one if none exists.

Specified by:
getContext in interface ConversationContextManager
Returns:

remove

public ConversationContext remove(String conversationName,
                                  String conversationId)
Remove the context identified by the given information, returning the context being removed

Specified by:
remove in interface ConversationContextManager
Returns:

destroy

public void destroy()
Cleanup and release the manager's resources

Specified by:
destroy in interface ConversationContextManager

removeMostStaleConversation

protected void removeMostStaleConversation(Map<String,ConversationContext> conversationContexts,
                                           String conversationName,
                                           long defaultDuration)
Recursively removes the least-recently accessed conversations until the number of remaining conversations equals maxInstances


getNextId

protected String getNextId()


Copyright © 2012-2013. All Rights Reserved.