Extracting selected pivot tree items

The pivot TreeView only returns selected paths. A path is a list of list indexes which refer to the underlying data model of a tree. Unfortunately, the treeview doesn’t have a convenience method for extracting the items referenced by those paths. Here’s that missing method:

public static List extractSelectedObjects(TreeView tv)
    {
        List retList = new ArrayList();
        
        for (Path p : tv.getSelectedPaths())
        {
            Object currBranch = tv.getTreeData();

            for (int i : p)
            {
                currBranch = ((List) currBranch).get(i);
            }
            retList.add(currBranch);
        }

        return retList;
    }

Preventing grizzly timeouts

In grizzly, the default timeout for an http process is 5 minutes. This applies to the total activity time. In most cases, this is fine, however for long uploads you may need to extend this. Oh say for uploading 50g files. There is a switch for disabling timeouts, however this is global. What we need is a timeout for connections that are still active. Inactive connections should close 5m after last activity.

Grizzly logs the following:

Aug 12, 2010 3:17:25 PM com.sun.grizzly.http.KeepAliveThreadAttachment timedOut
WARNING: GRIZZLY0023: Interrupting idle Thread: Grizzly-8080(2).
Aug 12, 2010 3:17:27 PM com.sun.grizzly.http.KeepAliveThreadAttachment timedOut
WARNING: GRIZZLY0023: Interrupting idle Thread: Grizzly-8080(3).

The somewhat messy solution is the pick apart the thread that your request is running in and toggle timeouts as needed.

while ((read = in.read(byteArray)) != -1)
            {
                if ((System.currentTimeMillis() - lastXmit) > 5000)
                {
                    HttpWorkerThread thread = (HttpWorkerThread)Thread.currentThread();
                    ((SelectionKeyAttachment) thread.getProcessorTask().getSelectionKey().attachment()).setTimeout(lastXmit);
                    lastXmit = System.currentTimeMillis();
                }
                buffer.clear();
                buffer.limit(read);
                openFile.write(buffer);
            }

Head bashing

When working with smartclient and trying to get pages to render on IE, you may see a lot of random “‘something’ is null or not an object” messages. This is caused by a dangling , in your list of items. Most times, look at the members or fields array for the little beastie hanging around at the end.

J2Weeeeeeeeeee

As strongbad would say, for good or for awesome…


@Path("/orders/")
@Interceptors(CallAudit.class)
@Stateless public class OrderService {

  @EJB BillingService billing;
  @EJB DeliveryService delivery;
  @EJB Warehouse warehouse;

  @PUT
  @Produces({"application/xml","application/json"})
  @Consumes({"application/xml","application/json"})
  public Order order(Order newOrder){
      Order order = warehouse.checkout(newOrder);
      billing.payForOrder(order);
      delivery.deliver(order);
      return order;
  }

  @GET
  @Path("{orderid}/")
  @Produces({"application/xml","application/json"})
  public Order status(@PathParam("orderid") long orderId){
     return delivery.status(orderId);
  }
}

Full details here