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.core.integ;
21
22
23 import org.apache.directory.api.ldap.model.entry.Entry;
24 import org.apache.directory.api.ldap.model.exception.LdapException;
25 import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
26 import org.apache.directory.server.core.api.filtering.EntryFilter;
27 import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
28 import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
29 import org.apache.directory.server.core.api.interceptor.Interceptor;
30 import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
31
32
33
34
35
36
37
38
39 public class DelayInducingInterceptor extends BaseInterceptor
40 {
41 private Long delayMillis;
42
43
44 public DelayInducingInterceptor()
45 {
46 super( "DelayInterceptor" );
47 }
48
49
50 @Override
51 public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
52 {
53 EntryFilteringCursor cursor = next( searchContext );
54 cursor.addEntryFilter( new EntryFilter()
55 {
56
57
58
59 public boolean accept( SearchOperationContext operation, Entry result ) throws LdapException
60 {
61 if ( delayMillis != null )
62 {
63 try
64 {
65 Thread.sleep( delayMillis );
66 }
67 catch ( InterruptedException ie )
68 {
69 throw new LdapOperationErrorException( ie.getMessage() );
70 }
71 }
72
73 return true;
74 }
75
76
77
78
79
80 public String toString( String tabs )
81 {
82 return tabs + "DelayInducingFilter";
83 }
84 } );
85
86 return cursor;
87 }
88
89
90 public void setDelayMillis( long delayMillis )
91 {
92 if ( delayMillis <= 0 )
93 {
94 this.delayMillis = null;
95 }
96
97 this.delayMillis = delayMillis;
98 }
99 }