0

BindUtils.postNotifyChange throws an exception (not in execution)

asked 2014-09-23 11:31:49 +0800

pasqualeleone gravatar image pasqualeleone flag of Italy
81 2

Hi guys, I have a problem with the update BindUtils.postNotifyChange (x, x, x, x) in a distributed environment. I describe to you the use case: I subscribed a queue on a listener who shall update the values ​​of an object FlightBean () on various distributed clients. The object that is used to handle the event is:

public class FlightWatchEvent extends FlightEvent implements Runnable{

private String operationToDo;
private FlightModifiedAttributesModel flightModifyAttributes = new FlightModifiedAttributesModel();
private Thread t;

public FlightWatchEvent() {
    super();    
    t = new Thread(this);
}
    public FlightWatchEvent(String eventSource, Date generateTime, String name,
            Integer oid, String flightNumber, Date operativeDate,
            Integer oidNature, String nature, Integer oidFlightCarrier,
            String iataCode2, String icaoCode,
            HashMap<String, StatusObject> listModifyAttributes,
            String operationToDo,
            FlightModifiedAttributesModel flightModifyAttributes) {
        super(eventSource, generateTime, name, oid, flightNumber,
                operativeDate, oidNature, nature, oidFlightCarrier, iataCode2,
                icaoCode, listModifyAttributes);
        this.operationToDo = operationToDo;
        this.flightModifyAttributes = flightModifyAttributes;
    }

    public void avviaThreadAggiornamento() {
        t.start();  
        t = new Thread(this);
    }

    @Override
    public void run() {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.clearListModifyAttributes();
        this.resetUpdateFlag();
        try{
            BindUtils.postNotifyChange(null, null, this, "flightModifyAttributes");
        }catch (Exception e){
             e.printStackTrace();
            Log.getLogger().debug("errorE");
        }//         final HashMap<String, Object> map = new HashMap<String, Object>();//            map.put("event", this);//           BindUtils.postGlobalCommand("FWQueue", null, "updateQualcosa", map);//          t = new Thread(this);
    }
}
//get e set methods}

The class FlightModifiedAttributesModel() contains flags that need to be reset after x seconds. To do this, use the thread t, that recalls after x seconds the clean flag method. These flags are binded on the UI and I need to update them after they are reset, so use the statement BindUtils.postNotifyChange (null, null, this, "flightModifyAttributes"); but at this point is throws exception

java.lang.IllegalStateException: Not in an execution
at org.zkoss.zk.ui.event.impl.EventQueueProviderImpl.lookup(EventQueueProviderImpl.java:43)
at org.zkoss.zkmax.ui.event.impl.EventQueueProviderImpl.lookup(EventQueueProviderImpl.java:58)
at org.zkoss.zk.ui.event.EventQueues.lookup(EventQueues.java:127)
at org.zkoss.bind.BindUtils.postNotifyChange(BindUtils.java:54)
at vis.eghos.web.ui.event.flt.FlightWatchEvent.run(FlightWatchEvent.java:77)
at java.lang.Thread.run(Unknown Source)

I wish that every distributed client which receives notification from the event queue, update the flag independently of the instance of the class FlightWatchEvent () on its own UI, but this exception does not allow me.

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted
0

answered 2014-09-24 22:17:07 +0800

Tristan2583 gravatar image Tristan2583
13 3

Hi pasqualeleone! As Chillworld said, have you tried something like that?

public class FlightWatchEvent extends FlightEvent implements Runnable{

private String operationToDo;
private FlightModifiedAttributesModel flightModifyAttributes = new FlightModifiedAttributesModel();
private Desktop _desktop;
//private Thread t;

public FlightWatchEvent() {
    super();    
    //t = new Thread(this);
}
    public FlightWatchEvent(String eventSource, Date generateTime, String name,
            Integer oid, String flightNumber, Date operativeDate,
            Integer oidNature, String nature, Integer oidFlightCarrier,
            String iataCode2, String icaoCode,
            HashMap<String, StatusObject> listModifyAttributes,
            String operationToDo,
            FlightModifiedAttributesModel flightModifyAttributes) {
        super(eventSource, generateTime, name, oid, flightNumber,
                operativeDate, oidNature, nature, oidFlightCarrier, iataCode2,
                icaoCode, listModifyAttributes);
        this.operationToDo = operationToDo;
        this.flightModifyAttributes = flightModifyAttributes;
    }

    //public void avviaThreadAggiornamento() {
    //    t.start();  
    //    t = new Thread(this);
    //}

    @Override
    public void run() {

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.clearListModifyAttributes();
        this.resetUpdateFlag();

        //Abilito il server push
        if(!_desktop.isEnabledServerPush())
            _desktop.enableServerPush(true);

        //Attivo l'esecuzione del thread concorrente che aggiorna il desktop.
        Executions.activate(_desktop);

        try{
            BindUtils.postNotifyChange(null, null, this, "flightModifyAttributes");
        }catch (Exception e){
             e.printStackTrace();
            Log.getLogger().debug("errorE");
        }
        finally{
            Executions.deactivate(_desktop);
        }
    }
}

You can pass a reference to the current desktop through:

Executions.getCurrent().getDesktop();
link publish delete flag offensive edit
0

answered 2014-09-23 11:44:02 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-09-23 11:46:02 +0800

You have to enable serverpush to allow that.

Here is a example with threading how to do so.

If I understand correctly you want to update each client logged in => Example of chat in mvvm.

Greetz chill.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-09-23 11:31:49 +0800

Seen: 55 times

Last updated: Sep 24 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More