Skip to content

Method: SpringSimpleMessageSubscriberSupport(Object)

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * These Foolish Things - Miscellaneous utilities
6: * http://thesefoolishthings.tidalwave.it - git clone git@bitbucket.org:tidalwave/thesefoolishthings-src.git
7: * %%
8: * Copyright (C) 2009 - 2018 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: * $Id$
24: *
25: * *********************************************************************************************************************
26: * #L%
27: */
28: package it.tidalwave.messagebus.impl.spring;
29:
30: import javax.annotation.Nonnull;
31: import javax.inject.Inject;
32: import org.springframework.beans.factory.annotation.Configurable;
33: import it.tidalwave.messagebus.MessageBusHelper;
34: import it.tidalwave.messagebus.MessageBus;
35: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
36: import org.springframework.beans.factory.BeanFactory;
37:
38: /***********************************************************************************************************************
39: *
40: * @author Fabrizio Giudici
41: * @version $Id$
42: *
43: **********************************************************************************************************************/
44: @Configurable(preConstruction = true)
45: public class SpringSimpleMessageSubscriberSupport
46: {
47: @Inject @Nonnull
48: private BeanFactory beanFactory;
49:
50: private final MessageBusHelper busHelper;
51:
52: public SpringSimpleMessageSubscriberSupport (final @Nonnull Object bean)
53:• {
54: final String source = bean.getClass().getAnnotation(SimpleMessageSubscriber.class).source();
55: final MessageBus messageBus = beanFactory.getBean(source, MessageBus.class);
56: busHelper = new MessageBusHelper(bean, new MessageBusAdapterFactory(messageBus));
57:• }
58:
59: public void subscribeAll()
60: {
61: busHelper.subscribeAll();
62: }
63:
64: public void unsubscribeAll()
65: {
66: busHelper.unsubscribeAll();
67: }
68: }