001package com.github.theholywaffle.teamspeak3; 002 003/* 004 * #%L 005 * TeamSpeak 3 Java API 006 * %% 007 * Copyright (C) 2014 Bert De Geyter 008 * %% 009 * Permission is hereby granted, free of charge, to any person obtaining a copy 010 * of this software and associated documentation files (the "Software"), to deal 011 * in the Software without restriction, including without limitation the rights 012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 013 * copies of the Software, and to permit persons to whom the Software is 014 * furnished to do so, subject to the following conditions: 015 * 016 * The above copyright notice and this permission notice shall be included in 017 * all copies or substantial portions of the Software. 018 * 019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 025 * THE SOFTWARE. 026 * #L% 027 */ 028 029import com.github.theholywaffle.teamspeak3.TS3Query.FloodRate; 030import com.github.theholywaffle.teamspeak3.api.reconnect.ConnectionHandler; 031import com.github.theholywaffle.teamspeak3.api.reconnect.ReconnectStrategy; 032 033import java.util.logging.Level; 034 035public class TS3Config { 036 037 private String host = null; 038 private int queryPort = 10011; 039 private FloodRate floodRate = FloodRate.DEFAULT; 040 private Level level = Level.WARNING; 041 private boolean debugToFile = false; 042 private int commandTimeout = 4000; 043 private ReconnectStrategy reconnectStrategy = ReconnectStrategy.disconnect(); 044 private ConnectionHandler connectionHandler = null; 045 046 public TS3Config setHost(String host) { 047 this.host = host; 048 return this; 049 } 050 051 String getHost() { 052 return host; 053 } 054 055 public TS3Config setQueryPort(int queryPort) { 056 this.queryPort = queryPort; 057 return this; 058 } 059 060 int getQueryPort() { 061 return queryPort; 062 } 063 064 public TS3Config setFloodRate(FloodRate rate) { 065 if (rate == null) throw new NullPointerException("rate cannot be null!"); 066 this.floodRate = rate; 067 return this; 068 } 069 070 FloodRate getFloodRate() { 071 return floodRate; 072 } 073 074 public TS3Config setDebugLevel(Level level) { 075 if (level == null) throw new NullPointerException("level cannot be null!"); 076 this.level = level; 077 return this; 078 } 079 080 Level getDebugLevel() { 081 return level; 082 } 083 084 public TS3Config setDebugToFile(boolean debugToFile) { 085 this.debugToFile = debugToFile; 086 return this; 087 } 088 089 boolean getDebugToFile() { 090 return debugToFile; 091 } 092 093 /** 094 * Sets how many milliseconds a call in {@link TS3Api} should block at most until a command 095 * without response fails. By default, this timeout is 4000 milliseconds. 096 * 097 * @param commandTimeout 098 * the maximum time to wait for a response until a synchronous command call fails 099 * 100 * @return this TS3Config object for chaining 101 * 102 * @throws IllegalArgumentException 103 * if the timeout value is smaller than or equal to {@code 0} 104 */ 105 public TS3Config setCommandTimeout(int commandTimeout) { 106 if (commandTimeout <= 0) { 107 throw new IllegalArgumentException("Timeout value must be greater than 0"); 108 } 109 110 this.commandTimeout = commandTimeout; 111 return this; 112 } 113 114 int getCommandTimeout() { 115 return commandTimeout; 116 } 117 118 public TS3Config setReconnectStrategy(ReconnectStrategy reconnectStrategy) { 119 if (reconnectStrategy == null) throw new NullPointerException("reconnectStrategy cannot be null!"); 120 this.reconnectStrategy = reconnectStrategy; 121 return this; 122 } 123 124 ReconnectStrategy getReconnectStrategy() { 125 return reconnectStrategy; 126 } 127 128 public TS3Config setConnectionHandler(ConnectionHandler connectionHandler) { 129 this.connectionHandler = connectionHandler; 130 return this; 131 } 132 133 ConnectionHandler getConnectionHandler() { 134 return connectionHandler; 135 } 136}