Examples of RosterPacket


Examples of org.jivesoftware.smack.packet.RosterPacket

    public void addEntry(RosterEntry entry) throws XMPPException {
        PacketCollector collector = null;
        // Only add the entry if it isn't already in the list.
        synchronized (entries) {
            if (!entries.contains(entry)) {
                RosterPacket packet = new RosterPacket();
                packet.setType(IQ.Type.SET);
                RosterPacket.Item item = RosterEntry.toRosterItem(entry);
                item.addGroupName(getName());
                packet.addRosterItem(item);
                // Wait up to a certain number of seconds for a reply from the server.
                collector = connection
                        .createPacketCollector(new PacketIDFilter(packet.getPacketID()));
                connection.sendPacket(packet);
            }
        }
        if (collector != null) {
            IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

        // Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
        // to take place the entry will exist in the group until a packet is received from the
        // server.
        synchronized (entries) {
            if (entries.contains(entry)) {
                RosterPacket packet = new RosterPacket();
                packet.setType(IQ.Type.SET);
                RosterPacket.Item item = RosterEntry.toRosterItem(entry);
                item.removeGroupName(this.getName());
                packet.addRosterItem(item);
                // Wait up to a certain number of seconds for a reply from the server.
                collector = connection
                        .createPacketCollector(new PacketIDFilter(packet.getPacketID()));
                connection.sendPacket(packet);
            }
        }
        if (collector != null) {
            IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

        // Create a RosterEntry-copy with the new name to create an update-RosterPacket
        RosterEntry updatedRosterEntry = new RosterEntry(this.user, name,
      this.type, this.status, this.roster, this.connection);
        RosterPacket packet = new RosterPacket();
        packet.setType(IQ.Type.SET);
        packet.addRosterItem(toRosterItem(updatedRosterEntry));
        connection.sendPacket(packet);
    }
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

     */
    public static void removeAllRosterEntries(DummyConnection connection, Roster roster)
            throws InterruptedException, XMPPException {
        for(RosterEntry entry : roster.getEntries()) {
            // prepare the roster push packet
            final RosterPacket rosterPush= new RosterPacket();
            rosterPush.setType(Type.SET);
            rosterPush.setTo(connection.getUser());

            // prepare the buddy's item entry which should be removed
            final RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
            item.setItemType(ItemType.remove);
            rosterPush.addRosterItem(item);

            // simulate receiving the roster push
            connection.processPacket(rosterPush);
        }
    }
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

        roster.reload();
        while (true) {
            final Packet sentPacket = connection.getSentPacket();
            if (sentPacket instanceof RosterPacket && ((IQ) sentPacket).getType() == Type.GET) {
                // setup the roster get request
                final RosterPacket rosterRequest = (RosterPacket) sentPacket;
                assertSame("The <query/> element MUST NOT contain any <item/> child elements!",
                        0,
                        rosterRequest.getRosterItemCount());

                // prepare the roster result
                final RosterPacket rosterResult = new RosterPacket();
                rosterResult.setTo(connection.getUser());
                rosterResult.setType(Type.RESULT);
                rosterResult.setPacketID(rosterRequest.getPacketID());

                // prepare romeo's roster entry
                final Item romeo = new Item("romeo@example.net", "Romeo");
                romeo.addGroupName("Friends");
                romeo.setItemType(ItemType.both);
                rosterResult.addRosterItem(romeo);

                // prepare mercutio's roster entry
                final Item mercutio = new Item("mercutio@example.com", "Mercutio");
                mercutio.setItemType(ItemType.from);
                rosterResult.addRosterItem(mercutio);

                // prepare benvolio's roster entry
                final Item benvolio = new Item("benvolio@example.net", "Benvolio");
                benvolio.setItemType(ItemType.both);
                rosterResult.addRosterItem(benvolio);

                // simulate receiving the roster result and exit the loop
                connection.processPacket(rosterResult);
                break;
            }
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

        public void run() {
            try {
                while (true) {
                    final Packet packet = connection.getSentPacket();
                    if (packet instanceof RosterPacket && ((IQ) packet).getType() == Type.SET) {
                        final RosterPacket rosterRequest = (RosterPacket) packet;

                        // Prepare and process the roster push
                        final RosterPacket rosterPush = new RosterPacket();
                        final Item item = rosterRequest.getRosterItems().iterator().next();
                        if (item.getItemType() != ItemType.remove) {
                            item.setItemType(ItemType.none);
                        }
                        rosterPush.setType(Type.SET);
                        rosterPush.setTo(connection.getUser());
                        rosterPush.addRosterItem(item);
                        connection.processPacket(rosterPush);

                        // Create and process the IQ response
                        final IQ response = new IQ() {
                            public String getChildElementXML() {
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

        // TODO: what should we do when a processing failure occurs??
        e.printStackTrace();
      }
        }
        else if (packet instanceof RosterPacket) {
            RosterPacket rosterPacket = (RosterPacket) packet;
            if (log.isDebugEnabled()) {
                log.debug("Roster packet with : " + rosterPacket.getRosterItemCount() + " item(s)");
                Iterator rosterItems = rosterPacket.getRosterItems();
                while (rosterItems.hasNext()) {
                    Object item = rosterItems.next();
                    log.debug("Roster item: " + item);
                }
            }
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

    }

    public void removeUser(String email) {
        try {
            RosterPacket pack = new RosterPacket();
            pack.setType(IQ.Type.SET);
            RosterPacket.Item item = new RosterPacket.Item(email, email);
            item.setItemType(RosterPacket.ItemType.remove);
            pack.addRosterItem(item);
            connection.sendPacket(pack);
            roster.removeEntry(roster.getEntry(email));
        } catch (XMPPException e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

            // will be fired for each affected entry
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();

            RosterPacket rosterPacket = (RosterPacket) packet;
            for (RosterPacket.Item item : rosterPacket.getRosterItems()) {
                RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
                        item.getItemType(), item.getItemStatus(), connection);

                // If the packet is of the type REMOVE then remove the entry
                if (RosterPacket.ItemType.remove.equals(item.getItemType())) {
View Full Code Here

Examples of org.jivesoftware.smack.packet.RosterPacket

     * Reloads the entire roster from the server. This is an asynchronous operation,
     * which means the method will return immediately, and the roster will be
     * reloaded at a later point when the server responds to the reload request.
     */
    public void reload() {
        connection.sendPacket(new RosterPacket());
    }
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.