StreamManagementException.java

  1. /**
  2.  *
  3.  * Copyright © 2014 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.sm;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.jivesoftware.smack.SmackException;
  21. import org.jivesoftware.smack.packet.Stanza;

  22. public abstract class StreamManagementException extends SmackException {

  23.     public StreamManagementException() {
  24.     }

  25.     public StreamManagementException(String message) {
  26.         super(message);
  27.     }

  28.     /**
  29.      *
  30.      */
  31.     private static final long serialVersionUID = 3767590115788821101L;

  32.     public static class StreamManagementNotEnabledException extends StreamManagementException {

  33.         /**
  34.          *
  35.          */
  36.         private static final long serialVersionUID = 2624821584352571307L;

  37.     }

  38.     public static class StreamIdDoesNotMatchException extends StreamManagementException {

  39.         /**
  40.          *
  41.          */
  42.         private static final long serialVersionUID = 1191073341336559621L;

  43.         public StreamIdDoesNotMatchException(String expected, String got) {
  44.             super("Stream IDs do not match. Expected '" + expected + "', but got '" + got + "'");
  45.         }
  46.     }

  47.     public static class StreamManagementCounterError extends StreamManagementException {

  48.         /**
  49.          *
  50.          */
  51.         private static final long serialVersionUID = 1L;

  52.         private final long handledCount;
  53.         private final long previousServerHandledCount;
  54.         private final long ackedStanzaCount;
  55.         private final int outstandingStanzasCount;
  56.         private final List<Stanza> ackedStanzas;

  57.         public StreamManagementCounterError(long handledCount, long previousServerHandlerCount,
  58.                         long ackedStanzaCount,
  59.                         List<Stanza> ackedStanzas) {
  60.             super(
  61.                             "There was an error regarding the Stream Mangement counters. Server reported "
  62.                                             + handledCount
  63.                                             + " handled stanzas, which means that the "
  64.                                             + ackedStanzaCount
  65.                                             + " recently send stanzas by client are now acked by the server. But Smack had only "
  66.                                             + ackedStanzas.size()
  67.                                             + " to acknowledge. The stanza id of the last acked outstanding stanza is "
  68.                                             + (ackedStanzas.isEmpty() ? "<no acked stanzas>"
  69.                                                             : ackedStanzas.get(ackedStanzas.size() - 1).getStanzaId()));
  70.             this.handledCount = handledCount;
  71.             this.previousServerHandledCount = previousServerHandlerCount;
  72.             this.ackedStanzaCount = ackedStanzaCount;
  73.             this.outstandingStanzasCount = ackedStanzas.size();
  74.             this.ackedStanzas = Collections.unmodifiableList(ackedStanzas);
  75.         }

  76.         public long getHandledCount() {
  77.             return handledCount;
  78.         }

  79.         public long getPreviousServerHandledCount() {
  80.             return previousServerHandledCount;
  81.         }

  82.         public long getAckedStanzaCount() {
  83.             return ackedStanzaCount;
  84.         }

  85.         public int getOutstandingStanzasCount() {
  86.             return outstandingStanzasCount;
  87.         }

  88.         public List<Stanza> getAckedStanzas() {
  89.             return ackedStanzas;
  90.         }
  91.     }
  92. }