[errai-dev] Fwd: Serialization working across the bus!

Rodney Russ rruss at redhat.com
Thu Oct 22 01:31:39 EDT 2009


----- Forwarded Message -----
From: "Mike Brock" <cbrock at redhat.com>
To: "Heiko Braun" <hbraun at redhat.com>
Cc: "Lillian Angel" <langel at redhat.com>, "Rodney Russ" <rruss at redhat.com>
Sent: Wednesday, October 21, 2009 7:39:40 PM GMT -07:00 US/Canada Mountain
Subject: Serialization working across the bus!

I have managed to get serialization working across the bus with a one-step annotated process. Now you can expose entities to the bus, which will auto-generate demarshalling stubs in the client which allow full Java classes to be used within the bus API. 


For example: 



@Entity 
@ExposeEntity 
public class User implements Serializable { 
@Id private String userId; 
private String name; 
private String fullname; 
private String password; 


public String getUserId() { 
return userId; 
} 


public void setUserId(String userId) { 
this.userId = userId; 
} 


public String getName() { 
return name; 
} 


public void setName(String name) { 
this.name = name; 
} 


public String getFullname() { 
return fullname; 
} 


public void setFullname(String fullname) { 
this.fullname = fullname; 
} 


public String getPassword() { 
return password; 
} 


public void setPassword(String password) { 
this.password = password; 
} 


@Override 
public String toString() { 
return "userId=" + userId + ";name=" + name + ";fullname=" + fullname; 
} 
} 


The @ExposeEntity annotation tells Errai it should generate stubs to support it across the bus. You can then send it across the wire using the standard bus API like magic: 



@Service 
public class UserManagement implements MessageCallback { 
private MessageBus bus; 


@Inject 
public UserManagement(MessageBus bus) { 
this.bus = bus; 
} 


public void callback(CommandMessage message) { 
User user = new User(); 
user.setName("jdoe"); 
user.setFullname("John Doe"); 
user.setUserId("0aE0101"); 


ConversationMessage.create(message) 
.set("UserObj", user) 
.sendNowWith(bus); 
} 
} 


... and pull it out on the client side ... 



bus.conversationWith(CommandMessage.create() 
.toSubject("UserManagement"), new MessageCallback() { 
public void callback(CommandMessage message) { 
User user = message.get(User.class, "UserObj"); 
System.out.println("::" + user.toString()); 
} 
}); 


This is one giant leap towards supporting things like WebBeans and JPA on the client side over ErraiBus. 


Thoughts? 


Mike. 



More information about the errai-dev mailing list