Search in sources :

Example 1 with IRCConnection

use of org.schwering.irc.lib.IRCConnection in project camel by apache.

the class IrcEndpoint method handleNickInUse.

private void handleNickInUse() {
    IRCConnection connection = component.getIRCConnection(configuration);
    String nick = connection.getNick() + "-";
    // hackish but working approach to prevent an endless loop. Abort after 4 nick attempts.
    if (nick.endsWith("----")) {
        LOG.error("Unable to set nick: " + nick + " disconnecting");
    } else {
        LOG.warn("Unable to set nick: " + nick + " Retrying with " + nick + "-");
        connection.doNick(nick);
        // if the nick failure was doing startup channels weren't joined. So join
        // the channels now. It's a no-op if the channels are already joined.
        joinChannels();
    }
}
Also used : IRCConnection(org.schwering.irc.lib.IRCConnection)

Example 2 with IRCConnection

use of org.schwering.irc.lib.IRCConnection in project camel by apache.

the class CodehausIrcChat method main.

public static void main(String[] args) throws InterruptedException {
    List<IrcChannel> channels = new ArrayList<IrcChannel>();
    channels.add(new IrcChannel("camel-test", null));
    final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-rc", "Camel IRC Component", channels);
    final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(), config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname());
    conn.addIRCEventListener(new CodehausIRCEventAdapter());
    conn.setEncoding("UTF-8");
    // conn.setDaemon(true);
    conn.setColors(false);
    conn.setPong(true);
    try {
        conn.connect();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // while (!conn.isConnected()) {
    // Thread.sleep(1000);
    // LOG.info("Sleeping");
    // }
    LOG.info("Connected");
    for (IrcChannel channel : config.getChannels()) {
        conn.doJoin(channel.getName());
    }
    conn.doPrivmsg("#camel-test", "hi!");
    Thread.sleep(Integer.MAX_VALUE);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IRCConnection(org.schwering.irc.lib.IRCConnection)

Example 3 with IRCConnection

use of org.schwering.irc.lib.IRCConnection in project camel by apache.

the class IrcComponent method createConnection.

protected IRCConnection createConnection(IrcConfiguration configuration) {
    IRCConnection conn = null;
    IRCEventListener ircLogger;
    if (configuration.getUsingSSL()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating SSL Connection to {} destination(s): {} nick: {} user: {}", new Object[] { configuration.getHostname(), configuration.getListOfChannels(), configuration.getNickname(), configuration.getUsername() });
        }
        if (configuration.getSslContextParameters() != null) {
            conn = new CamelSSLIRCConnection(configuration.getHostname(), configuration.getPorts(), configuration.getPassword(), configuration.getNickname(), configuration.getUsername(), configuration.getRealname(), configuration.getSslContextParameters(), getCamelContext());
        } else {
            SSLIRCConnection sconn = new SSLIRCConnection(configuration.getHostname(), configuration.getPorts(), configuration.getPassword(), configuration.getNickname(), configuration.getUsername(), configuration.getRealname());
            sconn.addTrustManager(configuration.getTrustManager());
            conn = sconn;
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating Connection to {} destination(s): {} nick: {} user: {}", new Object[] { configuration.getHostname(), configuration.getListOfChannels(), configuration.getNickname(), configuration.getUsername() });
        }
        conn = new IRCConnection(configuration.getHostname(), configuration.getPorts(), configuration.getPassword(), configuration.getNickname(), configuration.getUsername(), configuration.getRealname());
    }
    conn.setEncoding("UTF-8");
    conn.setColors(configuration.isColors());
    conn.setPong(true);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding IRC event logging listener");
        ircLogger = createIrcLogger(configuration.getHostname());
        conn.addIRCEventListener(ircLogger);
    }
    try {
        conn.connect();
    } catch (Exception e) {
        throw new RuntimeCamelException(e);
    }
    return conn;
}
Also used : IRCEventListener(org.schwering.irc.lib.IRCEventListener) SSLIRCConnection(org.schwering.irc.lib.ssl.SSLIRCConnection) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IRCConnection(org.schwering.irc.lib.IRCConnection) SSLIRCConnection(org.schwering.irc.lib.ssl.SSLIRCConnection) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 4 with IRCConnection

use of org.schwering.irc.lib.IRCConnection in project camel by apache.

the class IrcComponent method getIRCConnection.

public synchronized IRCConnection getIRCConnection(IrcConfiguration configuration) {
    final IRCConnection connection;
    if (connectionCache.containsKey(configuration.getCacheKey())) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Returning Cached Connection to {}:{}", configuration.getHostname(), configuration.getNickname());
        }
        connection = connectionCache.get(configuration.getCacheKey());
    } else {
        connection = createConnection(configuration);
        connectionCache.put(configuration.getCacheKey(), connection);
    }
    return connection;
}
Also used : IRCConnection(org.schwering.irc.lib.IRCConnection) SSLIRCConnection(org.schwering.irc.lib.ssl.SSLIRCConnection)

Example 5 with IRCConnection

use of org.schwering.irc.lib.IRCConnection in project camel by apache.

the class IrcEndpoint method joinChannel.

public void joinChannel(IrcChannel channel) {
    if (channel == null) {
        return;
    }
    IRCConnection connection = component.getIRCConnection(configuration);
    String chn = channel.getName();
    String key = channel.getKey();
    if (ObjectHelper.isNotEmpty(key)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Joining: {} using {} with secret key", channel, connection.getClass().getName());
        }
        connection.doJoin(chn, key);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Joining: {} using {}", channel, connection.getClass().getName());
        }
        connection.doJoin(chn);
    }
    if (configuration.isNamesOnJoin()) {
        connection.doNames(chn);
    }
}
Also used : IRCConnection(org.schwering.irc.lib.IRCConnection)

Aggregations

IRCConnection (org.schwering.irc.lib.IRCConnection)5 SSLIRCConnection (org.schwering.irc.lib.ssl.SSLIRCConnection)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 IRCEventListener (org.schwering.irc.lib.IRCEventListener)1