Skip to content

Instantly share code, notes, and snippets.

@mathieuancelin
Created January 24, 2012 10:37
Show Gist options
  • Save mathieuancelin/1669547 to your computer and use it in GitHub Desktop.
Save mathieuancelin/1669547 to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class AccountService {
@Inject @Detected Event<Fraud> event;
public void watchActivity(@Observes AccountActivity activity) {
Fraud fraud = new Fraud(System.currentTimeMillis());
event.fire(fraud);
}
}
@Service @ApplicationScoped
public class AccountServicePubSub implements MessageCallback {
  @Inject RequestDispatcher dispatcher;
public void callback(Message activity) {
MessageBuilder.createMessage()
.toSubject("FraudClientPubSub")
.signalling()
.with("fraudTimeStamp", System.currentTimeMillis())
.noErrorHandling()
.sendNowWith(dispatcher);
});
}
}
@Service @ApplicationScoped
public class AccountServiceRPC implements AccountService {
public Fraud watchActivity(AccountActivity activity) {
return new Fraud(System.currentTimeMillis());
}
}
public class FraudClient extends LayoutPanel {
@Inject Event<AccountActivity> event;
HTML responsePanel;
public FraudClient() {
super(new BoxLayout(BoxLayout.Orientation.VERTICAL));
}
@PostConstruct
public void buildUI() {
Button button = new Button("Create activity", new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
event.fire(new AccountActivity());
}
});
responsePanel = new HTML();
add(button);
add(responsePanel);
}
public void processFraud(@Observes @Detected Fraud fraudEvent) {
responsePanel.setText("Fraud detected: " + fraudEvent.getTimestamp());
}
}
public class FraudClientRPC extends LayoutPanel {
  private MessageBus bus = ErraiBus.get();
HTML responsePanel;
...
@PostConstruct
public void buildUI() {
bus.subscribe("BroadcastReceiver", new MessageCallback() {
       public void callback(CommandMessage message) {
         responsePanel.setText("Fraud detected: " + message.get(Long.class, "fraudTimeStamp");
       }
    });
Button button = new Button("Create activity", new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
MessageBuilder.createMessage()
.toSubject("AccountServicePubSub")
.signalling()
.noErrorHandling()
.sendNowWith(dispatcher);
}
});
...
}
}
public class FraudClientRPC extends LayoutPanel {
@Inject Caller<AccountService> service;
HTML responsePanel;
...
@PostConstruct
public void buildUI() {
Button button = new Button("Create activity", new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
service.call(new RemoteCallback<Fraud>() {
public void callback(Fraud fraud) {
responsePanel.setText("Fraud detected: " + fraudEvent.getTimestamp());
}
}).watchActivity(new AccountActivity());
}
});
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment