Examples of IRCConnection


Examples of org.schwering.irc.lib.IRCConnection

*/
public class CodehausIrcChat {
    public static void main(String[] args) throws InterruptedException {
        final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-irc", "Camel IRC Component", "#camel-test");

        final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(), config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname());

        conn.addIRCEventListener(new IRCEventAdapter() {

            @Override
            public void onRegistered() {
                super.onRegistered();
                System.out.println("onRegistered");
            }

            @Override
            public void onDisconnected() {
                super.onDisconnected();
                System.out.println("onDisconnected");
            }

            @Override
            public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser) {
                super.onMode(string, ircUser, ircModeParser);
                System.out.println("onMode.string = " + string);
                System.out.println("onMode.ircUser = " + ircUser);
                System.out.println("onMode.ircModeParser = " + ircModeParser);
            }

            @Override
            public void onMode(IRCUser ircUser, String string, String string1) {
                super.onMode(ircUser, string, string1);
                System.out.println("onMode.ircUser = " + ircUser);
                System.out.println("onMode.string = " + string);
                System.out.println("onMode.string1 = " + string1);
            }

            @Override
            public void onPing(String string) {
                super.onPing(string);
                System.out.println("onPing.string = " + string);
            }

            @Override
            public void onError(String string) {
                System.out.println("onError.string = " + string);
            }

            @Override
            public void onError(int i, String string) {
                super.onError(i, string);
                System.out.println("onError.i = " + i);
                System.out.println("onError.string = " + string);
            }

            @Override
            public void unknown(String string, String string1, String string2, String string3) {
                super.unknown(string, string1, string2, string3);
                System.out.println("unknown.string = " + string);
                System.out.println("unknown.string1 = " + string1);
                System.out.println("unknown.string2 = " + string2);
                System.out.println("unknown.string3 = " + string3);
            }
        });
        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);
//            System.out.println("Sleeping");
//        }
        System.out.println("Connected");
        //conn.send("/JOIN #camel-test");

        //System.out.println("Joining Channel: " + config.getTarget());
        conn.doJoin(config.getTarget());

        conn.doPrivmsg("#camel-test", "hi!");
        Thread.sleep(Integer.MAX_VALUE);
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

        setProperties(endpoint.getConfiguration(), parameters);
        return endpoint;
    }

    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());
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

        }
        return connection;
    }

    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()});
            }
            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;
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

            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();
        }
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

    public void joinChannel(String channel) {

        List<String> channels = configuration.getChannels();

        IRCConnection connection = component.getIRCConnection(configuration);

        // check for key for channel
        String key = configuration.getKey(channel);

        if (ObjectHelper.isNotEmpty(key)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Joining: {} using {} with key {}", new Object[]{channel, connection.getClass().getName(), key});
            }
            connection.doJoin(channel, key);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Joining: {} using {}", channel, connection.getClass().getName());
            }
            connection.doJoin(channel);
        }
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

        List<String> channels = new ArrayList<String>();
        channels.add("#camel-test");
        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);
        // System.out.println("Sleeping");
        // }
        System.out.println("Connected");
        // conn.send("/JOIN #camel-test");

        // System.out.println("Joining Channel: " + config.getTarget());

        for (String channel : config.getChannels()) {
            conn.doJoin(channel);
        }

        conn.doPrivmsg("#camel-test", "hi!");
        Thread.sleep(Integer.MAX_VALUE);
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

  }

  @Override
  public void open() throws IOException {
    // TODO (jon) check if the nick usage was successful or not
    conn = new IRCConnection(host, new int[] { port }, pass, nick, user, name);
    conn.addIRCEventListener(new Listener());
    conn.setEncoding(FlumeConfiguration.get().getFlurkerEncoding());
    conn.setPong(true);
    conn.setDaemon(false);
    conn.setColors(false);
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

    this(host, port, nick, null, null, null, chan, false);
  }

  public void open() throws IOException {

    conn = new IRCConnection(host, new int[] { port }, pass, nick, user, name);
    conn.addIRCEventListener(new Listener());
    conn.setEncoding("UTF-8");
    conn.setPong(true);
    conn.setDaemon(false);
    conn.setColors(false);
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

            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();
        }
    }
View Full Code Here

Examples of org.schwering.irc.lib.IRCConnection

    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);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.