TcpHostEvent.java

  1. /**
  2.  *
  3.  * Copyright 2019-2020 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.tcp;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.fsm.ConnectionStateEvent.DetailedTransitionIntoInformation;
  20. import org.jivesoftware.smack.fsm.State;
  21. import org.jivesoftware.smack.tcp.rce.Rfc6120TcpRemoteConnectionEndpoint;
  22. import org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint;

  23. public abstract class TcpHostEvent extends DetailedTransitionIntoInformation {
  24.     protected final RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address;

  25.     protected TcpHostEvent(State state, RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address) {
  26.         super(state);
  27.         this.address = address;
  28.     }

  29.     public RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> getAddress() {
  30.         return address;
  31.     }

  32.     @Override
  33.     public String toString() {
  34.         return super.toString() + ": " + address;
  35.     }

  36.     public static final class ConnectingToHostEvent extends TcpHostEvent {
  37.         ConnectingToHostEvent(State state,
  38.                         RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address) {
  39.             super(state, address);
  40.         }
  41.     }

  42.     public static final class ConnectedToHostEvent extends TcpHostEvent {
  43.         private final boolean connectionEstablishedImmediately;

  44.         ConnectedToHostEvent(State state, RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address, boolean immediately) {
  45.             super(state, address);
  46.             this.connectionEstablishedImmediately = immediately;
  47.         }

  48.         @Override
  49.         public String toString() {
  50.             return super.toString() + (connectionEstablishedImmediately ? "" : " not") + " connected immediately";
  51.         }
  52.     }

  53.     public static final class ConnectionToHostFailedEvent extends TcpHostEvent {
  54.         private final IOException ioException;

  55.         ConnectionToHostFailedEvent(State state,
  56.                         RemoteConnectionEndpoint.InetSocketAddressCoupling<Rfc6120TcpRemoteConnectionEndpoint> address,
  57.                         IOException ioException) {
  58.             super(state, address);
  59.             this.ioException = ioException;
  60.         }

  61.         @Override
  62.         public String toString() {
  63.             return super.toString() + ioException;
  64.         }
  65.     }
  66. }