001/**
002 *
003 * Copyright 2019-2020 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.c2s;
018
019import java.util.List;
020
021import javax.net.ssl.SSLSession;
022
023import org.jivesoftware.smack.SmackFuture;
024import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
025
026public abstract class XmppClientToServerTransport {
027
028    protected final ModularXmppClientToServerConnectionInternal connectionInternal;
029
030    protected XmppClientToServerTransport(ModularXmppClientToServerConnectionInternal connectionInternal) {
031        this.connectionInternal = connectionInternal;
032    }
033
034    protected abstract void resetDiscoveredConnectionEndpoints();
035
036    protected abstract List<SmackFuture<LookupConnectionEndpointsResult, Exception>> lookupConnectionEndpoints();
037
038    protected abstract void loadConnectionEndpoints(LookupConnectionEndpointsSuccess lookupConnectionEndpointsSuccess);
039
040    /**
041     * Notify the transport that new outgoing data is available. Usually this method does not need to be called
042     * explicitly, only if the filters are modified so that they potentially produced new data.
043     */
044    protected abstract void afterFiltersClosed();
045
046    /**
047     * Called by the CloseConnection state.
048     */
049    protected abstract void disconnect();
050
051    protected abstract void notifyAboutNewOutgoingElements();
052
053    public abstract SSLSession getSslSession();
054
055    public abstract boolean isConnected();
056
057    public boolean isTransportSecured() {
058        return getSslSession() != null;
059    }
060
061    public abstract Stats getStats();
062
063    public abstract static class Stats {
064    }
065
066    protected interface LookupConnectionEndpointsResult {
067    }
068
069    protected interface LookupConnectionEndpointsSuccess extends LookupConnectionEndpointsResult {
070    }
071
072    public interface LookupConnectionEndpointsFailed extends LookupConnectionEndpointsResult {
073        // TODO: Add something like getExceptions() or getConnectionExceptions()?
074    }
075
076}