Search in sources :

Example 21 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Openfire by igniterealtime.

the class ThrottleTestWriter method main.

/**
     * Starts the throttle test write client.
     *
     * @param args application arguments.
     */
public static void main(String[] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestWriter [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();
        con.login(username, password, "writer");
        System.out.print("success.");
        System.out.println("");
        // Get the "real" server address.
        server = con.getServiceName();
        String writerAddress = username + "@" + server + "/writer";
        final String readerAddress = username + "@" + server + "/reader";
        System.out.println("Registered as " + writerAddress);
        // Look for the reader process.
        System.out.print("Looking for " + readerAddress + "...");
        while (true) {
            IQ testIQ = new Time();
            testIQ.setType(IQ.Type.GET);
            testIQ.setTo(readerAddress);
            PacketCollector collector = con.createPacketCollector(new PacketIDFilter(testIQ.getPacketID()));
            con.sendPacket(testIQ);
            // Wait 5 seconds.
            long start = System.currentTimeMillis();
            Packet result = collector.nextResult(5000);
            collector.cancel();
            // If we got a result, continue.
            if (result != null && result.getError() == null) {
                System.out.println(" found reader. Starting packet flood.");
                break;
            }
            System.out.print(".");
            long end = System.currentTimeMillis();
            if (end - start < 5000) {
                try {
                    Thread.sleep(5000 - (end - start));
                } catch (Exception e) {
                // ignore.
                }
            }
        }
        // Create a process to log how many packets we're writing out.
        Runnable statsRunnable = new Runnable() {

            public void run() {
                while (!done) {
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                    /* ignore */
                    }
                    int count = packetCount.getAndSet(0);
                    System.out.println("Packets per second: " + (count / 5));
                }
            }
        };
        Thread statsThread = new Thread(statsRunnable);
        statsThread.setDaemon(true);
        statsThread.start();
        // Now start flooding packets.
        Message testMessage = new Message(readerAddress);
        testMessage.setBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        while (!done) {
            con.sendPacket(testMessage);
            packetCount.getAndIncrement();
        }
    } catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Time(org.jivesoftware.smackx.packet.Time) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 22 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class PEPManager method isSupported.

public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    BareJid localBareJid = connection.getUser().asBareJid();
    return serviceDiscoveryManager.supportsFeatures(localBareJid, REQUIRED_FEATURES);
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 23 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class MucBookmarkAutojoinManager method autojoinBookmarkedConferences.

public void autojoinBookmarkedConferences() {
    List<BookmarkedConference> bookmarkedConferences;
    try {
        bookmarkedConferences = bookmarkManager.getBookmarkedConferences();
    } catch (NotConnectedException | InterruptedException e) {
        LOGGER.log(Level.FINER, "Could not get MUC bookmarks", e);
        return;
    } catch (NoResponseException | XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not get MUC bookmarks", e);
        return;
    }
    final XMPPConnection connection = connection();
    Resourcepart defaultNick = connection.getUser().getResourcepart();
    for (BookmarkedConference bookmarkedConference : bookmarkedConferences) {
        if (!bookmarkedConference.isAutoJoin()) {
            continue;
        }
        Resourcepart nick = bookmarkedConference.getNickname();
        if (nick == null) {
            nick = defaultNick;
        }
        String password = bookmarkedConference.getPassword();
        MultiUserChat muc = multiUserChatManager.getMultiUserChat(bookmarkedConference.getJid());
        try {
            MucCreateConfigFormHandle handle = muc.createOrJoinIfNecessary(nick, password);
            if (handle != null) {
                handle.makeInstant();
            }
        } catch (NotConnectedException | InterruptedException e) {
            LOGGER.log(Level.FINER, "Could not autojoin bookmarked MUC", e);
            // abort here
            break;
        } catch (NotAMucServiceException | NoResponseException | XMPPErrorException e) {
            // Do no abort, just log,
            LOGGER.log(Level.WARNING, "Could not autojoin bookmarked MUC", e);
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)

Example 24 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class MamManager method queryMamPrefs.

private MamPrefsResult queryMamPrefs(MamPrefsIQ mamPrefsIQ) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow();
    return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ));
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 25 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class PushNotificationsManager method changePushNotificationsStatus.

private boolean changePushNotificationsStatus(IQ iq) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
    final XMPPConnection connection = connection();
    IQ responseIQ = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
    return responseIQ.getType() != Type.error;
}
Also used : DisablePushNotificationsIQ(org.jivesoftware.smackx.push_notifications.element.DisablePushNotificationsIQ) EnablePushNotificationsIQ(org.jivesoftware.smackx.push_notifications.element.EnablePushNotificationsIQ) IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Aggregations

XMPPConnection (org.jivesoftware.smack.XMPPConnection)64 XMPPException (org.jivesoftware.smack.XMPPException)14 Message (org.jivesoftware.smack.packet.Message)9 SmackException (org.jivesoftware.smack.SmackException)7 IQ (org.jivesoftware.smack.packet.IQ)7 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 SynchronousQueue (java.util.concurrent.SynchronousQueue)6 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 TimeoutException (java.util.concurrent.TimeoutException)5 StanzaCollector (org.jivesoftware.smack.StanzaCollector)5 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)4 ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)4 Packet (org.jivesoftware.smack.packet.Packet)4 Jid (org.jxmpp.jid.Jid)4