Skip to content

Instantly share code, notes, and snippets.

View AndrejGajdos's full-sized avatar

Andrej Gajdos AndrejGajdos

View GitHub Profile
@AndrejGajdos
AndrejGajdos / MessageController.java
Last active January 16, 2016 19:30
MessageController receives message from client and send back a reply
package gwt.user.server;
import org.jboss.errai.bus.client.api.base.MessageBuilder;
import org.jboss.errai.bus.client.api.messaging.Message;
import org.jboss.errai.bus.client.api.messaging.MessageCallback;
import org.jboss.errai.bus.client.api.messaging.RequestDispatcher;
import org.jboss.errai.bus.server.annotations.Service;
import com.google.inject.Inject;
@Service
public class MessageController implements MessageCallback {
@AndrejGajdos
AndrejGajdos / ClientService.java
Created January 16, 2016 19:34
Initializing RequestDispatcher and MessageBus
private RequestDispatcher dispatcher = ErraiBus.getDispatcher();
private MessageBus bus = ErraiBus.get();
@AndrejGajdos
AndrejGajdos / ClientService.java
Created January 16, 2016 19:38
Creating and sending message
MessageBuilder.createMessage()
.toSubject("MessageController")
.signalling()
.noErrorHandling()
.sendNowWith(getDispatcher());
@AndrejGajdos
AndrejGajdos / ClientService.java
Created January 16, 2016 19:43
Subscribing message from server
bus.subscribe("ClientService", new MessageCallback() {
public void callback(Message message) {
Window.alert("ClientService message is received. " + message.get(String.class, "text"));
}
});
@AndrejGajdos
AndrejGajdos / gwtErraiMessaging.gwt.xml
Created January 16, 2016 19:46
Initializing ErraiBus
<inherits name='org.jboss.errai.bus.ErraiBus' />
@AndrejGajdos
AndrejGajdos / web.xml
Last active January 16, 2016 19:51
ErraiServlet definition
<servlet>
<servlet-name>ErraiServlet</servlet-name>
<servlet-class>org.jboss.errai.bus.server.servlet.DefaultBlockingServlet</servlet-class>
<init-param>
<param-name>auto-discover-services</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
@AndrejGajdos
AndrejGajdos / ErraiApp.properties
Created January 16, 2016 19:52
Dispatcher definition
#
# Request dispatcher implementation (default is SimpleDispatcher)
#
errai.dispatcher_implementation=org.jboss.errai.bus.server.SimpleDispatcher
@AndrejGajdos
AndrejGajdos / web.xml
Created January 16, 2016 19:55
Property file definition
<context-param>
<param-name>ErraiApp.properties</param-name>
<param-value>WEB_INF/ErraiApp.properties</param-value>
</context-param>
@AndrejGajdos
AndrejGajdos / MessageController.java
Created January 16, 2016 19:59
Initializing MessageBus without RequestDispatcher
ErraiService<?> service = ErraiServiceSingleton.getService();
this.bus = service.getBus();
@AndrejGajdos
AndrejGajdos / MessageController.java
Created January 16, 2016 20:03
MessageController class
package gwt.user.server;
import org.jboss.errai.bus.client.api.base.MessageBuilder;
import org.jboss.errai.bus.client.api.messaging.Message;
import org.jboss.errai.bus.client.api.messaging.MessageBus;
import org.jboss.errai.bus.client.api.messaging.MessageCallback;
import org.jboss.errai.bus.server.annotations.Service;
import org.jboss.errai.bus.server.service.ErraiService;
import org.jboss.errai.bus.server.service.ErraiServiceSingleton;
@Service