zD12 / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Configuration.Builder and ListenerManager generics issue. #133

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attempt to override PircBotX in another class
2. Override the ListernerManager required with newly created function
3. Attempt to pass in the new ListenerManager into a Configuration.Builder

What is the expected output?
I expect the Configuration class to allow me to pass extensions of listener 
manager.

What do you see instead?
Compile errors are generated as the ListenerManager is forced to be PircBotX 
without extension.

What version of the product are you using? On what operating system?
Works in pircbotx-2.0-20130617.045513-62.jar
Doesn't work after that.

Please provide any additional information below.

Original issue reported on code.google.com by Jamie.Re...@gmail.com on 19 Jun 2013 at 3:34

GoogleCodeExporter commented 9 years ago
Sorry about that, the generics changes were implemented over many days and I 
didn't always test everything. Fixed in the latest snapshot:

class MyCustomBot extends PircBotX {
    public MyCustomBot(Configuration<? extends PircBotX> configuration) {
        super(configuration);
    }
}

class MyCustomListenerManager extends ThreadedListenerManager<MyCustomBot> {

}

public class Sandbox {
    void run() {
        //Compiles!
        Configuration<PircBotX> config = new Configuration.Builder<PircBotX>()
                .setListenerManager(new MyCustomListenerManager())
                .buildConfiguration();
    }
}

Original comment by Lord.Qua...@gmail.com on 26 Jun 2013 at 12:54

GoogleCodeExporter commented 9 years ago
Thanks seems to work perfectly apart from getConfiguration().getistenerManager()

That still seems to be storing and returning a copy of the PircBotX version of 
Configuration and subsequently the ListenerManager.

I can easily work around this by keeping my own reference to my extended 
ListenerManager.

Thanks again.

Original comment by Jamie.Re...@gmail.com on 27 Jun 2013 at 7:09

GoogleCodeExporter commented 9 years ago
Both Configuration<B> and Configuration.Builder<B> return ListenerManager<B>. 
Using Configuration<PircBotX> above was only an example to prove that it would 
compile since it takes an extended type. 

You probably are wanting to use Configuration<MyCustomBot>

Original comment by Lord.Qua...@gmail.com on 27 Jun 2013 at 9:14

GoogleCodeExporter commented 9 years ago
Exact code is:
ThreadedListenerManager<IrcBot> lm  = new ThreadedListenerManager<IrcBot>();

       Configuration<IrcBot> configuration =  new Configuration.Builder<IrcBot>()
                   .setName(nick) //Set the nick of the bot.
                   .setLogin(ident) //login part of hostmask, eg name:login@host
                   .setAutoNickChange(true) //Automatically change nick
                   .setVersion(VERSION)
                   .setCapEnabled(true) //Enable CAP features
                   .setFinger(FINGER_MSG)
                   .setAutoReconnect(true)
                   .setIdentServerEnabled(useident)
                   .setServerPort(port)
                   .setServerHostname(addr)
                   .setMessageDelay(1)
                   .setNickservPassword(password)
                   .setListenerManager(lm)
                   // TODO: 
                   //.setLocalAddress(local)
                   .setSocketTimeout(SOCKET_TIMEOUT)
               .buildConfiguration();

       newbot = new IrcBot(configuration);

and

bot.getConfiguration().getListenerManager().addListener(listener);

returns an error as it is receiving Configuration<PircBotX> which in turn 
forces it to return a ListenerManager<PircBotX>.

Original comment by Jamie.Re...@gmail.com on 27 Jun 2013 at 9:21

GoogleCodeExporter commented 9 years ago
On another note, providing any argument to .setLocalAddress() produces a null 
socket but I'm fairly sure this isn't related to your code.

Original comment by Jamie.Re...@gmail.com on 27 Jun 2013 at 9:22

GoogleCodeExporter commented 9 years ago
This is because your getting the configuration after the fact which always 
returns Configuration<PircBotX>. There was no other clean way to return the 
subclass so thats the signature I was stuck with

However listenerExists, addListener, and removeListener don't really care about 
the generic type, so I removed them in Revision 13a5ccb05a94

Original comment by Lord.Qua...@gmail.com on 27 Jun 2013 at 3:09

GoogleCodeExporter commented 9 years ago
Fantastic, I'll give it a try shortly.

I really appreciate your hard work, quick responses and more than anything the 
vast improvement you've made on PircBot.

Original comment by Jamie.Re...@gmail.com on 27 Jun 2013 at 3:12

GoogleCodeExporter commented 9 years ago
Always happy to help :-)

With setLocalAddress I'm not sure what could be causing the problem. Its usage 
is pretty basic ( 
https://code.google.com/p/pircbotx/source/browse/src/main/java/org/pircbotx/Pirc
BotX.java#181 ) and some quick tests with InetAddress.getLocalAddress() (can't 
connect) and InetAddress.getByName("192.168.0.X") (working) show expected 
results. My only guess is an exception is being swallowed somewhere, but its 
not in PircBotX

Original comment by Lord.Qua...@gmail.com on 27 Jun 2013 at 3:25