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();
}
}
}
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);
}
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;
}
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();
}
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("");
}
Aggregations