Skip to content

Commit

Permalink
cosmetic changes, rely on external emulators lib
Browse files Browse the repository at this point in the history
  • Loading branch information
undera committed May 5, 2016
1 parent ca15a45 commit 4bda438
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 447 deletions.
77 changes: 10 additions & 67 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.4</java-version>
<cmdrunner-version>1.0.1</cmdrunner-version>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-emulators</artifactId>
<version>0.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>kg.apc</groupId>
<artifactId>cmdrunner</artifactId>
<version>${cmdrunner-version}</version>
<version>1.0.2</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -110,70 +117,6 @@
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<!--
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
17 changes: 7 additions & 10 deletions src/kg/apc/perfmon/PerfMonMetricGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;

/**
* @author undera
*/
public class PerfMonMetricGetter {

public static final String TAB = "\t";
Expand Down Expand Up @@ -46,7 +43,7 @@ private void processCommand(String command) throws IOException {

String cmdType = command.trim();
String params = "";
if (command.indexOf(DVOETOCHIE) >= 0) {
if (command.contains(DVOETOCHIE)) {
cmdType = command.substring(0, command.indexOf(DVOETOCHIE)).trim();
params = command.substring(command.indexOf(DVOETOCHIE) + 1).trim();
}
Expand Down Expand Up @@ -96,7 +93,7 @@ public void addCommandString(String byteBufferToString) {

public boolean processNextCommand() throws IOException {
log.debug("Command line is: " + commandString);
if (commandString.indexOf(NEWLINE) >= 0) {
if (commandString.contains(NEWLINE)) {
int pos = commandString.indexOf(NEWLINE);
String cmd = commandString.substring(0, pos);
commandString = commandString.substring(pos + 1);
Expand All @@ -111,9 +108,9 @@ public ByteBuffer getMetricsLine() throws IOException {
log.debug("Building metrics");
StringBuffer res = new StringBuffer();
synchronized (channel) {
for (int n = 0; n < metrics.length; n++) {
for (AbstractPerfMonMetric metric : metrics) {
try {
metrics[n].getValue(res);
metric.getValue(res);
} catch (Exception ex) {
log.error("Error getting metric", ex);
}
Expand All @@ -132,7 +129,7 @@ private void setUpMetrics(String[] params) throws IOException {
for (int n = 0; n < params.length; n++) {
String metricParams = "";
String metricType = params[n];
if (metricType.indexOf(DVOETOCHIE) >= 0) {
if (DVOETOCHIE.contains(metricType)) {
metricParams = metricType.substring(metricType.indexOf(DVOETOCHIE) + 1).trim();
metricType = metricType.substring(0, metricType.indexOf(DVOETOCHIE)).trim();
}
Expand All @@ -149,13 +146,13 @@ public boolean isStarted() {
// FIXME: some kind of tokenizer would go better
private void setUpTransmitter(String params) throws IOException {
log.info("Starting UDP transmitter for: " + params);
if (params.indexOf(DVOETOCHIE) < 0) {
if (!params.contains(DVOETOCHIE)) {
throw new IllegalArgumentException("Wrong syntax for udp-transmitter command: " + params);
}
String transmitToAddr = params.substring(0, params.indexOf(DVOETOCHIE)).trim();
params = params.substring(params.indexOf(DVOETOCHIE) + 1).trim();

if (params.indexOf(DVOETOCHIE) < 0) {
if (!params.contains(DVOETOCHIE)) {
throw new IllegalArgumentException("Wrong syntax for udp-transmitter command: " + params);
}
int transmitToPort = Integer.parseInt(params.substring(0, params.indexOf(DVOETOCHIE)).trim());
Expand Down
18 changes: 6 additions & 12 deletions src/kg/apc/perfmon/PerfMonWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
import java.util.LinkedList;
import java.util.Properties;

/**
* @author undera
*/
public class PerfMonWorker implements Runnable {

private static final Logger log = LoggingManager.getLoggerForClass();
private int tcpPort = 4444;
private int udpPort = 4444;
private int exitCode = -1;
private boolean isFinished = true;
private final Selector acceptSelector;
private ServerSocketChannel tcpServer;
private final Thread writerThread;
private final Selector sendSelector;
private DatagramChannel udpServer;
private final LinkedList tcpConnections = new LinkedList();
private final LinkedList<SelectableChannel> tcpConnections = new LinkedList<SelectableChannel>();
private final Hashtable udpConnections = new Hashtable();
private long interval = 1000;
private final SigarProxy sigar;
Expand Down Expand Up @@ -98,7 +94,7 @@ public void processCommands() throws IOException {
}

public int getExitCode() {
return exitCode;
return -1;
}

public void startAcceptingCommands() {
Expand Down Expand Up @@ -292,9 +288,8 @@ private void processSenders() throws IOException {

private void sendToUDP(SelectionKey key) throws IOException {
synchronized (udpConnections) {
Iterator it = udpConnections.keySet().iterator();
while (it.hasNext()) {
SocketAddress addr = (SocketAddress) it.next();
for (Object o : udpConnections.keySet()) {
SocketAddress addr = (SocketAddress) o;
PerfMonMetricGetter getter = (PerfMonMetricGetter) udpConnections.get(addr);
if (getter.isStarted()) {
ByteBuffer metrics = getter.getMetricsLine();
Expand Down Expand Up @@ -344,9 +339,8 @@ public void sendToClient(SelectableChannel channel, ByteBuffer buf) throws IOExc
if (channel instanceof DatagramChannel) {
synchronized (udpConnections) {
DatagramChannel udpChannel = (DatagramChannel) channel;
Iterator it = udpConnections.keySet().iterator();
while (it.hasNext()) {
SocketAddress addr = (SocketAddress) it.next();
for (Object o : udpConnections.keySet()) {
SocketAddress addr = (SocketAddress) o;
if (udpConnections.get(addr) == udpChannel) {
udpChannel.send(buf, addr);
}
Expand Down
29 changes: 0 additions & 29 deletions test/kg/apc/emulators/BinaryTools.java

This file was deleted.

122 changes: 0 additions & 122 deletions test/kg/apc/emulators/DatagramChannelEmul.java

This file was deleted.

Loading

0 comments on commit 4bda438

Please sign in to comment.