1 /*
2  * Copyright 2002-2018 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 module hunt.stomp.simp.config.SimpleBrokerRegistration;
18 
19 import hunt.stomp.simp.config.AbstractBrokerRegistration;
20 
21 import hunt.stomp.MessageChannel;
22 
23 import hunt.stomp.simp.broker.SimpleBrokerMessageHandler;
24 // import hunt.framework.task.TaskScheduler;
25 
26 /**
27  * Registration class for configuring a {@link SimpleBrokerMessageHandler}.
28  *
29  * @author Rossen Stoyanchev
30  * @since 4.0
31  */
32 class SimpleBrokerRegistration : AbstractBrokerRegistration {
33 
34 	
35 	// private TaskScheduler taskScheduler;
36 
37 	
38 	private long[] heartbeat;
39 
40 	
41 	private string selectorHeaderName = "selector";
42 
43 
44 	this(SubscribableChannel inChannel, MessageChannel outChannel, string[] prefixes) {
45 		super(inChannel, outChannel, prefixes);
46 	}
47 
48 
49 	/**
50 	 * Configure the {@link hunt.framework.scheduling.TaskScheduler} to
51 	 * use for providing heartbeat support. Setting this property also sets the
52 	 * {@link #setHeartbeatValue heartbeatValue} to "10000, 10000".
53 	 * <p>By default this is not set.
54 	 * @since 4.2
55 	 */
56 	// SimpleBrokerRegistration setTaskScheduler(TaskScheduler taskScheduler) {
57 	// 	this.taskScheduler = taskScheduler;
58 	// 	return this;
59 	// }
60 
61 	/**
62 	 * Configure the value for the heartbeat settings. The first number
63 	 * represents how often the server will write or send a heartbeat.
64 	 * The second is how often the client should write. 0 means no heartbeats.
65 	 * <p>By default this is set to "0, 0" unless the {@link #setTaskScheduler
66 	 * taskScheduler} in which case the default becomes "10000,10000"
67 	 * (in milliseconds).
68 	 * @since 4.2
69 	 */
70 	SimpleBrokerRegistration setHeartbeatValue(long[] heartbeat) {
71 		this.heartbeat = heartbeat;
72 		return this;
73 	}
74 
75 	/**
76 	 * Configure the name of a header that a subscription message can have for
77 	 * the purpose of filtering messages matched to the subscription. The header
78 	 * value is expected to be a Spring EL  expression to be applied to
79 	 * the headers of messages matched to the subscription.
80 	 * <p>For example:
81 	 * <pre>
82 	 * headers.foo == 'bar'
83 	 * </pre>
84 	 * <p>By default this is set to "selector". You can set it to a different
85 	 * name, or to {@code null} to turn off support for a selector header.
86 	 * @param selectorHeaderName the name to use for a selector header
87 	 * @since 4.3.17
88 	 */
89 	void setSelectorHeaderName(string selectorHeaderName) {
90 		this.selectorHeaderName = selectorHeaderName;
91 	}
92 
93 
94 	override
95 	SimpleBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
96 		SimpleBrokerMessageHandler handler = new SimpleBrokerMessageHandler(getClientInboundChannel(),
97 				getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());
98 		// if (this.taskScheduler !is null) {
99 		// 	handler.setTaskScheduler(this.taskScheduler);
100 		// }
101 		if (this.heartbeat !is null) {
102 			handler.setHeartbeatValue(this.heartbeat);
103 		}
104 		handler.setSelectorHeaderName(this.selectorHeaderName);
105 		return handler;
106 	}
107 
108 }