1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.ldap.handlers;
21
22
23 import org.apache.directory.server.core.event.DirectoryListener;
24 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
25 import org.apache.directory.server.ldap.LdapService;
26 import org.apache.directory.shared.ldap.exception.OperationAbandonedException;
27 import org.apache.directory.shared.ldap.message.AbandonListener;
28 import org.apache.directory.shared.ldap.message.AbandonableRequest;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40 public class SearchAbandonListener implements AbandonListener
41 {
42 private static final Logger LOG = LoggerFactory.getLogger( SearchAbandonListener.class );
43 private final LdapService ldapService;
44 private EntryFilteringCursor cursor;
45 private DirectoryListener listener;
46
47
48 public SearchAbandonListener( LdapService ldapService, EntryFilteringCursor cursor, DirectoryListener listener )
49 {
50 if ( ldapService == null )
51 {
52 throw new NullPointerException( "ldapService" );
53 }
54
55 this.ldapService = ldapService;
56 this.cursor = cursor;
57 this.listener = listener;
58 }
59
60
61 public SearchAbandonListener( LdapService ldapService, DirectoryListener listener )
62 {
63 this ( ldapService, null, listener );
64 }
65
66
67 public SearchAbandonListener( LdapService ldapService, EntryFilteringCursor cursor )
68 {
69 this ( ldapService, cursor, null );
70 }
71
72
73 public void requestAbandoned( AbandonableRequest req )
74 {
75 if ( listener != null )
76 {
77 ldapService.getDirectoryService().getEventService().removeListener( listener );
78 }
79
80 try
81 {
82 if ( cursor != null )
83 {
84
85
86
87
88
89
90
91 cursor.close( new OperationAbandonedException() );
92 }
93 }
94 catch ( Exception e )
95 {
96 LOG.error( "Failed to close the search cursor for message {} on abandon request.",
97 req.getMessageId(), e );
98 }
99 }
100 }
101
102