mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
Fixes: #597 Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
parent
3b74ea1dad
commit
5977002c5f
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.smarthome.io.rest.sse.internal;
|
package org.eclipse.smarthome.io.rest.sse.internal;
|
||||||
|
|
||||||
|
import javax.ws.rs.ext.RuntimeDelegate;
|
||||||
|
|
||||||
import org.glassfish.jersey.media.sse.SseFeature;
|
import org.glassfish.jersey.media.sse.SseFeature;
|
||||||
import org.osgi.framework.BundleActivator;
|
import org.osgi.framework.BundleActivator;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
@ -27,6 +29,31 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class SseActivator implements BundleActivator {
|
public class SseActivator implements BundleActivator {
|
||||||
|
|
||||||
|
// See: https://github.com/openhab/openhab-core/issues/597
|
||||||
|
private static class WorkAroundIssue597 {
|
||||||
|
public static RuntimeDelegate getRuntimeDelegate(final long millisMax, final long millisSleep)
|
||||||
|
throws InterruptedException {
|
||||||
|
final Logger logger = LoggerFactory.getLogger(WorkAroundIssue597.class);
|
||||||
|
|
||||||
|
logger.trace("get runtime delegate");
|
||||||
|
final long begMillis = System.currentTimeMillis();
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
final RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance();
|
||||||
|
logger.trace("succeeded");
|
||||||
|
return runtimeDelegate;
|
||||||
|
} catch (final LinkageError ex) {
|
||||||
|
logger.trace("linkage error");
|
||||||
|
if (System.currentTimeMillis() - begMillis <= millisMax) {
|
||||||
|
Thread.sleep(millisSleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (System.currentTimeMillis() - begMillis <= millisMax);
|
||||||
|
logger.trace("give up");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(SseActivator.class);
|
private final Logger logger = LoggerFactory.getLogger(SseActivator.class);
|
||||||
|
|
||||||
private static BundleContext context;
|
private static BundleContext context;
|
||||||
@ -42,6 +69,7 @@ public class SseActivator implements BundleActivator {
|
|||||||
public void start(BundleContext bc) throws Exception {
|
public void start(BundleContext bc) throws Exception {
|
||||||
context = bc;
|
context = bc;
|
||||||
|
|
||||||
|
WorkAroundIssue597.getRuntimeDelegate(5000, 200);
|
||||||
String featureName = SseFeature.class.getName();
|
String featureName = SseFeature.class.getName();
|
||||||
if (bc.getServiceReference(featureName) == null) {
|
if (bc.getServiceReference(featureName) == null) {
|
||||||
sseFeatureRegistration = bc.registerService(featureName, new SseFeature(), null);
|
sseFeatureRegistration = bc.registerService(featureName, new SseFeature(), null);
|
||||||
|
Loading…
Reference in New Issue
Block a user