Search in sources :

Example 1 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class ClientMonitor method acceptState.

public void acceptState(int state, String message) {
    if (state == CONNECTION_CLOSED) {
        return;
    }
    if (state == CONNECTION_OK) {
        ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
        if (c != null) {
            try {
                Map m = new HashMap();
                m.put("status", "revert");
                // this method executes the command as well !!
                c.setParameters(m);
            } catch (Exception e) {
                m_logger.log(Level.SEVERE, e.toString(), e);
            }
        }
        return;
    }
    if (state == SERVER_SHUTDOWN) {
        DisplayManager.getDefaultDisplay().asyncExec(new Reconnector());
    }
    if (state == SERVER_NOT_FOUND) {
        boolean autoReConnect = "true".equalsIgnoreCase(getRuntime().getConfigManagerFactory().getConfigManager().getProperty("service.Client", "autoreconnect"));
        if (autoReConnect) {
            Runnable r = new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(60000);
                    } catch (InterruptedException e) {
                    }
                    ClientMonitor.this.start();
                }
            };
            Thread t = new Thread(r);
            t.setName("ClientMonitor-HeadlessReconnector");
            t.start();
        }
    }
}
Also used : HashMap(java.util.HashMap) ICommand(de.janrufmonitor.framework.command.ICommand) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class TrayIcon method createItem.

private void createItem(Menu menu, String actionCommand, boolean checkable) {
    MenuItem item = null;
    ICommand c = this.getRuntime().getCommandFactory().getCommand(actionCommand);
    String title = actionCommand;
    if (c != null) {
        title = c.getLabel();
    }
    if (checkable) {
        item = new MenuItem(menu, SWT.CHECK);
        item.setSelection(true);
    } else {
        item = new MenuItem(menu, SWT.PUSH);
    }
    item.setData("command", actionCommand);
    item.setText(title);
    if (actionCommand.length() == 0) {
        item.setEnabled(false);
    } else {
        item.addListener(SWT.Selection, this.m_ah);
        item.setEnabled((c != null ? c.isExecutable() : false));
    }
    this.menuItemMap.put(actionCommand, item);
}
Also used : ICommand(de.janrufmonitor.framework.command.ICommand) MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 3 with ICommand

use of de.janrufmonitor.framework.command.ICommand 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 4 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class AutoUpdateService method triggerUpdate.

private void triggerUpdate() {
    this.m_logger.info("Starting automatic Update-Check...");
    UpdateManager m = new UpdateManager();
    List u = m.getUpdates();
    if (u != null && u.size() > 0) {
        PropagationFactory.getInstance().fire(new Message(Message.INFO, getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "title", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)), new Exception(getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "newupdates", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)))), "Tray");
        this.m_logger.info("Automatic Update-Check is executed for " + u.size() + " modules.");
        ICommand updateCommand = this.getRuntime().getCommandFactory().getCommand("UpdatesCommand");
        if (updateCommand != null && updateCommand.isExecutable()) {
            try {
                this.m_logger.info("Executing UpdateCommand...");
                Map parameter = new HashMap(1);
                parameter.put("preload", Boolean.TRUE);
                updateCommand.setParameters(parameter);
                updateCommand.execute();
            } catch (Exception e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    } else {
        this.m_logger.info("No updates available.");
    }
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(NAMESPACE, "lastupdatecheck", Long.toString(System.currentTimeMillis()));
    getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
Also used : Message(de.janrufmonitor.exception.Message) HashMap(java.util.HashMap) ICommand(de.janrufmonitor.framework.command.ICommand) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class RunConsole method help.

public static void help() {
    System.out.println("Configuration must be done in janrufmonitor.properties.");
    System.out.println("");
    System.out.println("Help                - HELP + <ENTER>");
    String commands = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(RunConsole.NAMESPACE, "commands");
    StringTokenizer st = new StringTokenizer(commands, ",");
    while (st.hasMoreTokens()) {
        try {
            ICommand cmd = PIMRuntime.getInstance().getCommandFactory().getCommand(st.nextToken().trim());
            if (cmd != null && cmd instanceof IConsoleCommand && cmd.getLabel() != null) {
                System.out.println(cmd.getLabel());
            }
        } catch (NullPointerException e) {
        }
    }
    System.out.println("Re-start            - RESTART + <ENTER>");
    System.out.println("Quit                - QUIT + <ENTER>");
    System.out.println("");
}
Also used : StringTokenizer(java.util.StringTokenizer) ICommand(de.janrufmonitor.framework.command.ICommand) IConsoleCommand(de.janrufmonitor.framework.command.IConsoleCommand)

Aggregations

ICommand (de.janrufmonitor.framework.command.ICommand)12 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Message (de.janrufmonitor.exception.Message)3 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)3 IConsoleCommand (de.janrufmonitor.framework.command.IConsoleCommand)2 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)2 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)2 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)2 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)2 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)2 FritzBoxNotFoundException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)2 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)2 GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)2 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)2 GetCallerImageException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException)2 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)2 InvalidSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException)2 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)2