From: Aleš Křenek Date: Tue, 2 Jun 2009 09:38:43 +0000 (+0000) Subject: additional common event fields X-Git-Tag: gridsite-core_R_1_7_1~36 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=9ea195a60bb25a84482df9c34cb1d780f6866c1a;p=jra1mw.git additional common event fields --- diff --git a/org.glite.lb.client-java/src/org/glite/lb/Event.java b/org.glite.lb.client-java/src/org/glite/lb/Event.java index 3e61203..334dac9 100644 --- a/org.glite.lb.client-java/src/org/glite/lb/Event.java +++ b/org.glite.lb.client-java/src/org/glite/lb/Event.java @@ -1,12 +1,42 @@ package org.glite.lb; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.GregorianCalendar; +import org.glite.jobid.Jobid; + /** * Abstract class which serves as base for all events. * * @author Pavel Piskac (173297@mail.muni.cz) */ public abstract class Event { - + + private Timeval timestamp; + private Timeval arrived; + private String host; + private Level level; + private Integer priority; + private Jobid jobId; + private SeqCode seqcode; + private String user; + private Sources source; + private String srcInstance; + + public Event() { + } + + public Event(Jobid jobId) { + if (jobId == null) throw new IllegalArgumentException("jobId"); + + this.jobId = jobId; + } + + public Jobid getJobId() { + return jobId; + } + /** * When implemented, this method returns string which is specific for each event. * @@ -20,4 +50,111 @@ public abstract class Event { * @return name of event */ public abstract String getEventType(); + + public String info() { + String date = ""; + if (arrived != null) { + Calendar calendar = new GregorianCalendar(); + DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + calendar.setTimeInMillis(arrived.getTvSec()*1000); + date = df.format(calendar.getTime()); + } + return "DATE=" + date + " HOST=\"" + host + "\" " + + "LVL="+level+" DG.PRIORITY=" + priority + " DG.SOURCE=\""+ + source + "\" "+"DG.SRC_INSTANCE=\""+srcInstance+"\" "+ + "DG.EVNT=\""+getEventType()+"\" "+"DG.JOBID=\""+jobId+"\" "+ + "DG.SEQCODE=\""+seqcode+"\" "+"DG.USER=\""+user+"\""+ulm(); + } + + /** + * Get and set methods for Event attributes. + */ + + public Timeval getArrived() { + return arrived; + } + + public void setArrived(Timeval arrived) { + if (arrived == null) throw new IllegalArgumentException("arrived"); + this.arrived = arrived; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + if (host == null) throw new IllegalArgumentException("host"); + this.host = host; + } + + + public void setJobId(Jobid jobId) { + if (jobId == null) throw new IllegalArgumentException("jobId"); + this.jobId = jobId; + } + + public Level getLevel() { + return level; + } + + public void setLevel(Level level) { + if (level == null) throw new IllegalArgumentException("level"); + this.level = level; + } + + public Integer getPriority() { + return priority; + } + + public void setPriority(Integer priority) { + this.priority = priority; + } + + public SeqCode getSeqcode() { + return seqcode; + } + + public void setSeqcode(SeqCode seqcode) { + if (seqcode == null) throw new IllegalArgumentException("seqcode"); + this.seqcode = seqcode; + } + + public Sources getSource() { + return source; + } + + public void setSource(Sources source) { + if (source == null) throw new IllegalArgumentException("source"); + this.source = source; + } + + public String getSrcInstance() { + return srcInstance; + } + + public void setSrcInstance(String srcInstance) { + if (srcInstance == null) throw new IllegalArgumentException("srcInstance"); + this.srcInstance = srcInstance; + } + + public Timeval getTimestamp() { + return timestamp; + } + + public void setTimestamp(Timeval timestamp) { + if (timestamp == null) throw new IllegalArgumentException("timestamp"); + this.timestamp = timestamp; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + if (user == null) throw new IllegalArgumentException("user"); + this.user = user; + } + + } diff --git a/org.glite.lb.client-java/src/org/glite/lb/Level.java b/org.glite.lb.client-java/src/org/glite/lb/Level.java new file mode 100644 index 0000000..8d22986 --- /dev/null +++ b/org.glite.lb.client-java/src/org/glite/lb/Level.java @@ -0,0 +1,49 @@ +package org.glite.lb; + +/** + * This class represents logging level for events. + * + * @author Tomas Kramec, 207545@mail.muni.cz + */ +public class Level { + + private final int level; + + public static final Level LEVEL_UNDEFINED = new Level(0); + public static final Level LEVEL_EMERGENCY = new Level(1); + public static final Level LEVEL_ALERT = new Level(2); + public static final Level LEVEL_ERROR = new Level(3); + public static final Level LEVEL_WARNING = new Level(4); + public static final Level LEVEL_AUTH = new Level(5); + public static final Level LEVEL_SECURITY = new Level(6); + public static final Level LEVEL_USAGE = new Level(7); + public static final Level LEVEL_SYSTEM = new Level(8); + public static final Level LEVEL_IMPORTANT = new Level(9); + public static final Level LEVEL_DEBUG = new Level(10); + + private Level(int level) { + this.level = level; + } + + public int getInt() { + return level; + } + @Override + public String toString() { + switch (level) { + case 0: return "UNDEFINED"; + case 1: return "EMERGENCY"; + case 2: return "ALERT"; + case 3: return "ERROR"; + case 4: return "WARNING"; + case 5: return "AUTH"; + case 6: return "SECURITY"; + case 7: return "USAGE"; + case 8: return "SYSTEM"; + case 9: return "IMPORTANT"; + case 10: return "DEBUG"; + default: throw new IllegalArgumentException("wrong level type"); + } + } + +} diff --git a/org.glite.lb.client-java/src/org/glite/lb/Timeval.java b/org.glite.lb.client-java/src/org/glite/lb/Timeval.java new file mode 100644 index 0000000..31d8bdb --- /dev/null +++ b/org.glite.lb.client-java/src/org/glite/lb/Timeval.java @@ -0,0 +1,72 @@ +package org.glite.lb; + +/** + * This class represents the timestamp in this form: tvSec.tvUsec. + * It consists of two parts: + *
    + *
  1. tvSec - represents time in seconds
  2. + *
  3. tvUsec - represents time in microseconds
  4. + *
+ * + * For example: 1240415967.234999 + * @author Tomas Kramec, 207545@mail.muni.cz + */ +public class Timeval { + + private long tvSec; + private long tvUsec; + + public Timeval() { + } + + /** + * Creates an instance of Timeval. + * + * @param tvSec in seconds + * @param tvUsec in microseconds + */ + public Timeval(long tvSec, long tvUsec) { + this.tvSec = tvSec; + this.tvUsec = tvUsec; + } + + + /** + * Gets the tvSec value for this Timeval. + * + * @return tvSec in seconds + */ + public long getTvSec() { + return tvSec; + } + + + /** + * Sets the tvSec value for this Timeval. + * + * @param tvSec in seconds + */ + public void setTvSec(long tvSec) { + this.tvSec = tvSec; + } + + + /** + * Gets the tvUsec value for this Timeval. + * + * @return tvUsec in microseconds + */ + public long getTvUsec() { + return tvUsec; + } + + + /** + * Sets the tvUsec value for this Timeval. + * + * @param tvUsec in microseconds + */ + public void setTvUsec(long tvUsec) { + this.tvUsec = tvUsec; + } +}