Author: bdonlan
Date: 2005-01-07 00:12:44 -0500 (Fri, 07 Jan 2005)
New Revision: 533
Modified:
/
trunk/misc/javer/src/javer/HaverClient.java
trunk/misc/javer/src/javer/JaverUIPanel.java
trunk/misc/javer/src/javer/SimpleTextTab.java
Log:
[EMAIL PROTECTED]: bdonlan | 2005-01-07T05:12:06.471194Z
Improved IOException handling
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local:11207
+ 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local:11211
Modified: trunk/misc/javer/src/javer/HaverClient.java
===================================================================
--- trunk/misc/javer/src/javer/HaverClient.java 2005-01-07 04:14:34 UTC (rev
532)
+++ trunk/misc/javer/src/javer/HaverClient.java 2005-01-07 05:12:44 UTC (rev
533)
@@ -75,10 +75,15 @@
String s = reader.readLine();
eventDebugMessage("<<< " + s);
synchronized (lock) {
+ if (reader == null)
+ return;
dispatchCommand(s);
}
} catch (java.io.IOException e) {
- return; /* XXX */
+ if (!eventIOException(e)) {
+ disconnect();
+ return;
+ }
}
}
}
@@ -116,24 +121,24 @@
}
});
serverevents.put("ACCEPT", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
eventIdentAccepted();
}
});
serverevents.put("MSG", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
String[] msgArgs = subStringArray(args, 4, args.length - 1);
eventMessage(args[1], args[2], args[3], msgArgs);
}
});
serverevents.put("PMSG", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
String[] msgArgs = subStringArray(args, 3, args.length - 1);
eventPrivateMessage(args[1], args[2], msgArgs);
}
});
serverevents.put("JOIN", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
if (args[2].equals(uid)) {
eventChannelJoin(args[1]);
} else {
@@ -142,7 +147,7 @@
}
});
serverevents.put("PART", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
if (args[2].equals(uid)) {
eventChannelPart(args[1]);
} else {
@@ -151,12 +156,12 @@
}
});
serverevents.put("QUIT", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
eventQuit(args[1], args[2]);
}
});
serverevents.put("LIST", new ServerHandler() {
- public void trigger(String[] args) {
+ public void trigger(String[] args) throws java.io.IOException {
Set s = new HashSet();
if (!args[2].equals("user")) {
/* we only know how to list for users right now */
@@ -174,13 +179,7 @@
String[] parts = s.split("\t");
ServerHandler h = (ServerHandler) serverevents.get(parts[0]);
if (h != null) {
- try {
- h.trigger(parts);
- } catch(IOException e) {
- /* we should probably do something here */
- } catch(Exception e) {
- /* and here */
- }
+ h.trigger(parts);
}
}
@@ -192,35 +191,35 @@
send("PART\t" + channel);
}
- public void eventIdentAccepted() {
+ protected void eventIdentAccepted() throws java.io.IOException {
/* STUB */
}
- public void eventDebugMessage(String s) {
+ protected void eventDebugMessage(String s) throws java.io.IOException {
/* STUB */
}
- public void eventChannelJoin(String where) {
+ protected void eventChannelJoin(String where) throws java.io.IOException {
/* STUB */
}
- public void eventChannelJoin(String where, String who) {
+ protected void eventChannelJoin(String where, String who) throws
java.io.IOException {
/* STUB */
}
- public void eventChannelPart(String where) {
+ protected void eventChannelPart(String where) throws java.io.IOException {
/* STUB */
}
- public void eventChannelPart(String where, String who) {
+ protected void eventChannelPart(String where, String who) throws
java.io.IOException {
/* STUB */
}
- public void eventQuit(String who, String why) {
+ protected void eventQuit(String who, String why) throws
java.io.IOException {
/* STUB */
}
- public void eventMessage(String where, String who, String type, String[]
args) {
+ protected void eventMessage(String where, String who, String type,
String[] args) throws java.io.IOException {
if (type.equals("\"")) {
eventNormalMessage(where, who, args[0]);
} else if (type.equals(":")) {
@@ -228,14 +227,14 @@
}
}
- public void eventNormalMessage(String where, String who, String arg) {
+ protected void eventNormalMessage(String where, String who, String arg)
throws java.io.IOException {
/* STUB */
}
- public void eventAction(String where, String who, String arg) {
+ protected void eventAction(String where, String who, String arg) throws
java.io.IOException {
/* STUB */
}
- public void eventPrivateMessage(String who, String type, String[] args) {
+ protected void eventPrivateMessage(String who, String type, String[] args)
throws java.io.IOException {
if (type.equals("\"")) {
eventPrivateNormalMessage(who, args[0]);
} else if (type.equals(":")) {
@@ -243,18 +242,18 @@
}
}
- public void eventPrivateNormalMessage(String who, String arg) {
+ protected void eventPrivateNormalMessage(String who, String arg) throws
java.io.IOException {
/* STUB */
}
- public void eventPrivateAction(String who, String arg) {
+ protected void eventPrivateAction(String who, String arg) throws
java.io.IOException {
/* STUB */
}
- public void eventChannelList(String where, Set names) {
+ protected void eventChannelList(String where, Set names) throws
java.io.IOException {
/* STUB */
}
- public final String[] subStringArray(String[] array, int start, int end) {
+ public static final String[] subStringArray(String[] array, int start, int
end) {
if (start > end) {
return new String[0];
}
@@ -305,7 +304,7 @@
sendPrivateMessage(target, ":", message);
}
- public void eventIdenting() {
+ protected void eventIdenting() throws java.io.IOException {
/* STUB */
}
@@ -314,12 +313,26 @@
}
public void disconnect() {
- try {
- sock.close();
- } catch(Exception e) {}
- sock = null;
- reader = null;
- writer = null;
- uid = null;
+ synchronized (lock) {
+ try {
+ sock.close();
+ } catch(Exception e) {}
+ sock = null;
+ reader = null;
+ writer = null;
+ uid = null;
+ }
}
+
+ /**
+ * Called when an I/O exception is detected internally, or caught from
+ * within an event handler.
+ *
+ *
+ * @param e
+ * @return true to remain connected; false to disconnect
+ */
+ protected boolean eventIOException(IOException e) {
+ return false;
+ }
}
Modified: trunk/misc/javer/src/javer/JaverUIPanel.java
===================================================================
--- trunk/misc/javer/src/javer/JaverUIPanel.java 2005-01-07 04:14:34 UTC
(rev 532)
+++ trunk/misc/javer/src/javer/JaverUIPanel.java 2005-01-07 05:12:44 UTC
(rev 533)
@@ -104,29 +104,29 @@
}
public class Client extends HaverClient {
- public void eventDebugMessage(String s) {
+ protected void eventDebugMessage(String s) throws java.io.IOException {
System.out.println(s);
super.eventDebugMessage(s);
}
- public void eventIdentAccepted() {
+ protected void eventIdentAccepted() throws java.io.IOException {
putServer("Logged in successfully.");
status.setText("Connected.");
super.eventIdentAccepted();
}
- public void eventIdenting() {
+ protected void eventIdenting() throws java.io.IOException {
putServer("Connected, logging in...");
super.eventIdenting();
}
- public void eventChannelPart(String where) {
+ protected void eventChannelPart(String where) throws
java.io.IOException {
killTab((TabPair)channelTabs.get(where));
channelTabs.remove(where);
super.eventChannelPart(where);
}
- public void eventChannelJoin(String where) {
+ protected void eventChannelJoin(String where) throws
java.io.IOException {
TabPair t = (TabPair) channelTabs.get(where);
if (t == null) {
t = new TabPair();
@@ -137,18 +137,16 @@
}
QueryTab qt = (QueryTab) t.tab;
qt.putText("--- Joined " + where);
- try {
- cli.listChannel(where);
- } catch (IOException e) { /* XXX */ }
+ cli.listChannel(where);
super.eventChannelJoin(where);
}
- public void eventMessage(String where, String who, String type,
String[] args) {
+ protected void eventMessage(String where, String who, String type,
String[] args) throws java.io.IOException {
super.eventMessage(where, who, type, args);
}
- public void eventChannelList(String where, Set names) {
+ protected void eventChannelList(String where, Set names) throws
java.io.IOException {
ChannelTab tab;
TabPair t = (TabPair) channelTabs.get(where);
if (t == null)
@@ -158,7 +156,7 @@
super.eventChannelList(where, names);
}
- public void eventQuit(String who, String why) {
+ protected void eventQuit(String who, String why) throws
java.io.IOException {
Iterator it = tabs.values().iterator();
while (it.hasNext()) {
ChannelTab tab;
@@ -175,7 +173,7 @@
super.eventQuit(who, why);
}
- public void eventNormalMessage(String where, String who, String arg) {
+ protected void eventNormalMessage(String where, String who, String
arg) throws java.io.IOException {
TextTab tab;
TabPair t = (TabPair) channelTabs.get(where);
if (t == null)
@@ -185,7 +183,7 @@
super.eventNormalMessage(where, who, arg);
}
- public void eventChannelPart(String where, String who) {
+ protected void eventChannelPart(String where, String who) throws
java.io.IOException {
ChannelTab tab;
TabPair t = (TabPair) channelTabs.get(where);
if (t == null)
@@ -196,7 +194,7 @@
super.eventChannelPart(where, who);
}
- public void eventChannelJoin(String where, String who) {
+ protected void eventChannelJoin(String where, String who) throws
java.io.IOException {
ChannelTab tab;
TabPair t = (TabPair) channelTabs.get(where);
if (t == null)
@@ -204,13 +202,11 @@
tab = (ChannelTab) t.tab;
tab.addUser(who);
tab.putText("--- " + who + " has joined.");
- try {
- listChannel(where);
- } catch (IOException e) { /* XXX */ }
+ listChannel(where);
super.eventChannelJoin(where, who);
}
- public void eventAction(String where, String who, String arg) {
+ protected void eventAction(String where, String who, String arg)
throws java.io.IOException {
TextTab tab;
TabPair t = (TabPair) channelTabs.get(where);
if (t == null)
@@ -220,23 +216,36 @@
super.eventAction(where, who, arg);
}
- public void eventPrivateMessage(String who, String type, String[]
args) {
+ protected void eventPrivateMessage(String who, String type, String[]
args) throws java.io.IOException {
super.eventPrivateMessage(who, type, args);
}
- public void eventPrivateNormalMessage(String who, String arg) {
+ protected void eventPrivateNormalMessage(String who, String arg)
throws java.io.IOException {
getQuery(who).putText("<" + who + "> " + arg);
super.eventPrivateNormalMessage(who, arg);
}
- public void eventPrivateAction(String who, String arg) {
+ protected void eventPrivateAction(String who, String arg) throws
java.io.IOException {
getQuery(who).putText("* " + who + " " + arg);
super.eventPrivateAction(who, arg);
}
+
+ protected boolean eventIOException(IOException e) {
+ putServer("I/O exception: " + e.getLocalizedMessage());
+ return false;
+ }
}
public void disconnect() {
+ Set pairs = new java.util.HashSet(tabs.values());
+ Iterator it = pairs.iterator();
+ while (it.hasNext()) {
+ TabPair p = (TabPair) it.next();
+ if (p != serverTabPair) {
+ killTab(p);
+ }
+ }
if (cli != null) {
cli.disconnect();
cli = null;
@@ -370,7 +379,7 @@
}
});
commands.put("msg", new CommandHandler() {
- boolean trigger(String arg) {
+ boolean trigger(String arg) throws IOException {
UserQueryTab tab;
String who, what;
int space = arg.indexOf(' ');
@@ -380,14 +389,12 @@
what = arg.substring(space + 1);
tab = getQuery(who);
- try {
- tab.sendText(what);
- } catch (IOException e) { /* XXX */ }
+ tab.sendText(what);
return true;
}
});
commands.put("act", new CommandHandler() {
- boolean trigger(String arg) {
+ boolean trigger(String arg) throws IOException {
UserQueryTab tab;
String who, what;
int space = arg.indexOf(' ');
@@ -397,14 +404,17 @@
what = arg.substring(space + 1);
tab = getQuery(who);
- try {
- tab.sendAction(what);
- } catch (IOException e) { /* XXX */ }
+ tab.sendAction(what);
return true;
}
});
commands.put("close", new CommandHandler() {
- boolean trigger(String arg) {
+ boolean trigger(String arg) throws IOException {
+ try {
+ ChannelTab q = (ChannelTab)
jTabbedPane1.getSelectedComponent();
+ cli.part(q.getChannel());
+ return true;
+ } catch (ClassCastException e) {}
killTab(jTabbedPane1.getSelectedComponent());
return true;
}
@@ -440,7 +450,10 @@
} catch (java.lang.ClassCastException ex) {
return false;
}
- } catch (IOException e) { /* XXX */ }
+ } catch (IOException e) {
+ cli.eventIOException(e);
+ disconnect();
+ }
return false;
}
Modified: trunk/misc/javer/src/javer/SimpleTextTab.java
===================================================================
--- trunk/misc/javer/src/javer/SimpleTextTab.java 2005-01-07 04:14:34 UTC
(rev 532)
+++ trunk/misc/javer/src/javer/SimpleTextTab.java 2005-01-07 05:12:44 UTC
(rev 533)
@@ -39,6 +39,11 @@
textField.setCaretPosition(textField.getText().length() - 1);
}
+ public void setText(String s) {
+ textField.setText(s);
+ textField.setCaretPosition(textField.getText().length() - 1);
+ }
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea textField;