Nick 10 years ago
parent
commit
3a11701f85

+ 0 - 6
frameworks/Java/beyondj/README.md

@@ -27,10 +27,4 @@ public class Common {
             CORE_POOL_SIZE, MAX_POOL_SIZE, keepAliveTime, TimeUnit.MILLISECONDS,
             new LinkedBlockingQueue<Runnable>(CPU_COUNT * 100),
             new ThreadPoolExecutor.CallerRunsPolicy());
-
-    static {
-        System.out.println("Common.EXECUTOR.CPU_COUNT = " + CPU_COUNT);
-        System.out.println("Common.EXECUTOR.CORE_POOL_SIZE = " + CORE_POOL_SIZE);
-        System.out.println("Common.EXECUTOR.MAX_POOL_SIZE = " + MAX_POOL_SIZE);
-    }
 }

+ 6 - 0
frameworks/Java/beyondj/beyondj-data/src/main/java/com/techempower/beyondj/Message.java

@@ -80,6 +80,7 @@ public class BeyondJApplication {
         LaunchUtil.defaultConfig = config;
 
         LOG.debug("Resource install path is {}", config.getProperty(ApplicationConfiguration.BEYONDJ_HOME));
+        System.out.println("Resource install path is " + config.getProperty(ApplicationConfiguration.BEYONDJ_HOME));
 
         String path = LaunchUtil.getContainerInstallationDir(config);
         ProtectionDomain protectionDomain = BeyondJApplication.class.getProtectionDomain();
@@ -91,11 +92,13 @@ public class BeyondJApplication {
         if (codeSource.toString().indexOf(".jar") != -1) {
             if (codeSource.toString().indexOf(".jar!") != -1) {
                 LOG.debug("Copying jar resources to install folder");
+                System.out.println("Copying jar resources to install folder");
                 JarURLConnection conn = (JarURLConnection) location.openConnection();
                 LaunchUtil.copyJarResourcesToFolder(conn, installationDir);
             } else {
                 //assume we launched this from the bin folder
                 LOG.debug("Extracting jar resources to install folder");
+                System.out.println("Extracting jar resources to install folder");
                 File locFile = new File(location.toURI());
                 LaunchUtil.extractJar(locFile.getAbsolutePath(), installationDir.getAbsolutePath());
             }
@@ -110,6 +113,7 @@ public class BeyondJApplication {
         String[] fileNames = webAppLaunchersDir.list();
         if (fileNames != null) {
             LOG.debug("Extracting web-app resources to install folder");
+            System.out.println("Extracting web-app resources to install folder");
             for (String fileName : fileNames) {
                 String jarOrWarName = webAppsPath + File.separator + fileName.replace(".jar", "");
                 jarOrWarName = jarOrWarName.replace(".war", "");
@@ -128,6 +132,7 @@ public class BeyondJApplication {
 
         if (fileNames != null) {
             LOG.debug("Extracting jar-app resources to install folder");
+            System.out.println("Extracting jar-app resources to install folder");
             for (String fileName : fileNames) {
                 String jarOrWarName = jarAppsPath + File.separator + fileName.replace(".jar", "");
                 jarOrWarName = jarOrWarName.replace(".tar", "");
@@ -146,6 +151,7 @@ public class BeyondJApplication {
 
         if (fileNames != null) {
             LOG.debug("Extracting script-app resources to install folder");
+            System.out.println("Extracting script-app resources to install folder");
             for (String fileName : fileNames) {
                 String jarOrWarName = scriptAppsPath + File.separator + fileName.replace(".jar", "");
                 jarOrWarName = jarOrWarName.replace(".tar", "");

+ 1 - 2
frameworks/Java/beyondj/beyondj-launcher/src/main/resources/META-INF/persistence.xml

@@ -1,5 +1,4 @@
-
-BEYONDJ_HOME=/tmp/beyondj
+BEYONDJ_HOME=results
 system.platform.enable.activemq=false
 bundleActor.healthcheck.initial.delay.value=1
 bundleActor.healthcheck.initial.delay.unit=MINUTES

+ 5 - 1
frameworks/Java/beyondj/beyondj-launcher/src/main/resources/props/fields-metrics.properties

@@ -99,7 +99,11 @@ public abstract class BaseActionBean implements
         return getContext().getRequest().getPathInfo();
     }
 
-    protected void setResponseDate(){
+    protected void setResponseHeaders(Map<String,String>headers){
+        for(String key: headers.keySet()){
+            getContext().getResponse().setHeader(key, headers.get(key));
+        }
         getContext().getResponse().setHeader(DATE, new java.util.Date().toString());
     }
 }
+

+ 4 - 1
frameworks/Java/beyondj/beyondj-service/src/main/java/com/techempower/beyondj/action/ErrorActionBean.java

@@ -5,6 +5,8 @@ import net.sourceforge.stripes.action.ForwardResolution;
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.action.UrlBinding;
 
+import java.util.HashMap;
+
 /**
  * @author nickk
  */
@@ -15,7 +17,7 @@ public class ErrorActionBean extends BaseActionBean {
 
     @DefaultHandler
     public Resolution view() {
-        setResponseDate();
+        setResponseHeaders(new HashMap<>());
         return new ForwardResolution(JSP);
     }
 
@@ -24,3 +26,4 @@ public class ErrorActionBean extends BaseActionBean {
         return null;
     }
 }
+

+ 7 - 6
frameworks/Java/beyondj/beyondj-service/src/main/java/com/techempower/beyondj/action/FortuneActionBean.java

@@ -5,10 +5,7 @@ import com.techempower.beyondj.repository.FortuneRepository;
 import net.sourceforge.stripes.action.*;
 import net.sourceforge.stripes.integration.spring.SpringBean;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 @UrlBinding("/perf/fortunes/{_eventName}")
 public class FortuneActionBean extends BaseActionBean {
@@ -26,7 +23,9 @@ public class FortuneActionBean extends BaseActionBean {
         }
         fortunes.add(new Fortune(0, "Additional fortune added at request time."));
         Collections.sort(fortunes);
-        setResponseDate();
+        Map<String,String> headers = new HashMap<>();
+        headers.put(TRANSFER_ENCODING, Boolean.TRUE.toString());
+        setResponseHeaders(headers);
         return new ForwardResolution(JSP);
     }
 
@@ -37,6 +36,8 @@ public class FortuneActionBean extends BaseActionBean {
     @SpringBean
     private FortuneRepository fortuneRepository;
 
-    public static final String JSP = "/WEB-INF/templates/fortunes.jsp";
     public static final String FORTUNES = "fortunes";
+    public static final String JSP = "/WEB-INF/templates/fortunes.jsp";
+    public static final String TRANSFER_ENCODING = "Transfer-Encoding";
 }
+

+ 16 - 3
frameworks/Java/beyondj/beyondj-service/src/main/java/com/techempower/beyondj/action/HelloActionBean.java

@@ -1,19 +1,29 @@
 package com.techempower.beyondj.action;
 
 import net.sourceforge.stripes.action.*;
+import org.stripesrest.JsonBuilder;
 import org.stripesrest.JsonResolution;
 import com.techempower.beyondj.Message;
 import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
 
 @UrlBinding("/perf/hello/{_eventName}")
 public class HelloActionBean extends BaseActionBean {
 
+    public static final String CONTENT_LENGTH = "Content-Length";
+
     @HandlesEvent(JSON)
     @DefaultHandler
     public Resolution json() {
         Message message = new Message(HELLO_WORLD);
-        setResponseDate();
-        return new JsonResolution(message);
+
+        JsonBuilder builder = new JsonBuilder(message);
+        String rawJsonText = builder.build();
+        Map<String,String> headers = new HashMap<>();
+        headers.put(CONTENT_LENGTH,String.valueOf(rawJsonText.getBytes().length));
+        setResponseHeaders(headers);
+        return new JsonResolution(rawJsonText);
     }
 
     @HandlesEvent(PLAINTEXT)
@@ -21,7 +31,9 @@ public class HelloActionBean extends BaseActionBean {
         return new StreamingResolution(TEXT_PLAIN) {
             public void stream(final HttpServletResponse response) {
                 try {
-                    setResponseDate();
+                    Map<String,String> headers = new HashMap<>();
+                    headers.put(CONTENT_LENGTH,String.valueOf(HELLO_WORLD.getBytes().length));
+                    setResponseHeaders(headers);
                     response.getWriter().write(HELLO_WORLD);
                 } catch (Exception e) {
                     //do nothing
@@ -35,3 +47,4 @@ public class HelloActionBean extends BaseActionBean {
     private static final String HELLO_WORLD = "Hello, World!";
     private static final String TEXT_PLAIN = "text/plain";
 }
+

+ 52 - 27
frameworks/Java/beyondj/beyondj-service/src/main/java/com/techempower/beyondj/action/WorldDatabaseActionBean.java

@@ -11,11 +11,10 @@ import net.sourceforge.stripes.integration.spring.SpringBean;
 import net.sourceforge.stripes.validation.Validate;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.stripesrest.JsonBuilder;
 import org.stripesrest.JsonResolution;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -25,24 +24,27 @@ import java.util.concurrent.ThreadLocalRandom;
 public class WorldDatabaseActionBean extends BaseActionBean {
 
     @Validate(required = false)
-    private int queries = 1;
+    private String queries;
 
     @HandlesEvent(DB)
     @DefaultHandler
     public Resolution queryOne() {
         final Random random = ThreadLocalRandom.current();
-        World world = (World) worldRepository.findOne(random.nextInt(DB_ROWS) + 1);
-        setResponseDate();
-        return new JsonResolution(world);
+        World world = worldRepository.findOne(random.nextInt(DB_ROWS) + 1);
+        JsonBuilder builder = new JsonBuilder(world);
+        String rawJsonText = builder.build();
+        Map<String,String> headers = new HashMap<>();
+        headers.put(CONTENT_LENGTH, String.valueOf(rawJsonText.getBytes().length));
+         setResponseHeaders(headers);
+        return new JsonResolution(rawJsonText);
     }
 
     @HandlesEvent(QUERIES)
     @Transactional(readOnly = true)
-    public Resolution queries() {
-        boundQueryCount();
-        List<Future<World>> wfs = new ArrayList<>(queries);
-
-        for (int i = 0; i < queries; i++) {
+    public Resolution queries() throws Exception{
+        int value = boundQueryCount();
+        List<Future<World>> wfs = new ArrayList<>(value);
+        for (int i = 0; i < value; i++) {
             wfs.add(
                     Common.EXECUTOR.submit(
                             new Callable<World>() {
@@ -53,16 +55,32 @@ public class WorldDatabaseActionBean extends BaseActionBean {
                                 }
                             }));
         }
-        setResponseDate();
-        return new JsonResolution(wfs);
+        List<World> worlds = waitFor(wfs);
+        JsonBuilder builder = new JsonBuilder(worlds);
+        String rawJsonText = builder.build();
+        Map<String,String> headers = new HashMap<>();
+        headers.put(CONTENT_LENGTH, String.valueOf(rawJsonText.getBytes().length));
+         setResponseHeaders(headers);
+        return new JsonResolution(rawJsonText);
+    }
+
+    private int extractQueriesValue() {
+        int queriesValue = 1;
+        try {
+            queriesValue = Integer.valueOf(queries);
+        } catch (Exception e) {
+            //do nothing
+        }
+        return queriesValue;
     }
 
     @HandlesEvent(UPDATES)
     @Transactional
     public Resolution updates() {
-        boundQueryCount();
-        List<Future<World>> wfs = new ArrayList<>(queries);
-        for (int i = 0; i < queries; i++) {
+        int value = boundQueryCount();
+
+        List<Future<World>> wfs = new ArrayList<>(value);
+        for (int i = 0; i < value; i++) {
             wfs.add(Common.EXECUTOR.submit(
                     new Callable<World>() {
                         @Override
@@ -77,15 +95,19 @@ public class WorldDatabaseActionBean extends BaseActionBean {
                     }));
         }
         List<World> worlds = waitFor(wfs);
-        setResponseDate();
-        return new JsonResolution(worlds);
+        JsonBuilder builder = new JsonBuilder(worlds);
+        String rawJsonText = builder.build();
+        Map<String,String> headers = new HashMap<>();
+        headers.put(CONTENT_LENGTH, String.valueOf(rawJsonText.getBytes().length));
+         setResponseHeaders(headers);
+        return new JsonResolution(rawJsonText);
     }
 
-    public int getQueries() {
+    public String getQueries() {
         return queries;
     }
 
-    public void setQueries(int queries) {
+    public void setQueries(String queries) {
         this.queries = queries;
     }
 
@@ -101,12 +123,14 @@ public class WorldDatabaseActionBean extends BaseActionBean {
         return worlds;
     }
 
-    private void boundQueryCount() {
-        if (queries < 1) {
-            queries = 1;
-        } else if (queries > 500) {
-            queries = 500;
+    private int boundQueryCount() {
+        int queriesValue = extractQueriesValue();
+        if (queriesValue < 1) {
+            queriesValue = 1;
+        } else if (queriesValue > 500) {
+            queriesValue = 500;
         }
+        return queriesValue;
     }
 
 
@@ -114,8 +138,9 @@ public class WorldDatabaseActionBean extends BaseActionBean {
 
     @SpringBean
     private WorldRepository worldRepository;
-
     private static final String QUERIES = "queries";
     private static final String DB = "db";
     private static final String UPDATES = "updates";
+    public static final String CONTENT_LENGTH = "Content-Length";
 }
+

+ 3 - 2
frameworks/Java/beyondj/beyondj-service/src/main/resources/META-INF/persistence.xml

@@ -3,8 +3,9 @@
 fw_depends java8 maven
 
 # rm beyondj-launcher/src/main/resources/launchers/webapp-launchers/beyondj-service.war
-mvn clean package
+sudo chmod -R 777 .
+mvn package
 # cp beyondj-service/target/beyondj-service.war beyondj-launcher/src/main/resources/launchers/webapp-launchers/
 # mvn clean package
 
-java -jar beyondj-launcher/target/beyondj.jar system.platform.dbserver=${DBHOST} numInstances=10 &
+java -jar beyondj-launcher/target/beyondj.jar system.platform.dbserver=${DBHOST} numInstances=10

+ 0 - 0
frameworks/Java/beyondj/source_code