Skip to content

Commit

Permalink
0.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 12, 2020
1 parent 67fa4ec commit 48fb810
Show file tree
Hide file tree
Showing 47 changed files with 2,899 additions and 4,421 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ buildNumber.properties
### Gradle template
.gradle
build/
gradle

# Ignore Gradle GUI config
gradle-app.setting
Expand All @@ -36,3 +37,6 @@ gradle-app.setting
!gradle-wrapper.jar


# idea
.idea

111 changes: 66 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,90 @@ esl-client
This project is a fork of the unmaintained, original project at
<https://freeswitch.org/stash/projects/FS/repos/freeswitch-contrib/browse/dvarnes/java/esl-client>

Status: In Progress...
Status: done


Example
Inbound Example
------------------------------------------------------------------------------

```java
package com.ecovate.freeswitch.lb;
package org.freeswitch.esl.client;

import com.google.common.base.Throwables;
import org.freeswitch.esl.client.inbound.Client;
import org.freeswitch.esl.client.inbound.IEslEventListener;
import org.freeswitch.esl.client.internal.IModEslApi.EventFormat;
import org.freeswitch.esl.client.outbound.Context;
import org.freeswitch.esl.client.outbound.IClientHandler;
import org.freeswitch.esl.client.outbound.IClientHandlerFactory;
import org.freeswitch.esl.client.outbound.SocketClient;
import org.freeswitch.esl.client.transport.event.EslEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class FreeSwitchEventListener {
public class ClientTest {

private static Logger logger = LoggerFactory.getLogger(FreeSwitchEventListener.class);
private static class DemoEventListener implements IEslEventListener {

public static void main(String[] args) {
try {
@Override
public void eventReceived(EslEvent event) {
System.out.println("eventReceived:" + event.getEventName());
}

final Client inboudClient = new Client();
inboudClient.connect(new InetSocketAddress("localhost", 8021), "ClueCon", 10);
inboudClient.addEventListener(new IEslEventListener() {
@Override
public void onEslEvent(EslEvent eslEvent) {
public void backgroundJobResultReceived(EslEvent event) {
System.out.println("backgroundJobResultReceived:" + event.getEventName());
}
}

public static void main(String[] args) throws InterruptedException {
String host = "localhost";
int port = 8021;
String password = "ClueCon";
int timeoutSeconds = 10;
Client inboundClient = new Client(2, 8);
try {
inboundClient.connect(host, port, password, timeoutSeconds);
inboundClient.addEventListener(new DemoEventListener());
inboundClient.setEventSubscriptions("plain", "all");
} catch (Exception e) {
System.out.println("connect fail");
}
});
inboudClient.setEventSubscriptions(EventFormat.PLAIN, "all");

final SocketClient outboundServer = new SocketClient(
new InetSocketAddress("localhost", 8084),
new IClientHandlerFactory() {
@Override
public IClientHandler createClientHandler() {
return new IClientHandler() {
@Override
public void handleEslEvent(Context context, EslEvent eslEvent) {
}

@Override
public void onConnect(Context context, EslEvent eslEvent) {
}
};
}
});


} catch (Throwable t) {
Throwables.propagate(t);

//health-check
ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1);
service.scheduleAtFixedRate(() -> {
System.out.println(System.currentTimeMillis() + " " + inboundClient.canSend());
if (!inboundClient.canSend()) {
try {
//重连
inboundClient.connect(host, port, password, timeoutSeconds);
inboundClient.cancelEventSubscriptions();
inboundClient.setEventSubscriptions("plain", "all");
} catch (Exception e) {
System.out.println("connect fail");
}
}
}, 1, 500, TimeUnit.MILLISECONDS);

System.out.println("other process ...");
}
}
}

```

Outbound Example
------------------------------------------------------------------------------
```java
package org.freeswitch.esl.client;

import org.freeswitch.esl.client.outbound.SocketClient;
import org.freeswitch.esl.client.outbound.example.SimpleHangupPipelineFactory;

public class SocketClientTest {

public static void main(String[] args) {
SocketClient client = new SocketClient(8086, new SimpleHangupPipelineFactory(), 2, 16);
client.start();
System.out.println("started ...");
}
}

```

Authors
Expand All @@ -84,6 +104,7 @@ Authors
- [Dave Rusek](mailto:[email protected])
- [David Varnes](mailto:[email protected]) (original author)
- [Tobias Bieniek](https://github.com/Turbo87)
- [菩提树下的杨过](https://www.cnblogs.com/yjmyzz/)

License
------------------------------------------------------------------------------
Expand Down
34 changes: 0 additions & 34 deletions TODO.txt

This file was deleted.

24 changes: 18 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ apply plugin: 'java'
apply plugin: 'maven'

group = 'org.freeswitch.esl.client'
version = '0.10.0-SNAPSHOT'
version = '0.9.3'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
maven { url "http://repo.maven.apache.org/maven2" }
maven{url "http://maven.aliyun.com/nexus/content/groups/public"}
maven { url "http://repo.maven.apache.org/maven2" }
}

//打包源代码
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives sourcesJar
}

dependencies {
compile 'io.netty:netty-all:4.1.17.Final'
compile 'com.google.guava:guava:23.4-jre'
compile 'org.slf4j:slf4j-api:1.7.25'
runtime 'ch.qos.logback:logback-classic:1.2.3'
compile 'org.jboss.netty:netty:3.2.1.Final'
compile 'org.slf4j:slf4j-api:1.6.1'
compile 'com.google.guava:guava:28.0-jre'
compile 'ch.qos.logback:logback-classic:1.2.3'
testCompile 'junit:junit:4.8.1'
testCompile 'ch.qos.logback:logback-classic:0.9.24'
}
Binary file removed gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions gradle/wrapper/gradle-wrapper.properties

This file was deleted.

78 changes: 43 additions & 35 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## 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=""
# 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\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
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='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=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.
Expand All @@ -90,7 +89,7 @@ location of your Java installation."
fi

# 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`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand All @@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
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=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
Loading

0 comments on commit 48fb810

Please sign in to comment.