Skip to content

Commit

Permalink
Refactoring, added new documentation,...
Browse files Browse the repository at this point in the history
  • Loading branch information
cbockermann committed Mar 20, 2012
1 parent dd3e8c5 commit 65cc4c9
Show file tree
Hide file tree
Showing 52 changed files with 2,245 additions and 263 deletions.
Expand Up @@ -31,11 +31,11 @@ public RemoveAttributes( String keyString ){


public void setKeys( String keyString ){
keys = ParameterUtils.splitAndTrim( keyString );
keys = ParameterUtils.split( keyString );
}

public String getKeys(){
return ParameterUtils.trimAndJoin( keys );
return ParameterUtils.join( keys );
}


Expand Down
36 changes: 8 additions & 28 deletions stream-api/src/main/java/stream/data/mapper/SelectAttributes.java
Expand Up @@ -9,6 +9,7 @@

import stream.data.Data;
import stream.data.DataProcessor;
import stream.util.ParameterUtils;

/**
* @author chris
Expand All @@ -20,35 +21,14 @@ public class SelectAttributes implements DataProcessor {

Set<String> selected = new HashSet<String>();

/**
* @return the keys
*/
public String getKeys() {
if( keys == null || keys.length == 0 )
return "";

StringBuffer s = new StringBuffer();
for( int i = 0; i < keys.length; i++ ){
s.append( keys[i] );
if( i+1 < keys.length )
s.append( "," );
}
return s.toString();
}





/**
* @param keys the keys to set
*/
public void setKeys(String keys) {
this.keys = keys.split( "," );

for( String key : this.keys ){
public void setKeys( String keyString ){
keys = ParameterUtils.split( keyString );
for( String key : keys )
selected.add( key );
}
}

public String getKeys(){
return ParameterUtils.join( keys );
}


Expand Down
3 changes: 2 additions & 1 deletion stream-api/src/main/java/stream/util/ObjectFactory.java
Expand Up @@ -35,7 +35,8 @@ public class ObjectFactory
"stream.data.filter.",
"stream.data.stats.",
"stream.data.vector.",
"stream.data.test."
"stream.data.test.",
"stream.logic"
};

final List<String> searchPath = new ArrayList<String>();
Expand Down
13 changes: 6 additions & 7 deletions stream-api/src/main/java/stream/util/ParameterUtils.java
Expand Up @@ -10,12 +10,12 @@
public class ParameterUtils {


public final static String[] splitAndTrim( String keys ){
return splitAndTrim( keys, "," );
public final static String[] split( String keys ){
return split( keys, "," );
}


public final static String[] splitAndTrim( String keys, String separator ){
public final static String[] split( String keys, String separator ){

if( keys == null || keys.isEmpty() )
return new String[0];
Expand All @@ -33,16 +33,16 @@ public final static String[] splitAndTrim( String keys, String separator ){
String[] out = new String[ cnt ];
cnt = 0;
for( int i = 0; i < elements.length; i++ ){
if( !elements[i].trim().isEmpty() ){
out[cnt++] = elements[i].trim();
if( !elements[i].isEmpty() ){
out[cnt++] = elements[i];
}
}

return out;
}


public final static String trimAndJoin( String[] keys ){
public final static String join( String[] keys ){

if( keys == null )
return null;
Expand All @@ -54,7 +54,6 @@ public final static String trimAndJoin( String[] keys ){
if( ! key.trim().isEmpty() ){
if( cnt > 0 )
s.append( "," );
s.append( key.trim() );
cnt++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion stream-api/src/test/java/stream/logic/MessageTest.java
Expand Up @@ -31,7 +31,7 @@ public void test() throws Exception {
int i = 0;
Message m = new Message();
m.setTxt( "%{x1} ist kleiner als 0.5 und größer als 0.1" );
m.setCondition( "x1 @lt 0.5 and x1 @ge 0.1" );
m.setCondition( "x1 @lt 0.5 and x1 @ge 0.1" );

Data item = stream.readNext();
while( item != null && i++ < 10 ){
Expand Down
2 changes: 2 additions & 0 deletions stream-api/src/test/resources/condition-test.xml
Expand Up @@ -16,6 +16,8 @@

<stream.logic.Message txt="Test: %{x1}" condition="x1 @gt 0.5"/>

<stream.logic.Skip condition="x1 @gt 0.8" />

<!--
<Processor id="naiveBayes" class="stream.learner.NaiveBayes" labelAttribute="@label" />
-->
Expand Down
3 changes: 3 additions & 0 deletions stream-experiment/.classpath
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
2 changes: 1 addition & 1 deletion stream-experiment/pom.xml
Expand Up @@ -4,8 +4,8 @@
<parent>
<artifactId>streams</artifactId>
<groupId>org.jwall</groupId>
<version>0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
<version>1.0</version>
</parent>
<artifactId>stream-experiment</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion stream-log/.classpath
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
2 changes: 1 addition & 1 deletion stream-log/pom.xml
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>org.jwall</groupId>
<artifactId>org.jwall.web.audit</artifactId>
<version>0.5.5</version>
<version>0.5.6</version>
</dependency>
<dependency>
<groupId>org.jwall</groupId>
Expand Down
67 changes: 67 additions & 0 deletions stream-log/src/main/java/stream/data/mapper/DNSLookup.java
@@ -0,0 +1,67 @@
/**
*
*/
package stream.data.mapper;

import java.io.Serializable;

import org.jwall.web.audit.processor.DNSLookupProcessor;

import stream.data.Data;
import stream.util.Description;
import stream.util.Parameter;

/**
* @author chris
*
*/
@Description( name="DNS Lookup", group="Data Stream.Processing.Annotations" )
public class DNSLookup
extends DNSLookupProcessor {

/**
* @see org.jwall.web.audit.processor.DNSLookupProcessor#setKey(java.lang.String)
*/
@Override
@Parameter( required=true, defaultValue="REMOTE_ADDR" )
public void setKey(String key) {
super.setKey(key);
}


/**
* @see org.jwall.web.audit.processor.DNSLookupProcessor#setTarget(java.lang.String)
*/
@Override
@Parameter( required=true, defaultValue="REMOTE_HOSTNAME" )
public void setTarget(String target) {
super.setTarget(target);
}




/**
* @see org.jwall.web.audit.processor.DNSLookupProcessor#process(stream.data.Data)
*/
@Override
public Data process(Data data) {

if( data == null )
return data;

Serializable value = data.get( getKey() );
if( value != null ){
String hostname = resolve( value.toString() );
if( hostname != null )
data.put( getTarget(), hostname + "" );
}

return data;
}


protected String resolve( String name ){
return lookup( name );
}
}
22 changes: 22 additions & 0 deletions stream-log/src/main/java/stream/data/mapper/DNSReverseLookup.java
@@ -0,0 +1,22 @@
/**
*
*/
package stream.data.mapper;

import stream.util.Description;

/**
* @author chris
*
*/
@Description( name = "DNS Reverse lookup", group="Data Stream.Processing.Annotations" )
public class DNSReverseLookup extends DNSLookup {

/**
* @see stream.data.mapper.DNSLookup#resolve(java.lang.String)
*/
@Override
protected String resolve(String name) {
return this.reverseLookup( name );
}
}
17 changes: 17 additions & 0 deletions stream-log/src/main/resources/stream/data/mapper/DNSLookup.md
@@ -0,0 +1,17 @@
DNS Lookup
==========

This processor simply checks for the hostname of a given
IP address. The IP address can either be IPv4 or IPv6.
Lookup is carried out using the local naming services. The
processor integrates a simple, limited cache to speed up
lookups.

The following example will lookup the IP address of the
hostname found in attribute `REMOTE_HOST` and store the
resolved address in attribute `REMOTE_ADDR`:

<DNSLookup key="REMOTE_HOST" target="REMOTE_ADDR" />

The cache size is set with the `cacheSize` parameter. By
default the size of the cache is 10000 entries.
@@ -0,0 +1,21 @@
DNS Reverse Lookup
==================

This processor translates IP addresses back to their host
names. The lookup is performed using the local naming service.

Two keys need to be specified: the `key` parameter specifies
the attribute that is used as address (IPv4 or IPv6) to be
mapped to a hostname. The `target` parameter specifies the
name of the attribute into which the hostname should be stored.

The following example will lookup the attribute value for
`REMOTE_ADDR` and will write the result into the attribute
`HOSTNAME`:

<DNSReverseLookup key="REMOTE_ADDR" target="HOSTNAME" />

The processor integrates a simple, limited cache to speed up
lookups.
The cache size is set with the `cacheSize` parameter. By
default the size of the cache is 10000 entries.
7 changes: 6 additions & 1 deletion stream-plugin/.classpath
Expand Up @@ -2,8 +2,13 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="src/generated-sources/java">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

0 comments on commit 65cc4c9

Please sign in to comment.