Hello,
I am using restlet 2.1.1 to implement a HTTP server. everything works OK except
once in a while the server takes an awful long time to respond (even for a
simple HTTP GET via the browser).
On the server side I see these errors:
Jan 07, 2013 2:19:32 PM org.restlet.util.SelectionRegistration block
WARNING: The thread blocked at the cyclic barrier has timed out
java.util.concurrent.TimeoutException
at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:250)
at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:427)
at org.restlet.util.SelectionRegistration.block(SelectionRegistration.java:191)
at
org.restlet.engine.io.NbChannelInputStream.onFill(NbChannelInputStream.java:230)
at org.restlet.engine.io.Buffer.process(Buffer.java:601)
at
org.restlet.engine.io.NbChannelInputStream.read(NbChannelInputStream.java:307)
at java.io.InputStream.read(InputStream.java:101)
at org.restlet.engine.io.BioUtils.exhaust(BioUtils.java:238)
at org.restlet.representation.Representation.exhaust(Representation.java:247)
at
org.restlet.engine.connector.ServerOutboundWay.onMessageCompleted(ServerOutboundWay.java:174)
at
org.restlet.engine.connector.HttpServerOutboundWay.onMessageCompleted(HttpServerOutboundWay.java:118)
at
org.restlet.engine.connector.OutboundWay.processIoBuffer(OutboundWay.java:468)
at org.restlet.engine.connector.Way.onSelected(Way.java:445)
at
org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
at org.restlet.engine.connector.Connection.onSelected(Connection.java:614)
at
org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
at
org.restlet.engine.connector.ConnectionController.onSelected(ConnectionController.java:213)
at
org.restlet.engine.connector.ServerConnectionController.onSelected(ServerConnectionController.java:99)
at
org.restlet.engine.connector.ConnectionController.selectKeys(ConnectionController.java:299)
at
org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:167)
at org.restlet.engine.connector.Controller.run(Controller.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Jan 07, 2013 2:19:32 PM org.restlet.engine.connector.ServerOutboundWay
onMessageCompleted
WARNING: Unable to automatically exhaust the request entity.
java.io.IOException: The thread blocked at the cyclic barrier has timed out.
at org.restlet.util.SelectionRegistration.block(SelectionRegistration.java:197)
at
org.restlet.engine.io.NbChannelInputStream.onFill(NbChannelInputStream.java:230)
at org.restlet.engine.io.Buffer.process(Buffer.java:601)
at
org.restlet.engine.io.NbChannelInputStream.read(NbChannelInputStream.java:307)
at java.io.InputStream.read(InputStream.java:101)
at org.restlet.engine.io.BioUtils.exhaust(BioUtils.java:238)
at org.restlet.representation.Representation.exhaust(Representation.java:247)
at
org.restlet.engine.connector.ServerOutboundWay.onMessageCompleted(ServerOutboundWay.java:174)
at
org.restlet.engine.connector.HttpServerOutboundWay.onMessageCompleted(HttpServerOutboundWay.java:118)
at
org.restlet.engine.connector.OutboundWay.processIoBuffer(OutboundWay.java:468)
at org.restlet.engine.connector.Way.onSelected(Way.java:445)
at
org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
at org.restlet.engine.connector.Connection.onSelected(Connection.java:614)
at
org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
at
org.restlet.engine.connector.ConnectionController.onSelected(ConnectionController.java:213)
at
org.restlet.engine.connector.ServerConnectionController.onSelected(ServerConnectionController.java:99)
at
org.restlet.engine.connector.ConnectionController.selectKeys(ConnectionController.java:299)
at
org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:167)
at org.restlet.engine.connector.Controller.run(Controller.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:250)
at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:427)
at org.restlet.util.SelectionRegistration.block(SelectionRegistration.java:191)
... 24 more
Here is my code:
public static void Start(int port)
{
Component m_component = new Component();
m_component.getServers().add(Protocol.HTTP,
port);
m_component.getDefaultHost().attach("/",
RestAcceptor.class);
try
{
m_component.start();
}
catch (Exception ex)
{
m_logger.error("Error starting
RestAcceptor! " + ex.getMessage());
}
}
@SuppressWarnings("unchecked")
static Series<Header> getMessageHeaders(Message message)
{
ConcurrentMap<String, Object> attrs = message.getAttributes();
Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY);
if (headers == null)
{
headers = new Series<Header>(Header.class);
Series<Header> prev = (Series<Header>)
attrs.putIfAbsent(HEADERS_KEY, headers);
if (prev != null) { headers = prev; }
}
return headers;
}
@Get
public Representation doGet()
{
if (getReference().getRemainingPart().equals("favicon.ico"))
return new FileRepresentation(m_favicon, MediaType.IMAGE_ICON);
getMessageHeaders(getResponse()).add("Access-Control-Allow-Origin",
"*");
Map<String, Object> params = getRequest().getAttributes();
if(params == null)
params = new ConcurrentHashMap<String, Object>();
Form form = getReference().getQueryAsForm();
for (Parameter parameter : form)
{
params.put(parameter.getName().toLowerCase(), parameter.getValue());
}
// generate and return JSON
String jsonResult = null;
try
{
UrlParser.ParsedUrl result = UrlParser.ParseGetUrl(
getReference().getPath(), params);
jsonResult = ProcessResult(result);
}
catch(MyException ex)
{
m_logger.error("Error while processing GET "
+ getReference() + " Message: " + ex.getMessage());
jsonResult = GetErrorMessage(ex.getMessage());
}
catch(InterruptedException ex)
{
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
m_logger.info("returning " + jsonResult + " for " +
getReference().getRemainingPart());
return new StringRepresentation(jsonResult, MediaType.APPLICATION_JSON);
}
@Post
public Representation doPost(Representation file)
{
//some moere code
}
@Post("json:json")
public Representation doPost(JsonRepresentation entity)
{
//some moere code
}
@Delete
public Representation doDelete()
{
//some moere code
}
@Options
public void doOptions(Representation entity)
{
getMessageHeaders(getResponse()).add("Access-Control-Allow-Origin",
"*");
getMessageHeaders(getResponse()).add("Access-Control-Allow-Methods",
"GET, PUT, POST, DELETE, OPTIONS");
getMessageHeaders(getResponse()).add("Access-Control-Allow-Headers",
"Content-Type");
getMessageHeaders(getResponse()).add("Access-Control-Allow-Credentials",
"false");
getMessageHeaders(getResponse()).add("Access-Control-Max-Age", "60");
}
Any help appreciated.
Aliza
________________________________
This message is confidential and intended only for the addressee. If you have
received this message in error, please immediately notify the
[email protected] and delete it from your system as well as any copies. The
content of e-mails as well as traffic data may be monitored by NDS for
employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.
An NDS Group Limited company. www.nds.com
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3041588