Sponsored Link •
|
Summary
Recently, while working with a partner to integrate their software into our Jini infrastructure, I employeed a simple pattern which I have used many times.
Advertisement
|
This factory methods exception list needs to take into account current and future requirements for exceptions. If you are going to serialize an instance of the factory implementation as your service implementation, think carefully about if/when you might choose to make that a remote method call. Include IOException in the throws clause if you have any possibility of ever making the method call execute remotely.
package product.access; import product.parts.*; public interface ProductFactory { public ProductClient getInstance() throws Exception; }
This implementation just has to use new
to create an instance of the class that I want to be the service implementation, and return that. If you have parameters that you need to pass, then change the factory method definition, and the implementation method to have those arguments so that the user of the factory, can pass any arguments needed.
package product.access; import product.parts.*; import java.io.Serializable; public class ProductFactoryImpl implements ProductFactory, Serializable { public ProductClient getInstance() throws Exception { return new ProductClientImpl(); } }
This class definition below shows how I overrode the getExportedObject() method so that it just returns an instance of the Serializable factory class defined above. This is the object that is sent off to the Lookup Server, and will thus be what the user of the service gets when they lookup the service, and then download the implementation.
package product.access; import java.io.*; import product.parts.*; import net.jini.config.*; import org.wonderly.jini2.*; public class ProductFactoryService extends PersistentJiniService { public static void main( String args[] ) throws IOException, ConfigurationException { new ProductFactoryService( args ); } public ProductFactoryService( String args[] ) throws IOException, ConfigurationException { super( args ); startService("product", "product.ser"); } protected Object getExportedObject() { return new ProductFactoryImpl(); } }
import net.jini.core.entry.Entry; import net.jini.lookup.entry.Name; project.access.ProjectFactoryService { entries = new Entry[] { new Name( "project" ) }; }While there are still a couple of other items that I dealt with for specifics of this application, this is the basic structure of this pattern. The
ProductClient
interface and the ProductClientImpl
class are the things that change for each application. There are many variations on this pattern that include the remoting of the factory interface method as I described above.
Have an opinion? Readers have already posted 1 comment about this weblog entry. Why not add yours?
If you'd like to be notified whenever Gregg Wonderly adds a new entry to his weblog, subscribe to his RSS feed.
Gregg Wonderly graduated from Oklahoma State University in 1988 with an MS in COMSCI. His areas of concentration include Operating Systems and Languages. His first job was at the AT&T Bell Labs facilities in Naperville IL working on software retrofit for the 5ESS switch. He designed a procedure control language in the era of the development of Java with similar motivations that the Oak and then Java language development was driven by. Language design is still at the top of his list, but his focus tends to be on application languges layered on top of programming languages such as Java. Some just consider this API design, but there really is more to it! Gregg now works for Cyte Technologies Inc., where he does software engineering and design related to distributed systems in highly available environments. |
Sponsored Links
|