我想调用任意控制操作,由指定的String
,从Job
的子类。
我曾尝试接受答案这个问题 ,但发现,它并没有为我工作... WS.url("http://www.yahoo.com/").get();
作品,但WS.url("http://localhost/foo/bar").get()
块,并最终超时60秒后。
我也曾尝试增加play.pool
价值application.conf
,在推荐这个答案 ,但它并没有区别。
这里是我的代码:
application.conf:
# Execution pool
# ~~~~~
# Default to 1 thread in DEV mode or (nb processors + 1) threads in PROD mode.
# Try to keep a low as possible. 1 thread will serialize all requests (very useful for debugging purpose)
play.pool=3
路线:
PUT /jobs/invokejob Jobs.invokeTestJob
GET /jobs/sampleAction Jobs.sampleControllerAction
Jobs.java:
public static void invokeTestJob()
{
Logger.warn("Jobs.invokeTestJob() called");
new SampleJob("Jobs.sampleControllerAction").in(1);
Logger.warn("Finished scheduling SampleJob");
listJobs();
}
public static void sampleControllerAction()
{
Logger.warn("Jobs.sampleControllerAction() called");
renderText("OK");
}
SampleJob.java:
public class SampleJob extends QJob
{
public final String action;
public SampleJob(String actionSpec)
{
this.action = actionSpec;
}
@Override
public void doJob()
{
Logger.warn("SampleJob.doJob() called");
final ActionDefinition actionDefinition = Router.reverse(action);
actionDefinition.absolute();
final WSRequest URL = WS.url(actionDefinition.url);
HttpResponse response = null;
switch(actionDefinition.method)
{
case "GET":
{
Logger.warn("GETting %s", URL.url);
response = URL.get();
break;
}
case "POST":
{
Logger.warn("POSTting %s", URL.url);
response = URL.post();
break;
}
case "PUT":
{
Logger.warn("PUTting %s", URL.url);
response = URL.put();
break;
}
case "DELETE":
{
Logger.warn("DELETEing %s", URL.url);
response = URL.delete();
break;
}
}
Logger.warn("response=%s", response.getString());
}
}
日志输出:
13:22:50,783 WARN [play-thread-1] ~ Jobs.invokeTestJob() called
13:22:50,786 WARN [play-thread-1] ~ Finished scheduling SampleJob
13:22:51,804 WARN [jobs-thread-1] ~ SampleJob.doJob() called
13:22:51,857 WARN [jobs-thread-1] ~ GETting http://localhost/quattro/jobs/sampleAction
13:23:51,886 ERROR [jobs-thread-1] ~
@6fe61pf2p
Error during job execution (jobs.SampleJob)
Execution exception (In {module:quattro}/app/jobs/SampleJob.java around line 36)
RuntimeException occured : java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: No response received after 60000
play.exceptions.JavaExecutionException: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: No response received after 60000
at play.jobs.Job.call(Job.java:155)
at play.jobs.Job$2.call(Job.java:94)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: No response received after 60000
at play.libs.ws.WSAsync$WSAsyncRequest.get(WSAsync.java:223)
at jobs.SampleJob.doJob(SampleJob.java:36)
at play.jobs.Job.doJobWithResult(Job.java:50)
at play.jobs.Job.call(Job.java:146)
... 8 more
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: No response received after 60000
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyResponseFuture.java:223)
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyResponseFuture.java:187)
at play.libs.ws.WSAsync$WSAsyncRequest.get(WSAsync.java:221)
... 11 more
Caused by: java.util.concurrent.TimeoutException: No response received after 60000
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyResponseFuture.java:215)
... 13 more
注之间的时间间隔13:22:51,857
和13:23:51,886
-这是60秒的超时。
任何想法有什么不对?
现在,我只是试图让这个简单的情况下工作。 后来,我需要与请求提供饼干等。
另外,我不使用的念头超级舒适WS
对于这一点,因为我不是真的想另一台主机上访问web服务; 我试图调用一些代码,这是我自己的应用程序,因此它似乎有点傻不得不产生一个实际的HTTP请求回我自己。 是不是有什么办法可以在内部构建一个请求的内容,只是直接调用的操作方法?
正如上面提到的,这种预期的目的,是让任意控制器动作被调度在我的系统工作。 我想避免的每一个我们需要安排工作,做一些事情,一些控制器代码已经这样做时写的代码。