You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by John Coleman <jo...@ntlworld.com> on 2006/01/26 01:38:35 UTC

wait - notify

Hi,

Any ideas if it could be HiveMind stopping this wait/notify code running?

  public void dispatchEvent(EventObject event) {
    events.add(event);
    System.out.println("dispatch event..." + event);
    synchronized (this) {
      notify(); // break wait state
    }
    System.out.println("notified");
  }

  // a loop to dispatch events to the correct type of listeners
  public void run() {
    // loop handling all events until stop is true
    do {
      try {
        // wait for some event notifications
        synchronized (this) {
          wait();
        }....


If I do wait(10) then code works fine, but the sync blocks don't seem effective. If I directly instantiate the classes w/o HM, then code works!

John

Re: wait - notify

Posted by John Coleman <jo...@ntlworld.com>.
yes, I considered that it seems possible due to the use of another thread -
however, I even tried synchronize using a seperate string object I defined
in the class, and it fails as well

I think I'll try a this.toString() to check your idea though, see what
reference I get.

thanks,
John

----- Original Message ----- 
From: "Achim Huegen" <ac...@gmx.de>
To: <hi...@jakarta.apache.org>
Sent: Thursday, January 26, 2006 9:16 AM
Subject: Re: wait - notify


> Could it be that this != this because one method works on a hivemind
> proxy and the other one on the unproxied core implementation?
>
> Achim
>
> John Coleman wrote:
> >
> > Hi,
> >
> > Any ideas if it could be HiveMind stopping this wait/notify code
running?
> >
> >   public void dispatchEvent(EventObject event) {
> >     events.add(event);
> >     System.out.println("dispatch event..." + event);
> >     synchronized (this) {
> >       notify(); // break wait state
> >     }
> >     System.out.println("notified");
> >   }
> >
> >   // a loop to dispatch events to the correct type of listeners
> >   public void run() {
> >     // loop handling all events until stop is true
> >     do {
> >       try {
> >         // wait for some event notifications
> >         synchronized (this) {
> >           wait();
> >         }....
> >
> >
> > If I do wait(10) then code works fine, but the sync blocks don't seem
> > effective. If I directly instantiate the classes w/o HM, then code
works!
> >
> > John
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: wait - notify

Posted by Achim Huegen <ac...@gmx.de>.
Could it be that this != this because one method works on a hivemind 
proxy and the other one on the unproxied core implementation?

Achim

John Coleman wrote:
> 
> Hi,
>  
> Any ideas if it could be HiveMind stopping this wait/notify code running?
>  
>   public void dispatchEvent(EventObject event) {
>     events.add(event);
>     System.out.println("dispatch event..." + event);
>     synchronized (this) {
>       notify(); // break wait state
>     }
>     System.out.println("notified");
>   }
>  
>   // a loop to dispatch events to the correct type of listeners
>   public void run() {
>     // loop handling all events until stop is true
>     do {
>       try {
>         // wait for some event notifications
>         synchronized (this) {
>           wait();
>         }....
>  
>  
> If I do wait(10) then code works fine, but the sync blocks don't seem 
> effective. If I directly instantiate the classes w/o HM, then code works!
>  
> John
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: wait - notify

Posted by John Coleman <jo...@ntlworld.com>.
BTW, here is some of the main class:

public static final void main(String[] args) {
  // create an application main class using HiveMind factory
  Registry registry = RegistryBuilder.constructDefaultRegistry();
  VTMain main = (VTMain) registry.getService(VTMain.class);
  main.execute();
  registry.shutdown();
}

  public void setEventBroker(EventBroker broker) {
    this.broker = broker;
  }

I do get the broker reference, and can call it and get into the dispatcher.

John

Re: wait - notify

Posted by John Coleman <jo...@ntlworld.com>.
Yes, when it doesn't work.

<?xml version="1.0"?>
<module id="mainmodule" version="0.1.0">

  <service-point id="Dispatcher" interface="EventDispatcher">
    <create-instance class="EventDispatcherImpl"/>
  </service-point>

  <service-point id="Broker" interface="EventBroker">
    <invoke-factory>
      <construct class="EventBrokerImpl">
        <set-service property="dispatcher" service-id="Dispatcher"/>
    <invoke-factory>
  </service-point>

  <service-point id="VTMain" interface="VTMain">
    <invoke-factory>
      <construct class="VTMain"/>
    </invoke-factory>
  </service-point>


</module>

The above is something like the hivemod. The broker has a set dispatcher method, and the main class has a set broker method, both implement the interface as type.

I'm not sure why I had to use the set-service contrib, because I though HM would inject the dispatcher itself, it knows the interface. However, I am still quite new to this and am frustrated by lack of clear documentation by examples of the concepts.

John
  ----- Original Message ----- 
  From: James Carman 
  To: hivemind-user@jakarta.apache.org 
  Sent: Thursday, January 26, 2006 1:17 PM
  Subject: RE: wait - notify


  Where is this logic?  Is it inside a HiveMind service implementation object?

   


------------------------------------------------------------------------------

  From: John Coleman [mailto:john.s.coleman@ntlworld.com] 
  Sent: Wednesday, January 25, 2006 7:39 PM
  To: hivemind-user@jakarta.apache.org
  Subject: wait - notify

   

  Hi,

   

  Any ideas if it could be HiveMind stopping this wait/notify code running?

   

    public void dispatchEvent(EventObject event) {
      events.add(event);
      System.out.println("dispatch event..." + event);
      synchronized (this) {
        notify(); // break wait state
      }
      System.out.println("notified");
    }

   

    // a loop to dispatch events to the correct type of listeners
    public void run() {
      // loop handling all events until stop is true
      do {
        try {
          // wait for some event notifications
          synchronized (this) {
            wait();
          }....

   

   

  If I do wait(10) then code works fine, but the sync blocks don't seem effective. If I directly instantiate the classes w/o HM, then code works!

   

  John

   

RE: wait - notify

Posted by James Carman <ja...@carmanconsulting.com>.
Where is this logic?  Is it inside a HiveMind service implementation object?

 

  _____  

From: John Coleman [mailto:john.s.coleman@ntlworld.com] 
Sent: Wednesday, January 25, 2006 7:39 PM
To: hivemind-user@jakarta.apache.org
Subject: wait - notify

 

Hi,

 

Any ideas if it could be HiveMind stopping this wait/notify code running?

 

  public void dispatchEvent(EventObject event) {
    events.add(event);
    System.out.println("dispatch event..." + event);
    synchronized (this) {
      notify(); // break wait state
    }
    System.out.println("notified");
  }

 

  // a loop to dispatch events to the correct type of listeners
  public void run() {
    // loop handling all events until stop is true
    do {
      try {
        // wait for some event notifications
        synchronized (this) {
          wait();
        }....

 

 

If I do wait(10) then code works fine, but the sync blocks don't seem
effective. If I directly instantiate the classes w/o HM, then code works!

 

John