use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class TwitterPINCommand method asyncExecute.
public void asyncExecute() {
try {
WizardDialog.setDefaultImage(SWTImageManager.getInstance(getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
TwitterPINWizard tpw = new TwitterPINWizard();
WizardDialog dlg = new WizardDialog(new Shell(DisplayManager.getDefaultDisplay()), tpw);
dlg.open();
} catch (Throwable t) {
this.m_logger.log(Level.SEVERE, t.getMessage(), t);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, this.getNamespace(), t.toString().toLowerCase(), t));
} finally {
this.isExecuting = false;
}
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class InstallerEngine method installWithoutDescriptor.
private void installWithoutDescriptor(IInstaller installer, File f, boolean suppressPopup) throws InstallerException {
if (!suppressPopup) {
this.m_logger.warning("No module descriptor available. This module is not intended to be installed in this version: " + f.getName());
PropagationFactory.getInstance().fire(new Message(Message.INFO, NAMESPACE, "null", new Exception("Component with no module descriptor installed.")));
}
try {
installer.install(true);
} catch (InstallerException e) {
this.m_logger.severe("Installation of file " + f.getName() + " failed.");
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, NAMESPACE, "unknown", e));
}
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class FirmwareManager method login.
public void login() throws FritzBoxLoginException {
boolean dnl = Boolean.parseBoolean(System.getProperty("jam.fritzbox.session.donotlogin", "false"));
if (dnl)
return;
while (this.m_isLoggingIn) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
this.m_isLoggingIn = true;
if (this.m_fw == null) {
this.promptPassword();
try {
this.createFirmwareInstance();
} catch (FritzBoxInitializationException e) {
this.m_fw = null;
if (e.isUnsupportedFirmware()) {
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_UNSUPPORTED));
}
throw new FritzBoxLoginException(e.getMessage());
} catch (FritzBoxNotFoundException e) {
this.m_fw = null;
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_UNKNOWN_HOST));
throw new FritzBoxLoginException(e.getMessage());
} catch (InvalidSessionIDException e) {
this.m_fw = null;
if (e.getMessage().indexOf("user/password combination") > 0) {
System.setProperty("jam.fritzbox.session.password", "");
if (this.getFritzBoxPassword().trim().length() == 0) {
this.m_isLoggingIn = false;
this.login();
return;
}
}
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.login", "loginfailed", e, true));
throw new FritzBoxLoginException(e.getMessage());
} finally {
this.m_isLoggingIn = false;
}
}
this.m_isLoggingIn = false;
if (this.m_fw == null)
throw new FritzBoxLoginException("Login failed due to invalid firmware.");
this.m_fw.login();
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_RECONNECTED_SUCCESS));
}
use of de.janrufmonitor.exception.Message 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.exception.Message in project janrufmonitor by tbrandt77.
the class FirmwareManager method received.
public void received(IEvent event) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("New event received: " + event.getType());
switch(event.getType()) {
case IEventConst.EVENT_TYPE_HARDWARE_UNSUPPORTED:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_HARDWARE_UNSUPPORTED occured.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "unsupported", new Exception("Firmware not supported."), false), "Tray");
break;
case IEventConst.EVENT_TYPE_HARDWARE_RESTARTED:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_HARDWARE_RESTARTED occured.");
PropagationFactory.getInstance().fire(new Message(Message.WARNING, "fritzbox.firmware.hardware", "restarted", new String[] { getFritzBoxAddress() }, new Exception("FRITZ!Box " + getFritzBoxAddress() + " restart detected."), false), "Tray");
this.reconnect(10000L);
break;
case IEventConst.EVENT_TYPE_HARDWARE_NETWORK_UNAVAILABLE:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_HARDWARE_NETWORK_UNAVAILABLE occured.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "network", new String[] { getFritzBoxAddress() }, new Exception("Network unreachable."), false), "Tray");
this.reconnect(getFritzBoxMaxRetryTimeout());
break;
case IEventConst.EVENT_TYPE_HARDWARE_CONNECTION_LOST:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_CONNECTION_LOST occured.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "conlost", new String[] { getFritzBoxAddress(), getFritzBoxPort() }, new Exception("Connection to " + getFritzBoxAddress() + ":" + getFritzBoxPort() + " lost."), false), "Tray");
this.reconnect(getFritzBoxMaxRetryTimeout());
break;
case IEventConst.EVENT_TYPE_HARDWARE_UNKNOWN_HOST:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_UNKNOWN_HOST occured.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "unknownhost", new String[] { getFritzBoxAddress() }, new Exception("Unknown host " + getFritzBoxAddress()), false), "Tray");
this.reconnect(getFritzBoxMaxRetryTimeout());
break;
case IEventConst.EVENT_TYPE_HARDWARE_REFUSED:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection event EVENT_TYPE_HARDWARE_REFUSED occured.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "refused", new String[] { getFritzBoxAddress() }, new Exception("Connection refused: " + getFritzBoxAddress()), false));
this.reconnect(getFritzBoxMaxRetryTimeout());
break;
case IEventConst.EVENT_TYPE_HARDWARE_RECONNECTED_SUCCESS:
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Connection successfully established.");
if (getRuntime().getMonitorListener().isRunning() && this.isLoggedIn()) {
m_retryCount = 0;
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Retry counter = 0");
}
break;
default:
break;
}
}
Aggregations