001/** 002 * 003 * Copyright © 2014 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.sm; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.jivesoftware.smack.SmackException; 023import org.jivesoftware.smack.packet.Stanza; 024 025public abstract class StreamManagementException extends SmackException { 026 027 public StreamManagementException() { 028 } 029 030 public StreamManagementException(String message) { 031 super(message); 032 } 033 034 /** 035 * 036 */ 037 private static final long serialVersionUID = 3767590115788821101L; 038 039 public static class StreamManagementNotEnabledException extends StreamManagementException { 040 041 /** 042 * 043 */ 044 private static final long serialVersionUID = 2624821584352571307L; 045 046 } 047 048 public static class StreamIdDoesNotMatchException extends StreamManagementException { 049 050 /** 051 * 052 */ 053 private static final long serialVersionUID = 1191073341336559621L; 054 055 public StreamIdDoesNotMatchException(String expected, String got) { 056 super("Stream IDs do not match. Expected '" + expected + "', but got '" + got + "'"); 057 } 058 } 059 060 public static class StreamManagementCounterError extends StreamManagementException { 061 062 /** 063 * 064 */ 065 private static final long serialVersionUID = 1L; 066 067 private final long handledCount; 068 private final long previousServerHandledCount; 069 private final long ackedStanzaCount; 070 private final int outstandingStanzasCount; 071 private final List<Stanza> ackedStanzas; 072 073 public StreamManagementCounterError(long handledCount, long previousServerHandlerCount, 074 long ackedStanzaCount, 075 List<Stanza> ackedStanzas) { 076 super( 077 "There was an error regarding the Stream Management counters. Server reported " 078 + handledCount 079 + " handled stanzas, which means that the " 080 + ackedStanzaCount 081 + " recently send stanzas by client are now acked by the server. But Smack had only " 082 + ackedStanzas.size() 083 + " to acknowledge. The stanza id of the last acked outstanding stanza is " 084 + (ackedStanzas.isEmpty() ? "<no acked stanzas>" 085 : ackedStanzas.get(ackedStanzas.size() - 1).getStanzaId())); 086 this.handledCount = handledCount; 087 this.previousServerHandledCount = previousServerHandlerCount; 088 this.ackedStanzaCount = ackedStanzaCount; 089 this.outstandingStanzasCount = ackedStanzas.size(); 090 this.ackedStanzas = Collections.unmodifiableList(ackedStanzas); 091 } 092 093 public long getHandledCount() { 094 return handledCount; 095 } 096 097 public long getPreviousServerHandledCount() { 098 return previousServerHandledCount; 099 } 100 101 public long getAckedStanzaCount() { 102 return ackedStanzaCount; 103 } 104 105 public int getOutstandingStanzasCount() { 106 return outstandingStanzasCount; 107 } 108 109 public List<Stanza> getAckedStanzas() { 110 return ackedStanzas; 111 } 112 } 113} 114