001 /* 002 @license.text@ 003 */ 004 package biz.hammurapi.util; 005 006 import java.io.Serializable; 007 import java.net.MalformedURLException; 008 import java.rmi.Naming; 009 import java.rmi.NotBoundException; 010 import java.rmi.RemoteException; 011 012 import javax.rmi.PortableRemoteObject; 013 014 import org.w3c.dom.Element; 015 import org.w3c.dom.Node; 016 017 import biz.hammurapi.RuntimeException; 018 import biz.hammurapi.config.ConfigurationException; 019 import biz.hammurapi.config.Context; 020 021 022 /** 023 * Unwraps remote worker 024 * @author Pavel Vlasov 025 * @revision $Revision$ 026 */ 027 public class RemoteWorkerComponent implements Worker { 028 private RemoteWorker master; 029 private String url; 030 031 public void start() throws ConfigurationException { 032 try { 033 master=(RemoteWorker) PortableRemoteObject.narrow(Naming.lookup(url), RemoteWorker.class); 034 } catch (MalformedURLException e) { 035 throw new ConfigurationException("Could not lookup '"+url+"' - "+e, e); 036 } catch (RemoteException e) { 037 throw new ConfigurationException("Could not lookup '"+url+"' - "+e, e); 038 } catch (NotBoundException e) { 039 throw new ConfigurationException("Could not bind '"+url+"' - "+e, e); 040 } 041 } 042 043 public void stop() throws ConfigurationException { 044 // Nothing 045 } 046 047 public void setOwner(Object owner) { 048 // nothing 049 050 } 051 052 public void configure(Node configNode, Context context) throws ConfigurationException { 053 Element ce = (Element) configNode; 054 url=ce.getAttribute("worker-url"); 055 } 056 057 058 059 public boolean post(Runnable job) { 060 try { 061 return job instanceof Serializable && master.post(job); 062 } catch (RemoteException e) { 063 throw new RuntimeException("Could not post job to remote worker: "+e, e); 064 } 065 } 066 067 }