File tree Expand file tree Collapse file tree 4 files changed +86
-6
lines changed
spring-core/src/main/java/org/springframework/util
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client Expand file tree Collapse file tree 4 files changed +86
-6
lines changed Original file line number Diff line number Diff line change 2222import java .util .UUID ;
2323
2424/**
25- * A variation of {@link UUID#randomUUID()} that uses {@link SecureRandom} only for the
26- * initial seed and {@link Random} thereafter. This provides better performance in
27- * exchange for less securely random id's.
25+ * An {@link org.springframework.util.IdGenerator IdGenerator} that uses
26+ * {@link SecureRandom} for the initial seed and {@link Random} thereafter
27+ * instead of calling {@link UUID#randomUUID()} every time as
28+ * {@link org.springframework.util.JdkIdGenerator JdkIdGenerator} does.
29+ * This provides a better balance between securely random id's and performance.
2830 *
2931 * @author Rossen Stoyanchev
3032 * @author Rob Winch
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2002-2013 the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .util ;
18+
19+ import java .util .UUID ;
20+
21+ /**
22+ * An IdGenerator that calls {@link java.util.UUID#randomUUID()}.
23+ *
24+ * @author Rossen Stoyanchev
25+ * @since 4.2
26+ */
27+ public class JdkIdGenerator implements IdGenerator {
28+
29+
30+ public UUID generateId () {
31+ return UUID .randomUUID ();
32+ }
33+
34+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2002-2013 the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .util ;
18+
19+ import java .util .UUID ;
20+ import java .util .concurrent .atomic .AtomicLong ;
21+
22+ /**
23+ * An simple IdGenerator that starts at 1 and increments by 1 with each call.
24+ *
25+ * @author Rossen Stoyanchev
26+ * @since 4.2
27+ */
28+ public class SimpleIdGenerator implements IdGenerator {
29+
30+ private final AtomicLong mostSigBits = new AtomicLong (0 );
31+
32+ private final AtomicLong leastSigBits = new AtomicLong (0 );
33+
34+
35+ @ Override
36+ public UUID generateId () {
37+ long leastSigBits = this .leastSigBits .incrementAndGet ();
38+ if (leastSigBits == 0 ) {
39+ this .mostSigBits .incrementAndGet ();
40+ }
41+ return new UUID (this .mostSigBits .get (), leastSigBits );
42+ }
43+
44+ }
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2014 the original author or authors.
2+ * Copyright 2002-2015 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919import java .net .URI ;
2020import java .util .UUID ;
2121
22- import org .springframework .util .AlternativeJdkIdGenerator ;
2322import org .springframework .util .IdGenerator ;
23+ import org .springframework .util .JdkIdGenerator ;
2424import org .springframework .web .socket .sockjs .transport .TransportType ;
2525import org .springframework .web .util .UriComponentsBuilder ;
2626
3333 */
3434public class SockJsUrlInfo {
3535
36- private static final IdGenerator idGenerator = new AlternativeJdkIdGenerator ();
36+ private static final IdGenerator idGenerator = new JdkIdGenerator ();
3737
3838
3939 private final URI sockJsUrl ;
You can’t perform that action at this time.
0 commit comments