/** * Unwatches an event. * * @throws IOException I/O exception */ private void unwatch() throws IOException { final String name = in.readString(); final Sessions s = context.events.get(name); final boolean ok = s != null && s.contains(this); final String message; if (ok) { s.remove(this); message = UNWATCHING_EVENT_X; } else if (s == null) { message = EVENT_UNKNOWN_X; } else { message = EVENT_NOT_WATCHED_X; } info(Util.info(message, name), ok); out.flush(); }
/** * Watches an event. * * @throws IOException I/O exception */ private void watch() throws IOException { server.initEvents(); // initialize server-based event handling if (!events) { out.writeString(Integer.toString(context.mprop.num(MainProp.EVENTPORT))); out.writeString(Long.toString(getId())); out.flush(); events = true; } final String name = in.readString(); final Sessions s = context.events.get(name); final boolean ok = s != null && !s.contains(this); final String message; if (ok) { s.add(this); message = WATCHING_EVENT_X; } else if (s == null) { message = EVENT_UNKNOWN_X; } else { message = EVENT_WATCHED_X; } info(Util.info(message, name), ok); }
/** Exits the session. */ public synchronized void quit() { running = false; if (log != null) log.write(this, "LOGOUT " + context.user.name, OK); // wait until running command was stopped if (command != null) { command.stop(); while (command != null) Performance.sleep(50); } context.delete(this); try { new Close().execute(context); socket.close(); if (events) { esocket.close(); // remove this session from all events in pool for (final Sessions s : context.events.values()) s.remove(this); } } catch (final Exception ex) { if (log != null) log.write(ex.getMessage()); Util.stack(ex); } }