Generating Events Using J2SE Client
From EGEE-see WIki
This Wiki page is a part of SEE-GRID Gridification Guide. It is contributed by Belgrade University Computer Centre.
Contents |
Introduction
Here you can find instructions on how to generate events for the Event Logger Application using a remote J2SE client.
Event is a general set of information, that can be stored into an event archive. Meaning of every field can be freely interpreted, depending of usage and domain.
Explanation of Event fields are given in next table.
| Data type | Name | Typical meaning | Some examples |
|---|---|---|---|
| String | targetType | Represents Target that generates some event | vectorValue |
| String | eventType | Type of the event | processed.serverProcessing |
| Date | date | Exact time of the event | |
| String | source | Common part of various events that may be used for grouping | (IP address) 127.0.0.1 |
| String | sourceDetail | Additional source description | (IP address :port) 127.0.0.1:88 |
| String | destination | Common part of various events that may be used for grouping | (IP address) 127.0.0.10 |
| String | destinationDetail | Additional destination description | (IP address :port) 127.0.0.10:89 |
| float | value | Value of event, depending on eventType | (Server Process time) 5 ms |
| float | valueQualifier | Additional numerical attribute describing conditions when event was performed, used for filtering |
Group event represents two or more events that have common targetType and Date. For easier representation of rest of the fields, the class EventItem is used. EventItem fields are described in next table.
| Data type | Name |
|---|---|
| String | eventType |
| String | source |
| String | sourceDetail |
| String | destination |
| String | destinationDetail |
| Float | value |
| Float | valueQualifier |
Event Recording API
PerformanceMeasurementArchiveAccess gives us 3 methods for storing events into archive.
public interface PerformanceMeasurementArchiveAccess{
public void storeEvent(String targetType, String eventType, Date date, String source, String sourceDetail,
String destination, String destinationDetail, float value);
public void storeEvent(String targetType, String eventType, Date date, String source, String sourceDetail,
String destination, String destinationDetail, float value, float valueQualifier);
public void storeGroupEvent(String targetType, Date date, EventItem[] eventitems);
Compiling & Running the Client
In order to compile & run the client, we need to add certain jars into classpath:
- gel-remote.jar - remote access library available here
- jboss-libs - jboss & ejb specific libraries available here
Also, a custom java security policy file (client.policy) might be needed on some systems, example of this file (very insecure!) is listed:
grant {
permission java.security.AllPermission;
};
Example Source Code
This source code does not need a properties file, but loads java security policy file from c:/temp/client.policy
import java.net.UnknownHostException;
import java.rmi.RMISecurityManager;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import archiver.beanwrapper.JNDIPerformanceMeasurementArchiveAccess;
import archiver.beanwrapper.PerformanceMeasurementArchiveAccess;
public class EventLoggerTest {
public static void main(String[] args) {
System.setProperty("java.security.policy", "c:\\temp\\client.policy");
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
PerformanceMeasurementArchiveAccess remoteStub;
try {
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming.client:org.jboss.naming:org.jnp.interfaces");
prop.setProperty("java.naming.provider.url", "jnp://grid02.rcub.bg.ac.yu:1099");
prop.setProperty("org.jboss.naming.client", "org.jboss.naming.client:org.jboss.naming:org.jnp.interfaces");
prop.setProperty("jndiName", "PerfMeasurement/EventGenerationBean/remote");
prop.setProperty("domain", "TestApp");
prop.setProperty("password", "pass");
remoteStub = JNDIPerformanceMeasurementArchiveAccess.getAccess(prop);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Calendar rightNow = Calendar.getInstance();
rightNow.set(2008, Calendar.MARCH, 9, 10, 15, 01);
Date time = rightNow.getTime();
System.out.println(time);
java.net.InetAddress ip;
try {
ip = java.net.InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
throw new RuntimeException(e1);
}
for (int i = 1; i < 5; i++) {
rightNow.set(Calendar.MINUTE, i);
time = rightNow.getTime();
try {
remoteStub.storeEvent("applicationAccess", "test.final", time, ip.getHostAddress().toString(), ip.getHostName()
.toString(), "grid02.rcub.bg.ac.yu:8080", "grid02:8080", 1.5f * i);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
}
