Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeCaller usage: ThingManager impl. #914

Closed
maggu2810 opened this issue Jul 9, 2019 · 1 comment
Closed

SafeCaller usage: ThingManager impl. #914

maggu2810 opened this issue Jul 9, 2019 · 1 comment

Comments

@maggu2810
Copy link
Contributor

WRT the findings in #861 and #829 I am interested if there are any need to use the safecaller in the thing manager implementation on all its places.

I realized that the creation / update of thousand of things takes a lot of time.

safeCaller.create(thingHandlerFactory, ThingHandlerFactory.class).build()
.removeThing(thing.getUID());

safeCaller.create(thingHandler, ThingHandler.class).build().thingUpdated(thing);

safeCaller.create(thingHandler, ThingHandler.class).onTimeout(() -> {
logger.warn("Initializing handler for thing '{}' takes more than {}ms.", thingHandler.getThing().getUID(),
SafeCaller.DEFAULT_TIMEOUT);
}).onException(e -> {
ThingStatusInfo statusInfo = buildStatusInfo(ThingStatus.UNINITIALIZED,
ThingStatusDetail.HANDLER_INITIALIZING_ERROR, e.getMessage());
setThingStatus(thingHandler.getThing(), statusInfo);
logger.error("Exception occurred while initializing handler of thing '{}': {}",
thingHandler.getThing().getUID(), e.getMessage(), e);
}).build().initialize();

safeCaller.create(() -> {
ThingHandler thingHandler = thing.getHandler();
thingHandlerFactory.unregisterHandler(thing);
if (thingHandler != null) {
thingHandler.setCallback(null);
}
thing.setHandler(null);
boolean enabled = !isDisabledByStorage(thing.getUID());
ThingStatusDetail detail = enabled ? ThingStatusDetail.HANDLER_MISSING_ERROR : ThingStatusDetail.DISABLED;
setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, detail));
thingHandlers.remove(thing.getUID());
synchronized (thingHandlersByFactory) {
final Set<ThingHandler> thingHandlers = thingHandlersByFactory.get(thingHandlerFactory);
if (thingHandlers != null) {
thingHandlers.remove(thingHandler);
if (thingHandlers.isEmpty()) {
thingHandlersByFactory.remove(thingHandlerFactory);
}
}
}
}, Runnable.class).build().run();

safeCaller.create(thingHandler, ThingHandler.class).onTimeout(() -> {
logger.warn("Disposing handler for thing '{}' takes more than {}ms.", thingHandler.getThing().getUID(),
SafeCaller.DEFAULT_TIMEOUT);
}).onException(e -> {
logger.error("Exception occurred while disposing handler of thing '{}': {}",
thingHandler.getThing().getUID(), e.getMessage(), e);
}).build().dispose();

@kaikreuzer Do you agree that your comment is also valid at this place?

I do not see any reason to create a proxy at all.

@kaikreuzer
Copy link
Member

@kaikreuzer Do you agree that your comment is also valid at this place?

As far as I can overlook it, yes, I would agree that it is valid at those places as well.
@SJKA as the original author might be the best person to comment on it, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants