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.tcp;
018
019import java.io.IOException;
020
021import org.jivesoftware.smack.fsm.ConnectionStateEvent.DetailedTransitionIntoInformation;
022import org.jivesoftware.smack.fsm.State;
023import org.jivesoftware.smack.tcp.rce.Rfc6120TcpRemoteConnectionEndpoint;
024import org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint;
025
026public abstract class TcpHostEvent extends DetailedTransitionIntoInformation {
027    protected final RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address;
028
029    protected TcpHostEvent(State state, RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address) {
030        super(state);
031        this.address = address;
032    }
033
034    public RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> getAddress() {
035        return address;
036    }
037
038    @Override
039    public String toString() {
040        return super.toString() + ": " + address;
041    }
042
043    public static final class ConnectingToHostEvent extends TcpHostEvent {
044        ConnectingToHostEvent(State state,
045                        RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address) {
046            super(state, address);
047        }
048    }
049
050    public static final class ConnectedToHostEvent extends TcpHostEvent {
051        private final boolean connectionEstablishedImmediately;
052
053        ConnectedToHostEvent(State state, RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address, boolean immediately) {
054            super(state, address);
055            this.connectionEstablishedImmediately = immediately;
056        }
057
058        @Override
059        public String toString() {
060            return super.toString() + (connectionEstablishedImmediately ? "" : " not") + " connected immediately";
061        }
062    }
063
064    public static final class ConnectionToHostFailedEvent extends TcpHostEvent {
065        private final IOException ioException;
066
067        ConnectionToHostFailedEvent(State state,
068                        RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address,
069                        IOException ioException) {
070            super(state, address);
071            this.ioException = ioException;
072        }
073
074        @Override
075        public String toString() {
076            return super.toString() + ioException;
077        }
078    }
079}