Saturday, October 15, 2011

Browser plugin won't connect to dev mode?

I was driven almost to insanity yesterday trying to get GWT dev mode to work. In this case, the launch configuration (which had been working correctly for years) worked. Dev mode would start in eclipse and my application would load. Double click on the default URL, however, and nothing happens. The page loads in the browser but the GWT bootstrap doesn't seem to execute. No connection is made to the code server. No client appears under the OOPHM tree and no messages appear in the Development Mode window the way they should. I tried everything. I uninstalled and re-installed my Chrome plugin. I grabbed a fresh eclipse and checked out the project from source. I even resorted to trying IE. Nothing...

After beating my head against the wall for a few hours I cleared Chrome's cache. Problem solved. I don't know why I didn't think of that earlier, but I've never encountered this trouble before. So if dev mode won't connect: clear your cache...

Thursday, July 22, 2010

PMC Open Access JAXB Bindings

If you're trying to generate Java JAXB for the NLM Journal Publishing DTD http://dtd.nlm.nih.gov/publishing/w3c-schema.html you're going to run into some problems with the bindings. Some of these are related to MathML and some are related to the NLM schema. In particular mine look like:
Trying to override old definition of datatype resources
OpenAccesJaxb:
     [exec] parsing a schema...
     [exec] [ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict.
     [exec]   line 1185 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 1227 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd
     [exec] [ERROR] Element "{http://www.w3.org/1998/Math/MathML}ms" shows up in more than one properties.
     [exec]   line 132 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 113 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/tokens.xsd
     [exec] [ERROR] Property "MiOrMoOrMn" is already defined. Use <jaxb:property> to resolve this conflict.
     [exec]   line 132 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 138 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] Element "{http://www.w3.org/1998/Math/MathML}ms" shows up in more than one properties.
     [exec]   line 138 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 113 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/tokens.xsd
     [exec] Failed to parse a schema.
     [exec] Result: -1

The easiest solution is to add a custom bindings file. Thanks to this useful post the MathML errors are easily resolved. Then you just need to add one more to fix the "title" property problem. My final XJB file ends up looking like:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0">

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd"
    node="/xsd:schema/xsd:element[@name='bio']//xsd:element[@ref='title']">
    <property name="biotitle" />
  </bindings>

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/common/common-attribs.xsd"
    node="/xsd:schema/xsd:attributeGroup[@name='Common.attrib']/xsd:attribute[@name='class']">
    <property name="clazz" />
  </bindings>

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd"
    node="/xsd:schema/xsd:group[@name='mmultiscripts.content']">
    <property name="content" />
  </bindings>

</bindings>
and my ant task to generate the bindings looks like:
<target name="OpenAccesJaxb" description="Generate the Open Access JAXB bindings">
  <exec executable="xjc">
    <arg value="-b"/>
    <arg value="pmcOa.xjb"/>
    <arg value="-d"/>
    <arg value="src"/>
    <arg value="-p"/>
    <arg value="${pmc.oa.package.jaxb}"/>
    <arg value="${pmc.oa.schema}"/>
  </exec>
</target>

Where the last two properties point to the package the code should be generated in and pubmed schema location respectively...

Friday, May 7, 2010

Remote Katta client example

I couldn't find too much information on running external Katta clients so here's an example of how I ended up getting it to work:
import net.sf.katta.lib.lucene.Hit;
import net.sf.katta.lib.lucene.Hits;
import net.sf.katta.lib.lucene.ILuceneClient;

import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.io.Text;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;

import com.google.inject.Inject;
import com.google.inject.internal.Lists;

public class SomeSearchKattaImpl implements SomeSearch {

 private final Analyzer analyzer;
 private final ILuceneClient client;
 private final List indexedFields;
 private static final String[] indexName = {"field"}; 
 
 @Inject
 protected SomeSearchKattaImpl(Logger logger, StandardAnalyzer analyzer,
   ILuceneClient client) {
  this.logger = logger;
  this.client = client;
  this.analyzer = analyzer;
  
  indexedFields = Lists.newArrayList();
  indexedFields.add(Field1);
  indexedFields.add(Field2);
  this.logger.fine(getClass().getName() + " loaded...");
 }
 
 private Query getQuery(String query) throws ParseException {  
  MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_30,
    (String[])indexedFields.toArray(new String[0]), analyzer);
  return parser.parse(query);
 }
 
 @Override
 public List getResults(
   String query, int start, int count) throws Exception {
  Query q = getQuery(query);
  Hits hits = client.search(q, indexName, start + count);
  List window = hits.getHits().subList(start, 
    (hits.getHits().size() < start + count) ? hits.getHits().size() : start + count);
  List results = Lists.newArrayList();
  //TODO: Should we limit this by field?
  for (MapWritable writable: client.getDetails(window)) {
   ResultLite result = new ResultLite();

   result.setSomething(writable.get(new Text("title")).toString());
   results.add(result);
  }
  return results;
 }
}

and I injected the LuceneClient like this:
@Provides 
public ILuceneClient getLuceneClient() {  
 ZkConfiguration config = 
  new ZkConfiguration("/katta/katta.zk.properties");
        
 ILuceneClient client = new LuceneClient(config);
 return client;
}

Thursday, February 18, 2010

Postgres JDBC as a Memory Hog

I had a strange problem today when building an offline index of a large Postgres ResultSet. I launched jconsole and just watched the memory disappear until the heap was exhausted. After digging around it turns out that Postgres (unlike other JDBC drivers) will not use a cursor unless you set auto commit to false on your connection:
conn.setAutoCommit(false);
In addition I set specific options to the Statement:
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
which also may have helped, but I didn't test without those settings. Now I can watch the memory oscillate in jconsole but it never gets above 50m and more importantly I can close my ticket...

Sunday, December 6, 2009

Windows Media Center?

With Mark's goading I decided to install a "media center". Why? I have no clue. I've been using a Thinkpad T40 as a media server running VLC or Media Player Classic on an external HD projector. This works fine. I guess the "media center" is optimized for this sort of situation, but at the end of it I'm not convinced that it's worth the time - unless you're going to use it as a TV tuner (which I do not) or watch Netflix (which I do not). Here's how it went:

1) I tried Windows 7 Ultimate - which was a struggle. I finally got everything running but I had a very difficult time getting the ATI Radeon Mobility 9000 drivers running. Finally I got some Vista drivers but it ended up reversing the displays and I couldn't ever get them correct. Additionally it ran a bit slow on the old Pentium 1.7 w 2gb of RAM.

2) I thought about Vista, but realized that, too, would be a resource hog. Didn't bother to check it out.

3) Given that this machine is circa 2004 I tried Windows XP Media Center Edition 2005. The install process is a bit grueling because it wants a Windows XP Service Pack 2 CD, as well. I used a VL XP CD with Service Pack 3 and it seemed happy. Then in the end it asks for some other CD - but I just popped in CD 1 and it finished. Then of course there are 100 some updates to install. So essentially at this point I'm back where I started - an XP machine except it has "Windows Media Center". Sweet! Actually it has more - it also has the "Windows Dancers". They dance above the task bar in time to the music. If you ever wonder why Microsoft is going to loose to Google it's because of things like this. It's sort of amazing that management green lighted "Windows Dancers". Anyhow there's also "party mode" for audio. I tried this later that night but it did not seem to improve the party.

There are few problems with this setup, however:
1) Windows MCE 2005 won't play DVD content out of the box. I tried a few community codec packs but Windows is still not happy with any of the MPEG2 codecs. Finally I found this. I installed this MPEG2 codec and finally Media Center is happy.
2) The next problem is that it seems to not recognize DVDs folders on the hard drive. I installed "My Movies" and in a few minutes had a really slick display with covers, etc.

Of course with MCE 2005 you can't stream Netflix like you can in Windows 7 and much of the Online content is totally outdated. If you can make Windows 7 go - it's probably a much better bet. Another option that I only scratched the surface of it http://xbmc.org/. This runs a bit slow on the T40 but seems to have potential...

Tuesday, October 20, 2009

Vanishing Eclipse CVS Decorations

I'm not sure what I installed or changed but for the past week my CVS "Label Decorations" in eclipse have gone missing - driving my almost insane since I have to switch to the synchronization view to see what I've done to the code. It took me a while just to figure out that they're called "Label Decorations" and there are a whole bunch of options under Preferences->Team->CVS->Label Decorations. I toyed with this to no avail. But finally I've figure out the trouble. Something had turned off the "Label Decorations" in the Package view. To solve the problem:
1) Select a project in the package view
2) Choose Window->Preferences
3) Look at General->Appearance->Label Decorations
4) Make sure that CVS is checked

Thursday, October 8, 2009

Tomcat Locked Resources

So I spent a few minutes the other day setting up a nice ant task to deploy my war file to Tomcat automatically. It worked the first time, but not the second time - because Tomcat still had some jars locked down in the WEB-INF directory. Today I finally figured out a solution to the problem. One can add this the following attributes to the META-INF/context.xml file to solve the trouble...

antiJARLocking
If true, the Tomcat classloader will take extra measures to avoid JAR file locking when resources are accessed inside JARs through URLs. This will impact startup time of applications, but could prove to be useful on platforms or configurations where file locking can occur. If not specified, the default value is false.

antiResourceLocking
If true, Tomcat will prevent any file locking. This will significantly impact startup time of applications, but allows full webapp hot deploy and undeploy on platforms or configurations where file locking can occur. If not specified, the default value is false.
Please note that setting this to true has some side effects, including the disabling of JSP reloading in a running server: see Bugzilla 37668.
Please note that setting this flag to true in applications that are outside the appBase for the Host (the webapps directory by default) will cause the application to be deleted on Tomcat shutdown. You probably don't want to do this, so think twice before setting antiResourceLocking=true on a webapp that's outside the appBase for its Host.

the above from http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

In a minimal sense:
<Context antiJARLocking="true" antiResourceLocking="true" />

is all you need.