zmh-git / pircbotx

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

setAutoReconnect(boolean) #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to have a feature that allowed a PircBotX instance to 
automatically try to reconnect to all channels it was once connected to. 
Previously to do this I had to keep a List<String> of channels I was connected 
to at one point, then when I disconnect, I have to reconnect to the server and 
rejoin all of those channels. I don't know if it's really within the scope of 
the project to include such a feature, but it'd sure be sweet.

Original issue reported on code.google.com by imnothere199@gmail.com on 31 May 2012 at 4:04

GoogleCodeExporter commented 9 years ago
I think I could do two methods: setAutoReconnect and setAutoReconnectChannels. 
The reason for the seperation is that there are cases where auto joining all 
channels again.

Quick note: I'm fairly certain List<Channel> isn't the right way to do it 
because you'll interfere with the GC. There is a large spiderweb of references 
in PircBotX and if you hold on to just some of them (especially something like 
Channel), you'll prevent the whole thing from being GC'd.

Original comment by Lord.Qua...@gmail.com on 3 Jun 2012 at 4:51

GoogleCodeExporter commented 9 years ago
Fixed in Revision c0dceb8b0f47. Deployed snapshot as well, if you want to test 
it see http://code.google.com/p/pircbotx/wiki/DevVersion

The two new methods to use are setAutoReconnect and setAutoReconnectChannels. 

Original comment by Lord.Qua...@gmail.com on 3 Jun 2012 at 7:10

GoogleCodeExporter commented 9 years ago
Thanks Leon! One quick thing, I took a look at the diff, and saw that it will 
only try to reconnect once. In the event that it fails to reconnect the first 
time (say your internet disconnected, and you're waiting for the computer to 
re-obtain a connection), is there an event thrown or some way we can force it 
to continually try to reconnect? 

Original comment by imnothere199@gmail.com on 4 Jun 2012 at 2:18

GoogleCodeExporter commented 9 years ago
Hmm, didn't think about that. Maybe a ReconnectEvent with the status and 
information it tried to connect with? 

I'm nervous about adding a "continuously connect" option as if you fail to 
reconnect once there is usually something wrong. There is also no way to kill 
it besides trying to interrupt the random thread that its executing on. 

Will add later on today

Original comment by Lord.Qua...@gmail.com on 4 Jun 2012 at 4:20

GoogleCodeExporter commented 9 years ago
I think a ReconnectEvent would be a great way to go with this. Thanks for the 
quick update!

Original comment by imnothere199@gmail.com on 4 Jun 2012 at 4:30

GoogleCodeExporter commented 9 years ago
Sorry, I've been real busy. Fixed in Revision e96fa344d9a3

Original comment by Lord.Qua...@gmail.com on 6 Jul 2012 at 11:52

GoogleCodeExporter commented 9 years ago

Original comment by Lord.Qua...@gmail.com on 6 Jul 2012 at 11:53

GoogleCodeExporter commented 9 years ago
Has this been implemented as of version 2.0.1? I am not seeing 
ReconnectEvent.java in the compiled jar and am in the same boat as 
imnothere199. Occasionally the link to the IRC will die and as this is a 
critical bot for our server we want it to continuously reconnect until 
successful similar to the original PircBot.

Thanks!

Original comment by drcars...@gmail.com on 10 Mar 2014 at 3:42

GoogleCodeExporter commented 9 years ago
I changed the implementation in 2.0. Basically all you have to do is set 
setAutoReconnect to true in the configuration and call startBot. 

Now startBot will continuously reconnect until it encounters an exception. It 
will re-throw the exception so you can handle it, but if you don't care you can 
do something like

//somewhere else
stopReconnecting = falase;

while(!stopReconnecting)
try {
bot.startBot()
} catch(Exception e) {
log.error("Connection attempt failed", e);
}

Original comment by Lord.Qua...@gmail.com on 10 Mar 2014 at 3:49

GoogleCodeExporter commented 9 years ago
This worked perfectly. It is now happily looping in its own thread. I would 
still love an option in the builder to infinitely reconnect, but this is 
working swimmingly. Out of curiosity, is there a way to do this using the 
multibotmanager? Thats how i was running before, but now am not using it in 
order to implement this. 

Thanks for all your hard work!

Original comment by drcars...@gmail.com on 12 Mar 2014 at 6:35