package org.helios.apmrouter.catalog.domain;
// Generated Oct 27, 2012 1:30:47 PM by Hibernate Tools 3.6.0
import java.util.Date;
import javax.management.Notification;
import org.helios.apmrouter.catalog.jdbc.h2.AbstractTrigger;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Agent generated by hbm2java
*/
//@Document
public class Agent implements java.io.Serializable, DomainObject {
@SerializedName("agentId")
//@Indexed(unique=true)
//@Id
private int agentId;
@SerializedName("host")
//@DBRef
private Host host;
@SerializedName("name")
private String name;
@Expose(serialize=false)
private Date firstConnected;
@Expose(serialize=false)
private Date lastConnected;
@SerializedName("conn")
private Date connected;
@SerializedName("uri")
private String uri;
@SerializedName("minl")
private int minLevel;
public Agent() {
}
public Agent(Host host, String name, Date firstConnected,
Date lastConnected, short minLevel) {
this.host = host;
this.name = name;
this.firstConnected = firstConnected;
this.lastConnected = lastConnected;
this.minLevel = minLevel;
}
public Agent(Host host, String name, Date firstConnected,
Date lastConnected, Date connected, String uri, short minLevel
) {
this.host = host;
this.name = name;
this.firstConnected = firstConnected;
this.lastConnected = lastConnected;
this.connected = connected;
this.uri = uri;
this.minLevel = minLevel;
}
/**
* Creates a new Agent from a new agent notification
* @param notif The new agent notification emitted from the H2 catalog DB
*/
public Agent(Notification notif) {
if(notif==null) throw new IllegalArgumentException("The passed notification was null", new Throwable());
if(!AbstractTrigger.NEW_AGENT.equals(notif.getType())) throw new IllegalArgumentException("The passed notification was not the right type [" + notif.getType() + "] for an agent", new Throwable());
Object[] rowData = (Object[])notif.getUserData();
if(rowData==null) {
throw new IllegalArgumentException("The passed agent notification has a null UserData", new Throwable());
}
if(rowData.length!=8) {
throw new IllegalArgumentException("Unexpected rowData length [" + rowData.length + "] for agent notification", new Throwable());
}
this.agentId = (Integer)rowData[0];
this.host = new Host();
this.host.setHostId((Integer)rowData[1]);
this.name = (String)rowData[2];
this.minLevel = (Short)rowData[3];
this.firstConnected = new Date(((java.sql.Timestamp)rowData[4]).getTime());
this.lastConnected = new Date(((java.sql.Timestamp)rowData[5]).getTime());;
this.connected = rowData[6]==null ? null : new Date(((java.sql.Timestamp)rowData[6]).getTime());;
this.uri = (String)rowData[7];
}
public int getAgentId() {
return this.agentId;
}
public void setAgentId(int agentId) {
this.agentId = agentId;
}
public Host getHost() {
return this.host;
}
public void setHost(Host host) {
this.host = host;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Date getFirstConnected() {
return this.firstConnected;
}
public void setFirstConnected(Date firstConnected) {
this.firstConnected = firstConnected;
}
public Date getLastConnected() {
return this.lastConnected;
}
public void setLastConnected(Date lastConnected) {
this.lastConnected = lastConnected;
}
public Date getConnected() {
return this.connected;
}
public void setConnected(Date connected) {
this.connected = connected;
}
public String getUri() {
return this.uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public int getMinLevel() {
return this.minLevel;
}
public void setMinLevel(short minLevel) {
this.minLevel = minLevel;
}
/**
* {@inheritDoc}
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Agent [host=");
builder.append(host.getName());
builder.append(", agent=");
builder.append(name);
builder.append(", agentId=");
builder.append(agentId);
builder.append(", connected=");
builder.append(connected);
builder.append(", uri=");
builder.append(uri);
builder.append("]");
return builder.toString();
}
}