Skip to content

Commit c641398

Browse files
committed
Merge branch 'master' of https://github.com/openhab/openhab2
2 parents ea98935 + 02226d9 commit c641398

File tree

6 files changed

+295
-278
lines changed

6 files changed

+295
-278
lines changed

addons/binding/org.openhab.binding.avmfritz/META-INF/MANIFEST.MF

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Bundle-ClassPath: .,
1010
lib/jackson-databind-2.3.2.jar,
1111
lib/jackson-module-jaxb-annotations-2.3.2.jar
1212
Import-Package: com.google.common.collect,
13+
javax.xml.bind,
1314
org.apache.commons.lang,
1415
org.apache.commons.lang.builder,
1516
org.eclipse.jetty.client,

bundles/core/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractActiveBinding.java

+149-148
Original file line numberDiff line numberDiff line change
@@ -12,160 +12,161 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
1615
/**
1716
* Base class for active bindings which polls something and sends events frequently.
18-
*
17+
*
1918
* @author Thomas.Eichstaedt-Engelen
2019
* @author Kai Kreuzer
21-
*
20+
*
2221
* @since 0.6.0
2322
*/
2423
public abstract class AbstractActiveBinding<P extends BindingProvider> extends AbstractBinding<P> {
2524

26-
private static final Logger logger = LoggerFactory.getLogger(AbstractActiveBinding.class);
27-
28-
/** embedded active service to allow the binding to have some code executed in a given interval. */
29-
protected AbstractActiveService activeService = new BindingActiveService();
30-
31-
32-
/**
33-
* Adds <code>provider</code> to the list of {@link BindingProvider}s and
34-
* adds <code>this</code> as {@link BindingConfigChangeListener}. If
35-
* <code>provider</code> contains any binding an the refresh-Thread is
36-
* stopped it will be started.
37-
*
38-
* @param provider the new {@link BindingProvider} to add
39-
*/
40-
public void addBindingProvider(P provider) {
41-
super.addBindingProvider(provider);
42-
activeService.activate();
43-
}
44-
45-
/**
46-
* Removes <code>provider</code> from the list of providers. If there is no
47-
* provider left the refresh thread is getting interrupted.
48-
*
49-
* @param provider the {@link BindingProvider} to remove
50-
*/
51-
public void removeBindingProvider(P provider) {
52-
super.removeBindingProvider(provider);
53-
54-
// if there are no binding providers there is no need to run this
55-
// refresh thread any longer ...
56-
if (this.providers.size() == 0) {
57-
activeService.deactivate();
58-
}
59-
}
60-
61-
/**
62-
* {@inheritDoc}
63-
*/
64-
public void bindingChanged(BindingProvider provider, String itemName) {
65-
super.bindingChanged(provider, itemName);
66-
67-
if (bindingsExist()) {
68-
activeService.activate();
69-
} else {
70-
activeService.deactivate();
71-
}
72-
}
73-
74-
/**
75-
* {@inheritDoc}
76-
*/
77-
public void allBindingsChanged(BindingProvider provider) {
78-
super.allBindingsChanged(provider);
79-
80-
if (bindingsExist()) {
81-
activeService.activate();
82-
} else {
83-
activeService.deactivate();
84-
}
85-
}
86-
87-
/**
88-
* Used to define whether this binding is fully configured so that it can be
89-
* activated and used.
90-
* Note that the implementation will automatically start the active service if
91-
* <code>true</code> is passed as a parameter and there are binding providers available.
92-
*
93-
* @param properlyConfigured
94-
*/
95-
protected void setProperlyConfigured(boolean properlyConfigured) {
96-
if (providers.size() > 0) {
97-
activeService.setProperlyConfigured(properlyConfigured);
98-
}
99-
}
100-
101-
/**
102-
* @return <code>true</code> if this binding is configured properly which means
103-
* that all necessary data is available
104-
*/
105-
protected boolean isProperlyConfigured() {
106-
return activeService.isProperlyConfigured();
107-
}
108-
109-
/**
110-
* The working method which is called by the refresh thread frequently.
111-
* Developers should put their binding code here.
112-
*/
113-
protected abstract void execute();
114-
115-
/**
116-
* Returns the refresh interval to be used by the RefreshThread between to
117-
* calls of the execute method.
118-
*
119-
* @return the refresh interval
120-
*/
121-
protected abstract long getRefreshInterval();
122-
123-
/**
124-
* Returns the name of the Refresh thread.
125-
*
126-
* @return the name of the refresh thread.
127-
*/
128-
protected abstract String getName();
129-
130-
131-
/** private inner class, which delegates method calls to the outer binding instance */
132-
private class BindingActiveService extends AbstractActiveService {
133-
134-
/**
135-
* {@inheritDoc}
136-
*/
137-
@Override
138-
protected void start() {
139-
super.start();
140-
}
141-
142-
/**
143-
* @{inheritDoc}
144-
*/
145-
@Override
146-
public void interrupt() {
147-
if (!bindingsExist()) {
148-
super.interrupt();
149-
} else {
150-
logger.trace("{} won't be interrupted because bindings exist.", getName());
151-
}
152-
}
153-
154-
@Override
155-
protected void execute() {
156-
AbstractActiveBinding.this.execute();
157-
}
158-
159-
@Override
160-
protected long getRefreshInterval() {
161-
return AbstractActiveBinding.this.getRefreshInterval();
162-
}
163-
164-
@Override
165-
protected String getName() {
166-
return AbstractActiveBinding.this.getName();
167-
}
168-
169-
}
170-
25+
private static final Logger logger = LoggerFactory.getLogger(AbstractActiveBinding.class);
26+
27+
/** embedded active service to allow the binding to have some code executed in a given interval. */
28+
protected AbstractActiveService activeService = new BindingActiveService();
29+
30+
/**
31+
* Adds <code>provider</code> to the list of {@link BindingProvider}s and
32+
* adds <code>this</code> as {@link BindingConfigChangeListener}. If
33+
* <code>provider</code> contains any binding an the refresh-Thread is
34+
* stopped it will be started.
35+
*
36+
* @param provider the new {@link BindingProvider} to add
37+
*/
38+
@Override
39+
public void addBindingProvider(BindingProvider provider) {
40+
super.addBindingProvider(provider);
41+
activeService.activate();
42+
}
43+
44+
/**
45+
* Removes <code>provider</code> from the list of providers. If there is no
46+
* provider left the refresh thread is getting interrupted.
47+
*
48+
* @param provider the {@link BindingProvider} to remove
49+
*/
50+
@Override
51+
public void removeBindingProvider(BindingProvider provider) {
52+
super.removeBindingProvider(provider);
53+
54+
// if there are no binding providers there is no need to run this
55+
// refresh thread any longer ...
56+
if (this.providers.size() == 0) {
57+
activeService.deactivate();
58+
}
59+
}
60+
61+
/**
62+
* {@inheritDoc}
63+
*/
64+
@Override
65+
public void bindingChanged(BindingProvider provider, String itemName) {
66+
super.bindingChanged(provider, itemName);
67+
68+
if (bindingsExist()) {
69+
activeService.activate();
70+
} else {
71+
activeService.deactivate();
72+
}
73+
}
74+
75+
/**
76+
* {@inheritDoc}
77+
*/
78+
@Override
79+
public void allBindingsChanged(BindingProvider provider) {
80+
super.allBindingsChanged(provider);
81+
82+
if (bindingsExist()) {
83+
activeService.activate();
84+
} else {
85+
activeService.deactivate();
86+
}
87+
}
88+
89+
/**
90+
* Used to define whether this binding is fully configured so that it can be
91+
* activated and used.
92+
* Note that the implementation will automatically start the active service if
93+
* <code>true</code> is passed as a parameter and there are binding providers available.
94+
*
95+
* @param properlyConfigured
96+
*/
97+
protected void setProperlyConfigured(boolean properlyConfigured) {
98+
if (providers.size() > 0) {
99+
activeService.setProperlyConfigured(properlyConfigured);
100+
}
101+
}
102+
103+
/**
104+
* @return <code>true</code> if this binding is configured properly which means
105+
* that all necessary data is available
106+
*/
107+
protected boolean isProperlyConfigured() {
108+
return activeService.isProperlyConfigured();
109+
}
110+
111+
/**
112+
* The working method which is called by the refresh thread frequently.
113+
* Developers should put their binding code here.
114+
*/
115+
protected abstract void execute();
116+
117+
/**
118+
* Returns the refresh interval to be used by the RefreshThread between to
119+
* calls of the execute method.
120+
*
121+
* @return the refresh interval
122+
*/
123+
protected abstract long getRefreshInterval();
124+
125+
/**
126+
* Returns the name of the Refresh thread.
127+
*
128+
* @return the name of the refresh thread.
129+
*/
130+
protected abstract String getName();
131+
132+
/** private inner class, which delegates method calls to the outer binding instance */
133+
private class BindingActiveService extends AbstractActiveService {
134+
135+
/**
136+
* {@inheritDoc}
137+
*/
138+
@Override
139+
protected void start() {
140+
super.start();
141+
}
142+
143+
/**
144+
* @{inheritDoc}
145+
*/
146+
@Override
147+
public void interrupt() {
148+
if (!bindingsExist()) {
149+
super.interrupt();
150+
} else {
151+
logger.trace("{} won't be interrupted because bindings exist.", getName());
152+
}
153+
}
154+
155+
@Override
156+
protected void execute() {
157+
AbstractActiveBinding.this.execute();
158+
}
159+
160+
@Override
161+
protected long getRefreshInterval() {
162+
return AbstractActiveBinding.this.getRefreshInterval();
163+
}
164+
165+
@Override
166+
protected String getName() {
167+
return AbstractActiveBinding.this.getName();
168+
}
169+
170+
}
171+
171172
}

0 commit comments

Comments
 (0)