continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r574243 - /maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
Date Mon, 10 Sep 2007 13:20:38 GMT
Author: evenisse
Date: Mon Sep 10 06:20:38 2007
New Revision: 574243

URL: http://svn.apache.org/viewvc?rev=574243&view=rev
Log:
Use alternate nick if nick is already used.

Modified:
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java?rev=574243&r1=574242&r2=574243&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
Mon Sep 10 06:20:38 2007
@@ -79,7 +79,7 @@
     private int defaultPort;
 
     /**
-     * key is upper(hostname) + port + upper(nick)
+     * key is upper(hostname) + port + upper(nick) + upper(alternateNick)
      */
     private Map<String, IRCConnection> hostConnections = new HashMap<String, IRCConnection>();
 
@@ -112,7 +112,7 @@
                                            String userName, String realName, String channel,
boolean ssl )
         throws IOException
     {
-        String key = host.toUpperCase() + Integer.toString( port ) + nick.toUpperCase();
+        String key = getConnectionKey( host, port, nick, alternateNick );
         IRCConnection conn = hostConnections.get( key );
         if ( conn != null )
         {
@@ -130,13 +130,18 @@
             ( (SSLIRCConnection) conn ).addTrustManager( new SSLDefaultTrustManager() );
         }
 
-        conn.addIRCEventListener( new Listener() );
+        conn.addIRCEventListener( new Listener( conn, nick, alternateNick ) );
         checkConnection( conn, key );
         checkChannel( conn, key, channel );
         hostConnections.put( key, conn );
         return conn;
     }
 
+    private String getConnectionKey( String host, int port, String nick, String alternateNick
)
+    {
+        return host.toUpperCase() + Integer.toString( port ) + nick.toUpperCase() + alternateNick.toUpperCase();
+    }
+
     private void checkConnection( IRCConnection conn, String key )
         throws IOException
     {
@@ -398,6 +403,18 @@
     class Listener
         implements IRCEventListener
     {
+        private String nick;
+
+        private String alternateNick;
+
+        private IRCConnection conn;
+
+        public Listener( IRCConnection conn, String nick, String alternateNick )
+        {
+            this.conn = conn;
+            this.nick = nick;
+            this.alternateNick = alternateNick;
+        }
 
         public void onRegistered()
         {
@@ -417,6 +434,29 @@
         public void onError( int num, String msg )
         {
             getLogger().error( "Error #" + num + ": " + msg );
+            if ( num == 433 )
+            {
+                if ( alternateNick != null )
+                {
+                    getLogger().info( "reconnection with alternate nick: '" + alternateNick
+ "'" );
+                    try
+                    {
+                        boolean ssl = false;
+                        if ( conn instanceof SSLIRCConnection )
+                        {
+                            ssl = true;
+                        }
+                        String key = getConnectionKey( conn.getHost(), conn.getPort(), nick,
alternateNick );
+                        conn = getIRConnection( conn.getHost(), conn.getPort(), conn.getPassword(),
alternateNick, null,
+                                                conn.getUsername(), conn.getRealname(), "#foo",
ssl );
+                        hostConnections.put( key, conn );
+                    }
+                    catch ( IOException e )
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            }
         }
 
         public void onInvite( String chan, IRCUser u, String nickPass )



Mime
View raw message