001/** 002 * //////////////////////////////////////////////////////////////////////////////// 003 * // 004 * // D SOFTWARE INCORPORATED 005 * // Copyright 2007-2014 D Software Incorporated 006 * // All Rights Reserved. 007 * // 008 * // NOTICE: D Software permits you to use, modify, and distribute this file 009 * // in accordance with the terms of the license agreement accompanying it. 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 * // 015 * //////////////////////////////////////////////////////////////////////////////// 016 */ 017package com.thed.model; 018 019import java.net.UnknownHostException; 020 021/** 022 * Value Object containing infomation of logged in ZBot (also called agent) 023 * 024 * @author zephyrDev 025 */ 026public class Agent { 027 private String token; 028 private String agentHostAndIp; 029 private long lastPing; 030 private Long userId; 031 private long startDate; 032 033 /* count of testcaseBatchExecution instances running for this ZBot. 034 * 0: completed, no testcaseBatchExecution running 035 * Each new instance of testcaseBatchExecution bumps up the number and successful completion reduces count by 1*/ 036 private int status; 037 038 /* real time status of task in progress */ 039 private String realtimeStatus ; 040 041 /* ZBot agent is multi-threaded, i.e. executes batches in parallel */ 042 private boolean multiThreading = false ; 043 044 public Agent(){ 045 super(); 046 } 047 /** 048 * @param token 049 * @param agentHostAndIp 050 * @throws UnknownHostException 051 */ 052 public Agent(String token, String agentIp) throws UnknownHostException { 053 this.token = token; 054 this.agentHostAndIp = agentIp; 055 } 056 057 /** 058 * @return the agentHostAndIp 059 */ 060 public String getAgentHostAndIp() { 061 return agentHostAndIp; 062 } 063 064 /** 065 * @param agentHostAndIp 066 * the agentHostAndIp to set 067 */ 068 public void setAgentHostAndIp(String ip) { 069 this.agentHostAndIp = ip; 070 } 071 072 /** 073 * @return the lastPing 074 */ 075 public long getLastPing() { 076 return lastPing; 077 } 078 079 /** 080 * @param lastPing 081 * the lastPing to set 082 */ 083 public void setLastPing(long lastPing) { 084 this.lastPing = lastPing; 085 } 086 087 /** 088 * @return the token 089 */ 090 public String getToken() { 091 return token; 092 } 093 094 /** 095 * @param token 096 * the token to set 097 */ 098 public void setToken(String token) { 099 this.token = token; 100 } 101 102 103 /** 104 * @return the startDate 105 */ 106 public long getStartDate() { 107 return startDate; 108 } 109 110 /** 111 * @param startDate 112 * the startDate to set 113 */ 114 public void setStartDate(long startDate) { 115 this.startDate = startDate; 116 } 117 118 /** 119 * @return the status 120 */ 121 public int getStatus() { 122 return status; 123 } 124 125 /** 126 * @param status 127 * the status to set 128 */ 129 public void setStatus(int status) { 130 this.status = status; 131 } 132 133 134 135 public String getRealtimeStatus() { 136 return realtimeStatus; 137 } 138 public void setRealtimeStatus(String realtimeStatus) { 139 this.realtimeStatus = realtimeStatus; 140 } 141 /** 142 * @return the userId 143 */ 144 public Long getUserId() { 145 return userId; 146 } 147 148 /** 149 * @param userId 150 * the userId to set 151 */ 152 public void setUserId(Long userId) { 153 this.userId = userId; 154 } 155 156 /* 157 * (non-Javadoc) 158 * 159 * @see java.lang.Object#hashCode() 160 */ 161 @Override 162 public int hashCode() { 163 final int PRIME = 31; 164 int result = 1; 165 result = PRIME * result + ((agentHostAndIp == null) ? 0 : agentHostAndIp.hashCode()); 166 result = PRIME * result + ((token == null) ? 0 : token.hashCode()); 167 return result; 168 } 169 170 /* 171 * (non-Javadoc) 172 * 173 * @see java.lang.Object#equals(java.lang.Object) 174 */ 175 @Override 176 public boolean equals(Object obj) { 177 if (this == obj) 178 return true; 179 if (obj == null) 180 return false; 181 if (getClass() != obj.getClass()) 182 return false; 183 final Agent other = (Agent) obj; 184 if (agentHostAndIp == null) { 185 if (other.agentHostAndIp != null) 186 return false; 187 } else if (!agentHostAndIp.equals(other.agentHostAndIp)) 188 return false; 189 if (token == null) { 190 if (other.token != null) 191 return false; 192 } else if (!token.equals(other.token)) 193 return false; 194 return true; 195 } 196 197 198 199 @Override 200 public String toString() { 201 return "Agent: %s: %s : %s%s".formatted(this.getAgentHostAndIp(), this.getToken(), this.getLastPing(), this.getStartDate()); 202 } 203 204 public boolean isMultiThreading() { 205 return multiThreading; 206 } 207 public void setMultiThreading(boolean multiThreading) { 208 this.multiThreading = multiThreading; 209 } 210 211}