devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wk...@apache.org
Subject svn commit: r1749124 - in /devicemap/trunk/examples/1.0/java: pom.xml servlet/src/main/java/org/apache/devicemap/servlet/Classify.java spring/src/main/java/org/apache/devicemap/spring/Classifier.java
Date Sun, 19 Jun 2016 02:31:15 GMT
Author: wkeil
Date: Sun Jun 19 02:31:14 2016
New Revision: 1749124

URL: http://svn.apache.org/viewvc?rev=1749124&view=rev
Log:
DMAP-111: Improve Web Examples 

Task-Url: https://issues.apache.org/jira/browse/DMAP-111

Modified:
    devicemap/trunk/examples/1.0/java/pom.xml
    devicemap/trunk/examples/1.0/java/servlet/src/main/java/org/apache/devicemap/servlet/Classify.java
    devicemap/trunk/examples/1.0/java/spring/src/main/java/org/apache/devicemap/spring/Classifier.java

Modified: devicemap/trunk/examples/1.0/java/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/1.0/java/pom.xml?rev=1749124&r1=1749123&r2=1749124&view=diff
==============================================================================
--- devicemap/trunk/examples/1.0/java/pom.xml (original)
+++ devicemap/trunk/examples/1.0/java/pom.xml Sun Jun 19 02:31:14 2016
@@ -41,7 +41,7 @@
 			<dependency>
 				<groupId>org.apache.devicemap</groupId>
 				<artifactId>devicemap-client</artifactId>
-				<version>1.1.1-SNAPSHOT</version>
+				<version>1.2.0-SNAPSHOT</version>
 			</dependency>
 			<dependency>
 				<groupId>org.apache.devicemap</groupId>

Modified: devicemap/trunk/examples/1.0/java/servlet/src/main/java/org/apache/devicemap/servlet/Classify.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/1.0/java/servlet/src/main/java/org/apache/devicemap/servlet/Classify.java?rev=1749124&r1=1749123&r2=1749124&view=diff
==============================================================================
--- devicemap/trunk/examples/1.0/java/servlet/src/main/java/org/apache/devicemap/servlet/Classify.java
(original)
+++ devicemap/trunk/examples/1.0/java/servlet/src/main/java/org/apache/devicemap/servlet/Classify.java
Sun Jun 19 02:31:14 2016
@@ -36,36 +36,37 @@ import org.apache.devicemap.loader.Loade
  * @author Werner Keil
  */
 public class Classify extends HttpServlet {
-
-	/**
+    private static final boolean USE_SNAPSHOT = true;
+    
+    /**
      * 
      */
-	private static final long serialVersionUID = -5231604595735057872L;
+    private static final long serialVersionUID = -5231604595735057872L;
+
+    @Override
+    protected void doGet(HttpServletRequest request,
+	    HttpServletResponse response) throws ServletException, IOException {
+	String ua = request.getParameter("ua");
 
-	@Override
-	protected void doGet(HttpServletRequest request,
-			HttpServletResponse response) throws ServletException, IOException {
-		String ua = request.getParameter("ua");
-
-		if (ua == null || ua.isEmpty()) {
-			ua = request.getHeader("User-Agent");
-		}
-
-		long start = System.nanoTime();
-		final Device device = DeviceMapFactory.getClient(LoaderOption.URL)
-				.classifyDevice(ua);
-		long diff = (System.nanoTime() - start) / 1000;
-
-		final StringBuilder sb = new StringBuilder();
-		sb.append("\n{\n\"success\":true,\n\"user-agent\":\"").append(ua)
-				.append("\",\n\"time_microseconds\":");
-		sb.append(diff).append(",\n\"result\":").append(device.toString())
-				.append("\n}");
-
-		response.setHeader("Content-Type", "application/json");
-
-		Writer writer = response.getWriter();
-		writer.write(sb.toString());
-		writer.flush();
+	if (ua == null || ua.isEmpty()) {
+	    ua = request.getHeader("User-Agent");
 	}
+
+	long start = System.nanoTime();
+	final Device device = DeviceMapFactory.getClient(LoaderOption.URL, USE_SNAPSHOT)
+		.classifyDevice(ua);
+	long diff = (System.nanoTime() - start) / 1000;
+
+	final StringBuilder sb = new StringBuilder();
+	sb.append("\n{\n\"success\":true,\n\"user-agent\":\"").append(ua)
+		.append("\",\n\"time_microseconds\":");
+	sb.append(diff).append(",\n\"result\":").append(device.toString())
+		.append("\n}");
+
+	response.setHeader("Content-Type", "application/json");
+
+	Writer writer = response.getWriter();
+	writer.write(sb.toString());
+	writer.flush();
+    }
 }

Modified: devicemap/trunk/examples/1.0/java/spring/src/main/java/org/apache/devicemap/spring/Classifier.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/1.0/java/spring/src/main/java/org/apache/devicemap/spring/Classifier.java?rev=1749124&r1=1749123&r2=1749124&view=diff
==============================================================================
--- devicemap/trunk/examples/1.0/java/spring/src/main/java/org/apache/devicemap/spring/Classifier.java
(original)
+++ devicemap/trunk/examples/1.0/java/spring/src/main/java/org/apache/devicemap/spring/Classifier.java
Sun Jun 19 02:31:14 2016
@@ -29,16 +29,15 @@ import org.apache.log4j.Logger;
  *
  */
 public class Classifier {
-    
     private static final Logger log = Logger.getLogger(Classifier.class);
-
+    private static final boolean USE_SNAPSHOT = true;
     private DeviceMapClient client;
     
     public synchronized void init() throws Exception {
         long start = System.nanoTime();
         client = new DeviceMapClient();
         //client.initDeviceData(LoaderOption.JAR);
-        client.initDeviceData(LoaderOption.URL);
+        client.initDeviceData(LoaderOption.URL, USE_SNAPSHOT);
         long diff = (System.nanoTime() - start) / 1000;
         log.info("DeviceMap Classifier loaded " + client.getDeviceCount() + " devices and
" + client.getPatternCount() + " patterns in " + diff + "ms");
     }



Mime
View raw message