- public boolean joinChannel(final String channel) {
- final SynchronousQueue<Boolean> result = new SynchronousQueue<Boolean>();
- Object eventHandler = new Object() {
-
- @Subscribe
- public void channelJoined(ChannelJoined channelJoined) throws InterruptedException {
- if (!channelJoined.channel().equalsIgnoreCase(channel)) {
- return;
- }
- Optional<String> nickname = channelJoined.client().nick();
- if (!nickname.isPresent() || (nickname.isPresent() && nickname().equalsIgnoreCase(nickname.get()))) {
- eventBus.unregister(this);
- result.put(true);
- }
- }
-
- @Subscribe
- public void channelNotJoined(ChannelNotJoined channelNotJoined) throws InterruptedException {
- if (!channelNotJoined.channel().equalsIgnoreCase(channel)) {
- return;
- }
- eventBus.unregister(this);
- result.put(false);
- }
- };
- eventBus.register(eventHandler);
- try {
- connectionHandler.sendCommand("JOIN", channel);
- return result.take();
- } catch (IOException ioe1) {
- eventBus.unregister(eventHandler);
- } catch (InterruptedException ie1) {
- /* TODO - how to handle? */
- }
- return false;
+ public void joinChannel(final String channel) throws IOException {
+ connectionHandler.sendCommand("JOIN", channel);