You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2008/12/17 13:41:07 UTC
svn commit: r727359 - in
/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap:
LdapSession.java handlers/SearchHandler.java
handlers/controls/PagedSearchContext.java
handlers/controls/PagedSearchCookie.java
Author: elecharny
Date: Wed Dec 17 04:41:07 2008
New Revision: 727359
URL: http://svn.apache.org/viewvc?rev=727359&view=rev
Log:
o Renamed the PagedSearchCookie to PagedSearchContext, as it's a way better name
o Stored this context in the LdapSession instead of the IoSession
o Added methods in LdapSession to manage this context (add, remove, get)
Added:
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java
- copied, changed from r725712, directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java
Removed:
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java
Modified:
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapSession.java
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapSession.java?rev=727359&r1=727358&r2=727359&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapSession.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapSession.java Wed Dec 17 04:41:07 2008
@@ -28,6 +28,8 @@
import org.apache.directory.server.core.CoreSession;
import org.apache.directory.server.core.authn.LdapPrincipal;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.server.ldap.handlers.controls.PagedSearchContext;
import org.apache.directory.shared.ldap.message.AbandonableRequest;
import org.apache.directory.shared.ldap.message.BindStatus;
import org.apache.mina.core.session.IoSession;
@@ -82,6 +84,9 @@
*/
private Map<String, Object> saslProperties;
+ /** A map containing all the paged search context */
+ private Map<Integer, PagedSearchContext> pagedSearchContexts;
+
/**
* Creates a new instance of LdapSession associated with the underlying
@@ -96,6 +101,7 @@
outstandingRequests = new ConcurrentHashMap<Integer, AbandonableRequest>();
bindStatus = BindStatus.ANONYMOUS;
saslProperties = new HashMap<String, Object>();
+ pagedSearchContexts = new HashMap<Integer, PagedSearchContext>();
}
@@ -378,6 +384,67 @@
/**
+ * Add a new Paged Search context into the stored context. If some
+ * context with the same id already exists, it will be closed and
+ * removed.
+ *
+ * @param context The context to add
+ */
+ public void addPagedSearchContext( PagedSearchContext context ) throws Exception
+ {
+ synchronized ( pagedSearchContexts )
+ {
+ PagedSearchContext oldContext = pagedSearchContexts.put( context.getCookieValue(), context );
+
+ if ( oldContext != null )
+ {
+ EntryFilteringCursor cursor = oldContext.getCursor();
+
+ if ( cursor != null )
+ {
+ try
+ {
+ cursor.close();
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Failing on cursor close : {}", e.getMessage() );
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Remove a Paged Search context from the map storing all of them.
+ *
+ * @param contextId The context ID to remove
+ * @return The removed context if any found
+ */
+ public PagedSearchContext removePagedSearchContext( int contextId )
+ {
+ synchronized ( pagedSearchContexts )
+ {
+ return pagedSearchContexts.remove( contextId );
+ }
+ }
+
+
+ /**
+ * Get paged search context associated with an ID
+ * @param contextId The id for teh context we want to get
+ * @return The associated context, if any
+ */
+ public PagedSearchContext getPagedSearchContext( int contextId )
+ {
+ synchronized ( pagedSearchContexts )
+ {
+ return pagedSearchContexts.get( contextId );
+ }
+ }
+
+ /**
* The principal and remote address associated with this session.
* @see Object#toString()
*/
Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=727359&r1=727358&r2=727359&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Wed Dec 17 04:41:07 2008
@@ -31,7 +31,7 @@
import org.apache.directory.server.core.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.partition.PartitionNexus;
import org.apache.directory.server.ldap.LdapSession;
-import org.apache.directory.server.ldap.handlers.controls.PagedSearchCookie;
+import org.apache.directory.server.ldap.handlers.controls.PagedSearchContext;
import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
@@ -344,14 +344,14 @@
private void readPagedResults( LdapSession session, SearchRequest req, LdapResult ldapResult,
EntryFilteringCursor cursor, int sizeLimit, int pagedLimit, boolean isPaged,
- PagedSearchCookie cookieInstance, PagedResultsControl pagedResultsControl ) throws Exception
+ PagedSearchContext pagedContext, PagedResultsControl pagedResultsControl ) throws Exception
{
req.addAbandonListener( new SearchAbandonListener( ldapService, cursor ) );
setTimeLimitsOnCursor( req, session, cursor );
LOG.debug( "using <{},{}> for size limit", sizeLimit, pagedLimit );
int cookieValue = 0;
- int count = cookieInstance.getCurrentPosition();
+ int count = pagedContext.getCurrentPosition();
int pageCount = 0;
while ( ( count < sizeLimit ) && ( pageCount < pagedLimit ) && cursor.next() )
@@ -382,9 +382,8 @@
// That means we don't have anymore entry
// If we are here, it means we have returned all the entries
// We have to remove the cookie from the session
- cookieValue = cookieInstance.getCookieValue();
- PagedSearchCookie psCookie =
- (PagedSearchCookie)session.getIoSession().removeAttribute( cookieValue );
+ cookieValue = pagedContext.getCookieValue();
+ PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
// Close the cursor if there is one
if ( psCookie != null )
@@ -414,7 +413,7 @@
req.getResultResponse().add( pagedResultsControl );
// Stores the cursor current position
- cookieInstance.incrementCurrentPosition( pageCount );
+ pagedContext.incrementCurrentPosition( pageCount );
return;
}
else
@@ -427,7 +426,7 @@
cursor.close();
}
- session.getIoSession().removeAttribute( cookieValue );
+ session.removePagedSearchContext( cookieValue );
return;
}
@@ -452,8 +451,7 @@
// If the cookie is not null, we have to destroy the associated
// cursor stored into the session (if any)
int cookieValue = pagedSearchControl.getCookieValue();
- PagedSearchCookie psCookie =
- (PagedSearchCookie)session.getIoSession().removeAttribute( cookieValue );
+ PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
pagedResultsControl = new PagedResultsControl( 0, psCookie.getCookie(), true );
// Close the cursor
@@ -481,7 +479,7 @@
/**
* Remove a cookie instance from the session, if it exists.
*/
- private PagedSearchCookie removeCookie( LdapSession session, PagedSearchCookie cookieInstance )
+ private PagedSearchContext removeContext( LdapSession session, PagedSearchContext cookieInstance )
{
if ( cookieInstance == null )
{
@@ -490,7 +488,7 @@
int cookieValue = cookieInstance.getCookieValue();
- return (PagedSearchCookie)session.getIoSession().removeAttribute( cookieValue );
+ return session.removePagedSearchContext( cookieValue );
}
@@ -513,7 +511,7 @@
int pagedLimit = pagedSearchControl.getSize();
EntryFilteringCursor cursor = null;
- PagedSearchCookie cookieInstance = null;
+ PagedSearchContext pagedContext = null;
// We have the following cases :
// 1) The SIZE is 0 and the cookie is the same than the previous one : this
@@ -572,17 +570,16 @@
}
// If we had a cookie in the session, remove it
- removeCookie( session, cookieInstance );
+ removeContext( session, pagedContext );
return ( SearchResponseDone ) req.getResultResponse();
}
else
{
- // Case 2 : create the cookie
- cookieInstance = new PagedSearchCookie( req );
- cookie = cookieInstance.getCookie();
- int cookieValue = cookieInstance.getCookieValue();
+ // Case 2 : create the context
+ pagedContext = new PagedSearchContext( req );
- session.getIoSession().setAttribute( cookieValue, cookieInstance );
+ session.addPagedSearchContext( pagedContext );
+ cookie = pagedContext.getCookie();
pagedResultsControl = new PagedResultsControl( 0, cookie, true );
// No cursor : do a search.
@@ -592,7 +589,7 @@
cursor.beforeFirst();
// And stores the cursor into the session
- cookieInstance.setCursor( cursor );
+ pagedContext.setCursor( cursor );
}
}
else
@@ -600,10 +597,9 @@
// We have a cookie
// Either case 3, 4 or 5
int cookieValue = pagedSearchControl.getCookieValue();
- cookieInstance =
- (PagedSearchCookie)session.getIoSession().getAttribute( cookieValue );
+ pagedContext = session.getPagedSearchContext( cookieValue );
- if ( cookieInstance == null )
+ if ( pagedContext == null )
{
// We didn't found the cookie into the session : it must be invalid
// send an error.
@@ -613,32 +609,32 @@
return ( SearchResponseDone ) req.getResultResponse();
}
- if ( cookieInstance.hasSameRequest( req, session ) )
+ if ( pagedContext.hasSameRequest( req, session ) )
{
// Case 3 : continue the search
- cursor = cookieInstance.getCursor();
+ cursor = pagedContext.getCursor();
// get the cookie
- cookie = cookieInstance.getCookie();
+ cookie = pagedContext.getCookie();
pagedResultsControl = new PagedResultsControl( 0, cookie, true );
}
else
{
// case 2 : create a new cursor
// We have to close the cursor
- cursor = cookieInstance.getCursor();
+ cursor = pagedContext.getCursor();
if ( cursor != null )
{
cursor.close();
}
- // Now create a new cookie and stores it into the session
- cookieInstance = new PagedSearchCookie( req );
- cookie = cookieInstance.getCookie();
- cookieValue = cookieInstance.getCookieValue();
+ // Now create a new context and stores it into the session
+ pagedContext = new PagedSearchContext( req );
- session.getIoSession().setAttribute( cookieValue, cookieInstance );
+ session.addPagedSearchContext( pagedContext );
+
+ cookie = pagedContext.getCookie();
pagedResultsControl = new PagedResultsControl( 0, cookie, true );
}
}
@@ -650,7 +646,7 @@
*/
try
{
- readPagedResults( session, req, ldapResult, cursor, sizeLimit, pagedLimit, true, cookieInstance, pagedResultsControl );
+ readPagedResults( session, req, ldapResult, cursor, sizeLimit, pagedLimit, true, pagedContext, pagedResultsControl );
}
catch ( Exception e )
{
Copied: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java (from r725712, directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java?p2=directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java&p1=directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java&r1=725712&r2=727359&rev=727359&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java Wed Dec 17 04:41:07 2008
@@ -41,7 +41,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev: $
*/
-public class PagedSearchCookie
+public class PagedSearchContext
{
/** The previous search request */
private SearchRequest previousSearchRequest;
@@ -61,7 +61,7 @@
/**
* Creates a new instance of this class, storing the Searchrequest into it.
*/
- public PagedSearchCookie( SearchRequest searchRequest )
+ public PagedSearchContext( SearchRequest searchRequest )
{
previousSearchRequest = searchRequest;
currentPosition = 0;
@@ -314,6 +314,14 @@
*/
public String toString()
{
- return "PagedSearch cookie:" + StringTools.dumpBytes( cookie );
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "PagedSearch context : <" );
+ sb.append( StringTools.dumpBytes( cookie ) );
+ sb.append( ", " );
+ sb.append( currentPosition );
+ sb.append( ">" );
+
+ return sb.toString();
}
}