Ejemplo n.º 1
0
  @Override
  public void onStart(Application app) {
    if (Play.application().configuration().getString("app.envirement").equals("dev")) {
      AppConfig.setupDevEnv();
    } else if (Play.application().configuration().getString("app.envirement").equals("test")) {
      AppConfig.setupTestEnv();
    } else if (Play.application().configuration().getString("app.envirement").equals("prod")) {
      AppConfig.setupProdEnv();
    }

    play.libs.Akka.system()
        .scheduler()
        .schedule(
            Duration.create(0, TimeUnit.MILLISECONDS),
            Duration.create(1, TimeUnit.DAYS),
            new Runnable() {
              public void run() {
                System.out.println("tick");
                File dir = new File(AppConfig.temporaryFilesDirectory);
                for (String fname : dir.list()) {
                  if (fname.equals(".") || fname.equals("..")) continue;
                  File tmp = new File(AppConfig.temporaryFilesDirectory + fname);
                  if (tmp.exists()
                      && tmp.isFile()
                      && (new Date().getTime() - tmp.lastModified()) > (30L * 86400L * 1000L)) {
                    tmp.delete();
                  }
                }
              }
            });

    super.onStart(app);
  }
Ejemplo n.º 2
0
  @Override
  public void onStart(Application application) {

    tweetUrl = Play.application().configuration().getString("tweet.url");
    sentimentUrl = Play.application().configuration().getString("sentiment.url");

    if ((sentimentUrl == null) || (tweetUrl == null)) {
      throw new RuntimeException("Both sentiment.url and tweet.url configs must be specified");
    }

    usersActor = Akka.system().actorOf(new Props(UsersActor.class), "users");

    stockHolderActor = Akka.system().actorOf(new Props(StockHolderActor.class), "stocks");

    // fetch a new data point once every second
    Akka.system()
        .scheduler()
        .schedule(
            Duration.Zero(),
            Duration.create(50, TimeUnit.MILLISECONDS),
            stockHolderActor,
            FetchLatest.instance(),
            Akka.system().dispatcher());

    super.onStart(application);
  }
Ejemplo n.º 3
0
  static play.mvc.Result invokeMethod(
      Class<?> targetClass,
      play.GlobalSettings global,
      Method method,
      Map<String, Object> extractedArgs,
      play.mvc.Http.RequestHeader r) {
    try {
      Object[] argValues = new Object[0];
      List<Object> argVals = new ArrayList<Object>();
      Annotation[][] annos = method.getParameterAnnotations();

      for (Annotation[] ans : annos) {
        PathParam pathParam = null;
        QueryParam queryParam = null;

        for (Annotation an : ans) {
          if (an instanceof PathParam) pathParam = (PathParam) an;
          else if (an instanceof QueryParam) queryParam = (QueryParam) an;
        }
        if (pathParam != null) {
          Object v = extractedArgs.get(pathParam.value());
          if (v != null) argVals.add(v);
          else
            throw new IllegalArgumentException(
                "can not find annotation value for argument "
                    + pathParam.value()
                    + "in "
                    + targetClass
                    + "#"
                    + method);
        } else if (queryParam != null) {
          String queryString = r.getQueryString(queryParam.value());
          argVals.add(queryString); // string type conversion?
        } else
          throw new IllegalArgumentException(
              "can not find an appropriate JAX-RC annotation for an argument for method:"
                  + targetClass
                  + "#"
                  + method);
      }
      argValues = argVals.toArray(argValues);
      return (play.mvc.Result) method.invoke(global.getControllerInstance(targetClass), argValues);
    } catch (InvocationTargetException cause) {
      System.err.println(
          "Exception occured while trying to invoke: "
              + targetClass.getName()
              + "#"
              + method.getName()
              + " with "
              + extractedArgs
              + " for uri:"
              + r.path());
      throw new RuntimeException(cause.getCause());
    } catch (Exception e) {
      throw new RuntimeException(e.getCause());
    }
  }
Ejemplo n.º 4
0
  @Override
  public void onStart(play.Application argo) {
    super.beforeStart(argo);
    Logger.debug("** on start **");
    try {
      MorphiaObject.mongo = new MongoClient("127.0.0.1", 27017);
    } catch (Exception e) {
      e.printStackTrace();
    }
    MorphiaObject.morphia = new Morphia();
    MorphiaObject.datastore = MorphiaObject.morphia.createDatastore(MorphiaObject.mongo, "test");
    MorphiaObject.datastore.ensureIndexes();
    MorphiaObject.datastore.ensureCaps();

    Logger.debug("** Morphia datastore: " + MorphiaObject.datastore.getDB());
  }
Ejemplo n.º 5
0
  @Override
  public void onStart(Application app) {
    Logger.info("Global - onStart");
    super.onStart(app);
    /*
     * Sets the schedule for cleaning the media temp directory
     */
    Akka.system()
        .scheduler()
        .schedule(
            Duration.create(0, TimeUnit.MILLISECONDS),
            Duration.create(30, TimeUnit.MINUTES),
            new Runnable() {
              public void run() {
                MediaController.cleanUpTemp();
              }
            },
            Akka.system().dispatcher());

    InitialData.insert(app);
  }
Ejemplo n.º 6
0
 @Override
 public void onStop(Application application) {
   TimeTableTaskActorBase.getInstance().shutdown();
   super.onStop(application);
 }
Ejemplo n.º 7
0
 @Override
 public void beforeStart(Application application) {
   super.beforeStart(application);
 }
Ejemplo n.º 8
0
 @Override
 public void onStart(Application application) {
   // System.out.println("アプリケーションスタート");
   TimeTableTaskActorBase.getInstance().start();
   super.onStart(application);
 }
Ejemplo n.º 9
0
 @Override
 public void beforeStart(Application app) {
   Logger.info(" Global beforeStart");
   super.beforeStart(app);
 }