Search in sources :

Example 1 with AtomDeactivatedEvent

use of won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent in project webofneeds by researchstudio-sat.

the class DeactivateAllAtomsOfListAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    Collection<URI> toDeactivate = ctx.getBotContext().getUriList(uriListName);
    for (URI uri : toDeactivate) {
        ctx.getWonMessageSender().prepareAndSendMessage(WonMessageBuilder.deactivate().direction().fromOwner().atom(uri).build());
        ctx.getEventBus().publish(new AtomDeactivatedEvent(uri));
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) AtomDeactivatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent) URI(java.net.URI)

Example 2 with AtomDeactivatedEvent

use of won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent in project webofneeds by researchstudio-sat.

the class TwoPhaseCommitDeactivateOnCloseAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    // If we receive a close event, it must carry a commit message.
    if (event instanceof CloseFromOtherAtomEvent) {
        URI atomURI = ((CloseFromOtherAtomEvent) event).getAtomURI();
        WonMessage wonMessage = ((CloseFromOtherAtomEvent) event).getWonMessage();
        NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), model -> model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI())));
        assert ni.hasNext() : "no additional content found in close message, expected a commit";
        String coordinationMessageUri = ni.toList().get(0).asResource().getURI();
        assert coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_COMMIT.getURI()) : "expected a " + "Commit message";
        getEventListenerContext().getWonMessageSender().prepareAndSendMessage(WonMessageBuilder.deactivate().direction().fromOwner().atom(atomURI).build());
        getEventListenerContext().getEventBus().publish(new AtomDeactivatedEvent(atomURI));
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) AtomDeactivatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent) WonMessage(won.protocol.message.WonMessage) CloseFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherAtomEvent) URI(java.net.URI)

Example 3 with AtomDeactivatedEvent

use of won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent in project webofneeds by researchstudio-sat.

the class TwoPhaseCommitNoVoteDeactivateAllAtomsAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    // check the global COORDINATION_MESSAGE (must be ABORT)
    if (event instanceof CloseFromOtherAtomEvent) {
        WonMessage wonMessage = ((CloseFromOtherAtomEvent) event).getWonMessage();
        NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), model -> model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI())));
        if (ni.hasNext()) {
            String coordinationMessageUri = ni.toList().get(0).asResource().getURI();
            if (coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_ABORT.getURI()))
                logger.debug("Sent COORDINATION_MESSAGE: {}", coordinationMessageUri);
            else
                logger.error("Content of the COORDINATION_MESSAGE must be: {}. Currently it is: {}", WON_TX.COORDINATION_MESSAGE_ABORT.getURI(), coordinationMessageUri);
        }
    }
    Collection<URI> toDeactivate = getEventListenerContext().getBotContextWrapper().retrieveAllAtomUris();
    for (URI uri : toDeactivate) {
        getEventListenerContext().getWonMessageSender().prepareAndSendMessage(createWonMessage(uri));
        getEventListenerContext().getEventBus().publish(new AtomDeactivatedEvent(uri));
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) AtomDeactivatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent) WonMessage(won.protocol.message.WonMessage) CloseFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherAtomEvent) URI(java.net.URI)

Example 4 with AtomDeactivatedEvent

use of won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent in project webofneeds by researchstudio-sat.

the class DeactivateAllAtomsAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    Collection<URI> toDeactivate = getEventListenerContext().getBotContextWrapper().retrieveAllAtomUris();
    for (URI uri : toDeactivate) {
        getEventListenerContext().getWonMessageSender().prepareAndSendMessage(WonMessageBuilder.deactivate().direction().fromOwner().atom(uri).build());
        getEventListenerContext().getEventBus().publish(new AtomDeactivatedEvent(uri));
    }
}
Also used : AtomDeactivatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent) URI(java.net.URI)

Aggregations

URI (java.net.URI)4 AtomDeactivatedEvent (won.bot.framework.eventbot.event.impl.atomlifecycle.AtomDeactivatedEvent)4 NodeIterator (org.apache.jena.rdf.model.NodeIterator)2 CloseFromOtherAtomEvent (won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherAtomEvent)2 WonMessage (won.protocol.message.WonMessage)2 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1