summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonrpc/pom.xml12
-rw-r--r--jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java22
-rw-r--r--master/pom.xml32
-rw-r--r--master/src/main/java/com/orbekk/Broadcast.java5
-rw-r--r--master/src/main/java/com/orbekk/ConfigureLog4J.java18
-rw-r--r--master/src/main/java/com/orbekk/HelloAndroidActivity.java23
-rw-r--r--master/src/main/java/com/orbekk/PingServer.java7
7 files changed, 55 insertions, 64 deletions
diff --git a/jsonrpc/pom.xml b/jsonrpc/pom.xml
index 4d06cfd..7d2bba7 100644
--- a/jsonrpc/pom.xml
+++ b/jsonrpc/pom.xml
@@ -44,9 +44,15 @@
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.16</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</version>
</dependency>
<dependency>
diff --git a/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java b/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
index 50cdbc7..c0b66e0 100644
--- a/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
+++ b/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
@@ -5,40 +5,44 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class BroadcastListener {
private int port;
- private Logger logger = Logger.getLogger(getClass());
+ private Logger logger = LoggerFactory.getLogger(getClass());
public BroadcastListener(int port) {
this.port = port;
}
- public boolean listen() {
- logger.info("Waiting for broadcast on port " + port);
+ public DatagramPacket listen() {
+ logger.debug("Waiting for broadcast on port " + port);
DatagramSocket socket;
try {
socket = new DatagramSocket(port);
} catch (SocketException e) {
logger.warn("Failed to create socket.", e.fillInStackTrace());
- return true;
+ return null;
}
try {
socket.setBroadcast(true);
} catch (SocketException e) {
- logger.warn(e.fillInStackTrace());
+ logger.warn("Exception: {}", e);
}
byte[] buffer = new byte[2048];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
try {
socket.receive(packet);
} catch (IOException e) {
- logger.warn(e.fillInStackTrace());
+ logger.warn("Exception when listening for broadcast: {}", e);
+ return null;
}
- logger.info("Received broadcast from " + packet.getAddress() +
+
+ String address = packet.getAddress().getHostAddress();
+ logger.debug("Received broadcast from " + address +
": " + new String(packet.getData()));
- return true;
+ return packet;
}
public static void main(String[] args) {
diff --git a/master/pom.xml b/master/pom.xml
index 77fb614..ad0039a 100644
--- a/master/pom.xml
+++ b/master/pom.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.orbekk</groupId>
@@ -16,11 +18,6 @@
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.16</version>
- </dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -44,12 +41,25 @@
</dependency>
<dependency>
- <groupId>de.mindpipe.android</groupId>
- <artifactId>android-logging-log4j</artifactId>
- <version>1.0.2</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-android</artifactId>
+ <version>1.6.1-RC1</version>
</dependency>
-
-
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>com.orbekk</groupId>
<artifactId>jsonrpc</artifactId>
diff --git a/master/src/main/java/com/orbekk/Broadcast.java b/master/src/main/java/com/orbekk/Broadcast.java
index bacde0d..84b2d6e 100644
--- a/master/src/main/java/com/orbekk/Broadcast.java
+++ b/master/src/main/java/com/orbekk/Broadcast.java
@@ -7,7 +7,8 @@ import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import android.content.Context;
import android.net.DhcpInfo;
@@ -15,7 +16,7 @@ import android.net.wifi.WifiManager;
public class Broadcast {
private Context context;
- private Logger logger = Logger.getLogger(getClass());
+ private Logger logger = LoggerFactory.getLogger(getClass());
public Broadcast(Context context) {
this.context = context;
diff --git a/master/src/main/java/com/orbekk/ConfigureLog4J.java b/master/src/main/java/com/orbekk/ConfigureLog4J.java
deleted file mode 100644
index e6b1ac5..0000000
--- a/master/src/main/java/com/orbekk/ConfigureLog4J.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.orbekk;
-import org.apache.log4j.Level;
-import android.os.Environment;
-import de.mindpipe.android.logging.log4j.LogConfigurator;
-
-public class ConfigureLog4J {
- static {
- final LogConfigurator logConfigurator = new LogConfigurator();
-
- logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
- logConfigurator.setRootLevel(Level.DEBUG);
- logConfigurator.setUseLogCatAppender(true);
- // Set log level of a specific logger
- // logConfigurator.setLevel("org.apache", Level.ERROR);
- logConfigurator.configure();
- System.err.println("GOT HERE.");
- }
-} \ No newline at end of file
diff --git a/master/src/main/java/com/orbekk/HelloAndroidActivity.java b/master/src/main/java/com/orbekk/HelloAndroidActivity.java
index a142214..4160bf4 100644
--- a/master/src/main/java/com/orbekk/HelloAndroidActivity.java
+++ b/master/src/main/java/com/orbekk/HelloAndroidActivity.java
@@ -1,8 +1,7 @@
package com.orbekk;
-import org.apache.log4j.Level;
+import com.orbekk.net.Broadcaster;
-import de.mindpipe.android.logging.log4j.LogConfigurator;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
@@ -12,19 +11,6 @@ public class HelloAndroidActivity extends Activity {
private static String TAG = "master";
private PingServer pingServer;
- private void configureLog4j() {
- final LogConfigurator logConfigurator = new LogConfigurator();
-
- //logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
- logConfigurator.setRootLevel(Level.DEBUG);
- logConfigurator.setUseLogCatAppender(true);
- logConfigurator.setUseFileAppender(false);
- // Set log level of a specific logger
- // logConfigurator.setLevel("org.apache", Level.ERROR);
- logConfigurator.configure();
- System.err.println("GOT HERE.");
- }
-
/**
* Called when the activity is first created.
* @param savedInstanceState If the activity is being re-initialized after
@@ -39,7 +25,6 @@ public class HelloAndroidActivity extends Activity {
System.setProperty("java.net.preferIPv6Addresses", "false");
Log.i(TAG, "onCreate");
- configureLog4j();
setContentView(R.layout.main);
pingServer = PingServer.createPingServer(10080);
@@ -49,8 +34,10 @@ public class HelloAndroidActivity extends Activity {
throw new RuntimeException(e.getMessage());
}
- Broadcast broadcast = new Broadcast(this);
- broadcast.sendBroadcast("Broadcast test".getBytes(), 10010);
+// Broadcast broadcast = new Broadcast(this);
+// broadcast.sendBroadcast("Broadcast test".getBytes(), 10010);
+ Broadcaster broadcaster = new Broadcaster();
+ Log.i(TAG, "Broadcast success: " + broadcaster.sendBroadcast(10010, "Broadcast test from Android".getBytes()));
}
@Override
diff --git a/master/src/main/java/com/orbekk/PingServer.java b/master/src/main/java/com/orbekk/PingServer.java
index b1126d4..5df2346 100644
--- a/master/src/main/java/com/orbekk/PingServer.java
+++ b/master/src/main/java/com/orbekk/PingServer.java
@@ -1,7 +1,8 @@
package com.orbekk;
-import org.apache.log4j.Logger;
import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.rpc.PingService;
@@ -9,8 +10,8 @@ import com.orbekk.rpc.PingServiceImpl;
import com.orbekk.rpc.RpcHandler;
public class PingServer {
- Server server;
- Logger logger = Logger.getLogger(getClass());
+ private Server server;
+ private Logger logger = LoggerFactory.getLogger(getClass());
public PingServer(Server server) {
this.server = server;