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; 030 031import java.util.logging.Level; 032 033public class TS3Config { 034 035 private String host = null; 036 private int queryPort = 10011; 037 private FloodRate floodRate = FloodRate.DEFAULT; 038 private Level level = Level.WARNING; 039 private String username = null; 040 private String password = null; 041 private boolean debugToFile = false; 042 private int commandTimeout = 4000; 043 044 public TS3Config setHost(String host) { 045 this.host = host; 046 return this; 047 } 048 049 String getHost() { 050 return host; 051 } 052 053 public TS3Config setQueryPort(int queryPort) { 054 this.queryPort = queryPort; 055 return this; 056 } 057 058 int getQueryPort() { 059 return queryPort; 060 } 061 062 public TS3Config setFloodRate(FloodRate rate) { 063 this.floodRate = rate; 064 return this; 065 } 066 067 FloodRate getFloodRate() { 068 return floodRate; 069 } 070 071 public TS3Config setDebugLevel(Level level) { 072 this.level = level; 073 return this; 074 } 075 076 Level getDebugLevel() { 077 return level; 078 } 079 080 public TS3Config setLoginCredentials(String username, String password) { 081 this.username = username; 082 this.password = password; 083 return this; 084 } 085 086 String getUsername() { 087 return username; 088 } 089 090 String getPassword() { 091 return password; 092 } 093 094 public TS3Config setDebugToFile(boolean debugToFile) { 095 this.debugToFile = debugToFile; 096 return this; 097 } 098 099 boolean getDebugToFile() { 100 return debugToFile; 101 } 102 103 /** 104 * Sets how many milliseconds a call in {@link TS3Api} should block at most until a command 105 * without response fails. By default, this timeout is 4000 milliseconds. 106 * 107 * @param commandTimeout 108 * the maximum time to wait for a response until a synchronous command call fails 109 * 110 * @return this TS3Config object for chaining 111 * 112 * @throws IllegalArgumentException 113 * if the timeout value is smaller than or equal to {@code 0} 114 */ 115 public TS3Config setCommandTimeout(int commandTimeout) { 116 if (commandTimeout <= 0) { 117 throw new IllegalArgumentException("Timeout value must be greater than 0"); 118 } 119 120 this.commandTimeout = commandTimeout; 121 return this; 122 } 123 124 int getCommandTimeout() { 125 return commandTimeout; 126 } 127}