11/*
2- * Copyright (c) 2017 Pivotal Software Inc, All Rights Reserved.
2+ * Copyright (c) 2017-2019 Pivotal Software Inc, All Rights Reserved.
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.
2020
2121/**
2222 * Fluent API to specify the creation of a queue.
23+ * <p>
24+ * If a queue specification has a null name, the queue to be created
25+ * will have a server-generated name and will be non-durable, exclusive, and
26+ * auto-delete. To have more control over the properties of a queue with
27+ * a server-generated name, specify a non-null, empty string name, <code>""</code>.
2328 */
2429public class QueueSpecification {
2530
26- static class NullNameQueueSpecification extends QueueSpecification {
27-
28- NullNameQueueSpecification () {
29- this .name = null ;
30- this .durable = false ;
31- this .exclusive = true ;
32- this .autoDelete = true ;
33- }
34-
35- @ Override
36- public QueueSpecification name (String name ) {
37- if (name == null ) {
38- return this ;
39- }
40- return QueueSpecification .queue (name )
41- .durable (durable )
42- .exclusive (exclusive )
43- .autoDelete (autoDelete );
44- }
45-
46- @ Override
47- public QueueSpecification durable (boolean durable ) {
48- if (this .durable != durable ) {
49- throw new IllegalArgumentException ("once a queue has null name, durable is always false" );
50- }
51- return this ;
52- }
53-
54- @ Override
55- public QueueSpecification exclusive (boolean exclusive ) {
56- if (this .exclusive != exclusive ) {
57- throw new IllegalArgumentException ("once a queue has null name, exclusive is always true" );
58- }
59- return this ;
60- }
61-
62- @ Override
63- public QueueSpecification autoDelete (boolean autoDelete ) {
64- if (this .autoDelete != autoDelete ) {
65- throw new IllegalArgumentException ("once a queue has null name, autoDelete is always true" );
66- }
67- return this ;
68- }
69- }
70-
71- String name ;
72- boolean durable = false ;
73- boolean exclusive = false ;
74- boolean autoDelete = false ;
75- Map <String , Object > arguments ;
31+ protected String name ;
32+ protected boolean durable = false ;
33+ protected boolean exclusive = false ;
34+ protected boolean autoDelete = false ;
35+ protected Map <String , Object > arguments ;
7636
7737 public static QueueSpecification queue () {
7838 return new NullNameQueueSpecification ();
@@ -84,7 +44,7 @@ public static QueueSpecification queue(String name) {
8444
8545 public QueueSpecification name (String queue ) {
8646 if (queue == null ) {
87- return new NullNameQueueSpecification ();
47+ return new NullNameQueueSpecification (). arguments ( this . arguments ) ;
8848 }
8949
9050 this .name = queue ;
@@ -130,4 +90,54 @@ public boolean isAutoDelete() {
13090 public Map <String , Object > getArguments () {
13191 return arguments ;
13292 }
93+
94+ /**
95+ * Internal class to handle queues with a null name.
96+ * Those queues always have a server-generated name are non-durable,
97+ * exclusive, and auto-delete.
98+ */
99+ private static class NullNameQueueSpecification extends QueueSpecification {
100+
101+ NullNameQueueSpecification () {
102+ this .name = null ;
103+ this .durable = false ;
104+ this .exclusive = true ;
105+ this .autoDelete = true ;
106+ }
107+
108+ @ Override
109+ public QueueSpecification name (String name ) {
110+ if (name == null ) {
111+ return this ;
112+ }
113+ return QueueSpecification .queue (name )
114+ .durable (durable )
115+ .exclusive (exclusive )
116+ .autoDelete (autoDelete );
117+ }
118+
119+ @ Override
120+ public QueueSpecification durable (boolean durable ) {
121+ if (this .durable != durable ) {
122+ throw new IllegalArgumentException ("Once a queue has a null name, durable is always false" );
123+ }
124+ return this ;
125+ }
126+
127+ @ Override
128+ public QueueSpecification exclusive (boolean exclusive ) {
129+ if (this .exclusive != exclusive ) {
130+ throw new IllegalArgumentException ("Once a queue has a null name, exclusive is always true" );
131+ }
132+ return this ;
133+ }
134+
135+ @ Override
136+ public QueueSpecification autoDelete (boolean autoDelete ) {
137+ if (this .autoDelete != autoDelete ) {
138+ throw new IllegalArgumentException ("Once a queue has a null name, autoDelete is always true" );
139+ }
140+ return this ;
141+ }
142+ }
133143}
0 commit comments