Skip to content

Commit

Permalink
added some missing classes from last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsmj committed Sep 1, 2017
1 parent d1b9dbf commit 930b144
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ classes/
output/
temp/

!/src/org/yawlfoundation/yawl/balancer/output/
120 changes: 120 additions & 0 deletions src/org/yawlfoundation/yawl/balancer/output/AbstractLoadOutputter.java
@@ -0,0 +1,120 @@
package org.yawlfoundation.yawl.balancer.output;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
* @author Michael Adams
* @date 21/8/17
*/
abstract class AbstractLoadOutputter {

protected FileWriter _out;


public AbstractLoadOutputter(String baseFileName, String engineName) {
try {
_out = openFile(baseFileName, engineName);
writeHeader();
}
catch (IOException ioe) {
if (_out != null) _out = null;
}
}


abstract void writeValues(Map<String, String> values) throws IOException;

abstract String getHeader();


public void closeFile() {
if (_out != null) {
try {
_out.flush();
_out.close();
}
catch (IOException ioe) {
// we tried
}
}
}


public void add(String line) {
if (_out != null) {
try {
for (String sub : line.split("\\r?\\n")) {
writeTime();
_out.write(sub);
_out.write('\n');
}
_out.flush();
}
catch (IOException ioe) {
// forget it
}
}
}


public void add(Map<String, String> values) {
if (_out != null) {
try {
writeTime();
writeValues(values);
_out.write('\n');
_out.flush();
}
catch (IOException ioe) {
// forget it
}
}
}


private void writeHeader() throws IOException {
if (_out != null) {
_out.write(getHeader());
_out.write('\n');
}
}


private void writeTime() throws IOException {
if (_out != null) {
Date date = new Date();
String fDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date());
_out.write(fDate);
_out.write("," + date.getTime() + ",");
}
}


private FileWriter openFile(String baseFileName, String engineName) throws IOException {
File f = getFile(baseFileName, engineName);
if (f.createNewFile()) {
return new FileWriter(f);
}
return null;
}


private File getFile(String baseFileName, String engineName) {
String root = System.getenv("CATALINA_HOME");
String baseName = root + "/logs/" + baseFileName + '_' + engineName;
String extn = ".log";
File f = new File(baseName + extn);
int i = 1;
while (f.exists()) {
f = new File(baseName + "_" + i++ + extn);
}
return f;
}

}
45 changes: 45 additions & 0 deletions src/org/yawlfoundation/yawl/balancer/output/BusynessOutputter.java
@@ -0,0 +1,45 @@
package org.yawlfoundation.yawl.balancer.output;

import java.io.IOException;
import java.util.Map;

/**
* @author Michael Adams
* @date 21/8/17
*/
public class BusynessOutputter extends AbstractLoadOutputter {


public BusynessOutputter(String engineName) {
super("busyness", engineName);
}


protected void writeValues(Map<String, String> values) throws IOException {
_out.write(values.get("cpu_process"));
_out.write(',');
_out.write(values.get("cpu_system"));
_out.write(',');
_out.write(values.get("thread_count"));
_out.write(',');
_out.write(values.get("threads_busy"));
_out.write(',');
_out.write(values.get("threads_free"));
_out.write(',');
_out.write(values.get("process_time_factor"));
_out.write(',');
_out.write(values.get("requests_factor"));
_out.write(',');
_out.write(values.get("threads_factor"));
_out.write(',');
_out.write(values.get("busyness"));
}


protected String getHeader() {
return "time,timestamp,cpu_process,cpu_system,thread_count," +
"threads_busy,threads_free,process_time_factor,requests_factor," +
"threads_factor,busyness";
}

}
@@ -0,0 +1,29 @@
package org.yawlfoundation.yawl.balancer.output;

import java.io.IOException;
import java.util.Map;

/**
* @author Michael Adams
* @date 21/8/17
*/
public class RequestStatOutputter extends AbstractLoadOutputter {


public RequestStatOutputter(String engineName) {
super("requests", engineName);
}


protected void writeValues(Map<String, String> values) throws IOException { }


protected String getHeader() {
StringBuilder sb = new StringBuilder();
sb.append("time,timestamp,name,min,max,mean,count,perSec,");
sb.append("prevMin,prevMax,prevMean,prevCount,prevPerSec,");
sb.append("allMin,allMax,allMean,allCount,allPerSec");
return sb.toString();
}

}
Expand Up @@ -191,7 +191,7 @@ public void cleanseRepository() {
if (! foundOne) itemsToRemove.add(workitem.getIDString());
}
}
removeItems(itemsToRemove);
if (! itemsToRemove.isEmpty()) removeItems(itemsToRemove);
}


Expand Down

0 comments on commit 930b144

Please sign in to comment.