Exception propagation
This commit is contained in:
+28
-8
@@ -1,5 +1,6 @@
|
|||||||
package com.github.manevolent.ts3j.command.response;
|
package com.github.manevolent.ts3j.command.response;
|
||||||
|
|
||||||
|
import com.github.manevolent.ts3j.command.CommandException;
|
||||||
import com.github.manevolent.ts3j.command.MultiCommand;
|
import com.github.manevolent.ts3j.command.MultiCommand;
|
||||||
import com.github.manevolent.ts3j.util.Ts3Debugging;
|
import com.github.manevolent.ts3j.util.Ts3Debugging;
|
||||||
|
|
||||||
@@ -22,21 +23,40 @@ public abstract class AbstractCommandResponse<T> implements CommandResponse<T> {
|
|||||||
* Completes the command without any post-mapping processing, lowering overhead.
|
* Completes the command without any post-mapping processing, lowering overhead.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void complete()
|
public void complete() throws InterruptedException, CommandException {
|
||||||
throws ExecutionException, InterruptedException {
|
try {
|
||||||
future.get();
|
future.get();
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
if (ex.getCause() != null && ex.getCause() instanceof CommandException)
|
||||||
|
throw (CommandException) ex.getCause();
|
||||||
|
else
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get(long timeoutMillis)
|
public T get(long timeoutMillis)
|
||||||
throws TimeoutException, ExecutionException, InterruptedException {
|
throws TimeoutException, InterruptedException, CommandException {
|
||||||
return map(future.get(timeoutMillis, TimeUnit.MILLISECONDS));
|
try {
|
||||||
|
return map(future.get(timeoutMillis, TimeUnit.MILLISECONDS));
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
if (ex.getCause() != null && ex.getCause() instanceof CommandException)
|
||||||
|
throw (CommandException) ex.getCause();
|
||||||
|
else
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get()
|
public T get() throws InterruptedException, CommandException {
|
||||||
throws ExecutionException, InterruptedException {
|
try {
|
||||||
return map(future.get());
|
return map(future.get());
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
if (ex.getCause() != null && ex.getCause() instanceof CommandException)
|
||||||
|
throw (CommandException) ex.getCause();
|
||||||
|
else
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void completeSuccess(Iterable<MultiCommand> commands) {
|
public void completeSuccess(Iterable<MultiCommand> commands) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.github.manevolent.ts3j.command.response;
|
package com.github.manevolent.ts3j.command.response;
|
||||||
|
|
||||||
import com.github.manevolent.ts3j.command.Command;
|
import com.github.manevolent.ts3j.command.Command;
|
||||||
|
import com.github.manevolent.ts3j.command.CommandException;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
@@ -9,12 +10,11 @@ public interface CommandResponse<T> {
|
|||||||
|
|
||||||
Command getCommand();
|
Command getCommand();
|
||||||
|
|
||||||
default void complete()
|
default void complete() throws InterruptedException, CommandException {
|
||||||
throws ExecutionException, InterruptedException {
|
|
||||||
get();
|
get();
|
||||||
}
|
}
|
||||||
|
|
||||||
T get(long timeoutMillis) throws TimeoutException, ExecutionException, InterruptedException;
|
T get(long timeoutMillis) throws TimeoutException, InterruptedException, CommandException;
|
||||||
T get() throws ExecutionException, InterruptedException;
|
T get() throws InterruptedException, CommandException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-19
@@ -887,7 +887,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void clientAddPermission(int clientDatabaseId, Permission... permission)
|
public void clientAddPermission(int clientDatabaseId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"clientaddperm",
|
"clientaddperm",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -905,7 +905,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clientDeletePermission(int clientDatabaseId, Permission... permission)
|
public void clientDeletePermission(int clientDatabaseId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"clientdelperm",
|
"clientdelperm",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -923,7 +923,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void channelAddPermission(int channelId, Permission... permission)
|
public void channelAddPermission(int channelId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"channeladdperm",
|
"channeladdperm",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -941,7 +941,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void channelClientAddPermission(int channelId, int clientDatabaseId, Permission... permission)
|
public void channelClientAddPermission(int channelId, int clientDatabaseId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"channelclientaddperm",
|
"channelclientaddperm",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -960,7 +960,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void channelClientDeletePermission(int channelId, int clientDatabaseId, Permission... permission)
|
public void channelClientDeletePermission(int channelId, int clientDatabaseId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"channeldelperm",
|
"channeldelperm",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -1008,7 +1008,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
||||||
*/
|
*/
|
||||||
public void sendServerMessage(String message)
|
public void sendServerMessage(String message)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("targetmode", Integer.toString(3)));
|
command.add(new CommandSingleParameter("targetmode", Integer.toString(3)));
|
||||||
@@ -1023,7 +1023,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
||||||
*/
|
*/
|
||||||
public void sendChannelMessage(int channelId, String message)
|
public void sendChannelMessage(int channelId, String message)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("targetmode", Integer.toString(2)));
|
command.add(new CommandSingleParameter("targetmode", Integer.toString(2)));
|
||||||
@@ -1038,7 +1038,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
|
||||||
*/
|
*/
|
||||||
public void sendPrivateMessage(int clientId, String message)
|
public void sendPrivateMessage(int clientId, String message)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("targetmode", Integer.toString(1)));
|
command.add(new CommandSingleParameter("targetmode", Integer.toString(1)));
|
||||||
@@ -1054,7 +1054,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
channel has no password, the parameter can be omitted.
|
channel has no password, the parameter can be omitted.
|
||||||
*/
|
*/
|
||||||
public void clientMove(int clientId, int channelId, String password)
|
public void clientMove(int clientId, int channelId, String password)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("clientmove", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("clientmove", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("cid", Integer.toString(channelId)));
|
command.add(new CommandSingleParameter("cid", Integer.toString(channelId)));
|
||||||
@@ -1065,7 +1065,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void joinChannel(int channelId, String password)
|
public void joinChannel(int channelId, String password)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, TimeoutException, IOException, CommandException {
|
||||||
clientMove(getClientId(), channelId, password);
|
clientMove(getClientId(), channelId, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1075,7 +1075,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
channel has no password, the parameter can be omitted.
|
channel has no password, the parameter can be omitted.
|
||||||
*/
|
*/
|
||||||
public Iterable<Channel> listChannels()
|
public Iterable<Channel> listChannels()
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("channellist", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("channellist", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
return executeCommand(command, x -> new Channel(x.toMap())).get();
|
return executeCommand(command, x -> new Channel(x.toMap())).get();
|
||||||
@@ -1087,14 +1087,14 @@ public class LocalTeamspeakClientSocket
|
|||||||
channel has no password, the parameter can be omitted.
|
channel has no password, the parameter can be omitted.
|
||||||
*/
|
*/
|
||||||
public Iterable<Client> listClients()
|
public Iterable<Client> listClients()
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("clientlist", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("clientlist", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
return executeCommand(command, x -> new Client(x.toMap())).get();
|
return executeCommand(command, x -> new Client(x.toMap())).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serverGroupAddClient(int groupId, int clientDatabaseId)
|
public void serverGroupAddClient(int groupId, int clientDatabaseId)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("servergroupaddclient", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("servergroupaddclient", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("sgid", Integer.toString(groupId)));
|
command.add(new CommandSingleParameter("sgid", Integer.toString(groupId)));
|
||||||
@@ -1104,7 +1104,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void serverGroupRemoveClient(int groupId, int clientDatabaseId)
|
public void serverGroupRemoveClient(int groupId, int clientDatabaseId)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("servergroupdelclient", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("servergroupdelclient", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("sgid", Integer.toString(groupId)));
|
command.add(new CommandSingleParameter("sgid", Integer.toString(groupId)));
|
||||||
@@ -1119,7 +1119,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
channel has no password, the parameter can be omitted.
|
channel has no password, the parameter can be omitted.
|
||||||
*/
|
*/
|
||||||
public void clientPoke(int clientId, String message)
|
public void clientPoke(int clientId, String message)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("clientpoke", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("clientpoke", ProtocolRole.CLIENT);
|
||||||
|
|
||||||
command.add(new CommandSingleParameter("clid", Integer.toString(clientId)));
|
command.add(new CommandSingleParameter("clid", Integer.toString(clientId)));
|
||||||
@@ -1135,7 +1135,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
and may only have a maximum of 40 characters.
|
and may only have a maximum of 40 characters.
|
||||||
*/
|
*/
|
||||||
public void kick(Collection<Integer> clientIds, String message)
|
public void kick(Collection<Integer> clientIds, String message)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
"clientkick",
|
"clientkick",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -1151,13 +1151,13 @@ public class LocalTeamspeakClientSocket
|
|||||||
executeCommand(command).complete();
|
executeCommand(command).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void subscribeAll() throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
public void subscribeAll() throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand("channelsubscribeall", ProtocolRole.CLIENT);
|
Command command = new SingleCommand("channelsubscribeall", ProtocolRole.CLIENT);
|
||||||
executeCommand(command).get();
|
executeCommand(command).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client getClientInfo(int clientId)
|
public Client getClientInfo(int clientId)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand(
|
Command command = new SingleCommand(
|
||||||
"clientinfo",
|
"clientinfo",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
@@ -1178,7 +1178,7 @@ public class LocalTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Channel getChannelInfo(int channelId)
|
public Channel getChannelInfo(int channelId)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, InterruptedException, CommandException {
|
||||||
Command command = new SingleCommand(
|
Command command = new SingleCommand(
|
||||||
"channelinfo",
|
"channelinfo",
|
||||||
ProtocolRole.CLIENT,
|
ProtocolRole.CLIENT,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class ServerConnectionTest {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Ts3Debugging.setEnabled(true);
|
Ts3Debugging.setEnabled(true);
|
||||||
|
|
||||||
LocalIdentity identity = LocalIdentity.read(new File("ident.ini"));
|
LocalIdentity identity = LocalIdentity.generateNew(10);
|
||||||
|
|
||||||
LocalTeamspeakClientSocket client = new LocalTeamspeakClientSocket();
|
LocalTeamspeakClientSocket client = new LocalTeamspeakClientSocket();
|
||||||
client.setIdentity(identity);
|
client.setIdentity(identity);
|
||||||
|
|||||||
Reference in New Issue
Block a user