1 package fi.vtt.simantics.procore.internal;
3 import org.simantics.db.MonitorContext;
4 import org.simantics.db.MonitorHandler;
5 import org.simantics.db.SessionVariables;
6 import org.simantics.db.service.SessionMonitorSupport;
8 public class SessionMonitorSupportImpl implements SessionMonitorSupport {
10 final private SessionImplSocket session;
12 SessionMonitorSupportImpl(SessionImplSocket session) {
13 this.session = session;
17 public synchronized MonitorContext registerMonitor(MonitorHandler h) {
20 MonitorContext ctx = new MonitorContext() {
22 public int getInteger(String key) {
23 if (SessionVariables.QUEUED_READS.equals(key)) {
24 return session.state.getReadCount();
25 } else if (SessionVariables.QUEUED_WRITES.equals(key)) {
26 return session.state.getWriteCount();
32 public String getString(String key) {
36 session.monitorContexts.map(ctx, h);
38 MonitorHandler[] newHandlers = new MonitorHandler[session.monitorHandlers.length + 1];
39 System.arraycopy(session.monitorHandlers, 0, newHandlers, 0, session.monitorHandlers.length);
40 newHandlers[session.monitorHandlers.length] = h;
41 session.monitorHandlers = newHandlers;
47 public synchronized void unregisterMonitor(MonitorContext ctx) {
48 MonitorHandler h = session.monitorContexts.getRight(ctx);
52 for (i = 0; i < session.monitorHandlers.length; i++) {
53 if (h.equals(session.monitorHandlers))
56 if (i < session.monitorHandlers.length) {
57 MonitorHandler[] newHandlers = new MonitorHandler[session.monitorHandlers.length - 1];
58 System.arraycopy(session.monitorHandlers, 0, newHandlers, 0, i);
59 System.arraycopy(session.monitorHandlers, i + 1, newHandlers, i, session.monitorHandlers.length - i - 1);