/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.tridium.util.ThrowableUtil * javax.baja.log.Log * javax.baja.nre.util.IntHashMap * javax.baja.nre.util.SortUtil * javax.baja.spy.Spy * javax.baja.spy.SpyDir * javax.baja.spy.SpyWriter * javax.baja.sys.BRelTime * javax.baja.sys.Clock * javax.baja.sys.Sys */ package com.tridium.fox.sys.spy; import com.tridium.fox.message.FoxMessage; import com.tridium.fox.session.Fox; import com.tridium.fox.session.FoxSession; import com.tridium.util.ThrowableUtil; import java.io.Writer; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import javax.baja.log.Log; import javax.baja.nre.util.IntHashMap; import javax.baja.nre.util.SortUtil; import javax.baja.spy.Spy; import javax.baja.spy.SpyDir; import javax.baja.spy.SpyWriter; import javax.baja.sys.BRelTime; import javax.baja.sys.Clock; import javax.baja.sys.Sys; public class FoxLog { static int nextWhoId = 0; static final int SERVER = 1; static final int ERROR = 3; static final int WARNING = 2; static final int MESSAGE = 1; static final int TRACE = 0; static final int OPENED = 10; static final int CLOSED = 11; static final int REJECTED = 12; static DateFormat format = new SimpleDateFormat("HH:mm:ss dd-MMM-yy z"); static Object lock = new Object(); static final int max; static int size; static Rec head; static Rec tail; static HashMap whoHistory; Log log; String logName; FoxSession session; public static FoxLog make(String string) { return new FoxLog(Log.getLog((String)string)); } public Log log() { return this.log; } public String getLogName() { return this.logName; } public boolean isTraceOn() { return this.log.isTraceOn(); } public void error(String string) { this.log(3, string, null); } public void error(String string, Throwable throwable) { this.log(3, string, throwable); } public void warning(String string) { this.log(2, string, null); } public void warning(String string, Throwable throwable) { this.log(2, string, throwable); } public void message(String string) { this.log(1, string, null); } public void message(String string, Throwable throwable) { this.log(1, string, throwable); } public void trace(String string) { this.log(0, string, null); } public void trace(String string, Throwable throwable) { this.log(0, string, throwable); } public void log(int n, String string, Throwable throwable) { if (this.log.isLoggable(n)) { this.log.log(n, string, throwable); FoxLog.add(new Rec(n, this.session, this.logName, string, throwable)); } } public void logRecOnly(int n, String string) { if (this.log.isLoggable(n)) { FoxLog.add(new Rec(n, this.session, this.logName, string, null)); } } public FoxSession session() { return this.session; } public void setSession(FoxSession foxSession) { this.session = foxSession; } /* * WARNING - Removed try catching itself - possible behaviour change. * Enabled aggressive block sorting * Enabled unnecessary exception pruning * Enabled aggressive exception aggregation */ public void opened(FoxSession foxSession) { this.session = foxSession; String string = "Opened: " + FoxLog.toString(foxSession); if (!FoxLog.stationToStationConnection(foxSession)) { this.log.message(string); } else if (this.log.isTraceOn()) { this.log.trace(string); } FoxLog.add(new Rec(10, foxSession, this.logName, string, null)); String string2 = FoxLog.toWho(foxSession); Object object = lock; synchronized (object) { Who who = (Who)whoHistory.get(string2); if (who == null) { who = new Who(string2); whoHistory.put(string2, who); } who.opened(foxSession); return; } } /* * WARNING - Removed try catching itself - possible behaviour change. * Enabled aggressive block sorting * Enabled unnecessary exception pruning * Enabled aggressive exception aggregation */ public void closed(FoxSession foxSession, Throwable throwable) { block10: { String string; int n; if (this.session == foxSession) { n = 11; string = "Closed: " + FoxLog.toString(foxSession); } else { n = 12; string = "Rejected: " + FoxLog.toString(foxSession); } if (!FoxLog.stationToStationConnection(foxSession)) { this.log.message(string); } else if (this.log.isTraceOn()) { this.log.trace(string); } FoxLog.add(new Rec(n, foxSession, this.logName, string, throwable)); String string2 = FoxLog.toWho(foxSession); Object object = lock; synchronized (object) { Who who; block9: { who = (Who)whoHistory.get(string2); if (who == null) { who = new Who(string2); whoHistory.put(string2, who); } if (n != 11) break block9; who.closed(foxSession); break block10; } who.rejected(foxSession); } } this.session = null; } public static String toWho(FoxSession foxSession) { if (foxSession == null) { return "null"; } try { String string; FoxMessage foxMessage = foxSession.getRemoteHello(); if (foxMessage == null) { foxMessage = new FoxMessage(); try { string = foxSession.getSocket().getInetAddress().toString(); } catch (NullPointerException nullPointerException) { string = "unknown"; } } else { string = foxMessage.getString("hostName", "unknown"); } String string2 = foxMessage.getString("app.name", "unknown"); String string3 = foxMessage.getString("station.name", null); String string4 = foxMessage.getString("user", null); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(string2); if (string3 != null) { stringBuffer.append(" [").append(string3).append("]"); } else if (string4 != null) { stringBuffer.append(" [").append(string4).append("]"); } stringBuffer.append(" @ ").append(string); return stringBuffer.toString(); } catch (Exception exception) { exception.printStackTrace(); return "err"; } } public static String toString(FoxSession foxSession) { if (foxSession == null) { return "null"; } StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(foxSession.getId()); stringBuffer.append(foxSession.isServer() ? " <- " : " -> "); stringBuffer.append(foxSession.getRemoteId()); stringBuffer.append(" :: "); stringBuffer.append(FoxLog.toWho(foxSession)); return stringBuffer.toString(); } static String toTime(long l) { if (l <= 0L) { return "null"; } return format.format(new Date(Clock.millis() - Clock.ticks() + l)); } static String toAge(long l) { return BRelTime.toString((long)(Clock.ticks() - l)); } static String toDuration(long l) { return BRelTime.toString((long)l); } static boolean stationToStationConnection(FoxSession foxSession) { try { String string = foxSession.getRemoteHello().getString("app.name", ""); boolean bl = false; if (string.equals("Station") && string.equals(Fox.appName)) { bl = true; } return bl; } catch (Exception exception) { return false; } } static void header(SpyWriter spyWriter) { spyWriter.w((Object)"\n"); spyWriter.w((Object)Fox.appName).w((Object)" ").w((Object)Fox.appVersion); if (Sys.getStation() != null) { spyWriter.w((Object)(" [" + Sys.getStation().getStationName() + ']')); } spyWriter.w((Object)(" | " + FoxLog.toTime(Clock.ticks()))); spyWriter.w((Object)" | Log Index"); spyWriter.w((Object)(" | All Records [" + size + "]")); spyWriter.w((Object)"
");
ThrowableUtil.dump((Writer)spyWriter, (Throwable)this.ex);
spyWriter.w((Object)"");
}
}
Rec(int n, FoxSession foxSession, String string, String string2, Throwable throwable) {
this.type = n;
this.sessionId = foxSession == null ? -1 : foxSession.getId();
this.logName = string;
this.msg = string2;
this.ex = throwable;
}
}
static class Who {
int id = nextWhoId++;
String key;
int[] sessionIds;
int[] remoteIds;
long[] openTicks;
long[] closeTicks;
byte[] flags;
void opened(FoxSession foxSession) {
System.arraycopy(this.sessionIds, 0, this.sessionIds, 1, this.sessionIds.length - 1);
System.arraycopy(this.remoteIds, 0, this.remoteIds, 1, this.remoteIds.length - 1);
System.arraycopy(this.openTicks, 0, this.openTicks, 1, this.openTicks.length - 1);
System.arraycopy(this.closeTicks, 0, this.closeTicks, 1, this.closeTicks.length - 1);
System.arraycopy(this.flags, 0, this.flags, 1, this.flags.length - 1);
this.sessionIds[0] = foxSession.getId();
this.remoteIds[0] = foxSession.getRemoteId();
this.openTicks[0] = Clock.ticks();
this.closeTicks[0] = -1;
this.flags[0] = (byte)(foxSession.isServer() ? 1 : 0);
}
void closed(FoxSession foxSession) {
int n = foxSession.getId();
int n2 = 0;
while (n2 < this.sessionIds.length) {
if (this.sessionIds[n2] == n) {
this.closeTicks[n2] = Clock.ticks();
break;
}
++n2;
}
}
void rejected(FoxSession foxSession) {
this.opened(foxSession);
this.closeTicks[0] = Long.MAX_VALUE;
}
IntHashMap sessionsToIntHashMap() {
IntHashMap intHashMap = new IntHashMap();
int n = 0;
while (n < this.sessionIds.length) {
int n2 = this.sessionIds[n];
if (n2 >= 0) {
intHashMap.put(n2, (Object)this);
}
++n;
}
return intHashMap;
}
public String toString() {
return this.key;
}
Who(String string) {
this.key = string;
this.sessionIds = new int[20];
this.remoteIds = new int[20];
this.openTicks = new long[20];
this.closeTicks = new long[20];
this.flags = new byte[20];
int n = 0;
while (n < 20) {
this.sessionIds[n] = -1;
++n;
}
}
}
static class SpyRecs
extends SpyDir {
String title;
IntHashMap sessions;
public Spy find(String string) {
return FoxLog.findRec(Integer.parseInt(string));
}
public void write(SpyWriter spyWriter) throws Exception {
FoxLog.header(spyWriter);
spyWriter.startTable(true);
spyWriter.trTitle((Object)this.title, 6);
spyWriter.w((Object)"