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