[otj-users] callins in callbacks and multiple base calls
Miguel Pessoa Monteiro
mmonteiro at di.fct.unl.pt
Tue Jul 15 12:06:00 CEST 2008
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();
}
}
===========================================================================
--
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