Search in sources :

Example 1 with CloseFromOtherNeedEvent

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

the class TwoPhaseCommitNoVoteDeactivateAllNeedsAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    // check the global COORDINATION_MESSAGE (must be ABORT)
    if (event instanceof CloseFromOtherNeedEvent) {
        WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage();
        NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() {

            @Override
            public NodeIterator visit(final Model model) {
                return model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI()));
            }
        });
        if (ni.hasNext()) {
            String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString();
            if (coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_ABORT.getURI().toString()))
                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().getBotContext().retrieveAllNeedUris();
    for (URI uri : toDeactivate) {
        getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(uri));
        getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(uri));
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) CloseFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent) WonMessage(won.protocol.message.WonMessage) Model(org.apache.jena.rdf.model.Model) WonRdfUtils(won.protocol.util.WonRdfUtils) RdfUtils(won.protocol.util.RdfUtils) URI(java.net.URI) NeedDeactivatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)

Example 2 with CloseFromOtherNeedEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent 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 CloseFromOtherNeedEvent) {
        URI needURI = ((CloseFromOtherNeedEvent) event).getNeedURI();
        WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage();
        NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() {

            @Override
            public NodeIterator visit(final Model model) {
                return 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().toString();
        assert coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_COMMIT.getURI().toString()) : "expected a " + "Commmit message";
        getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(needURI));
        getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(needURI));
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) CloseFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent) WonMessage(won.protocol.message.WonMessage) Model(org.apache.jena.rdf.model.Model) WonRdfUtils(won.protocol.util.WonRdfUtils) RdfUtils(won.protocol.util.RdfUtils) URI(java.net.URI) NeedDeactivatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)

Aggregations

URI (java.net.URI)2 Model (org.apache.jena.rdf.model.Model)2 NodeIterator (org.apache.jena.rdf.model.NodeIterator)2 NeedDeactivatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)2 CloseFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent)2 WonMessage (won.protocol.message.WonMessage)2 RdfUtils (won.protocol.util.RdfUtils)2 WonRdfUtils (won.protocol.util.WonRdfUtils)2