[otj-users] callins in callbacks and multiple base calls
Miguel Pessoa Monteiro
mmonteiro at di.fct.unl.pt
Tue Jul 15 12:56:35 CEST 2008
Thanks. It's a good thing that you reply directly to the sender in addition to the
list as the digests take some time coming. Only just after I sent my latest post did
I receive a digest with Stephan challenging me to submit an example of Baseclass
Generalization.
For that, I would like to solve another hurdle: is it possible to bind roles to
bases at the object level rather than at the class level? In that Java Observer
example, observers are activated and deactivated dynamically and for each object
individually. Is there a way to do that with binding from roles to bases?
Thanks again,
mpm
Em Ter, Julho 15, 2008 11:28 am, Marco Mosconi escreveu:
> Hi Miguel,
>
> 1) To make the callin work also for the GUI thread, you have to activate the team
for all threads (either by using
> aTeam.activate(Team.ALL_THREADS) or using the Eclipse run configuration tab named
"Team Activation"). This is described in OTJLD §5 (global vs. thread-local activation).
>
> 2) For the racing issues in the output, this is because you use
> System.err in the role and System.out elsewhere. Changing to System.out gives the
intended result.
>
> Cheers,
> Marco
>
> Miguel Pessoa Monteiro schrieb:
>> Hi everybody,
>> One experiment of mine gave rise to a few issues, one of which quite surprised
me.
>> The code below is a simplified version that illustrates them. It comprises class
Window (extending JFrame) with a JButton in it, along an ActionListener object -
ButtonAction - with the action for click events.
>> ButtonAction also has a buttonClicked method that is called from both method main
(class Main) and method actionPerformed called by JButton from the swing thread.
Team has a role that binds to buttonClicked.
>> One issue is that the callin does not seem to work when calls to buttonClicked
originate from the swing component (and thread). It only works when buttonClicked is
>> called from Main. From this, I would assume that callins are implemented in a way
akin to AspectJ advice weaving for the call pointcut designator (PCD), as opposed to
>> AspectJ's execution PCD. In AspectJ speak, we would say that callins do not work
for
>> events originating outside the control flow of code accessed (controlled) by the
compiler.
>> Is there a way to circumvent this hurdle? Is there a way to "capture" events
originating from code not owned by the project?
>> As for the surprising thing: I expected that for each message to the console from
buttonClicked(), I would see one message from the role method appearing immediately
>> after. Instead, the role seems to "accumulate" _all_ calls to buttonClicked and
only
>> then it sends its own messages.
>> I couldn't find a mention to this behaviour of callins in the language
definition.
>> Is it there somewhere?
>> Thanks,
>> mpm
>> ===========================================================================
import javax.swing.*;
>> import java.awt.FlowLayout;
>> import java.awt.event.*;
>> public class Window extends JFrame {
>> private static final long serialVersionUID = 0L;
>> public Window(ActionListener buttonAction) {
>> super("Testing callins");
>> setLayout(new FlowLayout());
>> JButton button = new JButton("Click me");
>> button.addActionListener(buttonAction);
>> getContentPane().add(button);
>> JButton quitButton = new JButton("Quit");
>> quitButton.addActionListener(
>> new ActionListener() {
>> public void actionPerformed(ActionEvent e) {
>> System.out.println("Quiting...");
>> System.exit(0);
>> }
>> }
>> );
>> getContentPane().add(quitButton);
>> setBounds(10, 10, 200, 100);
>> setVisible(true);
>> }
>> }
>> ===========================================================================
import java.awt.event.ActionListener;
>> import java.awt.event.ActionEvent;
>> public class ButtonAction implements ActionListener {
>> public void actionPerformed(ActionEvent event) {
>> System.out.print("Click: ");
>> buttonClicked();
>> }
>> public void buttonClicked() {
>> System.out.println(getClass().getSimpleName() + " performing action.");
>> }
>> }
>> ===========================================================================
public team class Team {
>> public class Role playedBy ButtonAction {
>> private void react() {
>> System.err.println("JButton event occurred.");
>> }
>> react <- after buttonClicked;
>> }
>> }
>> ===========================================================================
public class Main {
>> public static void main(String[] args) {
>> ButtonAction buttonAction = new ButtonAction();
>> Team aTeam = new Team();
>> aTeam.activate();
>> Window window = new Window(buttonAction);
>> for(int i=0; i<10;i++) buttonAction.buttonClicked();
>> }
>> }
>> ===========================================================================
>
> --
> Dipl.-Inform. Marco Mosconi
> Technische Universität Berlin
> Fak. IV, Fachg. Softwaretechnik
>
--
Miguel P. Monteiro | cell phone +351 96 700 35 45
Departamento de Informatica | Phone +351 21 294 8536 ext. 10708
Faculdade Ciencias e Tecnol.| Fax: +351 21 294 8541
Universidade Nova de Lisboa | URL: http://ctp.di.fct.unl.pt/~mpm
2829-516 Caparica, PORTUGAL | e-mail: mmonteiro [at] di fct unl pt
More information about the otj-users
mailing list