Move files in anticipation of move to modular system
This commit is contained in:
0
java/application.ibuddy/build.gradle
Normal file
0
java/application.ibuddy/build.gradle
Normal file
0
java/application.itunes/build.gradle
Normal file
0
java/application.itunes/build.gradle
Normal file
3
java/application.lightroom/build.gradle
Normal file
3
java/application.lightroom/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
dependencies {
|
||||||
|
compile 'com.github.boukefalos:jlibwinapi:0.1'
|
||||||
|
}
|
||||||
14
java/application.lightroom/src/main/java/winapi/Amount.java
Normal file
14
java/application.lightroom/src/main/java/winapi/Amount.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package winapi;
|
||||||
|
|
||||||
|
public enum Amount {
|
||||||
|
DECREASE_MUCH ("--"),
|
||||||
|
DECREASE_LITTLE ("-"),
|
||||||
|
INCREASE_LITTLE ("+"),
|
||||||
|
INCREASE_MUCH ("++");
|
||||||
|
|
||||||
|
public String value;
|
||||||
|
|
||||||
|
Amount(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
java/application.lightroom/src/main/java/winapi/Slider.java
Normal file
20
java/application.lightroom/src/main/java/winapi/Slider.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package winapi;
|
||||||
|
public enum Slider {
|
||||||
|
EXPOSURE,
|
||||||
|
CONTRAST,
|
||||||
|
HIGHLIGHTS,
|
||||||
|
SHADOWS,
|
||||||
|
WHITES,
|
||||||
|
BLACKS,
|
||||||
|
CLARITY,
|
||||||
|
VIBRANCE;
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
String name = this.name();
|
||||||
|
return String.format("%s%s", name.substring(0, 1), name.toLowerCase().substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel(Amount amount) {
|
||||||
|
return String.format("%s %s", getLabel(), amount.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
115
java/application.lightroom/src/main/java/winapi/Test.java
Normal file
115
java/application.lightroom/src/main/java/winapi/Test.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package winapi;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.synthuse.Api;
|
||||||
|
import org.synthuse.objects.MenuItem;
|
||||||
|
|
||||||
|
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
protected Api api;
|
||||||
|
|
||||||
|
protected HashMap<Slider, HashMap<Amount, MenuItem>> sliderMap;
|
||||||
|
protected HashMap<Slider, HWND> valueMap;
|
||||||
|
|
||||||
|
public Test() {
|
||||||
|
api = new Api();
|
||||||
|
sliderMap = new HashMap<Slider, HashMap<Amount, MenuItem>>();
|
||||||
|
valueMap = new HashMap<Slider, HWND>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Test test = new Test();
|
||||||
|
test.start();
|
||||||
|
|
||||||
|
//test.moveSlider(Slider.CONTRAST, Amount.INCREASE_LITTLE);
|
||||||
|
|
||||||
|
for (int k = 0; k < 5; ++k) {
|
||||||
|
Slider slider = Slider.values()[new Random().nextInt(Slider.values().length)];
|
||||||
|
for (int j = 0; j < 5; ++j) {
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
test.moveSlider(slider, Amount.INCREASE_LITTLE);
|
||||||
|
System.out.println(test.getValue(slider));
|
||||||
|
Thread.sleep(200);
|
||||||
|
}
|
||||||
|
Thread.sleep(400);
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
test.moveSlider(slider, Amount.INCREASE_LITTLE);
|
||||||
|
Thread.sleep(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Slider[] getSliders() {
|
||||||
|
return sliderMap.keySet().toArray(new Slider[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveSlider(Slider slider, Amount amount) throws Exception {
|
||||||
|
MenuItem menuItem = sliderMap.get(slider).get(amount);
|
||||||
|
api.activateItem(menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getValue(Slider slider) {
|
||||||
|
if (valueMap.containsKey(slider)) {
|
||||||
|
HWND hWnd = valueMap.get(slider);
|
||||||
|
String text = Api.getWindowText(hWnd);
|
||||||
|
return Float.valueOf(text.replace(" ", ""));
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() throws Exception {
|
||||||
|
// Find Lightroom window
|
||||||
|
HWND hWndTopWindow = api.findTopWindow("Lightroom", "AgWinMainFrame");
|
||||||
|
if (hWndTopWindow == null) {
|
||||||
|
throw new Exception("Can't find top window");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find menu options from Keyboard Tamer
|
||||||
|
String[] path = {"&File", "Pl&ug-in Extras", ""};
|
||||||
|
for (Slider slider : Slider.values()) {
|
||||||
|
HashMap<Amount, MenuItem> amountMap = new HashMap<Amount, MenuItem>();
|
||||||
|
for (Amount amount : Amount.values()) {
|
||||||
|
String label = slider.getLabel(amount);
|
||||||
|
path[2] = String.format(" %s", label);
|
||||||
|
MenuItem menuItem = api.loadMenuItem(hWndTopWindow, true, path);
|
||||||
|
amountMap.put(amount, menuItem);
|
||||||
|
}
|
||||||
|
sliderMap.put(slider, amountMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find develop sliders
|
||||||
|
path = new String[]{"", "Top", "Main", "Panel", "Last Panel", "View", "ClipView", "Accordion", "Accordion"};
|
||||||
|
HWND hWnd = api.findChildWindow(hWndTopWindow, path);
|
||||||
|
if (hWnd == null) {
|
||||||
|
throw new Exception("Can't find window");
|
||||||
|
}
|
||||||
|
for (HWND hWndLoop : api.findAllChildWindow(hWnd, "Collapsible")) {
|
||||||
|
path = new String[]{"Basic", "View"};
|
||||||
|
hWnd = api.findChildWindow(hWndLoop, path);
|
||||||
|
if (hWnd != null) {
|
||||||
|
Slider slider = null;
|
||||||
|
for (HWND hWndSubLoop : api.findAllChildWindow(hWnd, "")) {
|
||||||
|
//String className = Api.getWindowClassName(hWndSubLoop);
|
||||||
|
String text = Api.getWindowText(hWndSubLoop);
|
||||||
|
if (!text.contains("Bridge") && !text.contains("View") && text.length() > 0) {
|
||||||
|
if (slider != null) {
|
||||||
|
System.out.printf("%s = %s (%.2f)\n", slider.getLabel(), text, Float.valueOf(text.replace(" ", "")));
|
||||||
|
valueMap.put(slider, hWndSubLoop);
|
||||||
|
slider = null;
|
||||||
|
} else {
|
||||||
|
for (Slider sliderLoop : Slider.values()) {
|
||||||
|
if (sliderLoop.getLabel().equals(text)) {
|
||||||
|
slider = sliderLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
java/base/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
java/base/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
#Sun Jun 14 13:41:53 BST 2015
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-bin.zip
|
|
||||||
164
java/base/gradlew
vendored
164
java/base/gradlew
vendored
@@ -1,164 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## Gradle start up script for UN*X
|
|
||||||
##
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS=""
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=`basename "$0"`
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD="maximum"
|
|
||||||
|
|
||||||
warn ( ) {
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
die ( ) {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
case "`uname`" in
|
|
||||||
CYGWIN* )
|
|
||||||
cygwin=true
|
|
||||||
;;
|
|
||||||
Darwin* )
|
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
|
||||||
if $cygwin ; then
|
|
||||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >&-
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >&-
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
||||||
else
|
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="java"
|
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
ulimit -n $MAX_FD
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
|
||||||
function splitJvmOpts() {
|
|
||||||
JVM_OPTS=("$@")
|
|
||||||
}
|
|
||||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
|
||||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
|
||||||
|
|
||||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
allprojects {
|
subprojects {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
apply plugin: 'license'
|
||||||
|
|
||||||
version = '0.1'
|
task wrapper(type: Wrapper) {
|
||||||
|
gradleVersion = '2.14'
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
@@ -34,8 +39,37 @@ allprojects {
|
|||||||
maven {
|
maven {
|
||||||
url 'https://github.com/Boukefalos/jlibxinput/raw/mvn-repo/'
|
url 'https://github.com/Boukefalos/jlibxinput/raw/mvn-repo/'
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://github.com/Boukefalos/jlibxinput/raw/mvn-repo/'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://github.com/Boukefalos/jlibwinapi/raw/mvn-repo/'
|
||||||
|
}
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
license {
|
||||||
|
header rootProject.file('HEADER.txt')
|
||||||
|
strictCheck true
|
||||||
|
|
||||||
|
skipExistingHeaders false
|
||||||
|
ext.year = Calendar.getInstance().get(Calendar.YEAR)
|
||||||
|
ext.name = 'Rik Veenboer'
|
||||||
|
ext.email = 'rik.veenboer@gmail.com'
|
||||||
|
ext.project = 'this program'
|
||||||
|
ext.Project = 'This program'
|
||||||
|
include "**/*.java"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.github.boukefalos'
|
||||||
|
version = '0.1'
|
||||||
|
archivesBaseName = 'mimis-' + project.name
|
||||||
|
|
||||||
|
uploadArchives {
|
||||||
|
repositories.mavenDeployer {
|
||||||
|
repository(url: uri('../../.maven'))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
task wrapper(type: Wrapper) {
|
|
||||||
gradleVersion = '2.2'
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral();
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.slf4j:slf4j-log4j12:1.7.7'
|
compile 'org.slf4j:slf4j-log4j12:1.7.7'
|
||||||
compile 'org.picocontainer:picocontainer:2.15'
|
compile 'org.picocontainer:picocontainer:2.15'
|
||||||
52
java/mimis/gradlew → java/core.legacy/gradlew
vendored
52
java/mimis/gradlew → java/core.legacy/gradlew
vendored
@@ -6,12 +6,30 @@
|
|||||||
##
|
##
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Attempt to set APP_HOME
|
||||||
DEFAULT_JVM_OPTS=""
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD="maximum"
|
||||||
|
|
||||||
@@ -30,6 +48,7 @@ die ( ) {
|
|||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
case "`uname`" in
|
case "`uname`" in
|
||||||
CYGWIN* )
|
CYGWIN* )
|
||||||
cygwin=true
|
cygwin=true
|
||||||
@@ -40,31 +59,11 @@ case "`uname`" in
|
|||||||
MINGW* )
|
MINGW* )
|
||||||
msys=true
|
msys=true
|
||||||
;;
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
|
||||||
if $cygwin ; then
|
|
||||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >&-
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >&-
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -90,7 +89,7 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
@@ -114,6 +113,7 @@ fi
|
|||||||
if $cygwin ; then
|
if $cygwin ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
180
java/base/gradlew.bat → java/core.legacy/gradlew.bat
vendored
180
java/base/gradlew.bat → java/core.legacy/gradlew.bat
vendored
@@ -1,90 +1,90 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
@rem Set local scope for the variables with windows NT shell
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
set DIRNAME=%~dp0
|
||||||
set DEFAULT_JVM_OPTS=
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
set DIRNAME=%~dp0
|
set APP_HOME=%DIRNAME%
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
|
||||||
set APP_BASE_NAME=%~n0
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set APP_HOME=%DIRNAME%
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
:init
|
||||||
@rem Get command-line arguments, handling Windowz variants
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||||
|
|
||||||
:win9xME_args
|
:win9xME_args
|
||||||
@rem Slurp the command line arguments.
|
@rem Slurp the command line arguments.
|
||||||
set CMD_LINE_ARGS=
|
set CMD_LINE_ARGS=
|
||||||
set _SKIP=2
|
set _SKIP=2
|
||||||
|
|
||||||
:win9xME_args_slurp
|
:win9xME_args_slurp
|
||||||
if "x%~1" == "x" goto execute
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
set CMD_LINE_ARGS=%*
|
||||||
goto execute
|
goto execute
|
||||||
|
|
||||||
:4NT_args
|
:4NT_args
|
||||||
@rem Get arguments from the 4NT Shell from JP Software
|
@rem Get arguments from the 4NT Shell from JP Software
|
||||||
set CMD_LINE_ARGS=%$
|
set CMD_LINE_ARGS=%$
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
:omega
|
:omega
|
||||||
79
java/core.legacy/sources.txt
Normal file
79
java/core.legacy/sources.txt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\module-info.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\Control.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\Duplex.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\Forwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\Receiver.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\Sender.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\LoaderException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\WorkerException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\ActivateException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\AlreadyActiveException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\AlreadyRunningException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\DeactivateException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\NotActiveException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\NotRunningException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\exception\worker\StartException.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\loader\AbstractLoader.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\channel\TcpClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\channel\TcpServer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\channel\TcpServerClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\AbstractUdpClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpDuplexAutoClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpDuplexClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpDuplexHelper.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpDuplexServer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpMulticastClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpMulticastServer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpSender.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\datagram\UdpServer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\TcpChannelServerForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\TcpClientChannelForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\TcpClientSocketForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\TcpSocketServerForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\UdpDuplexClientForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\UdpDuplexServerForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\forwarder\UdpServerForwarder.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\receiver\AbstractReceiver.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\socket\AbstractTcpClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\socket\TcpClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\socket\TcpServer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\server\socket\TcpServerClient.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\util\ArrayCycle.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\util\Buffer.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\util\Bufferable.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\util\BufferedArrayCycle.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\util\Dummy.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\work\Listen.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\work\ReflectiveListen.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\work\Work.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\BackgroundListener.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\DirectIntervalWorker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\DirectWorker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\ForegroundListener.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\IntervalWork.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\ThreadIntervalWorker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\ThreadWorker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\Worker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\Listener.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\ListenerPool.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\ListenerPoolRunnable.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\PooledListener.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\PooledWorker.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\WorkerPool.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\WorkerPoolRunnable.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\main\java\base\worker\pool\Wrapper.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\AllTests.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\TestTcpChannelCommunication.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\TestTcpSocketCommunication.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\TestUdpDuplexCommunication.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\TestUdpMulticastCommunication.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\junit\TestUdpUnicastCommunication.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\test\Test.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\TestDirectWork.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\TestIntervalWork.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\TestListen.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\TestPooledListen.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\TestPooledWork.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\dummy\DummyIntervalWork.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\dummy\DummyListen.java
|
||||||
|
C:\Users\Rik\Git\github\mimis\java\core.legacy\src\test\java\worker\dummy\DummyWork.java
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
public interface Control {
|
public interface Control {
|
||||||
public void start();
|
public void start();
|
||||||
public void stop();
|
public void stop();
|
||||||
public void exit();
|
public void exit();
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
public interface Duplex extends Forwarder, Sender {}
|
public interface Duplex extends Forwarder, Sender {}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
public interface Forwarder extends Control {
|
public interface Forwarder extends Control {
|
||||||
public void register(Receiver receiver);
|
public void register(Receiver receiver);
|
||||||
public void remove(Receiver receiver);
|
public void remove(Receiver receiver);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
public interface Receiver {
|
public interface Receiver {
|
||||||
public void receive(byte[] buffer);
|
public void receive(byte[] buffer);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public interface Sender extends Control {
|
public interface Sender extends Control {
|
||||||
public void send(byte[] buffer) throws IOException;
|
public void send(byte[] buffer) throws IOException;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package base.exception;
|
package base.exception;
|
||||||
|
|
||||||
public class LoaderException extends Exception {
|
public class LoaderException extends Exception {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public LoaderException(String message) {
|
public LoaderException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package base.exception;
|
package base.exception;
|
||||||
|
|
||||||
public class WorkerException extends Exception {
|
public class WorkerException extends Exception {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class ActivateException extends WorkerException {
|
public class ActivateException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class AlreadyActiveException extends WorkerException {
|
public class AlreadyActiveException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class AlreadyRunningException extends WorkerException {
|
public class AlreadyRunningException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class DeactivateException extends WorkerException {
|
public class DeactivateException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class NotActiveException extends WorkerException {
|
public class NotActiveException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class NotRunningException extends WorkerException {
|
public class NotRunningException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package base.exception.worker;
|
package base.exception.worker;
|
||||||
|
|
||||||
import base.exception.WorkerException;
|
import base.exception.WorkerException;
|
||||||
|
|
||||||
public class StartException extends WorkerException {
|
public class StartException extends WorkerException {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
@@ -1,146 +1,146 @@
|
|||||||
package base.loader;
|
package base.loader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.picocontainer.DefaultPicoContainer;
|
import org.picocontainer.DefaultPicoContainer;
|
||||||
import org.picocontainer.MutablePicoContainer;
|
import org.picocontainer.MutablePicoContainer;
|
||||||
import org.picocontainer.Parameter;
|
import org.picocontainer.Parameter;
|
||||||
import org.picocontainer.parameters.ConstantParameter;
|
import org.picocontainer.parameters.ConstantParameter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Forwarder;
|
import base.Forwarder;
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.LoaderException;
|
import base.exception.LoaderException;
|
||||||
import base.server.datagram.UdpSender;
|
import base.server.datagram.UdpSender;
|
||||||
import base.server.forwarder.UdpDuplexClientForwarder;
|
import base.server.forwarder.UdpDuplexClientForwarder;
|
||||||
import base.server.forwarder.UdpDuplexServerForwarder;
|
import base.server.forwarder.UdpDuplexServerForwarder;
|
||||||
|
|
||||||
public class AbstractLoader<T> {
|
public class AbstractLoader<T> {
|
||||||
protected static final String PROPERTIES_FILE = "loader.properties";
|
protected static final String PROPERTIES_FILE = "loader.properties";
|
||||||
protected static final Properties SERVER = null;
|
protected static final Properties SERVER = null;
|
||||||
|
|
||||||
protected Logger logger = LoggerFactory.getLogger(AbstractLoader.class);
|
protected Logger logger = LoggerFactory.getLogger(AbstractLoader.class);
|
||||||
protected MutablePicoContainer pico;
|
protected MutablePicoContainer pico;
|
||||||
|
|
||||||
public AbstractLoader() {
|
public AbstractLoader() {
|
||||||
/* Initialise container */
|
/* Initialise container */
|
||||||
pico = new DefaultPicoContainer();
|
pico = new DefaultPicoContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractLoader(Properties properties) {
|
public AbstractLoader(Properties properties) {
|
||||||
this();
|
this();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static <T> T getLoader() throws LoaderException {
|
public static <T> T getLoader() throws LoaderException {
|
||||||
return (T) new AbstractLoader(readProperties(PROPERTIES_FILE));
|
return (T) new AbstractLoader(readProperties(PROPERTIES_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Properties readProperties(String propertiesFile) throws LoaderException {
|
public static Properties readProperties(String propertiesFile) throws LoaderException {
|
||||||
/* Read properties file */
|
/* Read properties file */
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(AbstractLoader.class.getClassLoader().getResourceAsStream(propertiesFile));
|
properties.load(AbstractLoader.class.getClassLoader().getResourceAsStream(propertiesFile));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new LoaderException("Faield to read properties file: " + PROPERTIES_FILE);
|
throw new LoaderException("Faield to read properties file: " + PROPERTIES_FILE);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class<?> getSenderClass(String protocol, String implementation) throws LoaderException {
|
protected Class<?> getSenderClass(String protocol, String implementation) throws LoaderException {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
switch (implementation) {
|
switch (implementation) {
|
||||||
case "channel":
|
case "channel":
|
||||||
return base.server.channel.TcpClient.class;
|
return base.server.channel.TcpClient.class;
|
||||||
default:
|
default:
|
||||||
case "socket":
|
case "socket":
|
||||||
return base.server.socket.TcpClient.class;
|
return base.server.socket.TcpClient.class;
|
||||||
}
|
}
|
||||||
case "udp":
|
case "udp":
|
||||||
return UdpSender.class;
|
return UdpSender.class;
|
||||||
}
|
}
|
||||||
throw new LoaderException("Failed to determine <Sender>");
|
throw new LoaderException("Failed to determine <Sender>");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class<?> getClientForwarderClass(String protocol, String implementation) throws LoaderException {
|
protected Class<?> getClientForwarderClass(String protocol, String implementation) throws LoaderException {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
switch (implementation) {
|
switch (implementation) {
|
||||||
case "channel":
|
case "channel":
|
||||||
return base.server.forwarder.TcpClientChannelForwarder.class;
|
return base.server.forwarder.TcpClientChannelForwarder.class;
|
||||||
default:
|
default:
|
||||||
case "socket":
|
case "socket":
|
||||||
return base.server.forwarder.TcpClientSocketForwarder.class;
|
return base.server.forwarder.TcpClientSocketForwarder.class;
|
||||||
}
|
}
|
||||||
case "udp":
|
case "udp":
|
||||||
return UdpDuplexClientForwarder.class;
|
return UdpDuplexClientForwarder.class;
|
||||||
}
|
}
|
||||||
throw new LoaderException("Failed to determine <Forwarder>");
|
throw new LoaderException("Failed to determine <Forwarder>");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class<?> getServerForwarderClass(String protocol, String implementation) throws LoaderException {
|
protected Class<?> getServerForwarderClass(String protocol, String implementation) throws LoaderException {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
switch (implementation) {
|
switch (implementation) {
|
||||||
case "channel":
|
case "channel":
|
||||||
return base.server.forwarder.TcpChannelServerForwarder.class;
|
return base.server.forwarder.TcpChannelServerForwarder.class;
|
||||||
default:
|
default:
|
||||||
case "socket":
|
case "socket":
|
||||||
return base.server.forwarder.TcpSocketServerForwarder.class;
|
return base.server.forwarder.TcpSocketServerForwarder.class;
|
||||||
}
|
}
|
||||||
case "udp":
|
case "udp":
|
||||||
return UdpDuplexServerForwarder.class;
|
return UdpDuplexServerForwarder.class;
|
||||||
}
|
}
|
||||||
throw new LoaderException("Failed to determine <Forwarder>");
|
throw new LoaderException("Failed to determine <Forwarder>");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addClientSender(String protocol, String implementation, String host, int port) throws LoaderException {
|
protected void addClientSender(String protocol, String implementation, String host, int port) throws LoaderException {
|
||||||
Class<?> senderClass = getSenderClass(protocol, implementation);
|
Class<?> senderClass = getSenderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + senderClass);
|
logger.debug("Adding " + senderClass);
|
||||||
pico.addComponent(Sender.class, senderClass, new Parameter[]{
|
pico.addComponent(Sender.class, senderClass, new Parameter[]{
|
||||||
new ConstantParameter(host),
|
new ConstantParameter(host),
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addServerSender(String protocol, String implementation, int port) throws LoaderException {
|
protected void addServerSender(String protocol, String implementation, int port) throws LoaderException {
|
||||||
Class<?> senderClass = getSenderClass(protocol, implementation);
|
Class<?> senderClass = getSenderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + senderClass);
|
logger.debug("Adding " + senderClass);
|
||||||
pico.addComponent(Sender.class, senderClass, new Parameter[]{
|
pico.addComponent(Sender.class, senderClass, new Parameter[]{
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addClientForwarder(String protocol, String implementation, String host, int port) throws LoaderException {
|
protected void addClientForwarder(String protocol, String implementation, String host, int port) throws LoaderException {
|
||||||
Class<?> forwarderClass = getClientForwarderClass(protocol, implementation);
|
Class<?> forwarderClass = getClientForwarderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + forwarderClass);
|
logger.debug("Adding " + forwarderClass);
|
||||||
pico.addComponent(Forwarder.class, forwarderClass, new Parameter[]{
|
pico.addComponent(Forwarder.class, forwarderClass, new Parameter[]{
|
||||||
new ConstantParameter(host),
|
new ConstantParameter(host),
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addClientDuplex(String protocol, String implementation, String host, int port) throws LoaderException {
|
protected void addClientDuplex(String protocol, String implementation, String host, int port) throws LoaderException {
|
||||||
Class<?> duplexClass = getClientForwarderClass(protocol, implementation);
|
Class<?> duplexClass = getClientForwarderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + duplexClass);
|
logger.debug("Adding " + duplexClass);
|
||||||
pico.addComponent(Duplex.class, duplexClass, new Parameter[]{
|
pico.addComponent(Duplex.class, duplexClass, new Parameter[]{
|
||||||
new ConstantParameter(host),
|
new ConstantParameter(host),
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addServerForwarder(String protocol, String implementation, int port) throws LoaderException {
|
protected void addServerForwarder(String protocol, String implementation, int port) throws LoaderException {
|
||||||
Class<?> forwarderClass = getServerForwarderClass(protocol, implementation);
|
Class<?> forwarderClass = getServerForwarderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + forwarderClass);
|
logger.debug("Adding " + forwarderClass);
|
||||||
pico.addComponent(Forwarder.class, forwarderClass, new Parameter[]{
|
pico.addComponent(Forwarder.class, forwarderClass, new Parameter[]{
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addServerDuplex(String protocol, String implementation, int port) throws LoaderException {
|
protected void addServerDuplex(String protocol, String implementation, int port) throws LoaderException {
|
||||||
Class<?> duplexClass = getServerForwarderClass(protocol, implementation);
|
Class<?> duplexClass = getServerForwarderClass(protocol, implementation);
|
||||||
logger.debug("Adding " + duplexClass);
|
logger.debug("Adding " + duplexClass);
|
||||||
pico.addComponent(Duplex.class, duplexClass, new Parameter[]{
|
pico.addComponent(Duplex.class, duplexClass, new Parameter[]{
|
||||||
new ConstantParameter(port)});
|
new ConstantParameter(port)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,137 +1,137 @@
|
|||||||
package base.server.channel;
|
package base.server.channel;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
import base.worker.Worker;
|
import base.worker.Worker;
|
||||||
|
|
||||||
public class TcpClient extends Work implements Sender {
|
public class TcpClient extends Work implements Sender {
|
||||||
protected static final String HOST = "localhost";
|
protected static final String HOST = "localhost";
|
||||||
protected static final int BUFFER_SIZE = 1024;
|
protected static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
protected String host;
|
protected String host;
|
||||||
protected int port;
|
protected int port;
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected SocketChannel socketChannel;
|
protected SocketChannel socketChannel;
|
||||||
protected Selector selector;
|
protected Selector selector;
|
||||||
protected ArrayList<Listen<byte[]>> listenList = new ArrayList<Listen<byte[]>>();
|
protected ArrayList<Listen<byte[]>> listenList = new ArrayList<Listen<byte[]>>();
|
||||||
|
|
||||||
public TcpClient(int port) {
|
public TcpClient(int port) {
|
||||||
this(HOST, port);
|
this(HOST, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpClient(String host, int port) {
|
public TcpClient(String host, int port) {
|
||||||
this(host, port, BUFFER_SIZE);
|
this(host, port, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpClient(String host, int port, int bufferSize) {
|
public TcpClient(String host, int port, int bufferSize) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
System.out.println("Client: Activate!");
|
System.out.println("Client: Activate!");
|
||||||
try {
|
try {
|
||||||
InetSocketAddress hostAddress = new InetSocketAddress(host, port);
|
InetSocketAddress hostAddress = new InetSocketAddress(host, port);
|
||||||
socketChannel = SocketChannel.open(hostAddress);
|
socketChannel = SocketChannel.open(hostAddress);
|
||||||
socketChannel.configureBlocking(false);
|
socketChannel.configureBlocking(false);
|
||||||
while (!socketChannel.finishConnect()) {
|
while (!socketChannel.finishConnect()) {
|
||||||
sleep(Worker.SLEEP);
|
sleep(Worker.SLEEP);
|
||||||
}
|
}
|
||||||
selector = Selector.open();
|
selector = Selector.open();
|
||||||
socketChannel.register(selector, SelectionKey.OP_READ);
|
socketChannel.register(selector, SelectionKey.OP_READ);
|
||||||
synchronized (host) {
|
synchronized (host) {
|
||||||
host.notifyAll();
|
host.notifyAll();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
System.out.println("Client: Deactivate!");
|
System.out.println("Client: Deactivate!");
|
||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
socketChannel.close();
|
socketChannel.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new DeactivateException();
|
throw new DeactivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
if (selector != null) {
|
if (selector != null) {
|
||||||
selector.wakeup();
|
selector.wakeup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void work() {
|
public final void work() {
|
||||||
try {
|
try {
|
||||||
logger.debug("Client: Waiting for select... ");
|
logger.debug("Client: Waiting for select... ");
|
||||||
logger.debug("Client: Number of selected keys: " + selector.select());
|
logger.debug("Client: Number of selected keys: " + selector.select());
|
||||||
Set<SelectionKey> selectionKeySet = selector.selectedKeys();
|
Set<SelectionKey> selectionKeySet = selector.selectedKeys();
|
||||||
Iterator<SelectionKey> selectionKeyIterator = selectionKeySet.iterator();
|
Iterator<SelectionKey> selectionKeyIterator = selectionKeySet.iterator();
|
||||||
|
|
||||||
while (selectionKeyIterator.hasNext()) {
|
while (selectionKeyIterator.hasNext()) {
|
||||||
SelectionKey selectionKey = selectionKeyIterator.next();
|
SelectionKey selectionKey = selectionKeyIterator.next();
|
||||||
if (selectionKey.isReadable()) {
|
if (selectionKey.isReadable()) {
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
|
ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
|
||||||
socketChannel.read(byteBuffer);
|
socketChannel.read(byteBuffer);
|
||||||
byte[] buffer = byteBuffer.array();
|
byte[] buffer = byteBuffer.array();
|
||||||
input(buffer);
|
input(buffer);
|
||||||
} else if (selectionKey.isWritable()) {
|
} else if (selectionKey.isWritable()) {
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
buffer = (byte[]) selectionKey.attachment();
|
buffer = (byte[]) selectionKey.attachment();
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
|
||||||
socketChannel.write(byteBuffer);
|
socketChannel.write(byteBuffer);
|
||||||
//selectionKey.cancel();
|
//selectionKey.cancel();
|
||||||
socketChannel.register(selector, SelectionKey.OP_READ);
|
socketChannel.register(selector, SelectionKey.OP_READ);
|
||||||
}
|
}
|
||||||
selectionKeyIterator.remove();
|
selectionKeyIterator.remove();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {}
|
protected void input(byte[] buffer) {}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
if (selector == null) {
|
if (selector == null) {
|
||||||
try {
|
try {
|
||||||
synchronized (host) {
|
synchronized (host) {
|
||||||
host.wait();
|
host.wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
selector.wakeup();
|
selector.wakeup();
|
||||||
socketChannel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE, buffer);
|
socketChannel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
socketChannel.close();
|
socketChannel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void register(Listen<byte[]> listen) {
|
/*public void register(Listen<byte[]> listen) {
|
||||||
listenList.add(listen);
|
listenList.add(listen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Listen<byte[]> listen) {
|
public void remove(Listen<byte[]> listen) {
|
||||||
listenList.remove(listen);
|
listenList.remove(listen);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
@@ -1,158 +1,158 @@
|
|||||||
package base.server.channel;
|
package base.server.channel;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.server.channel.TcpServerClient;
|
import base.server.channel.TcpServerClient;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class TcpServer extends Work implements Sender {
|
public class TcpServer extends Work implements Sender {
|
||||||
protected static final Class<?> CLIENT_CLASS = TcpServerClient.class;
|
protected static final Class<?> CLIENT_CLASS = TcpServerClient.class;
|
||||||
protected static final int BUFFER_SIZE = 1024;
|
protected static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
protected int port;
|
protected int port;
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected Constructor<?> clientConstructor;
|
protected Constructor<?> clientConstructor;
|
||||||
protected Selector selector;
|
protected Selector selector;
|
||||||
protected ServerSocketChannel serverSocket;
|
protected ServerSocketChannel serverSocket;
|
||||||
protected ArrayList<TcpServerClient> clientList;
|
protected ArrayList<TcpServerClient> clientList;
|
||||||
|
|
||||||
public TcpServer(int port) {
|
public TcpServer(int port) {
|
||||||
this(port, CLIENT_CLASS);
|
this(port, CLIENT_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpServer(int port, Class<?> clientClass) {
|
public TcpServer(int port, Class<?> clientClass) {
|
||||||
this(port, clientClass, BUFFER_SIZE);
|
this(port, clientClass, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpServer(int port, Class<?> clientClass, int bufferSize) {
|
public TcpServer(int port, Class<?> clientClass, int bufferSize) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
try {
|
try {
|
||||||
// Allow dependency injection, constructor arguments
|
// Allow dependency injection, constructor arguments
|
||||||
clientConstructor = Class.forName(clientClass.getName()).getConstructor(TcpServer.class, SocketChannel.class, Integer.class);
|
clientConstructor = Class.forName(clientClass.getName()).getConstructor(TcpServer.class, SocketChannel.class, Integer.class);
|
||||||
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
||||||
logger.error("Failed to initialise client constructor", e);
|
logger.error("Failed to initialise client constructor", e);
|
||||||
}
|
}
|
||||||
clientList = new ArrayList<TcpServerClient>();
|
clientList = new ArrayList<TcpServerClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
System.out.println("Server: Activate!");
|
System.out.println("Server: Activate!");
|
||||||
try {
|
try {
|
||||||
// Get selector
|
// Get selector
|
||||||
selector = Selector.open();
|
selector = Selector.open();
|
||||||
|
|
||||||
// Get server socket channel and register with selector
|
// Get server socket channel and register with selector
|
||||||
serverSocket = ServerSocketChannel.open();
|
serverSocket = ServerSocketChannel.open();
|
||||||
InetSocketAddress hostAddress = new InetSocketAddress(port);
|
InetSocketAddress hostAddress = new InetSocketAddress(port);
|
||||||
serverSocket.bind(hostAddress);
|
serverSocket.bind(hostAddress);
|
||||||
serverSocket.configureBlocking(false);
|
serverSocket.configureBlocking(false);
|
||||||
serverSocket.register(selector, SelectionKey.OP_ACCEPT);
|
serverSocket.register(selector, SelectionKey.OP_ACCEPT);
|
||||||
synchronized (clientConstructor) {
|
synchronized (clientConstructor) {
|
||||||
clientConstructor.notifyAll();
|
clientConstructor.notifyAll();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (BindException e) {
|
} catch (BindException e) {
|
||||||
logger.error("Address already in use", e);
|
logger.error("Address already in use", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
System.out.println("Server: Deactivate!");
|
System.out.println("Server: Deactivate!");
|
||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
serverSocket.close();
|
serverSocket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new DeactivateException();
|
throw new DeactivateException();
|
||||||
} finally {
|
} finally {
|
||||||
for (TcpServerClient client : clientList) {
|
for (TcpServerClient client : clientList) {
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
if (selector != null) {
|
if (selector != null) {
|
||||||
selector.wakeup();
|
selector.wakeup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
System.out.println("Server: Waiting for select... ");
|
System.out.println("Server: Waiting for select... ");
|
||||||
System.out.println("Server: Number of selected keys: " + selector.select());
|
System.out.println("Server: Number of selected keys: " + selector.select());
|
||||||
|
|
||||||
Set<SelectionKey> selectionKeySet = selector.selectedKeys();
|
Set<SelectionKey> selectionKeySet = selector.selectedKeys();
|
||||||
Iterator<SelectionKey> selectionKeyIterator = selectionKeySet.iterator();
|
Iterator<SelectionKey> selectionKeyIterator = selectionKeySet.iterator();
|
||||||
|
|
||||||
while (selectionKeyIterator.hasNext()) {
|
while (selectionKeyIterator.hasNext()) {
|
||||||
SelectionKey selectionKey = selectionKeyIterator.next();
|
SelectionKey selectionKey = selectionKeyIterator.next();
|
||||||
if (selectionKey.isAcceptable()) {
|
if (selectionKey.isAcceptable()) {
|
||||||
// Accept the new client connection
|
// Accept the new client connection
|
||||||
SocketChannel socketChannel = serverSocket.accept();
|
SocketChannel socketChannel = serverSocket.accept();
|
||||||
socketChannel.configureBlocking(false);
|
socketChannel.configureBlocking(false);
|
||||||
|
|
||||||
// Add the new connection to the selector
|
// Add the new connection to the selector
|
||||||
TcpServerClient client = (TcpServerClient) clientConstructor.newInstance(this, socketChannel, bufferSize);
|
TcpServerClient client = (TcpServerClient) clientConstructor.newInstance(this, socketChannel, bufferSize);
|
||||||
clientList.add(client);
|
clientList.add(client);
|
||||||
socketChannel.register(selector, SelectionKey.OP_READ, client);
|
socketChannel.register(selector, SelectionKey.OP_READ, client);
|
||||||
//initClient(client);
|
//initClient(client);
|
||||||
System.out.println("Accepted new connection from client: " + socketChannel);
|
System.out.println("Accepted new connection from client: " + socketChannel);
|
||||||
} else if (selectionKey.isReadable()) {
|
} else if (selectionKey.isReadable()) {
|
||||||
// Read the data from client
|
// Read the data from client
|
||||||
TcpServerClient serverClient = (TcpServerClient) selectionKey.attachment();
|
TcpServerClient serverClient = (TcpServerClient) selectionKey.attachment();
|
||||||
serverClient.readable();
|
serverClient.readable();
|
||||||
} else if (selectionKey.isWritable()) {
|
} else if (selectionKey.isWritable()) {
|
||||||
// Write to client?
|
// Write to client?
|
||||||
}
|
}
|
||||||
selectionKeyIterator.remove();
|
selectionKeyIterator.remove();
|
||||||
}
|
}
|
||||||
}/* catch (IOException e) {} catch (InstantiationException e) {
|
}/* catch (IOException e) {} catch (InstantiationException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
} */catch (Exception e) {
|
} */catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initClient(TcpServerClient client) {
|
protected void initClient(TcpServerClient client) {
|
||||||
try {
|
try {
|
||||||
client.write(ByteBuffer.wrap(new String("Hi there!").getBytes()));
|
client.write(ByteBuffer.wrap(new String("Hi there!").getBytes()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
logger.debug("Number of clients = " + clientList.size());
|
logger.debug("Number of clients = " + clientList.size());
|
||||||
for (TcpServerClient client : clientList) {
|
for (TcpServerClient client : clientList) {
|
||||||
// Should be dealt with in clients own thread
|
// Should be dealt with in clients own thread
|
||||||
client.send(buffer);
|
client.send(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {}
|
public void input(TcpServerClient client, byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,54 +1,54 @@
|
|||||||
package base.server.channel;
|
package base.server.channel;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
|
|
||||||
public class TcpServerClient extends Listen<byte[]> implements Sender {
|
public class TcpServerClient extends Listen<byte[]> implements Sender {
|
||||||
protected static final int BUFFER_SIZE = 1024;
|
protected static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
protected TcpServer server;
|
protected TcpServer server;
|
||||||
protected SocketChannel socketChannel;
|
protected SocketChannel socketChannel;
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected ByteBuffer byteBuffer;
|
protected ByteBuffer byteBuffer;
|
||||||
|
|
||||||
public TcpServerClient(TcpServer server, SocketChannel socketChannel) {
|
public TcpServerClient(TcpServer server, SocketChannel socketChannel) {
|
||||||
this(server, socketChannel, BUFFER_SIZE);
|
this(server, socketChannel, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpServerClient(TcpServer server, SocketChannel socketChannel, Integer bufferSize) {
|
public TcpServerClient(TcpServer server, SocketChannel socketChannel, Integer bufferSize) {
|
||||||
super();
|
super();
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.socketChannel = socketChannel;
|
this.socketChannel = socketChannel;
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
byteBuffer = ByteBuffer.allocate(bufferSize);
|
byteBuffer = ByteBuffer.allocate(bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(ByteBuffer byteBuffer) throws IOException {
|
public void write(ByteBuffer byteBuffer) throws IOException {
|
||||||
socketChannel.write(byteBuffer);
|
socketChannel.write(byteBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readable() throws IOException {
|
public void readable() throws IOException {
|
||||||
int read;
|
int read;
|
||||||
while (( read = socketChannel.read(byteBuffer)) > 0) {
|
while (( read = socketChannel.read(byteBuffer)) > 0) {
|
||||||
byteBuffer.flip();
|
byteBuffer.flip();
|
||||||
byte[] buffer = byteBuffer.array();
|
byte[] buffer = byteBuffer.array();
|
||||||
input(buffer);
|
input(buffer);
|
||||||
byteBuffer.clear();
|
byteBuffer.clear();
|
||||||
}
|
}
|
||||||
if (read < 0) {
|
if (read < 0) {
|
||||||
socketChannel.close();
|
socketChannel.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
server.input(this, buffer);
|
server.input(this, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
write(ByteBuffer.wrap(buffer));
|
write(ByteBuffer.wrap(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,46 +1,46 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public abstract class AbstractUdpClient extends Work {
|
public abstract class AbstractUdpClient extends Work {
|
||||||
protected static final int BUFFER_SIZE = 2048;
|
protected static final int BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected MulticastSocket socket;
|
protected MulticastSocket socket;
|
||||||
protected DatagramPacket datagramPacket;
|
protected DatagramPacket datagramPacket;
|
||||||
|
|
||||||
public AbstractUdpClient() {}
|
public AbstractUdpClient() {}
|
||||||
|
|
||||||
public AbstractUdpClient(MulticastSocket socket) {
|
public AbstractUdpClient(MulticastSocket socket) {
|
||||||
this(socket, BUFFER_SIZE);
|
this(socket, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractUdpClient(MulticastSocket socket, int bufferSize) {
|
public AbstractUdpClient(MulticastSocket socket, int bufferSize) {
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
datagramPacket = new DatagramPacket(buffer, buffer.length);
|
datagramPacket = new DatagramPacket(buffer, buffer.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
System.out.println("iets ontvangen!!!!!");
|
System.out.println("iets ontvangen!!!!!");
|
||||||
buffer = packet.getData();
|
buffer = packet.getData();
|
||||||
input(buffer);
|
input(buffer);
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
socket.close();
|
socket.close();
|
||||||
super.stop();
|
super.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void input(byte[] buffer);
|
protected abstract void input(byte[] buffer);
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class UdpDuplexAutoClient extends UdpDuplexClient {
|
public class UdpDuplexAutoClient extends UdpDuplexClient {
|
||||||
public UdpDuplexAutoClient(int bindPort, int sendPort) throws UnknownHostException {
|
public UdpDuplexAutoClient(int bindPort, int sendPort) throws UnknownHostException {
|
||||||
super(HOST, bindPort, null, sendPort);
|
super(HOST, bindPort, null, sendPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpDuplexAutoClient(String bindHost, int bindPort, int sendPort) throws UnknownHostException {
|
public UdpDuplexAutoClient(String bindHost, int bindPort, int sendPort) throws UnknownHostException {
|
||||||
super(bindHost, bindPort, null, sendPort);
|
super(bindHost, bindPort, null, sendPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpDuplexAutoClient(String bindHost, int bindPort, int sendPort, int bufferSize) throws UnknownHostException {
|
public UdpDuplexAutoClient(String bindHost, int bindPort, int sendPort, int bufferSize) throws UnknownHostException {
|
||||||
super(bindHost, bindPort, null, sendPort, bufferSize);
|
super(bindHost, bindPort, null, sendPort, bufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,51 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
|
|
||||||
public class UdpDuplexClient extends UdpMulticastClient implements Sender {
|
public class UdpDuplexClient extends UdpMulticastClient implements Sender {
|
||||||
protected int sendPort;
|
protected int sendPort;
|
||||||
protected Sender sender;
|
protected Sender sender;
|
||||||
|
|
||||||
public UdpDuplexClient(int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
public UdpDuplexClient(int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
||||||
this(HOST, bindPort, sendHost, sendPort);
|
this(HOST, bindPort, sendHost, sendPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpDuplexClient(String bindHost, int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
public UdpDuplexClient(String bindHost, int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
||||||
this(bindHost, bindPort, sendHost, sendPort, BUFFER_SIZE);
|
this(bindHost, bindPort, sendHost, sendPort, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpDuplexClient(String bindHost, int bindPort, String sendHost, int sendPort, int bufferSize) throws UnknownHostException {
|
public UdpDuplexClient(String bindHost, int bindPort, String sendHost, int sendPort, int bufferSize) throws UnknownHostException {
|
||||||
super(bindHost, bindPort, bufferSize);
|
super(bindHost, bindPort, bufferSize);
|
||||||
this.sendPort = sendPort;
|
this.sendPort = sendPort;
|
||||||
if (sendHost != null) {
|
if (sendHost != null) {
|
||||||
sender = new UdpSender(sendHost, sendPort);
|
sender = new UdpSender(sendHost, sendPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
buffer = packet.getData();
|
buffer = packet.getData();
|
||||||
System.out.println("Receive from " + packet.getAddress().getHostAddress());
|
System.out.println("Receive from " + packet.getAddress().getHostAddress());
|
||||||
if (sender == null) {
|
if (sender == null) {
|
||||||
String sendHost = packet.getAddress().getHostAddress();
|
String sendHost = packet.getAddress().getHostAddress();
|
||||||
sender = new UdpSender(sendHost, sendPort);
|
sender = new UdpSender(sendHost, sendPort);
|
||||||
}
|
}
|
||||||
input(buffer);
|
input(buffer);
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
sender.send(buffer);
|
sender.send(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {}
|
public void input(byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
|
|
||||||
public class UdpDuplexHelper extends AbstractUdpClient {
|
public class UdpDuplexHelper extends AbstractUdpClient {
|
||||||
protected Listen<byte[]> listen;
|
protected Listen<byte[]> listen;
|
||||||
|
|
||||||
public UdpDuplexHelper(Listen<byte[]> listen, MulticastSocket socket) {
|
public UdpDuplexHelper(Listen<byte[]> listen, MulticastSocket socket) {
|
||||||
super(socket);
|
super(socket);
|
||||||
this.listen = listen;
|
this.listen = listen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
System.out.println("jajajaja");
|
System.out.println("jajajaja");
|
||||||
listen.add(buffer);
|
listen.add(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
|
|
||||||
public class UdpDuplexServer extends UdpMulticastServer {
|
public class UdpDuplexServer extends UdpMulticastServer {
|
||||||
protected int bindPort;
|
protected int bindPort;
|
||||||
protected UdpDuplexHelper helper;
|
protected UdpDuplexHelper helper;
|
||||||
|
|
||||||
public UdpDuplexServer(int sendPort, int bindPort) {
|
public UdpDuplexServer(int sendPort, int bindPort) {
|
||||||
super(sendPort);
|
super(sendPort);
|
||||||
this.bindPort = bindPort;
|
this.bindPort = bindPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
socket = new MulticastSocket(bindPort);
|
socket = new MulticastSocket(bindPort);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
helper = new UdpDuplexHelper(this, socket);
|
helper = new UdpDuplexHelper(this, socket);
|
||||||
helper.start();
|
helper.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
helper.stop();
|
helper.stop();
|
||||||
super.deactivate();
|
super.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
if (socket == null) {
|
if (socket == null) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
InetAddress group = InetAddress.getByName(host);
|
InetAddress group = InetAddress.getByName(host);
|
||||||
System.out.println("Send to " + host + " " + port);
|
System.out.println("Send to " + host + " " + port);
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port);
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,42 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
|
|
||||||
public class UdpMulticastClient extends AbstractUdpClient {
|
public class UdpMulticastClient extends AbstractUdpClient {
|
||||||
protected static final String HOST = "239.255.255.255";
|
protected static final String HOST = "239.255.255.255";
|
||||||
|
|
||||||
protected String host;
|
protected String host;
|
||||||
protected int port;
|
protected int port;
|
||||||
|
|
||||||
public UdpMulticastClient(int port) {
|
public UdpMulticastClient(int port) {
|
||||||
this(HOST, port);
|
this(HOST, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpMulticastClient(String host, int port) {
|
public UdpMulticastClient(String host, int port) {
|
||||||
this(host, port, BUFFER_SIZE);
|
this(host, port, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpMulticastClient(String host, int port, int bufferSize) {
|
public UdpMulticastClient(String host, int port, int bufferSize) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.bufferSize = BUFFER_SIZE;
|
this.bufferSize = BUFFER_SIZE;
|
||||||
System.out.println("Client bind: " + host + " " + port);
|
System.out.println("Client bind: " + host + " " + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
socket = new MulticastSocket(port);
|
socket = new MulticastSocket(port);
|
||||||
InetAddress group = InetAddress.getByName(host);
|
InetAddress group = InetAddress.getByName(host);
|
||||||
socket.joinGroup(group);
|
socket.joinGroup(group);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {}
|
protected void input(byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,61 +1,61 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
import base.worker.Worker;
|
import base.worker.Worker;
|
||||||
|
|
||||||
public class UdpMulticastServer extends Listen<byte[]> implements Sender {
|
public class UdpMulticastServer extends Listen<byte[]> implements Sender {
|
||||||
protected static final String HOST = "239.255.255.255";
|
protected static final String HOST = "239.255.255.255";
|
||||||
protected static final int BUFFER_SIZE = 2048;
|
protected static final int BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
protected String host;
|
protected String host;
|
||||||
protected int port;
|
protected int port;
|
||||||
protected MulticastSocket socket;
|
protected MulticastSocket socket;
|
||||||
|
|
||||||
public UdpMulticastServer(int port) {
|
public UdpMulticastServer(int port) {
|
||||||
this(HOST, port);
|
this(HOST, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpMulticastServer(String host, int port) {
|
public UdpMulticastServer(String host, int port) {
|
||||||
super(Worker.Type.BACKGROUND);
|
super(Worker.Type.BACKGROUND);
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
System.out.println("Server send: " + host + " " + port);
|
System.out.println("Server send: " + host + " " + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
socket = new MulticastSocket();
|
socket = new MulticastSocket();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
socket.close();
|
socket.close();
|
||||||
super.deactivate();
|
super.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
try {
|
try {
|
||||||
InetAddress group = InetAddress.getByName(host);
|
InetAddress group = InetAddress.getByName(host);
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port);
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
add(buffer);
|
add(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,56 +1,56 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
|
|
||||||
public class UdpSender implements Sender {
|
public class UdpSender implements Sender {
|
||||||
protected static final String HOST = "localhost";
|
protected static final String HOST = "localhost";
|
||||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
protected DatagramSocket datagramSocket;
|
protected DatagramSocket datagramSocket;
|
||||||
protected InetAddress inetAddress;
|
protected InetAddress inetAddress;
|
||||||
protected int port;
|
protected int port;
|
||||||
|
|
||||||
public UdpSender(int port) throws UnknownHostException {
|
public UdpSender(int port) throws UnknownHostException {
|
||||||
this(HOST, port);
|
this(HOST, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpSender(String host, int port) throws UnknownHostException {
|
public UdpSender(String host, int port) throws UnknownHostException {
|
||||||
System.out.println("Sender use: " + host + " " + port);
|
System.out.println("Sender use: " + host + " " + port);
|
||||||
inetAddress = InetAddress.getByName(host);
|
inetAddress = InetAddress.getByName(host);
|
||||||
this.port = port;
|
this.port = port;
|
||||||
try {
|
try {
|
||||||
datagramSocket = new DatagramSocket();
|
datagramSocket = new DatagramSocket();
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
logger.error("Failed to create socket", e);
|
logger.error("Failed to create socket", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {}
|
public void start() {}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
datagramSocket.close();
|
datagramSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) {
|
public void send(byte[] buffer) {
|
||||||
try {
|
try {
|
||||||
DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length, inetAddress, port);
|
DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length, inetAddress, port);
|
||||||
datagramSocket.send(datagramPacket);
|
datagramSocket.send(datagramPacket);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Failed to send buffer", e);
|
logger.error("Failed to send buffer", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,64 +1,64 @@
|
|||||||
package base.server.datagram;
|
package base.server.datagram;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class UdpServer extends Work {
|
public class UdpServer extends Work {
|
||||||
protected static final int BUFFER_SIZE = 1024;
|
protected static final int BUFFER_SIZE = 1024;
|
||||||
protected static final int TIMEOUT = 1000;
|
protected static final int TIMEOUT = 1000;
|
||||||
|
|
||||||
protected int port;
|
protected int port;
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected DatagramSocket diagramSocket;
|
protected DatagramSocket diagramSocket;
|
||||||
|
|
||||||
public UdpServer(int port) {
|
public UdpServer(int port) {
|
||||||
this(port, BUFFER_SIZE);
|
this(port, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpServer(int port, int bufferSize) {
|
public UdpServer(int port, int bufferSize) {
|
||||||
super();
|
super();
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
logger.debug("Starting datagram socket on port " + port);
|
logger.debug("Starting datagram socket on port " + port);
|
||||||
diagramSocket = new DatagramSocket(port);
|
diagramSocket = new DatagramSocket(port);
|
||||||
diagramSocket.setSoTimeout(TIMEOUT);
|
diagramSocket.setSoTimeout(TIMEOUT);
|
||||||
super.activate();
|
super.activate();
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
logger.error("Failed to initialize socket", e);
|
logger.error("Failed to initialize socket", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
if (diagramSocket != null) {
|
if (diagramSocket != null) {
|
||||||
diagramSocket.close();
|
diagramSocket.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length);
|
||||||
try {
|
try {
|
||||||
diagramSocket.receive(datagramPacket);
|
diagramSocket.receive(datagramPacket);
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
stop();
|
stop();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Failed to receive packet", e);
|
logger.error("Failed to receive packet", e);
|
||||||
stop();
|
stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
input(buffer);
|
input(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {}
|
protected void input(byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.channel.TcpServer;
|
import base.server.channel.TcpServer;
|
||||||
import base.server.channel.TcpServerClient;
|
import base.server.channel.TcpServerClient;
|
||||||
|
|
||||||
public class TcpChannelServerForwarder extends TcpServer implements Duplex {
|
public class TcpChannelServerForwarder extends TcpServer implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public TcpChannelServerForwarder(int port) {
|
public TcpChannelServerForwarder(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.socket.TcpClient;
|
import base.server.socket.TcpClient;
|
||||||
import base.server.socket.TcpServerClient;
|
import base.server.socket.TcpServerClient;
|
||||||
|
|
||||||
public class TcpClientChannelForwarder extends TcpClient implements Duplex {
|
public class TcpClientChannelForwarder extends TcpClient implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public TcpClientChannelForwarder(String host, int port) {
|
public TcpClientChannelForwarder(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.channel.TcpClient;
|
import base.server.channel.TcpClient;
|
||||||
import base.server.channel.TcpServerClient;
|
import base.server.channel.TcpServerClient;
|
||||||
|
|
||||||
public class TcpClientSocketForwarder extends TcpClient implements Duplex {
|
public class TcpClientSocketForwarder extends TcpClient implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public TcpClientSocketForwarder(String host, int port) {
|
public TcpClientSocketForwarder(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.socket.TcpServer;
|
import base.server.socket.TcpServer;
|
||||||
import base.server.socket.TcpServerClient;
|
import base.server.socket.TcpServerClient;
|
||||||
|
|
||||||
public class TcpSocketServerForwarder extends TcpServer implements Duplex {
|
public class TcpSocketServerForwarder extends TcpServer implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public TcpSocketServerForwarder(int port) {
|
public TcpSocketServerForwarder(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.datagram.UdpDuplexClient;
|
import base.server.datagram.UdpDuplexClient;
|
||||||
|
|
||||||
public class UdpDuplexClientForwarder extends UdpDuplexClient implements Duplex {
|
public class UdpDuplexClientForwarder extends UdpDuplexClient implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public UdpDuplexClientForwarder(String bindHost, int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
public UdpDuplexClientForwarder(String bindHost, int bindPort, String sendHost, int sendPort) throws UnknownHostException {
|
||||||
super(bindHost, bindPort, sendHost, sendPort);
|
super(bindHost, bindPort, sendHost, sendPort);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,30 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Duplex;
|
import base.Duplex;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.datagram.UdpDuplexServer;
|
import base.server.datagram.UdpDuplexServer;
|
||||||
|
|
||||||
public class UdpDuplexServerForwarder extends UdpDuplexServer implements Duplex {
|
public class UdpDuplexServerForwarder extends UdpDuplexServer implements Duplex {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public UdpDuplexServerForwarder(int port, int listenPort) {
|
public UdpDuplexServerForwarder(int port, int listenPort) {
|
||||||
super(port, listenPort);
|
super(port, listenPort);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,30 @@
|
|||||||
package base.server.forwarder;
|
package base.server.forwarder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Forwarder;
|
import base.Forwarder;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
import base.server.datagram.UdpServer;
|
import base.server.datagram.UdpServer;
|
||||||
|
|
||||||
public class UdpServerForwarder extends UdpServer implements Forwarder {
|
public class UdpServerForwarder extends UdpServer implements Forwarder {
|
||||||
protected ArrayList<Receiver> receiverList;
|
protected ArrayList<Receiver> receiverList;
|
||||||
|
|
||||||
public UdpServerForwarder(int port) {
|
public UdpServerForwarder(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
receiverList = new ArrayList<Receiver>();
|
receiverList = new ArrayList<Receiver>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Receiver receiver) {
|
public void register(Receiver receiver) {
|
||||||
receiverList.add(receiver);
|
receiverList.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Receiver receiver) {
|
public void remove(Receiver receiver) {
|
||||||
receiverList.remove(receiver);
|
receiverList.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
for (Receiver receiver: receiverList) {
|
for (Receiver receiver: receiverList) {
|
||||||
receiver.receive(buffer);
|
receiver.receive(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,33 @@
|
|||||||
package base.server.receiver;
|
package base.server.receiver;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import base.Control;
|
import base.Control;
|
||||||
import base.Forwarder;
|
import base.Forwarder;
|
||||||
import base.Receiver;
|
import base.Receiver;
|
||||||
|
|
||||||
public abstract class AbstractReceiver implements Receiver, Control {
|
public abstract class AbstractReceiver implements Receiver, Control {
|
||||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
protected Forwarder forwarder;
|
protected Forwarder forwarder;
|
||||||
|
|
||||||
public AbstractReceiver(Forwarder forwarder) {
|
public AbstractReceiver(Forwarder forwarder) {
|
||||||
this.forwarder = forwarder;
|
this.forwarder = forwarder;
|
||||||
forwarder.register(this);
|
forwarder.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
forwarder.start();
|
forwarder.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
forwarder.stop();
|
forwarder.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
forwarder.exit();
|
forwarder.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void receive(byte[] buffer);
|
abstract public void receive(byte[] buffer);
|
||||||
}
|
}
|
||||||
@@ -1,72 +1,72 @@
|
|||||||
package base.server.socket;
|
package base.server.socket;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public abstract class AbstractTcpClient extends Work implements Sender {
|
public abstract class AbstractTcpClient extends Work implements Sender {
|
||||||
protected static final int BUFFER_SIZE = 1024;
|
protected static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
protected Object object = new Object();
|
protected Object object = new Object();
|
||||||
protected int bufferSize;
|
protected int bufferSize;
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected InputStream inputStream;
|
protected InputStream inputStream;
|
||||||
protected OutputStream outputStream;
|
protected OutputStream outputStream;
|
||||||
|
|
||||||
public AbstractTcpClient(Integer bufferSize) {
|
public AbstractTcpClient(Integer bufferSize) {
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean active() {
|
public boolean active() {
|
||||||
return super.active() && socket.isConnected();
|
return super.active() && socket.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
super.deactivate();
|
super.deactivate();
|
||||||
try {
|
try {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
super.exit();
|
super.exit();
|
||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
try {
|
try {
|
||||||
while (inputStream.read(buffer) > 0) {
|
while (inputStream.read(buffer) > 0) {
|
||||||
input(buffer);
|
input(buffer);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void input(byte[] buffer);
|
protected abstract void input(byte[] buffer);
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
if (outputStream == null) {
|
if (outputStream == null) {
|
||||||
try {
|
try {
|
||||||
synchronized (object) {
|
synchronized (object) {
|
||||||
object.wait();
|
object.wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
outputStream.write(buffer);
|
outputStream.write(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,49 @@
|
|||||||
package base.server.socket;
|
package base.server.socket;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
|
|
||||||
public class TcpClient extends AbstractTcpClient implements Sender {
|
public class TcpClient extends AbstractTcpClient implements Sender {
|
||||||
protected static final String HOST = "localhost";
|
protected static final String HOST = "localhost";
|
||||||
|
|
||||||
protected String host;
|
protected String host;
|
||||||
protected int port;
|
protected int port;
|
||||||
|
|
||||||
public TcpClient(int port) {
|
public TcpClient(int port) {
|
||||||
this(HOST, port);
|
this(HOST, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpClient(String host, int port) {
|
public TcpClient(String host, int port) {
|
||||||
this(host, port, BUFFER_SIZE);
|
this(host, port, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpClient(String host, int port, int bufferSize) {
|
public TcpClient(String host, int port, int bufferSize) {
|
||||||
super(bufferSize);
|
super(bufferSize);
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
socket = new Socket(host, port);
|
socket = new Socket(host, port);
|
||||||
inputStream = socket.getInputStream();
|
inputStream = socket.getInputStream();
|
||||||
outputStream = socket.getOutputStream();
|
outputStream = socket.getOutputStream();
|
||||||
synchronized (object) {
|
synchronized (object) {
|
||||||
object.notifyAll();
|
object.notifyAll();
|
||||||
}
|
}
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {}
|
protected void input(byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,86 +1,86 @@
|
|||||||
package base.server.socket;
|
package base.server.socket;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import base.Sender;
|
import base.Sender;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class TcpServer extends Work implements Sender {
|
public class TcpServer extends Work implements Sender {
|
||||||
protected static final Class<?> CLIENT_CLASS = TcpServerClient.class;
|
protected static final Class<?> CLIENT_CLASS = TcpServerClient.class;
|
||||||
|
|
||||||
protected int port;
|
protected int port;
|
||||||
protected ServerSocket serverSocket;
|
protected ServerSocket serverSocket;
|
||||||
protected Constructor<?> clientConstructor;
|
protected Constructor<?> clientConstructor;
|
||||||
protected ArrayList<TcpServerClient> clientList;
|
protected ArrayList<TcpServerClient> clientList;
|
||||||
|
|
||||||
public TcpServer(int port) {
|
public TcpServer(int port) {
|
||||||
this(port, CLIENT_CLASS);
|
this(port, CLIENT_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpServer(int port, Class<?> clientClass) {
|
public TcpServer(int port, Class<?> clientClass) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
try {
|
try {
|
||||||
clientConstructor = Class.forName(clientClass.getName()).getConstructor(TcpServer.class, Socket.class);
|
clientConstructor = Class.forName(clientClass.getName()).getConstructor(TcpServer.class, Socket.class);
|
||||||
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
||||||
logger.error("Failed to initialise client constructor");
|
logger.error("Failed to initialise client constructor");
|
||||||
}
|
}
|
||||||
clientList = new ArrayList<TcpServerClient>();
|
clientList = new ArrayList<TcpServerClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(port);
|
serverSocket = new ServerSocket(port);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
for (TcpServerClient client : clientList) {
|
for (TcpServerClient client : clientList) {
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
super.exit();
|
super.exit();
|
||||||
try {
|
try {
|
||||||
serverSocket.close();
|
serverSocket.close();
|
||||||
for (TcpServerClient client : clientList) {
|
for (TcpServerClient client : clientList) {
|
||||||
client.exit();
|
client.exit();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
Socket socket = serverSocket.accept();
|
Socket socket = serverSocket.accept();
|
||||||
TcpServerClient client = (TcpServerClient) clientConstructor.newInstance(this, socket);
|
TcpServerClient client = (TcpServerClient) clientConstructor.newInstance(this, socket);
|
||||||
clientList.add(client);
|
clientList.add(client);
|
||||||
client.start();
|
client.start();
|
||||||
System.out.println("Accepted new connection from client: " + socket);
|
System.out.println("Accepted new connection from client: " + socket);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
stop();
|
stop();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] buffer) throws IOException {
|
public void send(byte[] buffer) throws IOException {
|
||||||
logger.debug("Number of clients = " + clientList.size());
|
logger.debug("Number of clients = " + clientList.size());
|
||||||
for (TcpServerClient client : clientList) {
|
for (TcpServerClient client : clientList) {
|
||||||
// Should be dealt with in clients own thread?
|
// Should be dealt with in clients own thread?
|
||||||
client.send(buffer);
|
client.send(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {}
|
public void input(TcpServerClient client, byte[] buffer) {}
|
||||||
}
|
}
|
||||||
@@ -1,37 +1,37 @@
|
|||||||
package base.server.socket;
|
package base.server.socket;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
|
|
||||||
public class TcpServerClient extends AbstractTcpClient {
|
public class TcpServerClient extends AbstractTcpClient {
|
||||||
private TcpServer server;
|
private TcpServer server;
|
||||||
|
|
||||||
public TcpServerClient(TcpServer server, Socket socket) {
|
public TcpServerClient(TcpServer server, Socket socket) {
|
||||||
this(server, socket, BUFFER_SIZE);
|
this(server, socket, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TcpServerClient(TcpServer server, Socket socket, Integer bufferSize) {
|
public TcpServerClient(TcpServer server, Socket socket, Integer bufferSize) {
|
||||||
super(bufferSize);
|
super(bufferSize);
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
try {
|
try {
|
||||||
inputStream = socket.getInputStream();
|
inputStream = socket.getInputStream();
|
||||||
outputStream = socket.getOutputStream();
|
outputStream = socket.getOutputStream();
|
||||||
synchronized (object) {
|
synchronized (object) {
|
||||||
object.notifyAll();
|
object.notifyAll();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
server.input(this, buffer);
|
server.input(this, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
package base.util;
|
package base.util;
|
||||||
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class ArrayCycle<E> extends CopyOnWriteArrayList<E> {
|
public class ArrayCycle<E> extends CopyOnWriteArrayList<E> {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected int index = 0;
|
protected int index = 0;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ArrayCycle(E... elementArray) {
|
public ArrayCycle(E... elementArray) {
|
||||||
if (elementArray != null) {
|
if (elementArray != null) {
|
||||||
for (E element : elementArray) {
|
for (E element : elementArray) {
|
||||||
add(element);
|
add(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public E current() {
|
public E current() {
|
||||||
return this.get(index);
|
return this.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized E previous() {
|
public synchronized E previous() {
|
||||||
if (--index < 0) {
|
if (--index < 0) {
|
||||||
index = Math.max(0, size() - 1);
|
index = Math.max(0, size() - 1);
|
||||||
}
|
}
|
||||||
return get(index);
|
return get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized E next() {
|
public synchronized E next() {
|
||||||
if (++index >= size()) {
|
if (++index >= size()) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
return size() == 0 ? null : get(index);
|
return size() == 0 ? null : get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public E reset() {
|
public E reset() {
|
||||||
return get(index = 0);
|
return get(index = 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
package base.util;
|
package base.util;
|
||||||
|
|
||||||
public class Buffer {
|
public class Buffer {
|
||||||
protected byte[] elements;
|
protected byte[] elements;
|
||||||
protected int capacity;
|
protected int capacity;
|
||||||
protected int index;
|
protected int index;
|
||||||
protected int size;
|
protected int size;
|
||||||
|
|
||||||
public Buffer(int capacity) {
|
public Buffer(int capacity) {
|
||||||
this.elements = new byte[capacity];
|
this.elements = new byte[capacity];
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
index = 0;
|
index = 0;
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void add(byte... elements) {
|
public synchronized void add(byte... elements) {
|
||||||
for (byte element : elements) {
|
for (byte element : elements) {
|
||||||
this.elements[index++ % capacity] = element;
|
this.elements[index++ % capacity] = element;
|
||||||
if (size < capacity) {
|
if (size < capacity) {
|
||||||
++size;
|
++size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void write(byte[] elements, int offset, int length) {
|
public synchronized void write(byte[] elements, int offset, int length) {
|
||||||
for (int i = offset; i < length; ++i) {
|
for (int i = offset; i < length; ++i) {
|
||||||
this.elements[index++ % capacity] = elements[i];
|
this.elements[index++ % capacity] = elements[i];
|
||||||
if (size < capacity) {
|
if (size < capacity) {
|
||||||
++size;
|
++size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized byte[] get() {
|
public synchronized byte[] get() {
|
||||||
byte[] elements = new byte[size];
|
byte[] elements = new byte[size];
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
elements[i] = this.elements[(index + i) % size];
|
elements[i] = this.elements[(index + i) % size];
|
||||||
}
|
}
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package base.util;
|
package base.util;
|
||||||
|
|
||||||
public interface Bufferable {
|
public interface Bufferable {
|
||||||
public void load();
|
public void load();
|
||||||
public void unload();
|
public void unload();
|
||||||
}
|
}
|
||||||
@@ -1,74 +1,74 @@
|
|||||||
package base.util;
|
package base.util;
|
||||||
|
|
||||||
public class BufferedArrayCycle<E extends Bufferable> extends ArrayCycle<E> {
|
public class BufferedArrayCycle<E extends Bufferable> extends ArrayCycle<E> {
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected ArrayCycle<? extends Bufferable> buffer;
|
protected ArrayCycle<? extends Bufferable> buffer;
|
||||||
protected int before;
|
protected int before;
|
||||||
protected int after;
|
protected int after;
|
||||||
protected int indexFirst;
|
protected int indexFirst;
|
||||||
protected int indexLast;
|
protected int indexLast;
|
||||||
//protected int indexBuffer;
|
//protected int indexBuffer;
|
||||||
//protected Bufferable[] bufferableArray;
|
//protected Bufferable[] bufferableArray;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BufferedArrayCycle(int before, int after) {
|
public BufferedArrayCycle(int before, int after) {
|
||||||
this.before = before;
|
this.before = before;
|
||||||
this.after = after;
|
this.after = after;
|
||||||
indexFirst = 0;
|
indexFirst = 0;
|
||||||
indexLast = 0;
|
indexLast = 0;
|
||||||
//bufferableArray = new Bufferable[before + after + 1];
|
//bufferableArray = new Bufferable[before + after + 1];
|
||||||
//buffer = new ArrayCycle<Bufferable>();
|
//buffer = new ArrayCycle<Bufferable>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public E previous() {
|
public E previous() {
|
||||||
get(indexFirst).unload();
|
get(indexFirst).unload();
|
||||||
indexFirst = previous(indexFirst);
|
indexFirst = previous(indexFirst);
|
||||||
indexLast = previous(indexLast);
|
indexLast = previous(indexLast);
|
||||||
get(indexLast).load();
|
get(indexLast).load();
|
||||||
// eerste before weg
|
// eerste before weg
|
||||||
|
|
||||||
// eerste after wordt huidig
|
// eerste after wordt huidig
|
||||||
|
|
||||||
// voeg laatste after toe
|
// voeg laatste after toe
|
||||||
|
|
||||||
return current();
|
return current();
|
||||||
}
|
}
|
||||||
|
|
||||||
public E next() {
|
public E next() {
|
||||||
|
|
||||||
// eerste before weg
|
// eerste before weg
|
||||||
|
|
||||||
// eerste after wordt huidig
|
// eerste after wordt huidig
|
||||||
|
|
||||||
// voeg laatste after toe
|
// voeg laatste after toe
|
||||||
|
|
||||||
return size() == 0 ? null : get(index);
|
return size() == 0 ? null : get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int previous(int index) {
|
protected int previous(int index) {
|
||||||
if (--index < 0) {
|
if (--index < 0) {
|
||||||
index = Math.max(0, size() - 1);
|
index = Math.max(0, size() - 1);
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int next(int index) {
|
protected int next(int index) {
|
||||||
System.out.println(index);
|
System.out.println(index);
|
||||||
if (++index >= size()) {
|
if (++index >= size()) {
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
BufferedArrayCycle<Dummy> bac = new BufferedArrayCycle<Dummy>(2, 3);
|
BufferedArrayCycle<Dummy> bac = new BufferedArrayCycle<Dummy>(2, 3);
|
||||||
for (int i = 1; i <= 10; ++i) {
|
for (int i = 1; i <= 10; ++i) {
|
||||||
bac.add(new Dummy(i));
|
bac.add(new Dummy(i));
|
||||||
}
|
}
|
||||||
bac.remove(0);
|
bac.remove(0);
|
||||||
System.out.println(bac.get(2).id);
|
System.out.println(bac.get(2).id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package base.util;
|
package base.util;
|
||||||
|
|
||||||
public class Dummy implements Bufferable {
|
public class Dummy implements Bufferable {
|
||||||
public int id;
|
public int id;
|
||||||
|
|
||||||
public Dummy(int id) {
|
public Dummy(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
System.out.println("Dummy #" + id + ": load()");
|
System.out.println("Dummy #" + id + ": load()");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unload() {
|
public void unload() {
|
||||||
System.out.println("Dummy #" + id + ": load()");
|
System.out.println("Dummy #" + id + ": load()");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package base.worker;
|
package base.worker;
|
||||||
|
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class DirectIntervalWorker extends ThreadIntervalWorker {
|
public class DirectIntervalWorker extends ThreadIntervalWorker {
|
||||||
public DirectIntervalWorker(Work work, int interval) {
|
public DirectIntervalWorker(Work work, int interval) {
|
||||||
super(work, false);
|
super(work, false);
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectIntervalWorker(IntervalWork intervalWork) {
|
public DirectIntervalWorker(IntervalWork intervalWork) {
|
||||||
super(intervalWork);
|
super(intervalWork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package base.worker;
|
package base.worker;
|
||||||
|
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class DirectWorker extends ThreadWorker {
|
public class DirectWorker extends ThreadWorker {
|
||||||
public DirectWorker(Work work) {
|
public DirectWorker(Work work) {
|
||||||
super(work, false);
|
super(work, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package base.worker;
|
package base.worker;
|
||||||
|
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
import base.worker.pool.Listener;
|
import base.worker.pool.Listener;
|
||||||
|
|
||||||
public class ForegroundListener<E> extends BackgroundListener<E> implements Listener<E> {
|
public class ForegroundListener<E> extends BackgroundListener<E> implements Listener<E> {
|
||||||
public ForegroundListener(Listen<E> listen) {
|
public ForegroundListener(Listen<E> listen) {
|
||||||
super(listen, false);
|
super(listen, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,37 +1,37 @@
|
|||||||
package base.worker;
|
package base.worker;
|
||||||
|
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public abstract class IntervalWork extends Work {
|
public abstract class IntervalWork extends Work {
|
||||||
protected IntervalWork() {
|
protected IntervalWork() {
|
||||||
this(WORKER_TYPE);
|
this(WORKER_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IntervalWork(int interval) {
|
protected IntervalWork(int interval) {
|
||||||
this(WORKER_TYPE, interval);
|
this(WORKER_TYPE, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IntervalWork(Worker.Type workerType) {
|
protected IntervalWork(Worker.Type workerType) {
|
||||||
switch (workerType) {
|
switch (workerType) {
|
||||||
case FOREGROUND:
|
case FOREGROUND:
|
||||||
worker = new DirectIntervalWorker(this);
|
worker = new DirectIntervalWorker(this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case BACKGROUND:
|
case BACKGROUND:
|
||||||
worker = new ThreadIntervalWorker(this);
|
worker = new ThreadIntervalWorker(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IntervalWork(Worker.Type workerType, int interval) {
|
protected IntervalWork(Worker.Type workerType, int interval) {
|
||||||
switch (workerType) {
|
switch (workerType) {
|
||||||
case FOREGROUND:
|
case FOREGROUND:
|
||||||
worker = new DirectIntervalWorker(this, interval);
|
worker = new DirectIntervalWorker(this, interval);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case BACKGROUND:
|
case BACKGROUND:
|
||||||
worker = new ThreadIntervalWorker(this, interval);
|
worker = new ThreadIntervalWorker(this, interval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
public interface Listener<E> {
|
public interface Listener<E> {
|
||||||
public void add(E element);
|
public void add(E element);
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,38 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ListenerPool<E> {
|
public class ListenerPool<E> {
|
||||||
protected int poolSize;
|
protected int poolSize;
|
||||||
protected BlockingQueue<Wrapper<E>> queue;
|
protected BlockingQueue<Wrapper<E>> queue;
|
||||||
protected ExecutorService executorService;
|
protected ExecutorService executorService;
|
||||||
|
|
||||||
public ListenerPool(int poolSize) {
|
public ListenerPool(int poolSize) {
|
||||||
this.poolSize = poolSize;
|
this.poolSize = poolSize;
|
||||||
queue = new LinkedBlockingQueue<Wrapper<E>>();
|
queue = new LinkedBlockingQueue<Wrapper<E>>();
|
||||||
executorService = Executors.newFixedThreadPool(poolSize);
|
executorService = Executors.newFixedThreadPool(poolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledListener<E> add(PooledListener<E> listener) {
|
public PooledListener<E> add(PooledListener<E> listener) {
|
||||||
listener.setPoolQueue(queue);
|
listener.setPoolQueue(queue);
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
for (int i = 0; i < poolSize; ++i) {
|
for (int i = 0; i < poolSize; ++i) {
|
||||||
Runnable runnable = new ListenerPoolRunnable<E>(queue, i);
|
Runnable runnable = new ListenerPoolRunnable<E>(queue, i);
|
||||||
executorService.execute(runnable);
|
executorService.execute(runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void await() {
|
public void await() {
|
||||||
try {
|
try {
|
||||||
executorService.awaitTermination(0, TimeUnit.SECONDS);
|
executorService.awaitTermination(0, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
class ListenerPoolRunnable<E> implements Runnable {
|
class ListenerPoolRunnable<E> implements Runnable {
|
||||||
protected BlockingQueue<Wrapper<E>> queue;
|
protected BlockingQueue<Wrapper<E>> queue;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public ListenerPoolRunnable(BlockingQueue<Wrapper<E>> queue, int id) {
|
public ListenerPoolRunnable(BlockingQueue<Wrapper<E>> queue, int id) {
|
||||||
this.queue = queue;
|
this.queue = queue;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.println("Thread #" + id + " waiting...");
|
System.out.println("Thread #" + id + " waiting...");
|
||||||
Wrapper<E> wrapper = queue.take();
|
Wrapper<E> wrapper = queue.take();
|
||||||
wrapper.deliver();
|
wrapper.deliver();
|
||||||
Thread.sleep((int) (Math.random() * 1000));
|
Thread.sleep((int) (Math.random() * 1000));
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
|
|
||||||
public class PooledListener<E> extends PooledWorker implements Listener<E> {
|
public class PooledListener<E> extends PooledWorker implements Listener<E> {
|
||||||
protected BlockingQueue<Wrapper<E>> poolQueue;
|
protected BlockingQueue<Wrapper<E>> poolQueue;
|
||||||
protected Listen<E> listen;
|
protected Listen<E> listen;
|
||||||
|
|
||||||
public PooledListener(Listen<E> listen) {
|
public PooledListener(Listen<E> listen) {
|
||||||
super(listen);
|
super(listen);
|
||||||
this.listen = listen;
|
this.listen = listen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoolQueue(BlockingQueue<Wrapper<E>> poolQueue) {
|
public void setPoolQueue(BlockingQueue<Wrapper<E>> poolQueue) {
|
||||||
this.poolQueue = poolQueue;
|
this.poolQueue = poolQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void add(E element) {
|
public synchronized void add(E element) {
|
||||||
Wrapper<E> wrapper = new Wrapper<E>(this, element);
|
Wrapper<E> wrapper = new Wrapper<E>(this, element);
|
||||||
poolQueue.add(wrapper);
|
poolQueue.add(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(E element) {
|
void input(E element) {
|
||||||
listen.input(element);
|
listen.input(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,49 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
import base.worker.Worker;
|
import base.worker.Worker;
|
||||||
|
|
||||||
public class PooledWorker extends Worker {
|
public class PooledWorker extends Worker {
|
||||||
protected BlockingQueue<Worker> activateQueue;
|
protected BlockingQueue<Worker> activateQueue;
|
||||||
protected BlockingQueue<Worker> deactivateQueue;
|
protected BlockingQueue<Worker> deactivateQueue;
|
||||||
|
|
||||||
public PooledWorker(Work work) {
|
public PooledWorker(Work work) {
|
||||||
super(work);
|
super(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivateQueue(BlockingQueue<Worker> activateQueue) {
|
public void setActivateQueue(BlockingQueue<Worker> activateQueue) {
|
||||||
this.activateQueue = activateQueue;
|
this.activateQueue = activateQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeactivateQueue(BlockingQueue<Worker> deactivateQueue) {
|
public void setDeactivateQueue(BlockingQueue<Worker> deactivateQueue) {
|
||||||
this.deactivateQueue = deactivateQueue;
|
this.deactivateQueue = deactivateQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
activate = true;
|
activate = true;
|
||||||
}
|
}
|
||||||
if (!run) {
|
if (!run) {
|
||||||
run = true;
|
run = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
deactivateQueue.remove(this);
|
deactivateQueue.remove(this);
|
||||||
activateQueue.put(this);
|
activateQueue.put(this);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
System.out.println("stop!! " + active);
|
System.out.println("stop!! " + active);
|
||||||
if (active) {
|
if (active) {
|
||||||
deactivate = true;
|
deactivate = true;
|
||||||
}
|
}
|
||||||
activateQueue.remove(this);
|
activateQueue.remove(this);
|
||||||
deactivateQueue.add(this);
|
deactivateQueue.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,42 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import base.util.ArrayCycle;
|
import base.util.ArrayCycle;
|
||||||
import base.worker.Worker;
|
import base.worker.Worker;
|
||||||
|
|
||||||
public class WorkerPool {
|
public class WorkerPool {
|
||||||
protected int poolSize;
|
protected int poolSize;
|
||||||
protected BlockingQueue<Worker> activateQueue;
|
protected BlockingQueue<Worker> activateQueue;
|
||||||
protected BlockingQueue<Worker> deactivateQueue;
|
protected BlockingQueue<Worker> deactivateQueue;
|
||||||
protected ArrayCycle<Worker> workerCycle;
|
protected ArrayCycle<Worker> workerCycle;
|
||||||
protected ExecutorService executorService;
|
protected ExecutorService executorService;
|
||||||
|
|
||||||
public WorkerPool(int poolSize) {
|
public WorkerPool(int poolSize) {
|
||||||
this.poolSize = poolSize;
|
this.poolSize = poolSize;
|
||||||
activateQueue = new LinkedBlockingQueue<Worker>();
|
activateQueue = new LinkedBlockingQueue<Worker>();
|
||||||
deactivateQueue = new LinkedBlockingQueue<Worker>();
|
deactivateQueue = new LinkedBlockingQueue<Worker>();
|
||||||
workerCycle = new ArrayCycle<Worker>();
|
workerCycle = new ArrayCycle<Worker>();
|
||||||
executorService = Executors.newFixedThreadPool(poolSize);
|
executorService = Executors.newFixedThreadPool(poolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
for (int i = 0; i < poolSize; ++i) {
|
for (int i = 0; i < poolSize; ++i) {
|
||||||
Runnable runnable = new WorkerPoolRunnable(activateQueue, deactivateQueue, workerCycle, i + 1);
|
Runnable runnable = new WorkerPoolRunnable(activateQueue, deactivateQueue, workerCycle, i + 1);
|
||||||
executorService.execute(runnable);
|
executorService.execute(runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
// Must be graceful
|
// Must be graceful
|
||||||
executorService.shutdownNow();
|
executorService.shutdownNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PooledWorker worker) {
|
public void add(PooledWorker worker) {
|
||||||
worker.setActivateQueue(activateQueue);
|
worker.setActivateQueue(activateQueue);
|
||||||
worker.setDeactivateQueue(deactivateQueue);
|
worker.setDeactivateQueue(deactivateQueue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
import base.util.ArrayCycle;
|
import base.util.ArrayCycle;
|
||||||
import base.worker.Worker;
|
import base.worker.Worker;
|
||||||
|
|
||||||
public class WorkerPoolRunnable implements Runnable {
|
public class WorkerPoolRunnable implements Runnable {
|
||||||
protected BlockingQueue<Worker> activateQueue;
|
protected BlockingQueue<Worker> activateQueue;
|
||||||
protected BlockingQueue<Worker> deactivateQueue;
|
protected BlockingQueue<Worker> deactivateQueue;
|
||||||
protected ArrayCycle<Worker> workerCycle;
|
protected ArrayCycle<Worker> workerCycle;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public WorkerPoolRunnable(BlockingQueue<Worker> activateQueue, BlockingQueue<Worker> deactivateQueue, ArrayCycle<Worker> workerCycle, int id) {
|
public WorkerPoolRunnable(BlockingQueue<Worker> activateQueue, BlockingQueue<Worker> deactivateQueue, ArrayCycle<Worker> workerCycle, int id) {
|
||||||
this.activateQueue = activateQueue;
|
this.activateQueue = activateQueue;
|
||||||
this.deactivateQueue = deactivateQueue;
|
this.deactivateQueue = deactivateQueue;
|
||||||
this.workerCycle = workerCycle;
|
this.workerCycle = workerCycle;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!deactivateQueue.isEmpty()) {
|
if (!deactivateQueue.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Worker worker = deactivateQueue.take();
|
Worker worker = deactivateQueue.take();
|
||||||
worker.runDeactivate();
|
worker.runDeactivate();
|
||||||
workerCycle.remove(worker);
|
workerCycle.remove(worker);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
} else if (!activateQueue.isEmpty() || workerCycle.isEmpty()) {
|
} else if (!activateQueue.isEmpty() || workerCycle.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Worker worker = activateQueue.take();
|
Worker worker = activateQueue.take();
|
||||||
worker.runActivate();
|
worker.runActivate();
|
||||||
workerCycle.add(worker);
|
workerCycle.add(worker);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
} else {
|
} else {
|
||||||
Worker worker = workerCycle.next();
|
Worker worker = workerCycle.next();
|
||||||
worker.runWork();
|
worker.runWork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package base.worker.pool;
|
package base.worker.pool;
|
||||||
|
|
||||||
|
|
||||||
class Wrapper<E> {
|
class Wrapper<E> {
|
||||||
protected PooledListener<E> listener;
|
protected PooledListener<E> listener;
|
||||||
protected E element;
|
protected E element;
|
||||||
|
|
||||||
public Wrapper(PooledListener<E> listener, E element) {
|
public Wrapper(PooledListener<E> listener, E element) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deliver() {
|
public void deliver() {
|
||||||
listener.input(element);
|
listener.input(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,94 +1,94 @@
|
|||||||
package junit;
|
package junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import base.server.channel.TcpClient;
|
import base.server.channel.TcpClient;
|
||||||
import base.server.channel.TcpServer;
|
import base.server.channel.TcpServer;
|
||||||
import base.server.channel.TcpServerClient;
|
import base.server.channel.TcpServerClient;
|
||||||
|
|
||||||
public class TestTcpChannelCommunication {
|
public class TestTcpChannelCommunication {
|
||||||
protected TestTcpServer server;
|
protected TestTcpServer server;
|
||||||
protected TestTcpClient client;
|
protected TestTcpClient client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
server = new TestTcpServer(1234);
|
server = new TestTcpServer(1234);
|
||||||
server.start();
|
server.start();
|
||||||
client = new TestTcpClient(1234);
|
client = new TestTcpClient(1234);
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
client.exit();
|
client.exit();
|
||||||
server.exit();
|
server.exit();
|
||||||
|
|
||||||
// Should add blocking stop and exit to worker
|
// Should add blocking stop and exit to worker
|
||||||
while (client.active() || server.active()) {
|
while (client.active() || server.active()) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendClientToServer() throws Exception {
|
public void testSendClientToServer() throws Exception {
|
||||||
String message = "test";
|
String message = "test";
|
||||||
client.send(message.getBytes());
|
client.send(message.getBytes());
|
||||||
synchronized (server) {
|
synchronized (server) {
|
||||||
server.wait(2000);
|
server.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = server.buffer;
|
byte[] buffer = server.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendServerToClient() throws Exception {
|
public void testSendServerToClient() throws Exception {
|
||||||
// If client can send, connection has been established
|
// If client can send, connection has been established
|
||||||
client.send("init".getBytes());
|
client.send("init".getBytes());
|
||||||
|
|
||||||
String message = "test";
|
String message = "test";
|
||||||
server.send(message.getBytes());
|
server.send(message.getBytes());
|
||||||
synchronized (client) {
|
synchronized (client) {
|
||||||
client.wait(2000);
|
client.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = client.buffer;
|
byte[] buffer = client.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestTcpServer extends TcpServer {
|
class TestTcpServer extends TcpServer {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestTcpServer(int port) {
|
public TestTcpServer(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestTcpClient extends TcpClient {
|
class TestTcpClient extends TcpClient {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestTcpClient(int port) {
|
public TestTcpClient(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {
|
protected void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,93 +1,93 @@
|
|||||||
package junit;
|
package junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import base.server.socket.TcpClient;
|
import base.server.socket.TcpClient;
|
||||||
import base.server.socket.TcpServer;
|
import base.server.socket.TcpServer;
|
||||||
import base.server.socket.TcpServerClient;
|
import base.server.socket.TcpServerClient;
|
||||||
|
|
||||||
public class TestTcpSocketCommunication {
|
public class TestTcpSocketCommunication {
|
||||||
protected TestTcpServer server;
|
protected TestTcpServer server;
|
||||||
protected TestTcpClient client;
|
protected TestTcpClient client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
server = new TestTcpServer(1234);
|
server = new TestTcpServer(1234);
|
||||||
server.start();
|
server.start();
|
||||||
client = new TestTcpClient(1234);
|
client = new TestTcpClient(1234);
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
client.exit();
|
client.exit();
|
||||||
server.exit();
|
server.exit();
|
||||||
|
|
||||||
// Should add blocking stop and exit to worker
|
// Should add blocking stop and exit to worker
|
||||||
while (client.active() || server.active()) {
|
while (client.active() || server.active()) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendClientToServer() throws Exception {
|
public void testSendClientToServer() throws Exception {
|
||||||
String message = "test";
|
String message = "test";
|
||||||
client.send(message.getBytes());
|
client.send(message.getBytes());
|
||||||
synchronized (server) {
|
synchronized (server) {
|
||||||
server.wait(2000);
|
server.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = server.buffer;
|
byte[] buffer = server.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendServerToClient() throws Exception {
|
public void testSendServerToClient() throws Exception {
|
||||||
// If client can send, connection has been established
|
// If client can send, connection has been established
|
||||||
client.send("init".getBytes());
|
client.send("init".getBytes());
|
||||||
|
|
||||||
String message = "test";
|
String message = "test";
|
||||||
server.send(message.getBytes());
|
server.send(message.getBytes());
|
||||||
synchronized (client) {
|
synchronized (client) {
|
||||||
client.wait(2000);
|
client.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = client.buffer;
|
byte[] buffer = client.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestTcpServer extends TcpServer {
|
class TestTcpServer extends TcpServer {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestTcpServer(int port) {
|
public TestTcpServer(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(TcpServerClient client, byte[] buffer) {
|
public void input(TcpServerClient client, byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestTcpClient extends TcpClient {
|
class TestTcpClient extends TcpClient {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestTcpClient(int port) {
|
public TestTcpClient(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void input(byte[] buffer) {
|
protected void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,96 +1,96 @@
|
|||||||
package junit;
|
package junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import base.server.datagram.UdpDuplexAutoClient;
|
import base.server.datagram.UdpDuplexAutoClient;
|
||||||
import base.server.datagram.UdpDuplexServer;
|
import base.server.datagram.UdpDuplexServer;
|
||||||
|
|
||||||
public class TestUdpDuplexCommunication {
|
public class TestUdpDuplexCommunication {
|
||||||
protected TestUdpDuplexServer server;
|
protected TestUdpDuplexServer server;
|
||||||
protected TestUdpDuplexClient client;
|
protected TestUdpDuplexClient client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
server = new TestUdpDuplexServer(1234, 1235);
|
server = new TestUdpDuplexServer(1234, 1235);
|
||||||
server.start();
|
server.start();
|
||||||
client = new TestUdpDuplexClient(1234, 1235);
|
client = new TestUdpDuplexClient(1234, 1235);
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
client.exit();
|
client.exit();
|
||||||
server.exit();
|
server.exit();
|
||||||
|
|
||||||
// Should add blocking stop and exit to worker
|
// Should add blocking stop and exit to worker
|
||||||
while (client.active() || server.active()) {
|
while (client.active() || server.active()) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerToClientCommunication() throws Exception {
|
public void testServerToClientCommunication() throws Exception {
|
||||||
String message = "test";
|
String message = "test";
|
||||||
server.send(message.getBytes());
|
server.send(message.getBytes());
|
||||||
System.err.println("send");
|
System.err.println("send");
|
||||||
synchronized (client) {
|
synchronized (client) {
|
||||||
client.wait(2000);
|
client.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = client.buffer;
|
byte[] buffer = client.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClientToServerCommunication() throws Exception {
|
public void testClientToServerCommunication() throws Exception {
|
||||||
// Let client discover server address
|
// Let client discover server address
|
||||||
testServerToClientCommunication();
|
testServerToClientCommunication();
|
||||||
|
|
||||||
String message = "test";
|
String message = "test";
|
||||||
client.send(message.getBytes());
|
client.send(message.getBytes());
|
||||||
System.err.println("send");
|
System.err.println("send");
|
||||||
synchronized (server) {
|
synchronized (server) {
|
||||||
server.wait(2000);
|
server.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = server.buffer;
|
byte[] buffer = server.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestUdpDuplexServer extends UdpDuplexServer {
|
public class TestUdpDuplexServer extends UdpDuplexServer {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestUdpDuplexServer(int sendPort, int bindPort) {
|
public TestUdpDuplexServer(int sendPort, int bindPort) {
|
||||||
super(sendPort, bindPort);
|
super(sendPort, bindPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestUdpDuplexClient extends UdpDuplexAutoClient {
|
class TestUdpDuplexClient extends UdpDuplexAutoClient {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestUdpDuplexClient(int bindPort, int sendPort) throws UnknownHostException {
|
public TestUdpDuplexClient(int bindPort, int sendPort) throws UnknownHostException {
|
||||||
super(bindPort, sendPort);
|
super(bindPort, sendPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,63 +1,63 @@
|
|||||||
package junit;
|
package junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import base.server.datagram.UdpMulticastClient;
|
import base.server.datagram.UdpMulticastClient;
|
||||||
import base.server.datagram.UdpMulticastServer;
|
import base.server.datagram.UdpMulticastServer;
|
||||||
|
|
||||||
public class TestUdpMulticastCommunication {
|
public class TestUdpMulticastCommunication {
|
||||||
protected UdpMulticastServer server;
|
protected UdpMulticastServer server;
|
||||||
protected TestUdpMulticastClient client;
|
protected TestUdpMulticastClient client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
server = new UdpMulticastServer(1234);
|
server = new UdpMulticastServer(1234);
|
||||||
server.start();
|
server.start();
|
||||||
client = new TestUdpMulticastClient(1234);
|
client = new TestUdpMulticastClient(1234);
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
client.exit();
|
client.exit();
|
||||||
server.exit();
|
server.exit();
|
||||||
|
|
||||||
// Should add blocking stop and exit to worker
|
// Should add blocking stop and exit to worker
|
||||||
while (client.active() || server.active()) {
|
while (client.active() || server.active()) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerToClientCommunication() throws Exception {
|
public void testServerToClientCommunication() throws Exception {
|
||||||
String message = "test";
|
String message = "test";
|
||||||
server.send(message.getBytes());
|
server.send(message.getBytes());
|
||||||
System.err.println("send");
|
System.err.println("send");
|
||||||
synchronized (client) {
|
synchronized (client) {
|
||||||
client.wait(2000);
|
client.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = client.buffer;
|
byte[] buffer = client.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestUdpMulticastClient extends UdpMulticastClient {
|
class TestUdpMulticastClient extends UdpMulticastClient {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestUdpMulticastClient(int port) {
|
public TestUdpMulticastClient(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
public void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,61 +1,61 @@
|
|||||||
package junit;
|
package junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import base.server.datagram.UdpSender;
|
import base.server.datagram.UdpSender;
|
||||||
import base.server.datagram.UdpServer;
|
import base.server.datagram.UdpServer;
|
||||||
|
|
||||||
public class TestUdpUnicastCommunication {
|
public class TestUdpUnicastCommunication {
|
||||||
protected TestUdpServer server;
|
protected TestUdpServer server;
|
||||||
protected UdpSender sender;
|
protected UdpSender sender;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
server = new TestUdpServer(1234);
|
server = new TestUdpServer(1234);
|
||||||
server.start();
|
server.start();
|
||||||
sender = new UdpSender(1234);
|
sender = new UdpSender(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
server.exit();
|
server.exit();
|
||||||
|
|
||||||
// Should add blocking stop and exit to worker
|
// Should add blocking stop and exit to worker
|
||||||
while (server.active()) {
|
while (server.active()) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendClientToServer() throws Exception {
|
public void testSendClientToServer() throws Exception {
|
||||||
String message = "test";
|
String message = "test";
|
||||||
sender.send(message.getBytes());
|
sender.send(message.getBytes());
|
||||||
synchronized (server) {
|
synchronized (server) {
|
||||||
server.wait(2000);
|
server.wait(2000);
|
||||||
}
|
}
|
||||||
byte[] buffer = server.buffer;
|
byte[] buffer = server.buffer;
|
||||||
assertNotNull("Received input", buffer);
|
assertNotNull("Received input", buffer);
|
||||||
assertEquals("Message intact", message, new String(buffer).trim());
|
assertEquals("Message intact", message, new String(buffer).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestUdpServer extends UdpServer {
|
class TestUdpServer extends UdpServer {
|
||||||
public byte[] buffer;
|
public byte[] buffer;
|
||||||
|
|
||||||
public TestUdpServer(int port) {
|
public TestUdpServer(int port) {
|
||||||
super(port);
|
super(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void input(byte[] buffer) {
|
protected void input(byte[] buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,54 +1,54 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
new Test().start();
|
new Test().start();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void start() throws Throwable {
|
private void start() throws Throwable {
|
||||||
input((Object) new A());
|
input((Object) new A());
|
||||||
input((Object) new B());
|
input((Object) new B());
|
||||||
input((Object) new String[] {"a", "b"});
|
input((Object) new String[] {"a", "b"});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(Object object) throws Throwable {
|
public void input(Object object) throws Throwable {
|
||||||
System.out.println("Object");
|
System.out.println("Object");
|
||||||
MethodType methodType = MethodType.methodType(void.class, object.getClass());
|
MethodType methodType = MethodType.methodType(void.class, object.getClass());
|
||||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||||
MethodHandle methodHandle = lookup.findVirtual(getClass(), "input", methodType);
|
MethodHandle methodHandle = lookup.findVirtual(getClass(), "input", methodType);
|
||||||
try {
|
try {
|
||||||
methodHandle.invoke(this, object);
|
methodHandle.invoke(this, object);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(A object) {
|
public void input(A object) {
|
||||||
System.out.println("A");
|
System.out.println("A");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(B object) {
|
public void input(B object) {
|
||||||
System.out.println("B");
|
System.out.println("B");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(String[] object) {
|
public void input(String[] object) {
|
||||||
System.out.println("String[]");
|
System.out.println("String[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class A {
|
public class A {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class B {
|
public class B {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package worker;
|
package worker;
|
||||||
|
|
||||||
import worker.dummy.DummyWork;
|
import worker.dummy.DummyWork;
|
||||||
|
|
||||||
|
|
||||||
public class TestDirectWork {
|
public class TestDirectWork {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
DummyWork work = new DummyWork(1);
|
DummyWork work = new DummyWork(1);
|
||||||
work.setWork(100);
|
work.setWork(100);
|
||||||
work.start();
|
work.start();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package worker;
|
package worker;
|
||||||
|
|
||||||
import worker.dummy.DummyIntervalWork;
|
import worker.dummy.DummyIntervalWork;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
|
|
||||||
public class TestIntervalWork {
|
public class TestIntervalWork {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Work work = new DummyIntervalWork(500);
|
Work work = new DummyIntervalWork(500);
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
work.start();
|
work.start();
|
||||||
System.out.println("--");
|
System.out.println("--");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
work.stop();
|
work.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
package worker;
|
package worker;
|
||||||
|
|
||||||
import worker.dummy.DummyListen;
|
import worker.dummy.DummyListen;
|
||||||
|
|
||||||
public class TestListen {
|
public class TestListen {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
DummyListen<Integer> listen = new DummyListen<Integer>(0);
|
DummyListen<Integer> listen = new DummyListen<Integer>(0);
|
||||||
listen.start();
|
listen.start();
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
listen.add(i);
|
listen.add(i);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,38 @@
|
|||||||
package worker;
|
package worker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import worker.dummy.DummyListen;
|
import worker.dummy.DummyListen;
|
||||||
import base.worker.pool.ListenerPool;
|
import base.worker.pool.ListenerPool;
|
||||||
|
|
||||||
public class TestPooledListen {
|
public class TestPooledListen {
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public TestPooledListen(int id) {
|
public TestPooledListen(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(Integer element) {
|
public void input(Integer element) {
|
||||||
System.out.println("#" + id + ": " + element);
|
System.out.println("#" + id + ": " + element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ListenerPool<Integer> listenerPool = new ListenerPool<Integer>(5);
|
ListenerPool<Integer> listenerPool = new ListenerPool<Integer>(5);
|
||||||
List<DummyListen<Integer>> listenList = new ArrayList<DummyListen<Integer>>();
|
List<DummyListen<Integer>> listenList = new ArrayList<DummyListen<Integer>>();
|
||||||
for (int i = 0; i < 20; ++i) {
|
for (int i = 0; i < 20; ++i) {
|
||||||
DummyListen<Integer> listen = new DummyListen<Integer>(listenerPool, i + 1);
|
DummyListen<Integer> listen = new DummyListen<Integer>(listenerPool, i + 1);
|
||||||
listenList.add(listen);
|
listenList.add(listen);
|
||||||
}
|
}
|
||||||
listenerPool.start();
|
listenerPool.start();
|
||||||
|
|
||||||
System.out.println("Starting to give out elements!");
|
System.out.println("Starting to give out elements!");
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
DummyListen<Integer> randomListen = listenList.get((new Random()).nextInt(listenList.size()));
|
DummyListen<Integer> randomListen = listenList.get((new Random()).nextInt(listenList.size()));
|
||||||
randomListen.add(i);
|
randomListen.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
//listenerPool.await();
|
//listenerPool.await();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,45 @@
|
|||||||
package worker;
|
package worker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import worker.dummy.DummyWork;
|
import worker.dummy.DummyWork;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
import base.worker.pool.WorkerPool;
|
import base.worker.pool.WorkerPool;
|
||||||
|
|
||||||
public class TestPooledWork {
|
public class TestPooledWork {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
WorkerPool workerPool = new WorkerPool(3);
|
WorkerPool workerPool = new WorkerPool(3);
|
||||||
|
|
||||||
List<DummyWork> workList = new ArrayList<DummyWork>();
|
List<DummyWork> workList = new ArrayList<DummyWork>();
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
DummyWork work = new DummyWork(workerPool, i + 1);
|
DummyWork work = new DummyWork(workerPool, i + 1);
|
||||||
workList.add(work);
|
workList.add(work);
|
||||||
}
|
}
|
||||||
workerPool.start();
|
workerPool.start();
|
||||||
|
|
||||||
System.out.println("Starting work!");
|
System.out.println("Starting work!");
|
||||||
ArrayList<Work> activeWorkList = new ArrayList<Work>();
|
ArrayList<Work> activeWorkList = new ArrayList<Work>();
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
DummyWork work = workList.get((new Random()).nextInt(workList.size()));
|
DummyWork work = workList.get((new Random()).nextInt(workList.size()));
|
||||||
work.setWork(1000);
|
work.setWork(1000);
|
||||||
work.start();
|
work.start();
|
||||||
activeWorkList.add(work);
|
activeWorkList.add(work);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Work work : activeWorkList) {
|
for (Work work : activeWorkList) {
|
||||||
if (++i > 5) {
|
if (++i > 5) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
work.stop();
|
work.stop();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100000);
|
Thread.sleep(100000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package worker.dummy;
|
package worker.dummy;
|
||||||
|
|
||||||
import base.worker.IntervalWork;
|
import base.worker.IntervalWork;
|
||||||
|
|
||||||
public class DummyIntervalWork extends IntervalWork {
|
public class DummyIntervalWork extends IntervalWork {
|
||||||
public DummyIntervalWork(int interval) {
|
public DummyIntervalWork(int interval) {
|
||||||
super(interval);
|
super(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
System.out.println(":-)");
|
System.out.println(":-)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,26 @@
|
|||||||
package worker.dummy;
|
package worker.dummy;
|
||||||
|
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
import base.worker.pool.ListenerPool;
|
import base.worker.pool.ListenerPool;
|
||||||
|
|
||||||
public class DummyListen<T> extends Listen<T> {
|
public class DummyListen<T> extends Listen<T> {
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public DummyListen(ListenerPool<T> listenerPool, int id) {
|
public DummyListen(ListenerPool<T> listenerPool, int id) {
|
||||||
super(listenerPool);
|
super(listenerPool);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DummyListen(int id) {
|
public DummyListen(int id) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(Integer input) {
|
public void input(Integer input) {
|
||||||
System.out.println("#" + id + ", input = " + input);
|
System.out.println("#" + id + ", input = " + input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(byte[] input) {
|
public void input(byte[] input) {
|
||||||
System.out.println("#" + id + ", input = " + new String(input).trim());
|
System.out.println("#" + id + ", input = " + new String(input).trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,42 @@
|
|||||||
package worker.dummy;
|
package worker.dummy;
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.work.Work;
|
import base.work.Work;
|
||||||
import base.worker.pool.WorkerPool;
|
import base.worker.pool.WorkerPool;
|
||||||
|
|
||||||
public class DummyWork extends Work {
|
public class DummyWork extends Work {
|
||||||
protected int id;
|
protected int id;
|
||||||
protected volatile int work;
|
protected volatile int work;
|
||||||
|
|
||||||
public DummyWork(int id) {
|
public DummyWork(int id) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DummyWork(WorkerPool workerPool, int id) {
|
public DummyWork(WorkerPool workerPool, int id) {
|
||||||
super(workerPool);
|
super(workerPool);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWork(int work) {
|
public void setWork(int work) {
|
||||||
System.out.println("#" + id + ", set work @ " + work);
|
System.out.println("#" + id + ", set work @ " + work);
|
||||||
this.work = work;
|
this.work = work;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work() {
|
public void work() {
|
||||||
System.out.println("#" + id + ", work = " + work);
|
System.out.println("#" + id + ", work = " + work);
|
||||||
if (--work < 1) {
|
if (--work < 1) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
sleep(300);
|
sleep(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
System.out.println("#" + id + ", activating...");
|
System.out.println("#" + id + ", activating...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
System.out.println("#" + id + ", deactivating...");
|
System.out.println("#" + id + ", deactivating...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0
java/core.networking/build.gradle
Normal file
0
java/core.networking/build.gradle
Normal file
0
java/core.routing/build.gradle
Normal file
0
java/core.routing/build.gradle
Normal file
0
java/core.worker/build.gradle
Normal file
0
java/core.worker/build.gradle
Normal file
0
java/device.lirc/build.gradle
Normal file
0
java/device.lirc/build.gradle
Normal file
6
java/exec.connected/.gitignore
vendored
6
java/exec.connected/.gitignore
vendored
@@ -1,6 +0,0 @@
|
|||||||
/.gradle
|
|
||||||
/.settings
|
|
||||||
/.classpath
|
|
||||||
/.project
|
|
||||||
/bin
|
|
||||||
/build
|
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'maven'
|
|
||||||
apply plugin: 'eclipse'
|
|
||||||
apply plugin: 'license'
|
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
|
||||||
gradleVersion = '2.2'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':base')
|
compile project(':core.legacy')
|
||||||
|
|
||||||
compile 'com.github.boukefalos:jlibmimis:0.1'
|
compile 'com.github.boukefalos:jlibmimis:0.1'
|
||||||
compile 'com.github.boukefalos:jlibitunes:0.3'
|
compile 'com.github.boukefalos:jlibitunes:0.3'
|
||||||
@@ -31,19 +22,6 @@ buildscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
license {
|
|
||||||
header rootProject.file('HEADER.txt')
|
|
||||||
strictCheck true
|
|
||||||
|
|
||||||
skipExistingHeaders false
|
|
||||||
ext.year = Calendar.getInstance().get(Calendar.YEAR)
|
|
||||||
ext.name = 'Rik Veenboer'
|
|
||||||
ext.email = 'rik.veenboer@gmail.com'
|
|
||||||
ext.project = 'this program'
|
|
||||||
ext.Project = 'This program'
|
|
||||||
include "**/*.java"
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
manifest {
|
manifest {
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user