diff options
Diffstat (limited to 'src/org/jogamp/jabot/irc/LogBot.java')
-rw-r--r-- | src/org/jogamp/jabot/irc/LogBot.java | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/org/jogamp/jabot/irc/LogBot.java b/src/org/jogamp/jabot/irc/LogBot.java index 3f76f61..80a6591 100644 --- a/src/org/jogamp/jabot/irc/LogBot.java +++ b/src/org/jogamp/jabot/irc/LogBot.java @@ -40,18 +40,20 @@ public class LogBot extends PircBot { private final Calendar calendar;
private final Object timeSync = new Object();
+ private final boolean reconnectOnDisconnect;
private final boolean xmlOut;
private final Object outSync = new Object();
private PrintStream out;
private int lineCount;
+ private long lastTS;
private Runnable postConnectAction;
- public LogBot(boolean showHostname, String joinMessage, boolean xmlOut) {
- this(showHostname, joinMessage, TimeTool.getNearZuluTimeZone(), Locale.getDefault(), System.out, xmlOut);
+ public LogBot(boolean showHostname, String joinMessage, boolean xmlOut, boolean reconnectOnDisconnect) {
+ this(showHostname, joinMessage, TimeTool.getNearZuluTimeZone(), Locale.getDefault(), System.out, xmlOut, reconnectOnDisconnect);
}
- public LogBot(boolean showHostname, String joinMessage, TimeZone timeZone, Locale locale, PrintStream out, boolean xmlOut) {
+ public LogBot(boolean showHostname, String joinMessage, TimeZone timeZone, Locale locale, PrintStream out, boolean xmlOut, boolean reconnectOnDisconnect) {
this.showHostname = showHostname;
this.calendar = new GregorianCalendar(timeZone, locale);
this.xmlOut = xmlOut;
@@ -59,6 +61,23 @@ public class LogBot extends PircBot { this.joinMessage = joinMessage;
this.lineCount = 0;
this.postConnectAction = null;
+ this.lastTS = System.currentTimeMillis();
+ this.reconnectOnDisconnect = reconnectOnDisconnect;
+ }
+
+ @Override
+ protected void handleLine(String line) {
+ lastTS = System.currentTimeMillis();
+ super.handleLine(line);
+ }
+
+ public void sendPing() {
+ this.sendRawLine("PING :" + getNick());
+ }
+
+ /** Returns the last timestamp as set by ctor or receiving a line from server. */
+ public final long getLastTS() {
+ return lastTS;
}
public final void setJoinMessage(String joinMessage) {
@@ -67,7 +86,7 @@ public class LogBot extends PircBot { public final String getJoinMessage() {
return joinMessage;
}
-
+
/**
* <p>
* Sets the internal login of the Bot. This should be set before joining
@@ -272,16 +291,18 @@ public class LogBot extends PircBot { @Override
public void onDisconnect() {
append(NAVY, "* Disconnected.");
- while (!isConnected()) {
- try {
- reconnect();
- }
- catch (Exception e) {
+ if( reconnectOnDisconnect ) {
+ while (!isConnected()) {
try {
- Thread.sleep(10000);
+ reconnect();
}
- catch (Exception anye) {
- // Do nothing.
+ catch (Exception e) {
+ try {
+ Thread.sleep(10000);
+ }
+ catch (Exception anye) {
+ // Do nothing.
+ }
}
}
}
|