Discussion:
[errai-users] Proposal for simple and secure CDI conversations with Errai
Mike Brock
2011-04-10 23:56:12 UTC
Permalink
This is my proposal for creating secure, typesafe conversations using CDI Events. As opposed to using an external API, what if we use an interface like so:

package org.muhtest.server;

import org.jboss.errai.cdi.server.ConversationalEvent;
import org.muhtest.client.ClientMsg;
import org.muhtest.client.ServerMsg;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;

@ApplicationScoped
public class HelloWorldService {
public void receive(@Observes ConversationalEvent<ClientMsg, ServerMsg> event) {
/**
* Get the incoming event.
*/
ClientMsg incoming = event.getEvent();

/**
* Build the outgoing event.
*/
ServerMsg outgoing = new ServerMsg(incoming.getMessage());

/**
* Return to sender!
*/
event.fire(outgoing);
}
}

Basically we create a a standard ConversationalEvent interface that is parameterized with the incoming type, and the outgoing type. The EventDispatcher can then simply wrap the incoming event before firing it into the BeanManager, and this way, the event payload itself contains a pre-loaded firing mechanism to fire an outgoing message back to the client.

I have already hacked a simple prototype on top of Heiko and Fillip's CDI integration code.

I added Dan Allen to this message, as I thought he might have something interesting to say, since he worked on this aspect of the CDI spec.

Thoughts?

Mike.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-users/attachments/20110410/1fb79c8c/attachment.html
Mike Brock
2011-04-11 03:02:04 UTC
Permalink
This is option two, which is more flexible but potentially will fall victim to misunderstanding in certain cases:

@ApplicationScoped
public class HelloWorldService {

@Inject
private Event<ServerMsg> serverMessage;

@Conversational
public void receive(@Observes ClientMsg msg) {
ServerMsg outgoing = new ServerMsg(msg.getMessage());
serverMessage.fire(outgoing);
}
}
Post by Mike Brock
package org.muhtest.server;
import org.jboss.errai.cdi.server.ConversationalEvent;
import org.muhtest.client.ClientMsg;
import org.muhtest.client.ServerMsg;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class HelloWorldService {
/**
* Get the incoming event.
*/
ClientMsg incoming = event.getEvent();
/**
* Build the outgoing event.
*/
ServerMsg outgoing = new ServerMsg(incoming.getMessage());
/**
* Return to sender!
*/
event.fire(outgoing);
}
}
Basically we create a a standard ConversationalEvent interface that is parameterized with the incoming type, and the outgoing type. The EventDispatcher can then simply wrap the incoming event before firing it into the BeanManager, and this way, the event payload itself contains a pre-loaded firing mechanism to fire an outgoing message back to the client.
I have already hacked a simple prototype on top of Heiko and Fillip's CDI integration code.
I added Dan Allen to this message, as I thought he might have something interesting to say, since he worked on this aspect of the CDI spec.
Thoughts?
Mike.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-users/attachments/20110410/dabed2dd/attachment.html
Peter Muir
2011-04-19 11:23:14 UTC
Permalink
Adding David Allen, who Mike meant, not Dan.
Post by Mike Brock
@ApplicationScoped
public class HelloWorldService {
@Inject
private Event<ServerMsg> serverMessage;
@Conversational
ServerMsg outgoing = new ServerMsg(msg.getMessage());
serverMessage.fire(outgoing);
}
}
Post by Mike Brock
package org.muhtest.server;
import org.jboss.errai.cdi.server.ConversationalEvent;
import org.muhtest.client.ClientMsg;
import org.muhtest.client.ServerMsg;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class HelloWorldService {
/**
* Get the incoming event.
*/
ClientMsg incoming = event.getEvent();
/**
* Build the outgoing event.
*/
ServerMsg outgoing = new ServerMsg(incoming.getMessage());
/**
* Return to sender!
*/
event.fire(outgoing);
}
}
Basically we create a a standard ConversationalEvent interface that is parameterized with the incoming type, and the outgoing type. The EventDispatcher can then simply wrap the incoming event before firing it into the BeanManager, and this way, the event payload itself contains a pre-loaded firing mechanism to fire an outgoing message back to the client.
I have already hacked a simple prototype on top of Heiko and Fillip's CDI integration code.
I added Dan Allen to this message, as I thought he might have something interesting to say, since he worked on this aspect of the CDI spec.
Thoughts?
Mike.
_______________________________________________
errai-users mailing list
errai-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/errai-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-users/attachments/20110419/6bf51232/attachment.html
Peter Muir
2011-04-21 11:41:15 UTC
Permalink
I prefer your first suggestion
Post by Mike Brock
@ApplicationScoped
public class HelloWorldService {
@Inject
private Event<ServerMsg> serverMessage;
@Conversational
ServerMsg outgoing = new ServerMsg(msg.getMessage());
serverMessage.fire(outgoing);
}
}
Post by Mike Brock
package org.muhtest.server;
import org.jboss.errai.cdi.server.ConversationalEvent;
import org.muhtest.client.ClientMsg;
import org.muhtest.client.ServerMsg;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class HelloWorldService {
/**
* Get the incoming event.
*/
ClientMsg incoming = event.getEvent();
/**
* Build the outgoing event.
*/
ServerMsg outgoing = new ServerMsg(incoming.getMessage());
/**
* Return to sender!
*/
event.fire(outgoing);
}
}
Basically we create a a standard ConversationalEvent interface that is parameterized with the incoming type, and the outgoing type. The EventDispatcher can then simply wrap the incoming event before firing it into the BeanManager, and this way, the event payload itself contains a pre-loaded firing mechanism to fire an outgoing message back to the client.
I have already hacked a simple prototype on top of Heiko and Fillip's CDI integration code.
I added Dan Allen to this message, as I thought he might have something interesting to say, since he worked on this aspect of the CDI spec.
Thoughts?
Mike.
_______________________________________________
errai-users mailing list
errai-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/errai-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-users/attachments/20110421/b58f080c/attachment.html
Mike Brock
2011-04-21 17:22:31 UTC
Permalink
I sort of do too. Christian and Dan seem to like @Conversational. So let me play devil's advocate with myself.

I think there's some merit to how this works. And it's not necessarily as "magical" as it appears.

If you think about the way in which ErraCDI and Weld federate, then what does @Conversational mean?

What it means is that when this method is dispatched, the federation visibility should be limited to the node that first fired the method.

From Weld's perspective, it has absolutely no effect on how things "should world". It does have an effect on how the remote CDI container and the local CDI container inter-operate with each other. So this is forming a visibility rule linked to the dispatch scope of a method. Is this really a bad way of going about it?

The absolute only pitfal is that you can't broadcast from within that method. And is that even a bad limitation? I'm not sure.

Thoughts?

Mike.
Post by Peter Muir
I prefer your first suggestion
Post by Mike Brock
@ApplicationScoped
public class HelloWorldService {
@Inject
private Event<ServerMsg> serverMessage;
@Conversational
ServerMsg outgoing = new ServerMsg(msg.getMessage());
serverMessage.fire(outgoing);
}
}
Post by Mike Brock
package org.muhtest.server;
import org.jboss.errai.cdi.server.ConversationalEvent;
import org.muhtest.client.ClientMsg;
import org.muhtest.client.ServerMsg;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class HelloWorldService {
/**
* Get the incoming event.
*/
ClientMsg incoming = event.getEvent();
/**
* Build the outgoing event.
*/
ServerMsg outgoing = new ServerMsg(incoming.getMessage());
/**
* Return to sender!
*/
event.fire(outgoing);
}
}
Basically we create a a standard ConversationalEvent interface that is parameterized with the incoming type, and the outgoing type. The EventDispatcher can then simply wrap the incoming event before firing it into the BeanManager, and this way, the event payload itself contains a pre-loaded firing mechanism to fire an outgoing message back to the client.
I have already hacked a simple prototype on top of Heiko and Fillip's CDI integration code.
I added Dan Allen to this message, as I thought he might have something interesting to say, since he worked on this aspect of the CDI spec.
Thoughts?
Mike.
_______________________________________________
errai-users mailing list
errai-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/errai-users
_______________________________________________
errai-users mailing list
errai-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/errai-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-users/attachments/20110421/f851d43d/attachment.html
Loading...