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();
}
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations