Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. Hai!
  2.  
  3. This is my controller file
  4.  
  5.  
  6. static boolean checkflag = false;
  7. static Double dataValue = 0.0;
  8. static Cancellable timerCall = null;
  9. static Thread tt;
  10. static Thread ttt;
  11. static Promise<Result> promiseOfPIValue1 = null;
  12.  
  13. public static Result index() {
  14.  
  15. Promise<Double> promiseOfPIValue = registerListener();
  16. System.out.println("initial value :"+promiseOfPIValue.get());
  17. Promise<Result> promiseOfResult = null;
  18. if(promiseOfPIValue != null)
  19. {
  20. promiseOfResult = promiseOfPIValue.map(
  21. new Function<Double,Result>()
  22. {
  23. public Result apply(Double pi) throws Throwable {
  24. {
  25. System.out.println("PI value computed: " + pi);
  26. return ok("PI value computed: " + pi);
  27. }
  28. }
  29. }
  30. );
  31. timerCall.cancel();
  32. checkflag = false;
  33. }
  34.  
  35. //return ok(index.render("Your new application is ready."));
  36. return Results.async(promiseOfResult);
  37. }
  38.  
  39. private static Promise<Double> registerListener() {
  40. // TODO Auto-generated method stub
  41.  
  42. System.out.println("Listener boolean value :"+checkflag);
  43. Promise<Double> pd = Akka.future(
  44. new Callable<Double>()
  45. {
  46. public Double call()
  47. {
  48.  
  49. if (checkflag)
  50. {
  51. dataValue = 3.14;
  52. return dataValue;
  53. }
  54. else
  55. {
  56. dataValue = null;
  57. return dataValue;
  58. }
  59. }
  60. }
  61. );
  62.  
  63. if(dataValue == null)
  64. {
  65. pd = null;
  66. System.out.println(Thread.currentThread().hashCode());
  67.  
  68. //ping();
  69. timerCall = Akka.system().scheduler().schedule(
  70. Duration.create(0, TimeUnit.MILLISECONDS),
  71. Duration.create(10, TimeUnit.SECONDS),
  72. new Runnable() {
  73. public void run()
  74. {
  75. System.out.println(Thread.currentThread().hashCode());
  76. System.out.println("Scheduler is calling ...");
  77. if(ping())
  78. {
  79. index();
  80. }
  81. }
  82. });
  83. }
  84. return pd;
  85. }
  86.  
  87. private static boolean ping() {
  88. // TODO Auto-generated method stub
  89. System.out.println("ping boolean value :"+checkflag);
  90. {
  91. if (checkflag)
  92. {
  93. timerCall.cancel();
  94. return true;
  95. }
  96. else
  97. {
  98. return false;
  99. }
  100.  
  101. }
  102. }
  103.  
  104. public static Result changeValue()
  105. {
  106. checkflag = true;
  107. return ok("getit");
  108. }
  109.  
  110.  
  111.  
  112. -------------------------------------------------
  113.  
  114.  
  115. This is my out :
  116.  
  117. PI value computed: null
  118.  
  119.  
  120. when i run this method changeValue();
  121.  
  122.  
  123. PI value computed: 3.14
  124.  
  125. ---------------------------------------------------
  126.  
  127. here
  128. list of return type method.
  129. 1. index ()
  130. 2. registerListener()
  131. 3. ping()
  132. 4. changeValue()
  133.  
  134.  
  135. My index method should not be returned null value ? is it possible? then help me.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement