Created
January 24, 2012 10:37
-
-
Save mathieuancelin/1669547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class AccountService { | |
@Inject @Detected Event<Fraud> event; | |
public void watchActivity(@Observes AccountActivity activity) { | |
Fraud fraud = new Fraud(System.currentTimeMillis()); | |
event.fire(fraud); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service @ApplicationScoped | |
public class AccountServiceRPC implements AccountService { | |
public Fraud watchActivity(AccountActivity activity) { | |
return new Fraud(System.currentTimeMillis()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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