/
KapuaApplicationBrokerFilter.java
72 lines (63 loc) · 2.45 KB
/
KapuaApplicationBrokerFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************************************
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.broker.core.plugin;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFilter;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.core.ServiceModuleBundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ActiveMQ application filter plugin implementation (application context lifecycle filter).<br>
* <br>
* <p>
* Filter to startup/shutdown proprly the application context.<br>
* <br>
* <p>
* This filter is added inside ActiveMQ filter chain plugin by {@link org.eclipse.kapua.broker.core.KapuaBrokerApplicationPlugin}
*
* @since 1.0
*/
public class KapuaApplicationBrokerFilter extends BrokerFilter {
private static final Logger logger = LoggerFactory.getLogger(KapuaApplicationBrokerFilter.class);
// The following line must be done before any invocation of KapuaLocator.getInstance()
private static ServiceModuleBundle application;
public KapuaApplicationBrokerFilter(Broker next) throws KapuaException {
super(next);
}
@Override
public void start()
throws Exception {
logger.info(">>> Application broker filter: calling start...");
synchronized (KapuaApplicationBrokerFilter.class) {
if (application == null) {
application = new ServiceModuleBundle() {
};
}
application.startup();
}
super.start();
logger.info(">>> Application broker filter: calling start... DONE");
}
@Override
public void stop()
throws Exception {
logger.info(">>> Application broker filter: calling stop...");
super.stop();
synchronized (KapuaApplicationBrokerFilter.class) {
if (application != null) {
application.shutdown();
}
}
logger.info(">>> Application broker filter: calling stop... DONE");
}
}