[otj-users] callins in callbacks and multiple base calls

Marco Mosconi mosconi at cs.tu-berlin.de
Tue Jul 15 13:01:53 CEST 2008


Hi Miguel,

I'm not sure if I understand you correctly, but perhaps this is what you 
want:
http://trac.objectteams.org/ot/wiki/OtPatterns/ObjectRegistration

Marco

Miguel Pessoa Monteiro schrieb:
> 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
>>
> 
> 

-- 
Dipl.-Inform. Marco Mosconi
Technische Universität Berlin
Fak. IV, Fachg. Softwaretechnik



More information about the otj-users mailing list