/*
 * The MIT License
 *
 * Copyright 2017 Fernando van Loenhout.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package me.ferrybig.javacoding.teamspeakconnector.internal;

import io.netty.util.concurrent.Promise;
import me.ferrybig.javacoding.teamspeakconnector.TeamspeakCommandException;
import me.ferrybig.javacoding.teamspeakconnector.TeamspeakException;
import me.ferrybig.javacoding.teamspeakconnector.internal.packets.ComplexRequest;
import me.ferrybig.javacoding.teamspeakconnector.internal.packets.ComplexResponse;

public class PendingPacket {

	private final Promise<ComplexResponse> promise;
	private final ComplexRequest request;
	private final SendBehaviour sendBehaviour;

	public PendingPacket(Promise<ComplexResponse> promise,
			ComplexRequest request, SendBehaviour sendBehaviour) {
		this.promise = promise;
		this.request = request;
		this.sendBehaviour = sendBehaviour;
	}

	public void onResponseReceived(ComplexResponse response) {
		if (response.getId() != 0) {
			promise.setFailure(new TeamspeakCommandException(request.getCmd(),
					response.getId(), response.getMsg(),
					response.getExtraMsg()));
		} else {
			promise.setSuccess(response);
		}
	}

	public void onChannelClose(Throwable lastException) {
		if (sendBehaviour != SendBehaviour.NORMAL) {
			promise.setSuccess(null);
		} else {
			TeamspeakException ex;
			if (lastException == null) {
				ex = new TeamspeakException(request.getCmd()
						+ ": -1: Channel closed");
			} else {
				final String message = lastException.getMessage();
				int index = message.indexOf(':');
				if (index < 0) {
					index = message.length() - 1;
				}
				ex = new TeamspeakException(request.getCmd()
						+ ": -1: Channel closed: "
						+ (message.substring(0, index)));
			}
			promise.setFailure(ex);
		}
	}
}

@@ -1240,16 +1240,105 @@
 romise;%0A
+import javax.annotation.Nullable;%0Aimport javax.annotation.ParametersAreNonnullByDefault;%0A
 import m
@@ -1397,32 +1397,32 @@
 mmandException;%0A
-
 import me.ferryb
@@ -1640,16 +1640,115 @@
 ponse;%0A%0A
+/**%0A * A container that stores a packet that has just been send%0A */%0A@ParametersAreNonnullByDefault%0A
 public c
@@ -1902,16 +1902,194 @@
 viour;%0A%0A
+%09/**%0A%09 * Creates a PendingPacket%0A%09 * @param promise A promise for the result%0A%09 * @param request The original send packet%0A%09 * @param sendBehaviour The sendbehaviour to apply%0A%09 */%0A
 %09public 
@@ -2284,24 +2284,115 @@
 aviour;%0A%09%7D%0A%0A
+%09/**%0A%09 * Called when a packet is received for this pending packet%0A%09 * @param response%0A%09 */%0A
 %09public void
@@ -2665,16 +2665,133 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09/**%0A%09 * Called when the channel is closed%0A%09 * @param lastException last exception thrown during the connection%0A%09 */%0A
 %09public 
@@ -2810,16 +2810,26 @@
 elClose(
+@Nullable 
 Throwabl

Add javadoc to PendingPacket