@Override public void sendStanza(Stanza packet) throws NotConnectedException { Objects.requireNonNull(packet, "Packet must not be null"); throwNotConnectedExceptionIfAppropriate(); switch (fromMode) { case OMITTED: packet.setFrom(null); break; case USER: packet.setFrom(getUser()); break; case UNCHANGED: default: break; } // Invoke interceptors for the new packet that is about to be sent. Interceptors may modify // the content of the packet. firePacketInterceptors(packet); sendStanzaInternal(packet); }
public static synchronized AndroidSmackManager getInstance(Context context) { Objects.requireNonNull(context, "Context argument must not be null"); if (INSTANCE == null) { INSTANCE = new AndroidSmackManager(context); } return INSTANCE; }
/** * Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222 * * @param fqdn Fully qualified domain name. * @param port The port to connect on. * @throws IllegalArgumentException If the fqdn is null or port is out of valid range (0 - 65535). */ public HostAddress(String fqdn, int port) { Objects.requireNonNull(fqdn, "FQDN is null"); if (port < 0 || port > 65535) throw new IllegalArgumentException( "Port must be a 16-bit unsiged integer (i.e. between 0-65535. Port was: " + port); if (fqdn.charAt(fqdn.length() - 1) == '.') { this.fqdn = fqdn.substring(0, fqdn.length() - 1); } else { this.fqdn = fqdn; } this.port = port; }
/** * Creates an filter using the specified filters. * * @param filters the filters to add. */ protected AbstractListFilter(StanzaFilter... filters) { Objects.requireNonNull(filters, "Parameter must not be null."); for(StanzaFilter filter : filters) { Objects.requireNonNull(filter, "Parameter must not be null."); } this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters)); }
/** * Sets the default identity the client will report. * * @param identity */ public synchronized void setIdentity(Identity identity) { this.identity = Objects.requireNonNull(identity, "Identity can not be null"); // Notify others of a state change of SDM. In order to keep the state consistent, this // method is synchronized renewEntityCapsVersion(); }
public AuthMechanism(String mechanism, String authenticationText) { this.mechanism = Objects.requireNonNull(mechanism, "SASL mechanism shouldn't be null."); this.authenticationText = StringUtils.requireNotNullOrEmpty(authenticationText, "SASL authenticationText must not be null or empty (RFC6120 6.4.2)"); }
@Override public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter, final StanzaListener callback, final ExceptionCallback exceptionCallback, long timeout) throws NotConnectedException { Objects.requireNonNull(stanza, "stanza must not be null"); // While Smack allows to add PacketListeners with a PacketFilter value of 'null', we // disallow it here in the async API as it makes no sense Objects.requireNonNull(replyFilter, "replyFilter must not be null"); Objects.requireNonNull(callback, "callback must not be null"); final StanzaListener packetListener = new StanzaListener() { @Override public void processPacket(Stanza packet) throws NotConnectedException { try { XMPPErrorException.ifHasErrorThenThrow(packet); callback.processPacket(packet); } catch (XMPPErrorException e) { if (exceptionCallback != null) { exceptionCallback.processException(e); } } finally { removeAsyncStanzaListener(this); } } }; removeCallbacksService.schedule(new Runnable() { @Override public void run() { boolean removed = removeAsyncStanzaListener(packetListener); // If the packetListener got removed, then it was never run and // we never received a response, inform the exception callback if (removed && exceptionCallback != null) { exceptionCallback.processException(NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter)); } } }, timeout, TimeUnit.MILLISECONDS); addAsyncStanzaListener(packetListener, replyFilter); sendStanza(stanza); }
public Manager(XMPPConnection connection) { Objects.requireNonNull(connection, "XMPPConnection must not be null"); weakConnection = new WeakReference<XMPPConnection>(connection); }
public static void setEncoder(Base64.Encoder encoder) { Objects.requireNonNull(encoder, "encoder must no be null"); base64encoder = encoder; }
public static void setEncoder(StringEncoder encoder) { Objects.requireNonNull(encoder, "encoder must no be null"); base64UrlSafeEncoder = encoder; }
public FlexibleStanzaTypeFilter(Class<S> packetType) { this.stanzaType = Objects.requireNonNull(packetType, "Type must not be null"); }
private IQTypeFilter(IQ.Type type) { super(IQ.class); this.type = Objects.requireNonNull(type, "Type must not be null"); }
private PresenceTypeFilter(Presence.Type type) { super(Presence.class); this.type = Objects.requireNonNull(type, "type must not be null"); }
/** * Constructs a new error IQ. * <p> * According to RFC 6120 § 8.3.1 "4. An error stanza MUST contain an <error/> child element.", so the xmppError argument is mandatory. * </p> * @param xmppError the XMPPError (required). */ public ErrorIQ(XMPPError xmppError) { super(ELEMENT, null); Objects.requireNonNull(xmppError, "XMPPError must not be null"); setType(IQ.Type.error); setError(xmppError); }
/** * Add a roster listener and invoke the roster entries with all entries of the roster. * <p> * The method guarantees that the listener is only invoked after * {@link RosterEntries#rosterEntires(Collection)} has been invoked, and that all roster events * that happen while <code>rosterEntires(Collection) </code> is called are queued until the * method returns. * </p> * <p> * This guarantee makes this the ideal method to e.g. populate a UI element with the roster while * installing a {@link RosterListener} to listen for subsequent roster events. * </p> * * @param rosterListener the listener to install * @param rosterEntries the roster entries callback interface * @since 4.1 */ public void getEntriesAndAddListener(RosterListener rosterListener, RosterEntries rosterEntries) { Objects.requireNonNull(rosterListener, "listener must not be null"); Objects.requireNonNull(rosterEntries, "rosterEntries must not be null"); synchronized (rosterListenersAndEntriesLock) { rosterEntries.rosterEntires(entries.values()); addRosterListener(rosterListener); } }
/** * Sets the type of the presence packet. * * @param type the type of the presence packet. */ public void setType(Type type) { this.type = Objects.requireNonNull(type, "Type cannot be null"); }
/** * Sets the type of the IQ packet. * <p> * Since the type of an IQ must present, an IllegalArgmentException will be thrown when type is * <code>null</code>. * </p> * * @param type the type of the IQ packet. */ public void setType(Type type) { this.type = Objects.requireNonNull(type, "type must not be null"); }
/** * Adds a filter to the filter list. A stanza will pass the filter if all of the filters in the * list accept it. * * @param filter a filter to add to the filter list. */ public void addFilter(StanzaFilter filter) { Objects.requireNonNull(filter, "Parameter must not be null."); filters.add(filter); }
/** * Creates a NOT filter using the specified filter. * * @param filter the filter. */ public NotFilter(StanzaFilter filter) { this.filter = Objects.requireNonNull(filter, "Parameter must not be null."); }