Revision history [back]

click to hide/show revision 1
initial version

asked 2017-04-19 13:43:32 +0800

lramellavotta gravatar image lramellavotta flag of Italy

my Achilles' heel: ExecutorService

This is my Achilles' heel... I'd like to read cyclically some data from db and warn the user on specified presence of event. I tried writing some solution...without success. Now the error is : "org.zkoss.zul.Timer cannot be cast to org.zkoss.zk.ui.event.EventListener"

Can someone help me? thanks, /Luca

zk.xml

<listener>
     <description>Utilizzato leggere dal database </description>
     <display-name>Ricontatto cellulare </display-name>
     <listener-class>rvl.gm.utility.RicontattoCellulare</listener-class>
</listener>

RicontattoCellulare

public class RicontattoCellulare implements WebAppInit, WebAppCleanup
{
    private static volatile ExecutorService executor;    
    public static ExecutorService getExecutor() 
    {
        return executor;
    }
    @Override
    public void cleanup(WebApp wapp) throws Exception 
    {
        if (executor != null) 
        {
            executor.shutdown();
            System.out.println("ExecutorService gestione telefonate a cellulare ->shutdown");
        }
    }
    @Override
    public void init(WebApp wapp) throws Exception 
    {
        executor = Executors.newSingleThreadExecutor();
        System.out.println("ExecutorService gestione telefonate a cellulare ->startup");
    }

}

RicontattoCellulareRun

public class RicontattoCellulareRun implements Runnable
{

    private final Desktop desktop;
    private final EventListener<Event> eventListener;
    private final Nazioni gNazione;

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public RicontattoCellulareRun(Desktop desktop, EventListener eventListener, Nazioni gNazione)
    {
        this.desktop = desktop;
        this.eventListener = eventListener;
        this.gNazione = gNazione;
    }

    @Override
    public void run() 
    {
        try 
        {
            desktop.enableServerPush(true);
            TelefonateSuCellulareDAO tdao = (TelefonateSuCellulareDAO) SpringUtil.getBean("TelefonateSuCellulareDAO");
            List<TelefonateSuCellulare> lstTel = tdao.findAll(gNazione);
            Executions.schedule(desktop, eventListener, new Event("onReadTel",null, lstTel));
            desktop.enableServerPush(false);
        } catch (Exception e) 
        {
            System.err.println("RicontattoCellulareRun: " + e.getMessage());
        }
    }
}

Menu

@Wire("#timer")
    Timer timer;
@AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view)
    {
...
    timer.addEventListener("onReadTel", new EventListener()
    {
        @Override
        public void onEvent(Event event) throws Exception 
        {
            System.out.println("WWW");
        }
    });

    RicontattoCellulare.getExecutor().execute((new RicontattoCellulareRun(desktop,(EventListener) timer, gNazione)));

SOLVED: my Achilles' heel: ExecutorService

This is my Achilles' heel... I'd like to read cyclically some data from db and warn the user on specified presence of event. I tried writing some solution...without success. Now the error is : "org.zkoss.zul.Timer cannot be cast to org.zkoss.zk.ui.event.EventListener"

Can someone help me? thanks, /Luca

zk.xml

<listener>
     <description>Utilizzato leggere dal database </description>
     <display-name>Ricontatto cellulare </display-name>
     <listener-class>rvl.gm.utility.RicontattoCellulare</listener-class>
</listener>

RicontattoCellulare

public class RicontattoCellulare implements WebAppInit, WebAppCleanup
{
    private static volatile ExecutorService executor;    
    public static ExecutorService getExecutor() 
    {
        return executor;
    }
    @Override
    public void cleanup(WebApp wapp) throws Exception 
    {
        if (executor != null) 
        {
            executor.shutdown();
            System.out.println("ExecutorService gestione telefonate a cellulare ->shutdown");
        }
    }
    @Override
    public void init(WebApp wapp) throws Exception 
    {
        executor = Executors.newSingleThreadExecutor();
        System.out.println("ExecutorService gestione telefonate a cellulare ->startup");
    }

}

RicontattoCellulareRun

public class RicontattoCellulareRun implements Runnable
{

    private final Desktop desktop;
    private final EventListener<Event> eventListener;
    private final Nazioni gNazione;

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public RicontattoCellulareRun(Desktop desktop, EventListener eventListener, Nazioni gNazione)
    {
        this.desktop = desktop;
        this.eventListener = eventListener;
        this.gNazione = gNazione;
    }

    @Override
    public void run() 
    {
        try 
        {
            desktop.enableServerPush(true);
            TelefonateSuCellulareDAO tdao = (TelefonateSuCellulareDAO) SpringUtil.getBean("TelefonateSuCellulareDAO");
            List<TelefonateSuCellulare> lstTel = tdao.findAll(gNazione);
            Executions.schedule(desktop, eventListener, new Event("onReadTel",null, lstTel));
            desktop.enableServerPush(false);
        } catch (Exception e) 
        {
            System.err.println("RicontattoCellulareRun: " + e.getMessage());
        }
    }
}

Menu

@Wire("#timer")
    Timer timer;
@AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view)
    {
...
    timer.addEventListener("onReadTel", new EventListener()
    {
        @Override
        public void onEvent(Event event) throws Exception 
        {
            System.out.println("WWW");
        }
    });

    RicontattoCellulare.getExecutor().execute((new RicontattoCellulareRun(desktop,(EventListener) timer, gNazione)));
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More