[JBoss Cache Users] - Re: Cache locking problem
by mlohbihler
A glorious end. The transactional stuff solved the problem.
Well, mostly... The evolved code is below. But even with transactions doing their duty i still noticed gaps in the data. I had to put sleeps into the loops because when all threads run at full speed a literal clusterf*** ensues... rollback and timeout exceptions go flying everywhere.
But with the delays in there, things calm down nicely. Even still, although the results are reassuring, they are not exact. The below code should end up with a final count of 1000, but instead twice it ended with 999. I assumed it was a bug, but in the output i noticed that this message was written twice: "Put 91". This means something slipped between the cluster cracks somewhere.
I don't need to do updates as quickly as i coded for in these tests - i was just testing the boundaries. And indeed, these results are good enough for my present purposes. Overall i think it's great stuff, but it would seem that there may still be small holes in the MVCC code.
public static void main(String[] args) throws Exception {
| Cache<String, Integer> cache = new DefaultCacheFactory<String, Integer>().createCache("conf/cache.xml");
|
| // Wait for other members.
| System.out.println("Waiting for other members...");
| while (cache.getMembers().size() < 4)
| Thread.sleep(50);
|
| System.out.println("Running...");
|
| TransactionManager txm = new DummyTransactionManagerLookup().getTransactionManager();
|
| Random random = new Random();
| int versioningFaults = 0;
| int rollbackFaults = 0;
| int suspectFaults = 0;
| int timeoutFaults = 0;
| for (int i=0; i<50; i++) {
| Thread.sleep(random.nextInt(2000));
|
| // Modify the cache
| while (true) {
| try {
| txm.begin();
|
| Integer count = cache.getRoot().get("key");
| if (count == null)
| count = 0;
| count++;
|
| while (true) {
| try {
| cache.getRoot().put("key", count);
| System.out.println("Put "+ count);
| break;
| }
| catch (SuspectException e) {
| suspectFaults++;
| }
| catch (TimeoutException e) {
| timeoutFaults++;
| }
| }
|
| txm.commit();
| break;
| }
| catch (DataVersioningException e) {
| txm.rollback();
| versioningFaults++;
| }
| catch (RollbackException e) {
| rollbackFaults++;
| }
| }
| }
|
| System.out.println("Final count: "+ cache.getRoot().get("key"));
| System.out.println("Versioning faults: "+ versioningFaults);
| System.out.println("Rollback faults: "+ rollbackFaults);
| System.out.println("Suspect faults: "+ suspectFaults);
| System.out.println("Timeout faults: "+ timeoutFaults);
|
| cache.stop();
| cache.destroy();
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260670#4260670
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260670
16 years, 9 months
[JBoss Web Services Users] - Getting error when submitting form using SpringMVC and REST
by socal_javaguy
Hello there,
Created an online form in JSP using SpringMVC tag libraries. The controller for my form is a RESTful web service (JBoss RESTEasy).
The RESTful web service has two calls:
(1) http://localhost:8080/myapp/applications/new
This brings up the online form in the browser (this works).
(2) http://localhost:8080/myapp/applications/create
This saves the form data to a database (handles submit). This is where it breaks.
Followed the conventions from the sample demo petclinic app which comes with the Spring Framework.
Online form:
| <%@ page contentType="text/html;charset=UTF-8" language="java"%>
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
| <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
| <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
| <html>
| <body>
| <form:form modelAttribute="application" method="POST" action="create">
| <table>
| <tr>
| <td>Name:</td>
| <td><form:input path="name" size="30" maxlength="80"/></td>
| </tr>
| <tr>
| <td>Description:</td>
| <td><form:input path="description" size="30" maxlength="80"/></td>
| </tr>
| <tr>
| <td>Image URL:</td>
| <td><form:input path="imgUrl" size="30" maxlength="80"/></td>
| </tr>
| </table>
| <input type="submit" value="Save" />
| </form:form>
| </body>
| </html>
|
The RESTful web service which serves as form controller:
| @Controller
| @Path(ApplicationsResource.APPLICATION_URL)
| public class ApplicationsResource
| {
| private final Logger log = LoggerFactory.getLogger(ApplicationsResource.class);
|
| public static final String APPLICATION_URL = "/applications";
|
| @Autowired
| private ApplicationManager applicationManager;
|
| @POST
| @Path("create")
| @Produces(MediaType.TEXT_HTML)
| @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
| public void getNewApplication(@Context HttpServletRequest request, @ModelAttribute Application app)
| {
| log.info("ApplicationsResource - Inside getNewApplication() method.");
| String contentType = request.getContentType();
| log.info("Content-Type:" + contentType);
|
| try
| {
| if ("POST".equalsIgnoreCase(request.getMethod()))
| {
| if (app != null)
| {
| applicationManager.save(app);
| log.info("Added application: " + app.getName());
| }
| else
| {
| log.info("Application not added");
| }
| }
| }
| catch (Exception e)
| {
| log.info("Exception: ", e);
| throw new WebApplicationException(Response.status(RestError.SERVER_ERROR_HTTP_RESP).
| type("application/json;charset=utf-8").
| entity(new ErrorOutput(RestError.SERVER_ERROR_CODE, RestError.SERVER_ERROR_MSG, e.toString())).build());
| }
| }
|
| @InitBinder
| public void setAllowedFields(WebDataBinder dataBinder)
| {
| dataBinder.setDisallowedFields(new String[] {"id"});
| }
|
| @GET
| @Path("new")
| @Produces( { MediaType.TEXT_HTML })
| public ModelAndView getNewApplicationForm()
| {
| log.info("ApplicationsResource - Inside getNewApplicationForm");
| ModelAndView mv = new ModelAndView("/applications/applications_new");
| mv.addObject("application", new Application());
| return mv;
| }
| }
|
Exception thrown when I click on submit:
| Failed executing POST /applications/create
|
| org.jboss.resteasy.spi.BadRequestException:
|
| Could not find message body reader for type:
|
| class com.myapp.domain.Application
|
| of content type: application/x-www-form-urlencoded
| at org.jboss.resteasy.core.MessageBodyParameterInjector$1.createReaderNotFound(MessageBodyParameterInjector.java:73)
| at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:105)
| at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93)
| at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:120)
| at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:93)
|
Does anyone know why I am getting this exception?
Would really appreciate it if someone could help me with this issue...
Happy programming and thank you for taking the time to read this.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260661#4260661
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260661
16 years, 9 months
[JBoss Cache Users] - Re: Cache locking problem
by mlohbihler
Ok, i've tried a number of different things now including using the configuration from Manik's demo, but nothing fixes the problem. The only thing i haven't tried is wrapping my put into a transaction, but since i can't find any code or documentation that suggests this is necessary, i'm saving it for my glorious last effort.
I've simplified the code that i can using to test. As before, using debugging it's easy to see that data versioning exceptions are not being thrown as they should. When i just let it run, the counter only gets incremented to around 2000, when it should reach exactly 3000.
public static void main(String[] args) throws Exception {
| Cache<String, Integer> cache = new DefaultCacheFactory<String, Integer>().createCache("conf/cache.xml");
| Node<String, Integer> root = cache.getRoot();
|
| // Wait for other members.
| System.out.println("Waiting for other members...");
| while (cache.getMembers().size() < 3)
| Thread.sleep(50);
|
| System.out.println("Running...");
|
| int versioningFaults = 0;
| for (int i=0; i<1000; i++) {
| // Modify the cache
| while (true) {
| try {
| Integer count = root.get("key");
| if (count == null)
| count = 0;
| count++;
| while (true) {
| try {
| root.put("key", count);
| break;
| }
| catch (SuspectException e) {}
| catch (TimeoutException e) {}
| }
| break;
| }
| catch (DataVersioningException e) {
| versioningFaults++;
| }
| }
| }
|
| System.out.println("Final count: "+ root.get("key") +", faults: "+ versioningFaults);
|
| cache.stop();
| cache.destroy();
| }
|
As before, any help, hints, and at this point even flames, etc are greatly appreciated.
Regards,
m@
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260656#4260656
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260656
16 years, 9 months