D:\DEV\PROJECTS\Harbor_Mailer_Ship\src\harbor_mailer_ship\CD_Unit.java
/*
 * Mailer Test CD_Unit.java
 */

package harbor_mailer_ship;
import kewlstuff.harbor.client.Vessel;
import kewlstuff.mailer.test.ui.interfaces.*;
import kewlstuff.harbor.mailer.interfaces.*;

/**
 *
 * @author Johnny Kewl
 * Compare this to the Original POJO CDTestUnit... almost identicle
 * It easy to forget, but remember that before you run this anywhere
 * You need to actually drop the POJO application into Harbor.
 * And if you want to show someone this working at their office
 * Remember to change the URL here to that of the actual server.
 * ie Harbor is amazing but you still have to put Tomcat online ;)
 */
public class CD_Unit implements I_CDTestUnit{
        private Vessel vessel = null;
        private I_MailEngine i_MailEngine = null;
    
    /**
     * Creates a new instance of CD_Unit
     */
    public CD_Unit() {
        String harborUrl = "http://localhost:8080/harbor/service"; //location of container harbor
        vessel = new Vessel(harborUrl); //get a vessel from the harbor         
    }
    
    public boolean startServer(String smtp){
        if(!i_MailEngine.isRunning()){
            if(i_MailEngine.prepareSession(smtp)){
                 i_MailEngine.startMailer(false); //Turn debugging on or off
                 return true;
            }
        }
        return false;
    }
    
    // NB NB This caught me.... This means MailPackage is going to be
    // serialized.... and I forgot to give it a serialized interface... oops
    public I_MailPackage getFirstFailedMail(){
        return i_MailEngine.getFirstFailedMail();
    }
    
    public void stopServer(){
        i_MailEngine.stopMailer();
    }
    
    public boolean qEmail(String to, String from, String subject, String sMessage){
        return i_MailEngine.queueMail(to, from, subject, sMessage,null, null);
    }
    
    public int getQSize(){
        return i_MailEngine.getMailQueueSize();
    }    
    
    public void start(){
        //Take notice of this.... we start the server as a singleton.
        //The way to understand the effect it has on the code, is start the CDUnit twice
        //ie you will have 2 user screens... now notice if you start the server in the one
        //the other one tells you its already started.... ie no matter how many times
        //you start a singleton... it only runs once.... its shared.
        //If you changed this to loadRemoteClassInst... then each UI would have its own server.
        //Its cool because you never have to change the actual app... just tell it what you want.
        i_MailEngine = (I_MailEngine)vessel.loadRemoteSingleton(I_MailEngine.class,"kewlstuff.harbor.mailer.MailEngine","HARBOR_MAILER");//load a class instance ON the harbor 
        if(i_MailEngine == null){
            System.out.print("Class does not exist or connection problems\n"); 
            return;
        }        
        Class uiApp = vessel.getRemoteClass("kewlstuff.mailer.test.ui.UI");//load a class from the harbor
        if(uiApp != null){
            I_UI i_UI = (I_UI)vessel.newInst(uiApp);
            i_UI.start(this);//INJECTION
        }
    }      
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new CD_Unit().start();
    }
    
}


Models, Models, Models! Free Modeling Portfolio! ModelCoast. Photographers! Free Photographic Portfolios. Imagegods. Visit The Best Free Image Hosting.