codemonkey
blog
blog
25 Aug 10
Had to sync imap mailboxes from the old (gentoo) server to the new (osx server) one, found multiple tools but couldn’t get any of them to work except for larch which works as an IMAP client instead of messing with the maildirs in some way.
On my OSX laptop I needed to install some dependent modules for ruby to run it:
$ gem install trollop --include-dependencies
and then
$ gem install larchAnd finally, to do the actual migration – connect to the old server and the new server and copy all messages:
$ bin/larch --from imaps://oldserver.local --to imap://newserver.local
24 Aug 10
PMD and NetBeans both give warnings about calling non-final non-private methods from the constructor of a class.
I never really understood why it was such a bad thing until today. I was hit by the problem it causes when subclassing one of the swing model classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class CustomButtonModel extends DefaultButtonModel { private final SomeClass object; public CustomButtonModel(SomeClass object) { if (object == null) throw new IllegalArgumentException("null object is a nono"); this.object = object; } public void setEnabled(boolean enabled) { super.setEnabled(enabled && object.evaluate()); } } |
And i was getting a NullPointerException in setEnabled which should be impossible if you just look at the class. Running a debugger I could confirm that object was null but it took quite a while to figure out that DefaultButtonModel was calling setEnabled() from its default constructor before object had been assigned.
23 Jul 10
The calendar server shipped with Snow Leopard Server includes some neat features if you actually use the open directory, for example if you are a small company. As we are not a company and the feature I had hoped for, syncing with our iPhones, was not present I decided to revert to our previous solution for sharing calendars in our household: webdav.
iCal has a very useable built in support for publishing calendars over HTTP to a WebDAV server. To set that up on Snow Leopard Server:
Create a directory for the calendars where apache may write:
$ sudo mkdir /Library/WebServer/Documents/calendars $ sudo chown _www /Library/WebServer/Documents/calendars
Enable authentication modules and webdav in /etc/apache2/httpd.conf by uncommenting the following rows:
LoadModule auth_basic_module libexec/apache2/mod_auth_basic.so ... LoadModule dav_module libexec/apache2/mod_dav.so ... LoadModule apple_auth_module libexec/apache2/mod_auth_apple.so
There is already some configuration for webdav present in the virtual host configuration file:
<IfModule mod_dav.c> DAVLockDB "/var/run/davlocks/.davlock100" DAVMinTimeout 600 </IfModule>
But the folder /var/run/davlocks did not exist on our server so it was created and setup with the apache user (_www) as owner so that apache was allowed to write to it.
We will setup dav so that authentivation is done with accounts on the server but you may just as well use .httpasswd or whatever auth scheme you prefer that there are apache modules for.
To configure apache to share the directory we created with DAV and require authentication we need to edit the virtual hosts files. We set it up to only be available through the HTTPS instance of apache to make sure our usernames and passwords are safely transmitted. On our server this was the file/etc/apache2/sites/0001_any_443_ourserver.com.conf:
<Directory "/Library/WebServer/Documents/calendars"> Options None AllowOverride None DAV On AuthName 'WebDAV' AuthType Basic AuthUserFile /dev/null AuthBasicAuthoritative Off Require valid-user </Directory>
Thats it, now it is possible to “publish” the iCal calendars at https://ourserver/calendars/ from inside iCal and share it with other people with accounts on the same server.
19 Jul 10
I stumbled upon this problem when I decided to use cable instead of wifi to connect my server to the internet. Even after connecting a fully working ethernet cable to the mac mini the interface did not appear in the network panel under “System Preferences”. Checkin ifconfig and the system profiler did not show any built in ethernet device.
It turns out the OSX Server version I had installed predates the hardware so therefore there were some drivers missing. After googling a bit and reading confusing posts at apple support this solved my problem:
From the OSX DVD bundled with the mac mini (regular snow leopard) i copied the following drivers:
Mac OS X Install DVD/System/Library/Extensions/AppleSDXC.kextMac OS X Install DVD/System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleBCM5701Ethernet.kextMac OS X Install DVD/System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/nvenet.kextinto the corresponding folders under /System/Library/Extensions on the server making sure to preserve permissions, owner and group. Also: the two kexts in IONetworkingFamily already existed so I kept a backup of those just in case this would screw something up.
I then reloaded the drivers with kextutil, like this:
sudo kextload /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/nvenet.kext sudo kextload /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleBCM5701Ethernet.kext sudo kextload /System/Library/Extensions/AppleSDXC.kext
And voila: the ethernet interface appeared without even restarting the server.
One more thing though: OSX keeps caches of the kexts to speed things up, if you do not trigger a rebuild of that cache the drivers will not be autoloaded on next boot and you will have to to do the manual loading with kextload
To trigger a rebuild of the cache simply change the timestamp on /System/Library/Extensions with touch and a system daemon (kextd) will rebuild the cache.
Some more info might be found in the apple discussion board post I based my solution on.
18 Jul 10
This saturday I decided to connect my 2010 MacBook Pro to the 5.1 reciever to watch mkv videos. After doing some reading i figured out that I needed a mini displayport to HDMI adapter for the video and a TosLink + a 3,5mm adapter for the optical output hidden in the headphone port on the laptop.
Checking out some stores in Stockholm it all would land on somewhere around 600 SEK (~60€). Quite a hefty price tag for two cables and in addition to that I had to visit two stores since neither had both the adapters in stock. On the way to the store I figured I should check out this radioshack-type-store called Kjell&Company where I to my surprise found all I needed for about half the expected price. Woho!
When I came home I connected the laptop to the receiver, fired up VLC to watch the videos and configured it to pass AC3 and DTS through the digital cable instead of decoding it. The receiver directly understood that there was 5.1 audio sent through the optical cable but once every 20 seconds or so it lost the signal and there was a short silence introduced. It was extremely annoying and unbearable so to live with it was not an option.
I sought all over the net (apples forums, vlc forums), tried every configuration parameter in VLC that could affect the sound, tried MPlayer, tried XMBC but nothing solved the problem. I tried to enable passthrough of audio directly from a DVD with the apple DVD player but got the same problem.
It turns out it was the cheap TosLink cable that was the problem. I had another device connected with a bit more expensive optical cable and switching the cables solved the problem. Hopes this helps someone having the same problem.
11 Dec 09
We have long had the problem that redeploying our Java EE application on JBoss 4.2.2 was leaking lots of memory. We have a quite large enterprise app and we are talking about 10 of megabytes permgen per redeploy resulting in a permgen out of memory exception crashing the Jboss instance after a few redeploys.
Searching the net we have found lots of “explanations” and “solutions” going from class generation (CGLIB or Javassist bugs) to just increasing the maximum permgen size or switching to another JVM that does not have a fixed part of its memory for classes (and actually just postponing the crash).
After spending some time with heapdumps and MAT (eclipse memory analyzer, great application by the way) I figured this out: the hibernate usertype for enums is the culprit. It keeps a list of the enum values and the java enums have a static references to the classloader making it impossible for the Jboss classloaders to be garbage collected after an application has been undeployed. The classloader holds a reference to each class in the previously deployed application that in turn cannot be garbage collected.
I found #HHH-4317 in the Hibernate issue management system that describes the problem. We have not figured out a solution yet though, I think it probably will end with a patched hibernate on our installation sites (keeping some kind of weak references to the enum values in EnumType).
Edit 2010-03-12: the hibernate developers seems to have solved this bug in hibernate 3.5.0!
10 Nov 09
Lately I have been setting up some second level cache for Hibernate to speed up our JEE application at work. To find out how good the cache was configured I wanted to setup the Hibernate statistics MBean and the EhCache monitoring MBeans so that I could do some monitoring with JConsole.
The problem was that we use Hibernate as a JPA provider rather than directly which made it a bit tricky to get the MBeans up and running. This is how I did it.
First tell JBoss to publish the entity manager on JNDI by putting this line in your persistence.xml-file: <property name="jboss.entity.manager.jndi.name" value="myapp/EntityManager" />. Also make sure you use the net.sf.ehcache.hibernate.SingletonEhCacheProvider second level cache provider.
Finally create a JBoss service, something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | @Local(MonitoringServiceMBean.class) @Service(objectName = "myapp:service=monitoring") @Management(MonitoringServiceMBean.class) public class MonitoringService implements MonitoringServiceMBean { private static final Logger LOGGER = Logger.getLogger(MonitoringService.class); public void start() throws Exception { LOGGER.info("MonitoringService - Starting"); // We need to do it this way to register beans on the JBoss mbean server MBeanServer mbs = MBeanServerFactory.findMBeanServer(null).get(0); ObjectName on = new ObjectName("Hibernate:type=statistics,application=myapp"); // Enable Hibernate JMX Statistics StatisticsService statsMBean = new StatisticsService(); SessionFactory sf = getSessionFactory(); statsMBean.setSessionFactory(sf); statsMBean.setStatisticsEnabled(true); mbs.registerMBean(statsMBean, on); // Enable Ehcache JMX Statistics // Use CacheManager.getInstance() instead of new CacheManager() // as net.sf.ehcache.hibernate.SingletonEhCacheProvider is used // to ensure reference to the same CacheManager instance as used // by Hibernate CacheManager cacheMgr = CacheManager.getInstance(); ManagementService.registerMBeans(cacheMgr, mbs, true, true, true, true); } ... |
Now you will have access to cache and entity statistics through JConsole for your Hibernate JEE app.
2 Nov 09
I was thinking about how the target audience for this blog was severely limited by writing in swedish and decided to start to write posts in english instead. I’ll leave to old swedish posts for now but all new posts will be in english.
1 Sep 09
Har precis installerat apples uppdatering till 10.6. Gick hyffsat snabbt och jag tjänade på något märkligt sätt 16 Gb i ledigt diskutrymme på det.
Alla program som följer med operativsystemet känns lite mer responsiva. Javascripttunga sidor som t.ex. google maps känns avsevärt mycket snabbare i Safari än förut. Mailprogrammet startar på nolltid vilket det kanske inte riktigt gjorde förut. Java verkar inte ha fått någon prestandaboost – Netbeans och JBoss känns som om de går med samma fart som förut.
Försökte testa exchangestödet men jobbets server var visst version 2003 och stödet är för 2007. Vi använder dessutom något slags gammal funktion som kallas “public folders” för våra gemensamma kalendrar etc. som microsoft rekommenderar folk att sluta med och som inte stöds.
Standbyläget är avsevärt mycket snabbare – vi snackar 4 sekunder efter att jag stängt ihop laptopen tills datorn faktiskt sover mot runt 15-20 sekunder förut.