Search in sources :

Example 1 with CloseFromOtherAtomEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherAtomEvent 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 2 with CloseFromOtherAtomEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherAtomEvent 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)

Aggregations

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