use of org.netxms.client.SessionListener in project netxms by netxms.
the class AlarmNotifier method init.
/**
* Initialize alarm notifier
*/
public static void init(NXCSession session) {
AlarmNotifier.session = session;
ps = Activator.getDefault().getPreferenceStore();
workspaceUrl = Platform.getInstanceLocation().getURL();
checkSounds();
lastReminderTime = System.currentTimeMillis();
try {
Map<Long, Alarm> alarms = session.getAlarms();
for (Alarm a : alarms.values()) {
alarmStates.put(a.getId(), a.getState());
if (a.getState() == Alarm.STATE_OUTSTANDING)
outstandingAlarms++;
}
} catch (Exception e) {
}
listener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.NEW_ALARM) || (n.getCode() == SessionNotification.ALARM_CHANGED)) {
processNewAlarm((Alarm) n.getObject());
} else if ((n.getCode() == SessionNotification.ALARM_TERMINATED) || (n.getCode() == SessionNotification.ALARM_DELETED)) {
Alarm a = (Alarm) n.getObject();
Integer state = alarmStates.get(a.getId());
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING)
outstandingAlarms--;
alarmStates.remove(a.getId());
}
} else if (n.getCode() == SessionNotification.MULTIPLE_ALARMS_RESOLVED) {
BulkAlarmStateChangeData d = (BulkAlarmStateChangeData) n.getObject();
for (Long id : d.getAlarms()) {
Integer state = alarmStates.get(id);
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING) {
outstandingAlarms--;
}
}
alarmStates.put(id, Alarm.STATE_RESOLVED);
}
} else if (n.getCode() == SessionNotification.MULTIPLE_ALARMS_TERMINATED) {
BulkAlarmStateChangeData d = (BulkAlarmStateChangeData) n.getObject();
for (Long id : d.getAlarms()) {
Integer state = alarmStates.get(id);
if (state != null) {
if (state == Alarm.STATE_OUTSTANDING)
outstandingAlarms--;
alarmStates.remove(id);
}
}
}
}
};
session.addListener(listener);
Thread reminderThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
long currTime = System.currentTimeMillis();
if (// $NON-NLS-1$
ps.getBoolean("OUTSTANDING_ALARMS_REMINDER") && (outstandingAlarms > 0) && (lastReminderTime + 300000 <= currTime)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
soundQueue.offer(SEVERITY_TEXT[SEVERITY_TEXT.length - 1]);
AlarmReminderDialog dlg = new AlarmReminderDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
dlg.open();
}
});
lastReminderTime = currTime;
}
}
}
}, // $NON-NLS-1$
"AlarmReminderThread");
reminderThread.setDaemon(true);
reminderThread.start();
Thread playerThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
String soundId;
try {
soundId = soundQueue.take();
} catch (InterruptedException e) {
continue;
}
Clip sound = null;
try {
String fileName = getSoundAndDownloadIfRequired(soundId);
if (fileName != null) {
sound = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
sound.open(AudioSystem.getAudioInputStream(new File(workspaceUrl.getPath(), fileName).getAbsoluteFile()));
sound.start();
while (!sound.isRunning()) Thread.sleep(10);
while (sound.isRunning()) {
Thread.sleep(10);
}
}
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Exception in alarm sound player", e);
} finally {
if ((sound != null) && sound.isOpen())
sound.close();
}
}
}
}, "AlarmSoundPlayer");
playerThread.setDaemon(true);
playerThread.start();
}
use of org.netxms.client.SessionListener in project netxms by netxms.
the class ApplicationWorkbenchAdvisor method postStartup.
/* (non-Javadoc)
* @see org.eclipse.ui.application.WorkbenchAdvisor#postStartup()
*/
@Override
public void postStartup() {
super.postStartup();
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
shell.addShellListener(new ShellAdapter() {
public void shellIconified(ShellEvent e) {
if (// $NON-NLS-1$
Activator.getDefault().getPreferenceStore().getBoolean("HIDE_WHEN_MINIMIZED"))
shell.setVisible(false);
}
});
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
session.addListener(new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
String productName = BrandingManager.getInstance().getProductName();
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ApplicationWorkbenchAdvisor_CommunicationError, ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? Messages.get().ApplicationWorkbenchAdvisor_SessionTerminated : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName))) + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
}
});
}
}
});
}
use of org.netxms.client.SessionListener in project netxms by netxms.
the class SessionStore method registerSession.
/**
* @param s
*/
public synchronized SessionToken registerSession(final NXCSession session) {
if (sessionManager == null) {
sessionManager = new Thread(new Runnable() {
@Override
public void run() {
sessionManagerThread();
}
}, "Session Manager");
sessionManager.setDaemon(true);
sessionManager.start();
}
final SessionToken token = new SessionToken(session);
sessions.put(token.getGuid(), token);
session.addListener(new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
log.info("Received disconnect notification for session " + token.getGuid());
session.disconnect();
unregisterSession(token.getGuid());
}
}
});
log.info("Session " + token.getGuid() + " registered");
return token;
}
use of org.netxms.client.SessionListener in project netxms by netxms.
the class EventProcessingPolicyEditor method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
// Initiate loading of required plugins if they was not loaded yet
try {
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
} catch (Exception e) {
}
// $NON-NLS-1$
imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
// $NON-NLS-1$
imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
// $NON-NLS-1$
imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
// $NON-NLS-1$
imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
// $NON-NLS-1$
imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
imageCollapse = SharedIcons.COLLAPSE.createImage();
imageExpand = SharedIcons.EXPAND.createImage();
imageEdit = SharedIcons.EDIT.createImage();
parent.setLayout(new FormLayout());
// Create filter area
filterControl = new FilterText(parent, SWT.NONE);
filterControl.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterControl.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
dataArea = new Composite(scroller, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
dataArea.setLayout(layout);
dataArea.setBackground(BACKGROUND_COLOR);
scroller.setContent(dataArea);
scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scroller.getClientArea();
scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterControl);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
scroller.setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterControl.setLayoutData(fd);
normalFont = JFaceResources.getDefaultFont();
boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
sessionListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
processSessionNotification(n);
}
};
session.addListener(sessionListener);
selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {
@Override
public int compare(RuleEditor arg0, RuleEditor arg1) {
return arg0.getRuleNumber() - arg1.getRuleNumber();
}
});
createActions();
contributeToActionBars();
openEventProcessingPolicy();
activateContext();
// Set initial focus to filter input line
if (filterEnabled)
filterControl.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.client.SessionListener in project netxms by netxms.
the class ApplicationWorkbenchAdvisor method doLogin.
/**
* Show login dialog and perform login
*/
private void doLogin() {
boolean success = false;
final Properties properties = new AppPropertiesLoader().load();
String password = "";
// $NON-NLS-1$
boolean autoLogin = (Application.getParameter("auto") != null);
String ssoTicket = Application.getParameter("ticket");
if (ssoTicket != null) {
autoLogin = true;
// $NON-NLS-1$
String server = Application.getParameter("server");
if (server == null)
// $NON-NLS-1$ //$NON-NLS-2$
server = properties.getProperty("server", "127.0.0.1");
success = connectToServer(server, null, ssoTicket);
} else if (autoLogin) {
// $NON-NLS-1$
String server = Application.getParameter("server");
if (server == null)
// $NON-NLS-1$ //$NON-NLS-2$
server = properties.getProperty("server", "127.0.0.1");
// $NON-NLS-1$
String login = Application.getParameter("login");
if (login == null)
login = "guest";
// $NON-NLS-1$
password = Application.getParameter("password");
if (password == null)
password = "";
success = connectToServer(server, login, password);
}
if (!autoLogin || !success) {
Window loginDialog;
do {
loginDialog = BrandingManager.getInstance().getLoginForm(Display.getCurrent().getActiveShell(), properties);
if (loginDialog.open() != Window.OK)
continue;
password = ((LoginForm) loginDialog).getPassword();
success = connectToServer(// $NON-NLS-1$ //$NON-NLS-2$
properties.getProperty("server", "127.0.0.1"), ((LoginForm) loginDialog).getLogin(), password);
} while (!success);
}
if (success) {
final NXCSession session = (NXCSession) RWT.getUISession().getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
final Display display = Display.getCurrent();
session.addListener(new SessionListener() {
private final Object MONITOR = new Object();
@Override
public void notificationHandler(final SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
display.asyncExec(new Runnable() {
@Override
public void run() {
RWT.getUISession().setAttribute("NoPageReload", Boolean.TRUE);
PlatformUI.getWorkbench().close();
String productName = BrandingManager.getInstance().getProductName();
String msg = (n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? "Communication session was terminated by system administrator" : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName));
JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
if (executor != null)
executor.execute("document.body.innerHTML='" + "<div style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: none; background-color: white;\">" + "<p style=\"margin-top: 30px; margin-left: 30px; color: #800000; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; font-weight: bold; font-size: 2em;\">" + msg + "</p><br/>" + "<button style=\"margin-left: 30px\" onclick=\"location.reload(true)\">RELOAD</button>" + "</div>';");
synchronized (MONITOR) {
MONITOR.notifyAll();
}
}
});
synchronized (MONITOR) {
try {
MONITOR.wait(5000);
} catch (InterruptedException e) {
}
}
((UISessionImpl) RWT.getUISession(display)).shutdown();
}
}
});
try {
RWT.getSettingStore().loadById(session.getUserName() + "@" + session.getServerId());
} catch (IOException e) {
}
// Suggest user to change password if it is expired
if (session.isPasswordExpired()) {
final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null, session.getGraceLogins());
while (true) {
if (dlg.open() != Window.OK)
return;
final String currentPassword = password;
IRunnableWithProgress job = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
NXCSession session = (NXCSession) RWT.getUISession(display).getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
session.setUserPassword(session.getUserId(), dlg.getPassword(), currentPassword);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
ProgressMonitorDialog pd = new ProgressMonitorDialog(null);
pd.run(false, false, job);
MessageDialog.openInformation(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Information, Messages.get().ApplicationWorkbenchWindowAdvisor_PasswordChanged);
return;
} catch (InvocationTargetException e) {
MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Error, Messages.get().ApplicationWorkbenchWindowAdvisor_CannotChangePswd + e.getCause().getLocalizedMessage());
} catch (InterruptedException e) {
MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Exception, e.toString());
}
}
}
}
}
Aggregations