Search in sources :

Example 1 with IMonitorListener

use of de.janrufmonitor.framework.monitor.IMonitorListener in project janrufmonitor by tbrandt77.

the class FirmwareManager method reconnect.

private void reconnect(long timeout) {
    if (this.m_isReconnecting) {
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Re-connecting already in progress. Exiting thread " + Thread.currentThread().getName());
        return;
    }
    while (this.m_isReconnecting) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    this.m_isReconnecting = true;
    IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
    if (ml != null && ml.isRunning()) {
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Disconnecting FritzBox monitor on port 1012.");
        ml.stop();
    }
    ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
    if (c != null) {
        try {
            Map m = new HashMap();
            m.put("status", "delay");
            // this method executes the command as well !!
            c.setParameters(m);
        } catch (Exception e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    if (m_logger.isLoggable(Level.INFO))
        m_logger.info("Disconnecting FritzBox sync on port 80 and 49443/49000.");
    if (m_restartedThread != null && m_restartedThread.isAlive()) {
        m_restartedThread.interrupt();
    }
    if (m_timeoutThread != null && m_timeoutThread.isAlive()) {
        m_timeoutThread.interrupt();
    }
    if (this.m_fw != null) {
        this.m_fw.destroy();
    }
    this.m_fw = null;
    if (getFritzBoxAutoReconnect() && m_retryCount < getFritzBoxMaxRetryCount()) {
        m_retryCount++;
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e1) {
        }
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Re-connecting is configured. Retry counter = " + m_retryCount);
        PropagationFactory.getInstance().fire(new Message(Message.INFO, "fritzbox.firmware.hardware", "reconnect", new String[] { getFritzBoxAddress(), Integer.toString(m_retryCount) }, new Exception("Reconnecting to FRITZ!Box " + getFritzBoxAddress()), false), "Tray");
        try {
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Sleeping " + timeout + " ms before re-connect try.");
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
        }
        try {
            this.login();
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Automatic re-connect to FritzBox done...");
        } catch (FritzBoxLoginException e) {
            // check for reason
            m_logger.log(Level.WARNING, e.getMessage(), e);
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Automatic re-connect to FritzBox failed...");
        }
        Thread t = new Thread(new Runnable() {

            public void run() {
                IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
                if (ml != null && !ml.isRunning()) {
                    ml.start();
                    ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
                    if (c != null) {
                        try {
                            Map m = new HashMap();
                            m.put("status", "delay");
                            // this method executes the command as well !!
                            c.setParameters(m);
                        } catch (Exception e) {
                            m_logger.log(Level.SEVERE, e.toString(), e);
                        }
                    }
                }
            }
        });
        t.setName("JAM-FritzBoxFirmwareRestartMonitor-Thread-(daemon)");
        t.setDaemon(true);
        t.start();
    } else if (getFritzBoxAutoReconnect() && m_retryCount >= getFritzBoxMaxRetryCount()) {
        PropagationFactory.getInstance().fire(new Message(Message.INFO, "fritzbox.firmware.hardware", "maxreconnect", new String[] { Integer.toString((m_retryCount > getFritzBoxMaxRetryCount() ? getFritzBoxMaxRetryCount() : m_retryCount)) }, new Exception("Maximum retry count reached " + m_retryCount), false), "Tray");
    }
    this.m_isReconnecting = false;
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) HashMap(java.util.HashMap) ICommand(de.janrufmonitor.framework.command.ICommand) HashMap(java.util.HashMap) Map(java.util.Map) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) GetAddressbooksException(de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException) InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) GetCallerImageException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException) IOException(java.io.IOException) SetCallerException(de.janrufmonitor.fritzbox.firmware.exception.SetCallerException) DeleteCallerException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)

Example 2 with IMonitorListener

use of de.janrufmonitor.framework.monitor.IMonitorListener in project janrufmonitor by tbrandt77.

the class Activator method setParameters.

public void setParameters(Map m) {
    if (m != null) {
        String status = (String) m.get("status");
        if (status != null && status.length() > 0) {
            IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
            if (status.equalsIgnoreCase("invert")) {
                ml.stop();
            }
            if (status.equalsIgnoreCase("revert")) {
                ml.start();
            }
            if (status.equalsIgnoreCase("delay")) {
            // do nothing so far
            }
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            if (tray != null && tray instanceof TrayIcon) {
                ((TrayIcon) tray).setIconStateMonitorListener();
            }
            if (!status.equalsIgnoreCase("delay"))
                PropagationFactory.getInstance().fire(new Message((ml.isRunning() ? Message.INFO : Message.WARNING), getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "title", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)), new Exception((ml.isRunning() ? getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "on", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)) : getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "off", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE))))), "Tray");
        }
    }
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) Message(de.janrufmonitor.exception.Message) IService(de.janrufmonitor.service.IService)

Example 3 with IMonitorListener

use of de.janrufmonitor.framework.monitor.IMonitorListener in project janrufmonitor by tbrandt77.

the class Activator method execute.

public void execute() {
    IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
    if (ml.isRunning()) {
        ml.stop();
    } else {
        ml.start();
    }
    IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
    if (tray != null && tray instanceof TrayIcon) {
        ((TrayIcon) tray).setIconStateMonitorListener();
    }
    getRuntime().getEventBroker().register(this);
    getRuntime().getEventBroker().send(this, getRuntime().getEventBroker().createEvent(IEventConst.EVENT_TYPE_APPLICATION_READY));
    getRuntime().getEventBroker().unregister(this);
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) IService(de.janrufmonitor.service.IService)

Aggregations

IMonitorListener (de.janrufmonitor.framework.monitor.IMonitorListener)3 Message (de.janrufmonitor.exception.Message)2 IService (de.janrufmonitor.service.IService)2 ICommand (de.janrufmonitor.framework.command.ICommand)1 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)1 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)1 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)1 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)1 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 FritzBoxNotFoundException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)1 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)1 GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)1 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)1 GetCallerImageException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException)1 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)1 InvalidSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException)1 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1