<commit_before>/**
 * Copyright (C) 2007-2008 Elastic Grid, LLC.
 *
 * Licensed under the GNU Lesser General Public License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.gnu.org/licenses/lgpl-3.0.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.elasticgrid.tools.cli.jabber;

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.rioproject.core.jsb.ServiceBeanContext;
import org.rioproject.event.DynamicEventConsumer;
import org.rioproject.event.RemoteServiceEvent;
import org.rioproject.event.RemoteServiceEventListener;
import org.rioproject.jsb.ServiceBeanAdapter;
import org.rioproject.resources.util.RioVersion;
import org.rioproject.sla.SLAThresholdEvent;
import org.rioproject.tools.cli.CLI;
import org.rioproject.tools.cli.OptionHandler;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.rmi.RemoteException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author <NAME>
 */
public class JabberCLIJSB extends ServiceBeanAdapter implements JabberCLI,
                                                                RemoteServiceEventListener {
    protected MultiUserChat chat;
    protected XMPPConnection jabberConnection;
    private String jabberUser;
    private String jabberDomain;
    private String jabberPassword;
    private String jabberChatroom;
    private DynamicEventConsumer consumer;
    private CLI cli;
    protected Logger logger = Logger.getLogger(getClass().getName());

    public void initialize(ServiceBeanContext context) throws Exception {
        super.initialize(context);
        jabberUser = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberUser", String.class
        );
        jabberDomain = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberDomain", String.class
        );
        jabberPassword = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberPassword", String.class
        );
        jabberChatroom = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberChatroom", String.class
        );
        try {
            logger.info("In init()");
            cli = CLI.getInstance();
            //CLI.initCLI(new String[] {});
            initializeJabberConnection();
            consumer =
                new DynamicEventConsumer(SLAThresholdEvent.getEventDescriptor(),
                                         this,
                                         context.getDiscoveryManagement());
        } catch (Throwable t) {
            logger.log(Level.WARNING, "Can't connect to Jabber server", t);
            t.printStackTrace();
        }
    }

    private void initializeJabberConnection() throws XMPPException {
        XMPPConnection.DEBUG_ENABLED = true;
        logger.info("Initialization of Jabber connection");
        ConnectionConfiguration connectionConfiguration =
            new ConnectionConfiguration(jabberDomain, 5223, jabberDomain);
        connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
        logger.info("Initiating Jabber connection");
        jabberConnection = new XMPPConnection(connectionConfiguration);
        logger.info("Logging in");
        jabberConnection.login(jabberUser, jabberPassword);

        // accept all buddies requesting to be added in the administrator roaster
        Roster roster = jabberConnection.getRoster();
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);

        // try to create a jabberChatroom, otherwise try to join it
        chat = new MultiUserChat(jabberConnection, jabberChatroom);
        try {<commit_msg>Change to support Rio modifications<commit_after>/**
 * Copyright (C) 2007-2008 Elastic Grid, LLC.
 *
 * Licensed under the GNU Lesser General Public License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.gnu.org/licenses/lgpl-3.0.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.elasticgrid.tools.cli.jabber;

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.rioproject.core.jsb.ServiceBeanContext;
import org.rioproject.event.DynamicEventConsumer;
import org.rioproject.event.RemoteServiceEvent;
import org.rioproject.event.RemoteServiceEventListener;
import org.rioproject.jsb.ServiceBeanAdapter;
import org.rioproject.resources.util.RioVersion;
import org.rioproject.sla.SLAThresholdEvent;
import org.rioproject.tools.cli.CLI;
import org.rioproject.tools.cli.OptionHandler;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.rmi.RemoteException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author <NAME>
 */
public class JabberCLIJSB extends ServiceBeanAdapter implements JabberCLI,
                                                                RemoteServiceEventListener {
    protected MultiUserChat chat;
    protected XMPPConnection jabberConnection;
    private String jabberUser;
    private String jabberDomain;
    private String jabberPassword;
    private String jabberChatroom;
    private DynamicEventConsumer consumer;
    private CLI cli;
    protected Logger logger = Logger.getLogger(getClass().getName());

    public void initialize(ServiceBeanContext context) throws Exception {
        super.initialize(context);
        jabberUser = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberUser", String.class
        );
        jabberDomain = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberDomain", String.class
        );
        jabberPassword = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberPassword", String.class
        );
        jabberChatroom = (String) context.getConfiguration().getEntry(
            "com.elasticgrid.tools.cli.jabber",
            "jabberChatroom", String.class
        );
        try {
            logger.info("In init()");
            cli = CLI.getInstance();
            initializeJabberConnection();
            consumer =
                new DynamicEventConsumer(SLAThresholdEvent.getEventDescriptor(),
                                         this,
                                         context.getDiscoveryManagement());
        } catch (Throwable t) {
            logger.log(Level.WARNING, "Can't connect to Jabber server", t);
            t.printStackTrace();
        }
    }

    private void initializeJabberConnection() throws XMPPException {
        XMPPConnection.DEBUG_ENABLED = true;
        logger.info("Initialization of Jabber connection");
        ConnectionConfiguration connectionConfiguration =
            new ConnectionConfiguration(jabberDomain, 5223, jabberDomain);
        connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
        logger.info("Initiating Jabber connection");
        jabberConnection = new XMPPConnection(connectionConfiguration);
        logger.info("Logging in");
        jabberConnection.login(jabberUser, jabberPassword);

        // accept all buddies requesting to be added in the administrator roaster
        Roster roster = jabberConnection.getRoster();
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);

        // try to create a jabberChatroom, otherwise try to join it
        chat = new MultiUserChat(jabberConnection, jabberChatroom);
        try {
{'fraction_non_alphanumeric': 0.08709960508995174, 'fraction_numerical': 0.0035103115401491883, 'mean_word_length': 3.064645563976817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6724183', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2363, 'n_words': 576}