author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.jndi.ldap; |
|
27 |
||
28 |
import java.io.IOException; |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
29 |
import java.util.concurrent.BlockingQueue; |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
30 |
import java.util.concurrent.LinkedBlockingQueue; |
2 | 31 |
import javax.naming.CommunicationException; |
32 |
||
33 |
final class LdapRequest { |
|
34 |
||
35 |
LdapRequest next; // Set/read in synchronized Connection methods |
|
36 |
int msgId; // read-only |
|
37 |
||
38 |
private int gotten = 0; |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
39 |
private BlockingQueue<BerDecoder> replies; |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
40 |
private int highWatermark = -1; |
2 | 41 |
private boolean cancelled = false; |
42 |
private boolean pauseAfterReceipt = false; |
|
43 |
private boolean completed = false; |
|
44 |
||
45 |
LdapRequest(int msgId, boolean pause) { |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
46 |
this(msgId, pause, -1); |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
47 |
} |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
48 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
49 |
LdapRequest(int msgId, boolean pause, int replyQueueCapacity) { |
2 | 50 |
this.msgId = msgId; |
51 |
this.pauseAfterReceipt = pause; |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
52 |
if (replyQueueCapacity == -1) { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
53 |
this.replies = new LinkedBlockingQueue<BerDecoder>(); |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
54 |
} else { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
55 |
this.replies = |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
56 |
new LinkedBlockingQueue<BerDecoder>(replyQueueCapacity); |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
57 |
highWatermark = (replyQueueCapacity * 80) / 100; // 80% capacity |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
58 |
} |
2 | 59 |
} |
60 |
||
61 |
synchronized void cancel() { |
|
62 |
cancelled = true; |
|
63 |
||
64 |
// Unblock reader of pending request |
|
25808 | 65 |
// Should only ever have at most one waiter |
2 | 66 |
notify(); |
67 |
} |
|
68 |
||
69 |
synchronized boolean addReplyBer(BerDecoder ber) { |
|
70 |
if (cancelled) { |
|
71 |
return false; |
|
72 |
} |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
73 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
74 |
// Add a new reply to the queue of unprocessed replies. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
75 |
try { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
76 |
replies.put(ber); |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
77 |
} catch (InterruptedException e) { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
78 |
// ignore |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
79 |
} |
2 | 80 |
|
81 |
// peek at the BER buffer to check if it is a SearchResultDone PDU |
|
82 |
try { |
|
83 |
ber.parseSeq(null); |
|
84 |
ber.parseInt(); |
|
85 |
completed = (ber.peekByte() == LdapClient.LDAP_REP_RESULT); |
|
86 |
} catch (IOException e) { |
|
87 |
// ignore |
|
88 |
} |
|
89 |
ber.reset(); |
|
90 |
||
91 |
notify(); // notify anyone waiting for reply |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
92 |
/* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
93 |
* If a queue capacity has been set then trigger a pause when the |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
94 |
* queue has filled to 80% capacity. Later, when the queue has drained |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
95 |
* then the reader gets unpaused. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
96 |
*/ |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
97 |
if (highWatermark != -1 && replies.size() >= highWatermark) { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
98 |
return true; // trigger the pause |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
99 |
} |
2 | 100 |
return pauseAfterReceipt; |
101 |
} |
|
102 |
||
103 |
synchronized BerDecoder getReplyBer() throws CommunicationException { |
|
104 |
if (cancelled) { |
|
105 |
throw new CommunicationException("Request: " + msgId + |
|
106 |
" cancelled"); |
|
107 |
} |
|
108 |
||
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
109 |
/* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
110 |
* Remove a reply if the queue is not empty. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
111 |
* poll returns null if queue is empty. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
112 |
*/ |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
113 |
BerDecoder reply = replies.poll(); |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
5506
diff
changeset
|
114 |
return reply; |
2 | 115 |
} |
116 |
||
117 |
synchronized boolean hasSearchCompleted() { |
|
118 |
return completed; |
|
119 |
} |
|
120 |
} |